public function parsePunchData($postArr) { $attendanceObj = new AttendanceRecord(); if (isset($postArr['hdnTimestampDiff'])) { $timestampDiffToPass = $postArr['hdnTimestampDiff']; // Means the corresponding timestampDiff has been already saved in the database. } else { $timestampDiffToPass = $this->_getTimestampDiff(); // Means a new record. Need to calculate timestampDiff } if (isset($postArr['hdnAttendanceId'])) { $attendanceObj->setAttendanceId($postArr['hdnAttendanceId']); } $attendanceObj->setEmployeeId($postArr['hdnEmployeeId']); if (isset($postArr['txtInDate']) && isset($postArr['txtInTime'])) { $value = trim($postArr['txtInDate']) . ' ' . trim($postArr['txtInTime']); $attendanceObj->setInDate($this->_adjustToServerTime('date', $timestampDiffToPass, $value)); $attendanceObj->setInTime($this->_adjustToServerTime('time', $timestampDiffToPass, $value)); } if (isset($postArr['txtInNote'])) { $attendanceObj->setInNote($postArr['txtInNote']); } if (isset($postArr['txtOutDate']) && isset($postArr['txtOutTime'])) { $value = trim($postArr['txtOutDate']) . ' ' . trim($postArr['txtOutTime']); $attendanceObj->setOutDate($this->_adjustToServerTime('date', $timestampDiffToPass, $value)); $attendanceObj->setOutTime($this->_adjustToServerTime('time', $timestampDiffToPass, $value)); } if (!isset($postArr['hdnAttendanceId'])) { $attendanceObj->setTimestampDiff($this->_getTimestampDiff()); } if (isset($postArr['txtOutNote'])) { $attendanceObj->setOutNote($postArr['txtOutNote']); } return $attendanceObj; }
private function _buildRecordObjects($result, $adjustTime = true) { while ($row = mysql_fetch_array($result)) { $attendanceObj = new AttendanceRecord(); $attendanceObj->setAttendanceId($row['attendance_id']); $attendanceObj->setEmployeeId($row['employee_id']); /* $row['punchin_time'] comes in '0000-00-00 00:00:00' format. * We want date in '0000-00-00' format and time in '00:00' format. */ $tmpArr = explode(' ', $row['punchin_time']); $attendanceObj->setInDate($tmpArr[0]); $attendanceObj->setInTime(substr($tmpArr[1], 0, 5)); if ($row['punchout_time'] != null) { $tmpArr = explode(' ', $row['punchout_time']); $attendanceObj->setOutDate($tmpArr[0]); $attendanceObj->setOutTime(substr($tmpArr[1], 0, 5)); // Omiting 'seconds' part is ok since it is always zero } if ($row['in_note'] != null) { $attendanceObj->setInNote($row['in_note']); } if ($row['out_note'] != null) { $attendanceObj->setOutNote($row['out_note']); } $attendanceObj->setTimestampDiff($row['timestamp_diff']); $attendanceObj->setStatus($row['status']); /* Adjusting time according to the timezone of the place * where the record was first entered. */ if ($adjustTime) { /* When saving in the database, timestampDiff is calculated by substracting * server timezone offset from client timezone offset. When showing records * to user this timestampDiff should be added to each date and time shown. */ $value = $attendanceObj->getInDate() . ' ' . $attendanceObj->getInTime(); $date = date('Y-m-d', strtotime($value) + $row['timestamp_diff']); $time = date('H:i', strtotime($value) + $row['timestamp_diff']); $attendanceObj->setInDate($date); $attendanceObj->setInTime($time); if ($row['punchout_time'] != null) { $value = $attendanceObj->getOutDate() . ' ' . $attendanceObj->getOutTime(); $date = date('Y-m-d', strtotime($value) + $row['timestamp_diff']); $time = date('H:i', strtotime($value) + $row['timestamp_diff']); $attendanceObj->setOutDate($date); $attendanceObj->setOutTime($time); } } $attendanceArr[] = $attendanceObj; } return $attendanceArr; }