| Code Coverage | ||||||||||
| Classes and Traits | Functions and Methods | Lines | ||||||||
| Total |  | 0.00% | 0 / 1 |  | 0.00% | 0 / 10 | CRAP |  | 0.00% | 0 / 87 | 
| AttendanceMarkSwappingService |  | 0.00% | 0 / 1 |  | 0.00% | 0 / 10 | 650.00 |  | 0.00% | 0 / 87 | 
| __construct |  | 0.00% | 0 / 1 | 2.00 |  | 0.00% | 0 / 3 | |||
| __clone |  | 0.00% | 0 / 1 | 2.00 |  | 0.00% | 0 / 2 | |||
| getInstance |  | 0.00% | 0 / 1 | 6.00 |  | 0.00% | 0 / 7 | |||
| addAttendanceSwappingRequest |  | 0.00% | 0 / 1 | 30.00 |  | 0.00% | 0 / 9 | |||
| updateAttendanceMarkingRequestCompleted |  | 0.00% | 0 / 1 | 6.00 |  | 0.00% | 0 / 8 | |||
| updateAttendanceMarkingStaff |  | 0.00% | 0 / 1 | 6.00 |  | 0.00% | 0 / 8 | |||
| removeAttendanceSwappingRequestById |  | 0.00% | 0 / 1 | 6.00 |  | 0.00% | 0 / 8 | |||
| addAttendanceConfirmingStaff |  | 0.00% | 0 / 1 | 12.00 |  | 0.00% | 0 / 14 | |||
| removeAttendanceConfirmingStaffByRequestId |  | 0.00% | 0 / 1 | 6.00 |  | 0.00% | 0 / 8 | |||
| getAttendanceSwappingRequest |  | 0.00% | 0 / 1 | 30.00 |  | 0.00% | 0 / 20 | |||
| <?php | |
| namespace com\linways\core\ams\professional\service; | |
| use com\linways\core\ams\professional\dto\AttendaneSwappingDetails; | |
| use com\linways\core\ams\professional\exception\ProfessionalException; | |
| use com\linways\core\ams\professional\dto\AttendanceConfirmingStaff; | |
| use com\linways\core\ams\professional\mapper\AttendanceMarkSwappingServiceMapper; | |
| use com\linways\base\util\SecurityUtils; | |
| class AttendanceMarkSwappingService extends BaseService | |
| { | |
| // /Condition 1 - Presence of a static member variable | |
| private static $_instance = null; | |
| private $mapper = []; | |
| // /Condition 2 - Locked down the constructor | |
| private function __construct() | |
| { | |
| $this->mapper = AttendanceMarkSwappingServiceMapper::getInstance()->getMapper(); | |
| } | |
| // Prevent any oustide instantiation of this class | |
| // /Condition 3 - Prevent any object or instance of that class to be cloned | |
| private function __clone() | |
| { | |
| } | |
| // Prevent any copy of this object | |
| // /Condition 4 - Have a single globally accessible static method | |
| public static function getInstance() | |
| { | |
| if (!is_object(self::$_instance))// or if( is_null(self::$_instance) ) or if( self::$_instance == null ) | |
| { | |
| self::$_instance = new self(); | |
| } | |
| return self::$_instance; | |
| } | |
| /** | |
| * add attendance swapping request | |
| * @param AttendaneSwappingDetails $attendaneSwappingDetails | |
| * @throws ProfessionalException | |
| * @return object|NULL|\com\linways\base\util\$objectList[] | |
| */ | |
| public function addAttendanceSwappingRequest(AttendaneSwappingDetails $attendaneSwappingDetails) | |
| { | |
| $attendaneSwappingDetails = $this->realEscapeObject($attendaneSwappingDetails); | |
| $sql ="INSERT INTO attendance_swapping_details (assigned_staff_id, rule, hour, date, sbs_id, ps_id, created_by, created_date, updated_by, updated_date) VALUES ('$attendaneSwappingDetails->assignedStaffId', ".($attendaneSwappingDetails->rule?"'".SecurityUtils::prepareSafeHTML($attendaneSwappingDetails->rule)."'":"null").", '$attendaneSwappingDetails->hour', '$attendaneSwappingDetails->date', ".($attendaneSwappingDetails->sbsId?"'$attendaneSwappingDetails->sbsId'":"null").", ".($attendaneSwappingDetails->psId?"'$attendaneSwappingDetails->psId'":"null").", '$attendaneSwappingDetails->createdBy', utc_timestamp(), '$attendaneSwappingDetails->updatedBy', utc_timestamp())"; | |
| try { | |
| return $this->executeQuery($sql,TRUE); | |
| } catch (Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| public function updateAttendanceMarkingRequestCompleted($requestId) | |
| { | |
| try { | |
| $sql = "UPDATE attendance_swapping_details SET request_completed=1 WHERE id='$requestId'"; | |
| return $this->executeQuery($sql); | |
| } catch (Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| public function updateAttendanceMarkingStaff($requestId, $staffId) | |
| { | |
| try { | |
| $sql = "UPDATE attendance_confirming_staff SET is_confirmed=1 WHERE id='$requestId' AND staff_id=$staffId"; | |
| return $this->executeQuery($sql); | |
| } catch (Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| public function removeAttendanceSwappingRequestById($requestId) | |
| { | |
| $sql ="DELETE FROM attendance_swapping_details WHERE id='$requestId'"; | |
| try { | |
| $this->executeQuery($sql); | |
| } catch (Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * add attendance confirming staff | |
| * @param array $attendanceConfirmingStaffList | |
| * @throws ProfessionalException | |
| */ | |
| public function addAttendanceConfirmingStaff($attendanceConfirmingStaffList) | |
| { | |
| $sql ="INSERT INTO attendance_confirming_staff (attendance_swapping_details_id, staff_id, created_by, created_date, updated_by, updated_date) VALUES "; | |
| $values=[]; | |
| foreach($attendanceConfirmingStaffList as $attendanceConfirmingStaff) | |
| { | |
| $values[]="('$attendanceConfirmingStaff->attendanceSwappingDetailsId', '$attendanceConfirmingStaff->staffId', '$attendanceConfirmingStaff->createdBy', '$attendanceConfirmingStaff->createdDate', '$attendanceConfirmingStaff->updatedBy', '$attendanceConfirmingStaff->updatedDate')"; | |
| } | |
| $sql .=implode(', ',$values); | |
| try { | |
| $this->executeQuery($sql); | |
| } catch (Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| public function removeAttendanceConfirmingStaffByRequestId($requestId) | |
| { | |
| $sql ="DELETE FROM attendance_confirming_staff WHERE attendance_swapping_details_id='$requestId'"; | |
| try { | |
| $this->executeQuery($sql); | |
| } catch (Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * get attendance swapping request details | |
| * @param AttendaneSwappingDetails $attendaneSwappingDetails | |
| * @throws ProfessionalException | |
| * @return object|NULL|\com\linways\base\util\$objectList[] | |
| */ | |
| public function getAttendanceSwappingRequest(AttendaneSwappingDetails $attendaneSwappingDetails) | |
| { | |
| $sql ="select asd.id, asd.assigned_staff_id, asd.date, asd.hour, asd.sbs_id, asd.ps_id, asd.request_completed, asd.rule, acs.staff_id, acs.is_confirmed from attendance_swapping_details asd inner join attendance_confirming_staff acs ON asd.id=acs.attendance_swapping_details_id WHERE asd.date='$attendaneSwappingDetails->date' AND asd.hour='$attendaneSwappingDetails->hour'"; | |
| if($attendaneSwappingDetails->psId) | |
| { | |
| $sql .=" AND asd.ps_id='$attendaneSwappingDetails->psId'"; | |
| } | |
| else if($attendaneSwappingDetails->sbsId) | |
| { | |
| $sql .=" AND asd.sbs_id='$attendaneSwappingDetails->sbsId'"; | |
| } | |
| if($attendaneSwappingDetails->assignedStaffId) | |
| { | |
| $sql .=" AND asd.assigned_staff_id='$attendaneSwappingDetails->assignedStaffId'"; | |
| } | |
| try { | |
| return $this->executeQueryForObject($sql,false,$this->mapper[AttendanceMarkSwappingServiceMapper::GET_ATTENDANCE_SWAPPING_REQUEST]); | |
| } catch (Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| } | |