public function parseEditData($postArr) { $tmpArr = null; for ($i = 0; $i < count($postArr['cmbActivity']); $i++) { $tmpObj = new TimeEvent(); $projectId = $postArr['cmbProject'][$i]; if (!CommonFunctions::isValidId($projectId)) { continue; } $tmpObj->setActivityId($postArr['cmbActivity'][$i]); $tmpObj->setProjectId($projectId); $txtStartTime = trim($postArr['txtStartTime'][$i]); if (!empty($txtStartTime)) { $tmpObj->setStartTime(LocaleUtil::getInstance()->convertToStandardDateTimeFormat($txtStartTime)); } $txtEndTime = trim($postArr['txtEndTime'][$i]); if (!empty($txtEndTime)) { $tmpObj->setEndTime(LocaleUtil::getInstance()->convertToStandardDateTimeFormat($txtEndTime)); } $txtReportedDate = trim($postArr['txtReportedDate'][$i]); $tmpObj->setReportedDate(LocaleUtil::getInstance()->convertToStandardDateFormat($txtReportedDate)); if (isset($postArr['txtDuration'][$i])) { $txtDuration = trim($postArr['txtDuration'][$i]); if (!empty($txtDuration)) { $tmpObj->setDuration($txtDuration * 3600); } } $tmpObj->setDescription(stripslashes($postArr['txtDescription'][$i])); if (isset($postArr['txtTimeEventId'][$i])) { $tmpObj->setTimeEventId(trim($postArr['txtTimeEventId'][$i])); } $tmpObj->setEmployeeId(trim($postArr['txtEmployeeId'])); $tmpObj->setTimesheetId(trim($postArr['txtTimesheetId'])); $tmpArr[] = $tmpObj; } return $tmpArr; }
/** * 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 parseEditTimegrid($postArr) { $gridCount = $postArr['hdnGridCount']; $datesCount = $postArr['hdnDatesCount']; $employeeId = $postArr['txtEmployeeId']; $timesheetId = $postArr['txtTimesheetId']; $updateList = array(); $addList = array(); for ($i = 0; $i < $gridCount; $i++) { for ($j = 0; $j < $datesCount; $j++) { if (isset($postArr["hdnTimeEventId-{$i}-{$j}"])) { // An exsiting time event if ($postArr["txtDuration-{$i}-{$j}"] != $postArr["hdnDuration-{$i}-{$j}"] || $postArr["txtComment-{$i}-{$j}"] != $postArr["hdntxtComment-{$i}-{$j}"] || $postArr["cmbProject-{$i}"] != $postArr["hdnProject-{$i}"] || $postArr["cmbActivity-{$i}"] != $postArr["hdnActivity-{$i}"]) { // If there is no change from previous value, no need to update the time event // This check can only be done if $postArr["hdnTimeEventId-$i-$j"] is set $timeEvent = new TimeEvent(); $timeEvent->setTimeEventId($postArr["hdnTimeEventId-{$i}-{$j}"]); $timeEvent->setEmployeeId($employeeId); $timeEvent->setProjectId($postArr["cmbProject-{$i}"]); $timeEvent->setActivityId($postArr["cmbActivity-{$i}"]); $timeEvent->setDuration($postArr["txtDuration-{$i}-{$j}"] * 3600); $timeEvent->setReportedDate($postArr["hdnReportedDate-{$j}"]); $timeEvent->setDescription($postArr["txtComment-{$i}-{$j}"]); $updateList[] = $timeEvent; } } else { // A new time event if ($postArr["txtDuration-{$i}-{$j}"] != '') { // If no value has been put, no need to add a new time event $timeEvent = new TimeEvent(); $timeEvent->setTimesheetId($timesheetId); $timeEvent->setEmployeeId($employeeId); $timeEvent->setProjectId($postArr["cmbProject-{$i}"]); $timeEvent->setActivityId($postArr["cmbActivity-{$i}"]); $timeEvent->setDuration($postArr["txtDuration-{$i}-{$j}"] * 3600); $timeEvent->setReportedDate($postArr["hdnReportedDate-{$j}"]); $timeEvent->setDescription($postArr["txtComment-{$i}-{$j}"]); $addList[] = $timeEvent; } } } } $eventsList[0] = $updateList; $eventsList[1] = $addList; return $eventsList; }
/** * Constructs and returns time event with given parameters */ private function _getTimeEvent($timeEventId, $projectId, $employeeId, $timesheetId, $startTime, $endTime, $reportedDate, $duration, $description, $activityId = 1) { $timeEvent = new TimeEvent(); $timeEvent->setTimeEventId($timeEventId); $timeEvent->setActivityId($activityId); $timeEvent->setProjectId($projectId); $timeEvent->setEmployeeId($employeeId); $timeEvent->setTimesheetId($timesheetId); $timeEvent->setStartTime($startTime); $timeEvent->setEndTime($endTime); $timeEvent->setReportedDate($reportedDate); $timeEvent->setDuration($duration); $timeEvent->setDescription($description); return $timeEvent; }
/** * Parse time events and generate the information for timesheets * * @param Timesheet timesheet */ private function _generateTimesheet($timesheet) { $timeEventObj = new TimeEvent(); $timeEventObj->setTimesheetId($timesheet->getTimesheetId()); $timeEventObj->setEmployeeId($timesheet->getEmployeeId()); $timeEventObj->setStartTime($timesheet->getStartDate()); $timeEventObj->setEndTime($timesheet->getEndDate()); $timeEvents = $timeEventObj->fetchTimeEvents(); $durationArr = null; $dailySum = null; $activitySum = null; $totalTime = 0; for ($i = 0; $i < count($timeEvents); $i++) { $projectId = $timeEvents[$i]->getProjectId(); $activityId = $timeEvents[$i]->getActivityId(); if ($timeEvents[$i]->getStartTime() != null) { $expenseDate = strtotime(date('Y-m-d', strtotime($timeEvents[$i]->getStartTime()))); } else { $expenseDate = strtotime(date('Y-m-d', strtotime($timeEvents[$i]->getReportedDate()))); } if (!isset($durationArr[$projectId][$activityId][$expenseDate])) { $durationArr[$projectId][$activityId][$expenseDate] = 0; } if (!isset($dailySum[$expenseDate])) { $dailySum[$expenseDate] = 0; } if (!isset($activitySum[$projectId][$activityId])) { $activitySum[$projectId][$activityId] = 0; } $durationArr[$projectId][$activityId][$expenseDate] += $timeEvents[$i]->getDuration(); $dailySum[$expenseDate] += $timeEvents[$i]->getDuration(); $activitySum[$projectId][$activityId] += $timeEvents[$i]->getDuration(); $totalTime += $timeEvents[$i]->getDuration(); } return array($durationArr, $dailySum, $activitySum, $totalTime); }