Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 14 |
CRAP | |
0.00% |
0 / 309 |
AttendanceLockService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 14 |
2256.00 | |
0.00% |
0 / 309 |
__construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
__clone | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
getInstance | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 7 |
|||
createAttendanceLock | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 17 |
|||
getAttendanceLocks | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 49 |
|||
getAttendanceLockById | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 52 |
|||
activateLockByID | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 12 |
|||
disableLockByID | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 12 |
|||
deleteLockByID | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 12 |
|||
disableActiveLocks | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 15 |
|||
updateAttendanceLockByRequest | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 29 |
|||
checkAttendanceLockByTimetableRequest | |
0.00% |
0 / 1 |
132.00 | |
0.00% |
0 / 40 |
|||
getAttendanceDayLockByBatchId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
getLockDetailsForNonTimetable | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 50 |
<?php | |
namespace com\linways\core\ams\professional\service; | |
use com\linways\core\ams\professional\exception\ProfessionalException; | |
use Exception; | |
/** | |
* | |
* @Date 07/01/21 | |
* @author Joel M John | |
*/ | |
class AttendanceLockService extends BaseService | |
{ | |
/** | |
* Presence of a static member variable | |
* | |
* @var null | |
*/ | |
private static $_instance = null; | |
/** | |
* Mapper variable | |
* @var array | |
*/ | |
private $mapper = []; | |
/** | |
* Initialise mapper, logger, hooks here | |
* | |
* | |
*/ | |
private function __construct() | |
{ | |
} | |
/** | |
* Prevent any object or instance of that class to be cloned | |
*/ | |
private function __clone() | |
{ | |
} | |
/** | |
* Have a single globally accessible static method | |
* | |
* @return AttendanceLockService|null | |
*/ | |
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; | |
} | |
/** | |
* method to create an Attendance Lock | |
* @param Object $request | |
* @return Boolean | |
* @throws ProfessionalException | |
*/ | |
public function createAttendanceLock($request) | |
{ | |
// $request->courseTypeId // $request->semID * requests at a glance | |
// $request->batchID // $request->hour //$request->deptID | |
// $request->sbsID // $request->subjectID | |
// $request->fromDate // $request->toDate | |
// $request->startTime // $request->endTime // $request->userID | |
if(!$request->courseTypeId || !$request->fromDate || !$request->toDate){ | |
throw new Exception("Fields cannot be empty!"); | |
} | |
try { | |
$sql = "INSERT INTO `lock_attendance` (`course_type_id`, `deptID`,`semID`,`batchID`, `hour`, `sbsID`, | |
`subjectID`, `from_date`, `to_date`, `start_time`, `end_time`, `created_by`) | |
VALUES ('$request->courseTypeId','$request->deptID', '$request->semID', '$request->batchID', '$request->hour', '$request->sbsID', | |
'$request->subjectID', '$request->fromDate', '$request->toDate ', '$request->startTime', '$request->endTime', '$request->userID')"; | |
if($this->executeQueryForObject($sql,true)) { | |
return true; | |
} | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return false; | |
} | |
/** | |
* method to get all Attendance Locks | |
* @return Result | |
* @throws ProfessionalException | |
*/ | |
public function getAttendanceLocks() | |
{ | |
try { | |
$sql = "SELECT | |
la.id, | |
la.deptID, | |
la.semID, | |
la.batchID, | |
la.sbsID, | |
la.subjectID, | |
ct.typeName as CourseTypeName, | |
dept.deptName, | |
sem.semName, | |
btch.batchName, | |
la.hour, | |
sa.staffName, | |
sub.subjectName, | |
la.from_date, | |
la.to_date, | |
la.start_time, | |
la.end_time, | |
la.lock_status, | |
aa.adminName, | |
la.created_at | |
FROM | |
course_type ct | |
INNER JOIN | |
lock_attendance la ON ct.courseTypeID = la.course_type_id | |
LEFT JOIN | |
adminaccount aa ON aa.adminID = la.created_by | |
LEFT JOIN | |
semesters sem ON la.semID = sem.semID | |
LEFT JOIN | |
department dept ON la.deptID = dept.deptID | |
LEFT JOIN | |
batches btch ON btch.batchID = la.batchID | |
LEFT JOIN | |
subjects sub ON sub.subjectID = la.subjectID | |
LEFT JOIN | |
sbs_relation sbs ON sbs.sbsID = la.sbsID | |
LEFT JOIN | |
staffaccounts sa ON sbs.staffID = sa.staffID | |
ORDER BY la.created_at DESC"; | |
$result = $this->executeQueryForList($sql); | |
return $result; | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return false; | |
} | |
/** | |
* method to get Attendance Lock by ID | |
* @param lockID | |
* @return Result | |
* @throws ProfessionalException | |
*/ | |
public function getAttendanceLockById($lockID) | |
{ | |
try { | |
$sql = "SELECT | |
la.id, | |
la.course_type_id as courseTypeID, | |
la.deptID, | |
la.semID, | |
la.batchID, | |
la.sbsID, | |
la.subjectID, | |
ct.typeName as CourseTypeName, | |
dept.deptName, | |
sem.semName, | |
btch.batchName, | |
la.hour, | |
sa.staffName, | |
sub.subjectName, | |
la.from_date, | |
la.to_date, | |
la.start_time, | |
la.end_time, | |
la.lock_status, | |
aa.adminName, | |
la.created_at | |
FROM | |
course_type ct | |
INNER JOIN | |
lock_attendance la ON ct.courseTypeID = la.course_type_id | |
LEFT JOIN | |
adminaccount aa ON aa.adminID = la.created_by | |
LEFT JOIN | |
semesters sem ON la.semID = sem.semID | |
LEFT JOIN | |
department dept ON la.deptID = dept.deptID | |
LEFT JOIN | |
batches btch ON btch.batchID = la.batchID | |
LEFT JOIN | |
subjects sub ON sub.subjectID = la.subjectID | |
LEFT JOIN | |
sbs_relation sbs ON sbs.sbsID = la.sbsID | |
LEFT JOIN | |
staffaccounts sa ON sbs.staffID = sa.staffID | |
WHERE | |
la.id = '$lockID' | |
ORDER BY la.created_at DESC"; | |
$result = $this->executeQueryForList($sql); | |
return $result; | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return false; | |
} | |
/** | |
* method to activate lock by Id | |
* @param id | |
* @return Boolean | |
* @throws ProfessionalException | |
*/ | |
public function activateLockByID($id) | |
{ | |
try { | |
$sql = "UPDATE `lock_attendance` SET `lock_status`='1' | |
WHERE `id`='$id'"; | |
if($this->executeQuery($sql)) { | |
return true; | |
} | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return false; | |
} | |
/** | |
* method to disable lock by Id | |
* @param id | |
* @return Boolean | |
* @throws ProfessionalException | |
*/ | |
public function disableLockByID($id) | |
{ | |
try { | |
$sql = "UPDATE `lock_attendance` SET `lock_status`='0' | |
WHERE `id`='$id'"; | |
if($this->executeQuery($sql,true)) { | |
return true; | |
} | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return false; | |
} | |
/** | |
* method to delete lock by Id | |
* @param id | |
* @return Boolean | |
* @throws ProfessionalException | |
*/ | |
public function deleteLockByID($id) | |
{ | |
try { | |
$sql = "DELETE FROM `lock_attendance` | |
WHERE `id`='$id'"; | |
if($this->executeQuery($sql,true)) { | |
return true; | |
} | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return false; | |
} | |
/** | |
* method to disable all active locks | |
* @return Boolean | |
* @throws ProfessionalException | |
*/ | |
public function disableActiveLocks() | |
{ | |
try { | |
$sql = "UPDATE lock_attendance | |
SET | |
lock_status = 0 | |
WHERE | |
lock_status = 1"; | |
if($this->executeQuery($sql,true)) { | |
return true; | |
} | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return false; | |
} | |
/** | |
* method to update Atteandance Lock by request | |
* @param request | |
* @return Boolean | |
* @throws ProfessionalException | |
*/ | |
public function updateAttendanceLockByRequest($request) | |
{ | |
// $request->courseTypeId // $request->semID * requests at a glance | |
// $request->batchID // $request->hour //$request->deptID | |
// $request->sbsID // $request->subjectID | |
// $request->fromDate // $request->toDate | |
// $request->startTime // $request->endTime // $request->userID // $request->lockID | |
if(!$request->courseTypeId || !$request->fromDate || !$request->toDate){ | |
throw new Exception("Fields cannot be empty!"); | |
} | |
try { | |
$sql = "UPDATE lock_attendance | |
SET | |
`course_type_id` = '$request->courseTypeId', | |
`deptID` = '$request->deptID', | |
`semID` = '$request->semID', | |
`batchID` = '$request->batchID', | |
`hour` = '$request->hour', | |
`sbsID` = '$request->sbsID', | |
`subjectID` = '$request->subjectID', | |
`from_date` = '$request->fromDate', | |
`to_date` = '$request->toDate', | |
`start_time` = '$request->startTime', | |
`end_time` = '$request->endTime', | |
`created_by` = '$request->userID' | |
WHERE | |
`id` = '$request->lockID'"; | |
if($this->executeQuery($sql,true)) { | |
return true; | |
} | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return false; | |
} | |
/** | |
* method to check attendanceLockByTimetable | |
* @param timetable request | |
* @return Boolean | |
* @throws ProfessionalException | |
*/ | |
public function checkAttendanceLockByTimetableRequest($timetable) | |
{ | |
if(!$timetable->courseTypeID || !$timetable->timetableDate){ | |
throw new Exception("Fields cannot be empty!"); | |
} | |
$cond = ''; | |
if($timetable->batchID){ | |
$cond .= " AND batchID IN ('0',$timetable->batchID) "; | |
} | |
if($timetable->semID){ | |
$cond .= "AND semID IN ('0',$timetable->semID) "; | |
} | |
if($timetable->subjectID){ | |
$cond .= "AND subjectID IN ('0',$timetable->subjectID) "; | |
} | |
if($timetable->sbsID){ | |
$cond .= "AND sbsID IN ('0',$timetable->sbsID) "; | |
} | |
if($timetable->hourID){ | |
$cond .= "AND hour IN ('0',$timetable->hourID) "; | |
} | |
if($timetable->deptID){ | |
$cond .= "AND deptID IN ('0',$timetable->deptID) "; | |
} | |
try { | |
$sql = "SELECT | |
lock_status | |
FROM | |
lock_attendance | |
WHERE | |
course_type_id = $timetable->courseTypeID AND lock_status = 1 | |
AND '$timetable->timetableDate' BETWEEN from_date AND to_date ".$cond; | |
$result = $this->executeQueryForObject($sql); | |
if($result->lock_status == 1) { | |
return true; | |
} | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return false; | |
} | |
/** | |
* get attendance lock for lazy restriction | |
* | |
* attendance lock for restricting staff putting of older dates | |
* | |
* @param Int $batchID | |
* @return Object | |
* @throws ProfessionalException | |
* @author Ajay C | |
**/ | |
public function getAttendanceDayLockByBatchId($batchID) | |
{ | |
$batchID = $this->realEscapeString($batchID); | |
$sql = "SELECT batchID ,markingPeriodType,attendancelimit,lockingType from attendance_limit al WHERE batchID IN ($batchID)"; | |
try { | |
$result = $this->executeQueryForObject($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return $result; | |
} | |
/** | |
* get locakmanager details | |
* | |
* get lock details for non timetable method | |
* | |
* @param Integer $batchID,$date,$hour | |
* @return Object | |
* @throws ProfessionalException | |
**/ | |
public function getLockDetailsForNonTimetable($batchID,$date,$hour = null) | |
{ | |
$condition = " AND hour IN ('0','$hour')"; | |
$sql = "SELECT | |
la.id, | |
la.deptID, | |
la.semID, | |
la.batchID, | |
la.sbsID, | |
la.subjectID, | |
ct.typeName as CourseTypeName, | |
dept.deptName, | |
sem.semName, | |
btch.batchName, | |
la.hour, | |
sa.staffName, | |
sub.subjectName, | |
la.from_date, | |
la.to_date, | |
la.start_time, | |
la.end_time, | |
la.lock_status, | |
aa.adminName, | |
la.created_at | |
FROM | |
course_type ct | |
INNER JOIN | |
lock_attendance la ON ct.courseTypeID = la.course_type_id | |
LEFT JOIN | |
adminaccount aa ON aa.adminID = la.created_by | |
LEFT JOIN | |
semesters sem ON la.semID = sem.semID | |
LEFT JOIN | |
department dept ON la.deptID = dept.deptID | |
LEFT JOIN | |
batches btch ON btch.batchID = la.batchID | |
LEFT JOIN | |
subjects sub ON sub.subjectID = la.subjectID | |
LEFT JOIN | |
sbs_relation sbs ON sbs.sbsID = la.sbsID | |
LEFT JOIN | |
staffaccounts sa ON sbs.staffID = sa.staffID | |
WHERE la.batchID in ('0','$batchID') and la.course_type_id in (SELECT courseTypeID from batches WHERE batchID = '$batchID') or la.course_type_id in (0) | |
and '$date' BETWEEN la.from_date and la.to_date $condition and la.lock_status = 1 | |
ORDER BY la.created_at DESC"; | |
try { | |
return $this->executeQueryForObject($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
} | |