Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 116 |
CentralizedTimingService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 11 |
702.00 | |
0.00% |
0 / 116 |
__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 |
|||
createCentralizedTiming | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 12 |
|||
selectAllCentralizedTiming | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 15 |
|||
checkDuplicateCentralizedTiming | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 14 |
|||
getCentalizedTimingById | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 12 |
|||
removeCentalizedTimingById | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 12 |
|||
updateTimingById | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 11 |
|||
getCentralizedTimingByDayHour | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 14 |
|||
removeAllCentralizedTimingByCourseId | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 15 |
<?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 CentralizedTimingService 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 CentralizedTimingService|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 a CentralizedTiming | |
* @param Object $request | |
* @return Boolean | |
* @throws ProfessionalException | |
*/ | |
public function createCentralizedTiming($request) | |
{ | |
try { | |
$sql = "INSERT INTO `centralized_timing` (`course_type_id`, `day`, `hour`, `start_time`, `end_time`, `created_by`) | |
VALUES ('$request->courseTypeID', '$request->day', '$request->hour', '$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 select all CentralizedTiming by CourseTypeID | |
* @param Int,Boolean | |
* @return Result | |
* @throws ProfessionalException | |
*/ | |
public function selectAllCentralizedTiming($courseTypeID, $orderByDay = false) | |
{ | |
try { | |
$cond = ''; | |
if($orderByDay){ | |
$cond = 'ORDER BY day ASC'; | |
} | |
$sql = "SELECT id,course_type_id, day, hour, start_time, end_time, created_by | |
FROM centralized_timing | |
WHERE course_type_id = '$courseTypeID'".$cond; | |
$result = $this->executeQueryForList($sql); | |
return $result; | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
/** | |
* method to check duplicate timing entry in table | |
* @param Object request | |
* @return Boolean | |
* @throws ProfessionalException | |
*/ | |
public function checkDuplicateCentralizedTiming($request) | |
{ | |
try { | |
$sql = "SELECT id,course_type_id, day, hour, start_time, end_time, created_by | |
FROM centralized_timing | |
WHERE course_type_id = $request->courseTypeID AND day = $request->day AND hour = $request->hour"; | |
$result = $this->executeQueryForList($sql); | |
if($result){ | |
return true; | |
} | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return false; | |
} | |
/** | |
* method to get ct by id | |
* @param id | |
* @return Result | |
* @throws ProfessionalException | |
*/ | |
public function getCentalizedTimingById($id) | |
{ | |
try { | |
$sql = "SELECT id,course_type_id, day, hour, start_time, end_time, created_by | |
FROM centralized_timing | |
WHERE id = '$id'"; | |
$result = $this->executeQueryForObject($sql); | |
return $result; | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return false; | |
} | |
/** | |
* method to remove ct by id | |
* @param id | |
* @return Boolean | |
* @throws ProfessionalException | |
*/ | |
public function removeCentalizedTimingById($id) | |
{ | |
try { | |
$sql = "DELETE | |
FROM centralized_timing | |
WHERE id = '$id'"; | |
if($this->executeQuery($sql)) | |
return true; | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return false; | |
} | |
/** | |
* method to update timing by id | |
* @param INT startTime, endTime, timingId | |
* @return Boolean | |
* @throws ProfessionalException | |
*/ | |
public function updateTimingById($startTime,$endTime,$timingId) | |
{ | |
try { | |
$sql = "UPDATE `centralized_timing` | |
SET `start_time`='$startTime', `end_time`='$endTime' WHERE `id`='$timingId'"; | |
if($this->executeQuery($sql)) | |
return true; | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return false; | |
} | |
/** | |
* method to get ct by day and hour | |
* @param INT day, hour | |
* @return result | |
* @throws ProfessionalException | |
*/ | |
public function getCentralizedTimingByDayHour($day,$hour,$courseTypeID) | |
{ | |
try { | |
$sql = "SELECT | |
id, course_type_id, day, hour, start_time, end_time | |
FROM | |
centralized_timing | |
WHERE | |
day = '$day' AND hour = '$hour' AND course_type_id = '$courseTypeID' "; | |
$result = $this->executeQueryForObject($sql); | |
return $result; | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
/** | |
* method to remove all timing by courseType | |
* @param INT day, hour | |
* @return Boolean | |
* @throws ProfessionalException | |
*/ | |
public function removeAllCentralizedTimingByCourseId($courseTypeID) | |
{ | |
try { | |
$sql = "DELETE | |
FROM | |
centralized_timing | |
WHERE | |
course_type_id = '$courseTypeID'"; | |
if($this->executeQuery($sql)){ | |
return true; | |
} | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return false; | |
} | |
} | |