/** * 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; }
/** * 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; }
public function parseSingleEvent($postArr) { $tmpObj = new TimeEvent(); $tmpObj->setProjectId($postArr['cmbProject']); $tmpObj->setActivityId($postArr['cmbActivity']); if (!empty($postArr['txtStartTime'])) { $tmpObj->setStartTime(LocaleUtil::getInstance()->convertToStandardDateTimeFormat($postArr['txtStartTime'])); } if (!empty($postArr['txtEndTime'])) { $tmpObj->setEndTime(LocaleUtil::getInstance()->convertToStandardDateTimeFormat($postArr['txtEndTime'])); } $tmpObj->setReportedDate(LocaleUtil::getInstance()->convertToStandardDateFormat($postArr['txtReportedDate'])); if (isset($postArr['txtDuration']) && !empty($postArr['txtDuration'])) { $tmpObj->setDuration(trim($postArr['txtDuration']) * 3600); } else { if (isset($postArr['txtStartTime']) && isset($postArr['txtEndTime'])) { $startTime = strtotime($tmpObj->getStartTime()); $endTime = strtotime($tmpObj->getEndTime()); if ($endTime > $startTime) { $tmpObj->setDuration($endTime - $startTime); } else { $tmpObj->setDuration(0); } } } $tmpObj->setDescription(stripslashes($postArr['txtDescription'])); if (isset($postArr['txtTimeEventId'])) { $tmpObj->setTimeEventId($postArr['txtTimeEventId']); } $tmpObj->setEmployeeId($_SESSION['empID']); return $tmpObj; }
/** * Validates the timeevent against the given timesheet. * * @param TimeEvent $timeEvent Time event to validate * @param Timesheet $timesheet Time sheet * @return mixed true if validate success, error string if not. */ public function validateTimeEvent($timeEvent, $timesheet) { $eventStartTime = $timeEvent->getStartTime(); $eventEndTime = $timeEvent->getEndTime(); $eventStart = strtotime($eventStartTime); $eventEnd = strtotime($eventEndTime); $periodStartDate = $timesheet->getStartDate(); $periodEndDate = $timesheet->getEndDate(); $periodStart = strtotime($periodStartDate); $periodEnd = strtotime($periodEndDate); $periodEnd = strtotime("+1 day", $periodEnd); // strtotime returns false (-1 before php 5.1.0) on error if (!($periodStart > 0) || !($periodEnd > 0) || $periodStart >= $periodEnd) { return self::INVALID_TIMESHEET_PERIOD_ERROR; } $reportedDate = $timeEvent->getReportedDate(); $reported = strtotime($reportedDate); $eventId = $timeEvent->getTimeEventId(); $newEvent = empty($eventId); if (!CommonFunctions::IsValidId($timeEvent->getProjectId())) { return self::ProjectNotSpecified_ERROR; } if (!CommonFunctions::IsValidId($timeEvent->getActivityId())) { return self::ActivityNotSpecified_ERROR; } if (!empty($eventStartTime) && !($eventStart > 0)) { return self::InvalidStartTime_ERROR; } if (!empty($eventEndTime) && !($eventEnd > 0)) { return self::InvalidEndTime_ERROR; } if (empty($reportedDate)) { return self::ReportedDateNotSpecified_ERROR; } else { if (!($reported > 0)) { return self::InvalidReportedDate_ERROR; } } $duration = $timeEvent->getDuration(); $duration = $duration === "" ? null : $duration; // 0 not allowed for duration in last row. if (!is_null($duration) && ($duration < 0 || $newEvent && $duration == 0)) { return self::InvalidDuration_ERROR; } // Validate period/interval if (empty($eventStartTime) && empty($eventEndTime) && !empty($duration)) { // reported date + duration if ($reported < $periodStart || $reported + $duration > $periodEnd) { return self::EVENT_OUTSIDE_PERIOD_FAILURE; } } else { if (!empty($eventStartTime) && empty($eventEndTime) && is_null($duration)) { // start time only if ($eventStart < $periodStart || $eventStart > $periodEnd) { return self::EVENT_OUTSIDE_PERIOD_FAILURE; } } else { if (!empty($eventStartTime) && !empty($eventEndTime)) { if (!empty($duration) && $newEvent) { return self::NotAllowedToSpecifyDurationAndInterval_ERROR; } // start and end time if ($eventStart >= $eventEnd) { return self::ZeroOrNegativeIntervalSpecified_ERROR; } if ($eventStart < $periodStart || $eventEnd > $periodEnd) { return self::EVENT_OUTSIDE_PERIOD_FAILURE; } $timeEvent->setDuration($eventEnd - $eventStart); } else { if (!empty($eventStartTime) && !empty($duration) && empty($eventEndTime)) { // start time and duration if ($eventStart < $periodStart || $eventStart + $duration > $periodEnd) { return self::EVENT_OUTSIDE_PERIOD_FAILURE; } $timeEvent->setEndTime(date("Y-m-d H:i", $eventStart + $duration)); } else { return self::NoValidDurationOrInterval_ERROR; } } } } return true; }