Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 50 |
SubjectDepartmentService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 6 |
182.00 | |
0.00% |
0 / 50 |
__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 / 5 |
|||
assignSubjectToDepartment | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
assignSubjectsToDepartments | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 15 |
|||
assignSubjectToDepartments | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 14 |
<?php | |
/** | |
* User: jithinvijayan | |
* Date: 04/11/19 | |
* Time: 11:56 AM | |
*/ | |
namespace com\linways\core\ams\professional\service; | |
use com\linways\core\ams\professional\exception\ProfessionalException; | |
use com\linways\core\ams\professional\logging\AMSLogger; | |
use com\linways\core\ams\professional\request\AssignSubjectToDepartmentsRequest; | |
use com\linways\core\ams\professional\request\AssignSubjectToDepartmentRequest; | |
class SubjectDepartmentService extends BaseService | |
{ | |
/** | |
* Presence of a static member variable | |
* | |
* @var null | |
*/ | |
private static $_instance = null; | |
/** | |
* @var null | |
*/ | |
private $logger = null; | |
/** | |
* Mapper variable | |
* @var array | |
*/ | |
private $mapper = []; | |
/** | |
* Initialise mapper, logger, hooks here | |
* | |
* ReportGenderService constructor. | |
*/ | |
private function __construct() | |
{ | |
/** | |
* Initialising mapper | |
*/ | |
// $this->mapper = SBSServiceMapper::getInstance()->getMapper(); | |
/** | |
* Initialising ams logger | |
* logging to elastic search | |
*/ | |
$this->logger = AMSLogger::getLogger(); | |
} | |
/** | |
* Prevent any object or instance of that class to be cloned | |
*/ | |
private function __clone() | |
{ | |
} | |
/** | |
* Have a single globally accessible static method | |
* | |
* @return SubjectDepartmentService|null | |
*/ | |
public static function getInstance() | |
{ | |
if (!is_object(self::$_instance)) | |
self::$_instance = new self (); | |
return self::$_instance; | |
} | |
/** | |
* Assign subject to department | |
* | |
* @param AssignSubjectToDepartmentRequest $request | |
* @throws ProfessionalException | |
* @author jithinvijayan | |
*/ | |
public function assignSubjectToDepartment(AssignSubjectToDepartmentRequest $request) | |
{ | |
$request = $this->realEscapeObject($request); | |
$sql = "INSERT IGNORE INTO sd_relation (subjectID, deptID, createdBy, updatedBy, createdDate, updatedDate) | |
VALUES ($request->subjectId,$request->departmentId,$request->createdBy,$request->updatedBy, | |
UTC_TIMESTAMP(),UTC_TIMESTAMP())"; | |
try { | |
$this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
/** | |
* Assigning subjects to departments | |
* | |
* @param AssignSubjectToDepartmentsRequest[] $requests | |
* @throws ProfessionalException | |
* @author jithinvijayan | |
*/ | |
public function assignSubjectsToDepartments(array $requests) | |
{ | |
$requests = $this->realEscapeObject($requests); | |
$sql = "INSERT IGNORE INTO sd_relation (subjectID, deptID, createdBy, updatedBy, createdDate, updatedDate) VALUES "; | |
foreach ($requests as $request) { | |
foreach ($request->departmentIds as $departmentId) { | |
$sql .= " ($request->subjectId,$departmentId,$request->createdBy,$request->updatedBy,UTC_TIMESTAMP(),UTC_TIMESTAMP()),"; | |
} | |
} | |
$sql = rtrim($sql, ","); | |
try { | |
$this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
/** | |
* Assigning subject to the departments | |
* | |
* @param AssignSubjectToDepartmentsRequest $request | |
* @throws ProfessionalException | |
* @author jithinvijayan | |
*/ | |
public function assignSubjectToDepartments(AssignSubjectToDepartmentsRequest $request) | |
{ | |
$request = $this->realEscapeObject($request); | |
$sql = "INSERT IGNORE INTO sd_relation (subjectID, deptID, createdBy, updatedBy, createdDate, updatedDate) | |
VALUES "; | |
foreach ($request->departmentIds as $departmentId) { | |
$sql .= " ($request->subjectId,$departmentId,$request->createdBy,$request->updatedBy,UTC_TIMESTAMP(),UTC_TIMESTAMP()),"; | |
} | |
$sql = rtrim($sql, ","); | |
try { | |
$this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
} |