⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timeevent.php

📁 国外的人才求职招聘最新版
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/** * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures * all the essential functionalities required for any enterprise. * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com * * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of * the GNU General Public License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program; * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA  02110-1301, USA * */require_once ROOT_PATH . '/lib/dao/DMLFunctions.php';require_once ROOT_PATH . '/lib/dao/SQLQBuilder.php';require_once ROOT_PATH . '/lib/common/UniqueIDGenerator.php';/** * Handles all function related to Time Event */class TimeEvent {	/**	 * Class constants	 */	const TIME_EVENT_DB_TABLE_TIME_EVENT = "hs_hr_time_event";	const TIME_EVENT_DB_FIELD_TIME_EVENT_ID = "time_event_id";	const TIME_EVENT_DB_FIELD_PROJECT_ID = "project_id";	const TIME_EVENT_DB_FIELD_ACTIVITY_ID = "activity_id";	const TIME_EVENT_DB_FIELD_EMPLOYEE_ID = "employee_id";	const TIME_EVENT_DB_FIELD_TIMESHEET_ID = "timesheet_id";	const TIME_EVENT_DB_FIELD_START_TIME = "start_time";	const TIME_EVENT_DB_FIELD_END_TIME = "end_time";	const TIME_EVENT_DB_FIELD_REPORTED_DATE = "reported_date";	const TIME_EVENT_DB_FIELD_DURATION = "duration";	const TIME_EVENT_DB_FIELD_DESCRIPTION = "description";	const TIME_EVENT_PUNCH_PROJECT_ID = 0;	const TIME_EVENT_PUNCH_ACTIVITY_ID = 0;	const TIME_EVENT_PUNCH_IN = 1;	const TIME_EVENT_PUNCH_OUT = 2;	/**	 * Class atributes	 */	private $timeEventId;	private $projectId;	private $activityId;	private $employeeId;	private $timesheetId;	private $startTime;	private $endTime;	private $reportedDate;	private $duration;	private $description;	private $selectFields;	/**	 * Class atribute getters and setters	 */	public function setTimeEventId($timeEventId) {		$this->timeEventId=$timeEventId;	}	public function getTimeEventId() {		return $this->timeEventId;	}	public function setProjectId($projectId) {		$this->projectId=$projectId;	}	public function getProjectId() {		return $this->projectId;	}	public function setActivityId($activityId) {		$this->activityId=$activityId;	}	public function getActivityId() {		return $this->activityId;	}	public function setEmployeeId($employeeId) {		$this->employeeId=$employeeId;	}	public function getEmployeeId() {		return $this->employeeId;	}	public function setTimesheetId($timesheetId) {		$this->timesheetId=$timesheetId;	}	public function getTimesheetId() {		return $this->timesheetId;	}	public function setStartTime($startTime) {		$this->startTime=$startTime;	}	public function getStartTime() {		return $this->startTime;	}	public function setEndTime($endTime) {		$this->endTime=$endTime;	}	public function getEndTime() {		return $this->endTime;	}	public function setReportedDate($reportedDate) {		$this->reportedDate=$reportedDate;	}	public function getReportedDate() {		return $this->reportedDate;	}	public function setDuration($duration) {		$this->duration=$duration;	}	public function getDuration() {		return $this->duration;	}	public function setDescription($description) {		$this->description=$description;	}	public function getDescription() {		return $this->description;	}	public function __construct() {		//nothing to do	}	public function __distruct() {		//nothing to do	}	/**	 * Used to determine there are overlapping time events with the current	 * time event.	 *	 */	private function _isOverlapping() {		$punch = false;		if ($this->getProjectId() == self::TIME_EVENT_PUNCH_PROJECT_ID && $this->getActivityId() == self::TIME_EVENT_PUNCH_ACTIVITY_ID) {		    $punch = true;		}		$selectTable = "`".self::TIME_EVENT_DB_TABLE_TIME_EVENT."` a ";		$selectFields[0] = "a.`".self::TIME_EVENT_DB_FIELD_TIME_EVENT_ID."`";		if ($this->getStartTime() != null) {			// This Start Time = 09:00		DB Time = 08:30-09:30			$tmpQuery = "(a.`".self::TIME_EVENT_DB_FIELD_START_TIME."` <= '{$this->getStartTime()}' AND ";			$tmpQuery .= "(a.`".self::TIME_EVENT_DB_FIELD_END_TIME."` >= '{$this->getStartTime()}'))";			if ($this->getEndTime() != null) {				// This End Time = 10:00	DB Time = 09:30-10:30				$tmpQuery .= " OR (a.`".self::TIME_EVENT_DB_FIELD_START_TIME."` <= '{$this->getEndTime()}' AND ";				$tmpQuery .= "(a.`".self::TIME_EVENT_DB_FIELD_END_TIME."` >= '{$this->getEndTime()}'))";				// This Time = 09:00-10:00	DB Time = 08:30-10:30				$tmpQuery .= " OR (a.`".self::TIME_EVENT_DB_FIELD_START_TIME."` <= '{$this->getStartTime()}' AND ";				$tmpQuery .= "(a.`".self::TIME_EVENT_DB_FIELD_END_TIME."` >= '{$this->getEndTime()}'))";				// This Time = 09:00-10:00	DB Time = 09:15-09:45				$tmpQuery .= " OR (a.`".self::TIME_EVENT_DB_FIELD_START_TIME."` >= '{$this->getStartTime()}' AND ";				$tmpQuery .= "(a.`".self::TIME_EVENT_DB_FIELD_END_TIME."` <= '{$this->getEndTime()}'))";				// This Time = 09:00-10:00	DB Start Time = 09:30				$tmpQuery .= " OR (a.`".self::TIME_EVENT_DB_FIELD_START_TIME."` >= '{$this->getStartTime()}' AND ";				$tmpQuery .= "(a.`".self::TIME_EVENT_DB_FIELD_START_TIME."` <= '{$this->getEndTime()}'))";			}			$selectConditions[] = "({$tmpQuery})";		} else {			return false;		}		// Overlapping is allowed between default project and others because default project can be used for Punch In/Out		// So that overlapping should be checked either among default project events or other project events		if ($punch) {			$selectConditions[] = "a.`".self::TIME_EVENT_DB_FIELD_PROJECT_ID."` = '".self::TIME_EVENT_PUNCH_PROJECT_ID."' AND a.`".self::TIME_EVENT_DB_FIELD_ACTIVITY_ID."` = '".self::TIME_EVENT_PUNCH_ACTIVITY_ID."'";		} else {			$selectConditions[] = "a.`".self::TIME_EVENT_DB_FIELD_PROJECT_ID."` != '".self::TIME_EVENT_PUNCH_PROJECT_ID."' AND a.`".self::TIME_EVENT_DB_FIELD_ACTIVITY_ID."` != '".self::TIME_EVENT_PUNCH_ACTIVITY_ID."'";		}		if ($this->getTimeEventId() != null) {			$selectConditions[] = "a.`".self::TIME_EVENT_DB_FIELD_TIME_EVENT_ID."` != {$this->getTimeEventId()}";		}		if ($this->getEmployeeId() != null) {			$selectConditions[] = "a.`".self::TIME_EVENT_DB_FIELD_EMPLOYEE_ID."` = {$this->getEmployeeId()}";		}		$sqlBuilder = new SQLQBuilder();		$query = $sqlBuilder->simpleSelect($selectTable, $selectFields, $selectConditions, $selectFields[0], 'ASC');		$dbConnection = new DMLFunctions();		$result = $dbConnection -> executeQuery($query);		if ($dbConnection->dbObject->numberOfRows($result) == 0) {			return false;		}		throw new TimeEventException("Overlapping time period", TimeEventException::OVERLAPPING_TIME_PERIOD);	}	/**	 * Add new time event	 *	 * Time event id will be over written	 *	 * @throws TimeEventException Overlapping time period 2	 */	public function addTimeEvent() {		$this->_isOverlapping();		$newId = UniqueIDGenerator::getInstance()->getNextID(self::TIME_EVENT_DB_TABLE_TIME_EVENT, self::TIME_EVENT_DB_FIELD_TIME_EVENT_ID);		$this->setTimeEventId($newId);		$insertTable = "`".self::TIME_EVENT_DB_TABLE_TIME_EVENT."`";		$insertFields[0] = "`".self::TIME_EVENT_DB_FIELD_TIME_EVENT_ID."`";		$insertFields[1] = "`".self::TIME_EVENT_DB_FIELD_PROJECT_ID."`";		$insertFields[2] = "`".self::TIME_EVENT_DB_FIELD_ACTIVITY_ID."`";		$insertFields[3] = "`".self::TIME_EVENT_DB_FIELD_EMPLOYEE_ID."`";		$insertFields[4] = "`".self::TIME_EVENT_DB_FIELD_TIMESHEET_ID."`";		$insertValues[0] = $this->getTimeEventId();		$insertValues[1] = $this->getProjectId();		$insertValues[2] = $this->getActivityId();		$insertValues[3] = $this->getEmployeeId();		$insertValues[4] = $this->getTimesheetId();		if ($this->getStartTime() != null) {			$insertFields[] = "`".self::TIME_EVENT_DB_FIELD_START_TIME."`";			$insertValues[] = "'".$this->getStartTime()."'";		}		if ($this->getEndTime() != null) {			$insertFields[] = "`".self::TIME_EVENT_DB_FIELD_END_TIME."`";			$insertValues[] = "'".$this->getEndTime()."'";		}		if ($this->getReportedDate() != null) {			$insertFields[] = "`".self::TIME_EVENT_DB_FIELD_REPORTED_DATE."`";			$insertValues[] = "'".$this->getReportedDate()."'";		}		if ($this->getDuration() != null) {			$insertFields[] = "`".self::TIME_EVENT_DB_FIELD_DURATION."`";			$insertValues[] = $this->getDuration();		}		if ($this->getDescription() != null) {			$insertFields[] = "`".self::TIME_EVENT_DB_FIELD_DESCRIPTION."`";			$insertValues[] = "'".$this->getDescription()."'";		}		$sqlBuilder = new SQLQBuilder();		$query = $sqlBuilder->simpleInsert($insertTable, $insertValues, $insertFields);		$dbConnection = new DMLFunctions();		$result = $dbConnection -> executeQuery($query);		if ($result) {			if (mysql_affected_rows() > 0) {				return true;			}		}		return false;	}	/**	 * Editing time event	 *	 * All except time event id is editable	 */	public function editTimeEvent() {		if ($this->_isOverlapping()) {			return false;		}		$sqlBuilder = new SQLQBuilder();		$updateTable = "`".self::TIME_EVENT_DB_TABLE_TIME_EVENT."`";		if ($this->getProjectId() != null) {			$updateFields[] = "`".self::TIME_EVENT_DB_FIELD_PROJECT_ID."`";			$updateValues[] = $this->getProjectId();		}		if ($this->getEmployeeId() != null) {			$updateFields[] = "`".self::TIME_EVENT_DB_FIELD_EMPLOYEE_ID."`";			$updateValues[] = $this->getEmployeeId();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -