📄 timeevent.php
字号:
} if ($this->getActivityId() != null) { $updateFields[] = "`".self::TIME_EVENT_DB_FIELD_ACTIVITY_ID."`"; $updateValues[] = $this->getActivityId(); } if ($this->getTimesheetId() != null) { $updateFields[] = "`".self::TIME_EVENT_DB_FIELD_TIMESHEET_ID."`"; $updateValues[] = $this->getTimesheetId(); } if ($this->getStartTime() != null) { $updateFields[] = "`".self::TIME_EVENT_DB_FIELD_START_TIME."`"; $updateValues[] = "'".$this->getStartTime()."'"; } else { $updateFields[] = "`".self::TIME_EVENT_DB_FIELD_START_TIME."`"; $updateValues[] = "null"; } if ($this->getEndTime() != null) { $updateFields[] = "`".self::TIME_EVENT_DB_FIELD_END_TIME."`"; $updateValues[] = "'".$this->getEndTime()."'"; } else { $updateFields[] = "`".self::TIME_EVENT_DB_FIELD_END_TIME."`"; $updateValues[] = "null"; } if ($this->getReportedDate() != null) { $updateFields[] = "`".self::TIME_EVENT_DB_FIELD_REPORTED_DATE."`"; $updateValues[] = "'".$this->getReportedDate()."'"; } if ($this->getDuration() != null) { $updateFields[] = "`".self::TIME_EVENT_DB_FIELD_DURATION."`"; $updateValues[] = $this->getDuration(); } if ($this->getDescription() != null) { $updateFields[] = "`".self::TIME_EVENT_DB_FIELD_DESCRIPTION."`"; $updateValues[] = "'".$this->getDescription()."'"; } $updateConditions[] = "`".self::TIME_EVENT_DB_FIELD_TIME_EVENT_ID."` = {$this->getTimeEventId()}"; $query = $sqlBuilder->simpleUpdate($updateTable, $updateFields, $updateValues, $updateConditions); $dbConnection = new DMLFunctions(); $result = $dbConnection->executeQuery($query); if ($result) { if (mysql_affected_rows() > 0) { return true; } else { return 2; } } return false; } public function deleteTimeEvent() { $tableName = self::TIME_EVENT_DB_TABLE_TIME_EVENT; $arrFieldList[0] = self::TIME_EVENT_DB_FIELD_TIME_EVENT_ID; $sql_builder = new SQLQBuilder(); $sql_builder->table_name = $tableName; $sql_builder->flg_delete = 'true'; $sql_builder->arr_delete = $arrFieldList; $arrList = array(array($this->getTimeEventId())); $sqlQString = $sql_builder->deleteRecord($arrList); //echo $sqlQString; $dbConnection = new DMLFunctions(); $message2 = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function return $message2; } /** * Fetch a list of pending time events */ public function pendingTimeEvents($punch=false) { $sqlBuilder = new SQLQBuilder(); $selectTable = "`".self::TIME_EVENT_DB_TABLE_TIME_EVENT."` a "; $selectFields[0] = "a.`".self::TIME_EVENT_DB_FIELD_TIME_EVENT_ID."`"; $selectFields[1] = "a.`".self::TIME_EVENT_DB_FIELD_PROJECT_ID."`"; $selectFields[2] = "a.`".self::TIME_EVENT_DB_FIELD_ACTIVITY_ID."`"; $selectFields[3] = "a.`".self::TIME_EVENT_DB_FIELD_EMPLOYEE_ID."`"; $selectFields[4] = "a.`".self::TIME_EVENT_DB_FIELD_TIMESHEET_ID."`"; $selectFields[5] = "a.`".self::TIME_EVENT_DB_FIELD_START_TIME."`"; $selectFields[6] = "a.`".self::TIME_EVENT_DB_FIELD_END_TIME."`"; $selectFields[7] = "a.`".self::TIME_EVENT_DB_FIELD_REPORTED_DATE."`"; $selectFields[8] = "a.`".self::TIME_EVENT_DB_FIELD_DURATION."`"; $selectFields[9] = "a.`".self::TIME_EVENT_DB_FIELD_DESCRIPTION."`"; if ($this->getTimeEventId() != null) { $selectConditions[] = "a.`".self::TIME_EVENT_DB_FIELD_TIME_EVENT_ID."` = {$this->getTimeEventId()}"; } if ($this->getProjectId() != null) { $selectConditions[] = "a.`".self::TIME_EVENT_DB_FIELD_PROJECT_ID."` = {$this->getProjectId()}"; } if ($this->getActivityId() != null) { $selectConditions[] = "a.`".self::TIME_EVENT_DB_FIELD_ACTIVITY_ID."` = {$this->getActivityId()}"; } if ($this->getEmployeeId() != null) { $selectConditions[] = "a.`".self::TIME_EVENT_DB_FIELD_EMPLOYEE_ID."` = {$this->getEmployeeId()}"; } if ($this->getTimesheetId() != null) { $selectConditions[] = "a.`".self::TIME_EVENT_DB_FIELD_TIMESHEET_ID."` = {$this->getTimesheetId()}"; } $selectConditions[] = "a.`".self::TIME_EVENT_DB_FIELD_DURATION."` IS NULL"; if ($punch) { $query = $sqlBuilder->simpleSelect($selectTable, $selectFields, $selectConditions, $selectFields[5], 'DESC', 1); } else { $query = $sqlBuilder->simpleSelect($selectTable, $selectFields, $selectConditions, $selectFields[0], 'ASC'); } $dbConnection = new DMLFunctions(); $result = $dbConnection -> executeQuery($query); $eventArr = $this->_buildObjArr($result); return $eventArr; } /** * Fetch time event records and build objects * * If any atributes are set records will searched against them. * If the parameter $punch is set, it will be the last Work Time * event that will be returned * * If punch is true, only the last record will be retrieved * * @param bool punch * @return TimeEvent[] array of time events */ public function fetchTimeEvents($punch=false) { $sqlBuilder = new SQLQBuilder(); $selectTable = "`".self::TIME_EVENT_DB_TABLE_TIME_EVENT."` a "; $selectFields[0] = "a.`".self::TIME_EVENT_DB_FIELD_TIME_EVENT_ID."`"; $selectFields[1] = "a.`".self::TIME_EVENT_DB_FIELD_PROJECT_ID."`"; $selectFields[2] = "a.`".self::TIME_EVENT_DB_FIELD_ACTIVITY_ID."`"; $selectFields[3] = "a.`".self::TIME_EVENT_DB_FIELD_EMPLOYEE_ID."`"; $selectFields[4] = "a.`".self::TIME_EVENT_DB_FIELD_TIMESHEET_ID."`"; $selectFields[5] = "a.`".self::TIME_EVENT_DB_FIELD_START_TIME."`"; $selectFields[6] = "a.`".self::TIME_EVENT_DB_FIELD_END_TIME."`"; $selectFields[7] = "a.`".self::TIME_EVENT_DB_FIELD_REPORTED_DATE."`"; $selectFields[8] = "a.`".self::TIME_EVENT_DB_FIELD_DURATION."`"; $selectFields[9] = "a.`".self::TIME_EVENT_DB_FIELD_DESCRIPTION."`"; if ($this->getTimeEventId() != null) { $selectConditions[] = "a.`".self::TIME_EVENT_DB_FIELD_TIME_EVENT_ID."` = {$this->getTimeEventId()}"; } if ($this->getProjectId() !== null) { $selectConditions[] = "a.`".self::TIME_EVENT_DB_FIELD_PROJECT_ID."` = {$this->getProjectId()}"; } if ($this->getActivityId() !== null) { $selectConditions[] = "a.`".self::TIME_EVENT_DB_FIELD_ACTIVITY_ID."` = {$this->getActivityId()}"; } if ($this->getEmployeeId() != null) { $selectConditions[] = "a.`".self::TIME_EVENT_DB_FIELD_EMPLOYEE_ID."` = {$this->getEmployeeId()}"; } if ($this->getTimesheetId() != null) { $selectConditions[] = "a.`".self::TIME_EVENT_DB_FIELD_TIMESHEET_ID."` = {$this->getTimesheetId()}"; } if ($punch) { $query = $sqlBuilder->simpleSelect($selectTable, $selectFields, $selectConditions, $selectFields[5], 'DESC', 1); } else { $query = $sqlBuilder->simpleSelect($selectTable, $selectFields, $selectConditions, $selectFields[0], 'ASC'); } $dbConnection = new DMLFunctions(); $result = $dbConnection -> executeQuery($query); $eventArr = $this->_buildObjArr($result); return $eventArr; } /** * Build the object with fetched records * * @access private * @return TimeEvent[] array of time events */ private function _buildObjArr($result) { $objArr = null; while ($row = mysql_fetch_assoc($result)) { $tmpEventArr = new TimeEvent(); $tmpEventArr->setTimeEventId($row[self::TIME_EVENT_DB_FIELD_TIME_EVENT_ID]); $tmpEventArr->setProjectId($row[self::TIME_EVENT_DB_FIELD_PROJECT_ID]); $tmpEventArr->setActivityId($row[self::TIME_EVENT_DB_FIELD_ACTIVITY_ID]); $tmpEventArr->setEmployeeId($row[self::TIME_EVENT_DB_FIELD_EMPLOYEE_ID]); $tmpEventArr->setTimesheetId($row[self::TIME_EVENT_DB_FIELD_TIMESHEET_ID]); if (!empty($row[self::TIME_EVENT_DB_FIELD_START_TIME])) { $tmpEventArr->setStartTime(date('Y-m-d H:i', strtotime($row[self::TIME_EVENT_DB_FIELD_START_TIME]))); } if (!empty($row[self::TIME_EVENT_DB_FIELD_END_TIME])) { $tmpEventArr->setEndTime(date('Y-m-d H:i', strtotime($row[self::TIME_EVENT_DB_FIELD_END_TIME]))); } $tmpEventArr->setReportedDate(date('Y-m-d', strtotime($row[self::TIME_EVENT_DB_FIELD_REPORTED_DATE]))); $tmpEventArr->setDuration($row[self::TIME_EVENT_DB_FIELD_DURATION]); $tmpEventArr->setDescription($row[self::TIME_EVENT_DB_FIELD_DESCRIPTION]); $objArr[] = $tmpEventArr; } return $objArr; } public function resolveTimesheet($submissionPeriodId=null) { if ($this->getTimesheetId() == null) { $timesheetObj = new Timesheet(); $timesheetSubmissionPeriodObj = new TimesheetSubmissionPeriod(); if ($submissionPeriodId != null) { $timesheetSubmissionPeriodObj->setTimesheetPeriodId($submissionPeriodId); } $timesheetSubmissionPeriods = $timesheetSubmissionPeriodObj->fetchTimesheetSubmissionPeriods(); $currTime = strtotime($this->getStartTime()); $day=date('N', $currTime); $diff=$timesheetSubmissionPeriods[0]->getStartDay()-$day; if ($diff > 0) { $diff=$diff-7; } $timesheetObj->setStartDate(date('Y-m-d', $currTime+($diff*3600*24))); $diff=$timesheetSubmissionPeriods[0]->getEndDay()-$day; if (0 > $diff) { $diff=$diff+7; } $timesheetObj->setEndDate(date('Y-m-d', $currTime+($diff*3600*24))." 23:59:59"); $timesheetObj->setTimesheetPeriodId($timesheetSubmissionPeriods[0]->getTimesheetPeriodId()); $timesheetObj->setEmployeeId($this->getEmployeeId()); $timesheets = $timesheetObj->fetchTimesheets(); if (!$timesheets || !$timesheets[0]) { $timesheetObj->setStatus(Timesheet::TIMESHEET_STATUS_NOT_SUBMITTED); $timesheetObj->addTimesheet(); $timesheetObj->setTimesheetId(null); $timesheets = $timesheetObj->fetchTimesheets(); } $this->setTimesheetId($timesheets[0]->getTimesheetId()); } } public function timeReport($startDate, $endDate) { $sqlBuilder = new SQLQBuilder(); $selectTable = "`".self::TIME_EVENT_DB_TABLE_TIME_EVENT."` a "; $selectFields[0] = "a.`".self::TIME_EVENT_DB_FIELD_PROJECT_ID."`"; $selectFields[1] = "a.`".self::TIME_EVENT_DB_FIELD_ACTIVITY_ID."`"; $selectFields[2] = "SUM(a.`".self::TIME_EVENT_DB_FIELD_DURATION."`) as ".self::TIME_EVENT_DB_FIELD_DURATION; $selectConditions[0] = "a.`".self::TIME_EVENT_DB_FIELD_START_TIME."` >= '{$startDate} 00:00:00'"; $selectConditions[1] = "a.`".self::TIME_EVENT_DB_FIELD_START_TIME."` <= '{$endDate} 23:59:59'"; if ($this->getProjectId() != null) { $selectConditions[] = "a.`".self::TIME_EVENT_DB_FIELD_PROJECT_ID."` = {$this->getProjectId()}"; } if ($this->getActivityId() != null) { $selectConditions[] = "a.`".self::TIME_EVENT_DB_FIELD_ACTIVITY_ID."` = {$this->getActivityId()}"; } if ($this->getEmployeeId() != null) { $selectConditions[] = "a.`".self::TIME_EVENT_DB_FIELD_EMPLOYEE_ID."` = {$this->getEmployeeId()}"; } $query = $sqlBuilder->simpleSelect($selectTable, $selectFields, $selectConditions); $query .= " GROUP BY {$selectFields[0]}, {$selectFields[1]}"; $dbConnection = new DMLFunctions(); $result = $dbConnection->executeQuery($query); $arrData=null; while ($row = mysql_fetch_assoc($result)) { $arrData[$row[self::TIME_EVENT_DB_FIELD_PROJECT_ID]][$row[self::TIME_EVENT_DB_FIELD_ACTIVITY_ID]]=$row[self::TIME_EVENT_DB_FIELD_DURATION]; } return $arrData; }}class TimeEventException extends Exception { const OVERLAPPING_TIME_PERIOD = 2;}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -