public function parseReportData($postArr) { $parsedObjs = array(); for ($i = 0; $i < $postArr['recordsCount']; $i++) { $attendanceRecordObj = new AttendanceRecord(); $changed = false; if (trim($postArr['txtNewInDate-' . $i]) != $postArr['hdnOldInDate-' . $i]) { $changed = true; } elseif (trim($postArr['txtNewInTime-' . $i]) != $postArr['hdnOldInTime-' . $i]) { $changed = true; } elseif (trim($postArr['txtNewInNote-' . $i]) != $postArr['hdnOldInNote-' . $i]) { $changed = true; } elseif (trim($postArr['txtNewOutDate-' . $i]) != $postArr['hdnOldOutDate-' . $i]) { $changed = true; } elseif (trim($postArr['txtNewOutTime-' . $i]) != $postArr['hdnOldOutTime-' . $i]) { $changed = true; } elseif (trim($postArr['txtNewOutNote-' . $i]) != $postArr['hdnOldOutNote-' . $i]) { $changed = true; } elseif (isset($postArr['chkDeleteStatus-' . $i])) { $attendanceRecordObj->setStatus(AttendanceRecord::STATUS_DELETED); $changed = true; } if ($changed) { /* Even if only one value is changed, setting other properties * is required to carry out functions like checking overlapping */ $attendanceRecordObj->setAttendanceId($postArr['hdnAttendanceId-' . $i]); $attendanceRecordObj->setEmployeeId($postArr['hdnEmployeeId']); $value = trim($postArr['txtNewInDate-' . $i]) . ' ' . trim($postArr['txtNewInTime-' . $i]); $attendanceRecordObj->setInDate($this->_adjustToServerTime('date', $postArr['hdnTimestampDiff-' . $i], $value)); $attendanceRecordObj->setInTime($this->_adjustToServerTime('time', $postArr['hdnTimestampDiff-' . $i], $value)); $attendanceRecordObj->setInNote(trim($postArr['txtNewInNote-' . $i])); $value = trim($postArr['txtNewOutDate-' . $i]) . ' ' . trim($postArr['txtNewOutTime-' . $i]); $attendanceRecordObj->setOutDate($this->_adjustToServerTime('date', $postArr['hdnTimestampDiff-' . $i], $value)); $attendanceRecordObj->setOutTime($this->_adjustToServerTime('time', $postArr['hdnTimestampDiff-' . $i], $value)); $attendanceRecordObj->setOutNote(trim($postArr['txtNewOutNote-' . $i])); $parsedObjs[] = $attendanceRecordObj; } } return $parsedObjs; }
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; }