Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 23 |
CRAP | |
0.00% |
0 / 220 |
DutyLeaveService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 23 |
2256.00 | |
0.00% |
0 / 220 |
__construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
__clone | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
getInstance | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 5 |
|||
createCategory | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 12 |
|||
updateDutyLeaveCategory | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
deleteDutyLeaveCategory | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
getAllDutyLeaveCategory | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
getDutyLeaveCategoryById | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
getDutyLeaveCategoryByParentId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
assignStaffToCategory | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 15 |
|||
getCategoryAssignedStaffsByCategoryId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
deleteCategoryAssignedStaffsByCategoryId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
getDLRulesById | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
getAllDLRules | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
assignDLRulesToCategory | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 15 |
|||
getDLRulesAssignedToCategoryByCategoryId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
getDLRulesAssignedByCategoryId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
deleteAssignDLRulesToCategory | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
deleteCategoryByParentId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
getCategories | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 15 |
|||
getLeaveTypeById | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
getStaffAssignedCategoriesByStaffId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
getStaffAssignedLeaveTypeByStaffId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
<?php | |
namespace com\linways\core\ams\professional\service; | |
use com\linways\core\ams\professional\exception\ProfessionalException; | |
use com\linways\core\ams\professional\dto\DutyLeaveCategory; | |
use com\linways\core\ams\professional\mapper\DutyLeaveServiceMapper; | |
class DutyLeaveService extends BaseService | |
{ | |
// private $batchService = BatchService::getInstance(); | |
// /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 = DutyLeaveServiceMapper::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; | |
} | |
/** | |
* Create duty leave category | |
* @param DutyLeaveCategory $dutyLeaveCategory | |
* @throws ProfessionalException | |
* @return \com\linways\base\connection\Object | |
*/ | |
public function createCategory($dutyLeaveCategory) | |
{ | |
$dutyLeaveCategory= $this->realEscapeObject($dutyLeaveCategory); | |
$sql = "INSERT INTO dutyLeaveCategory (categoryName, parentCatId, leaveTypeId,createdBy, createdDate, updatedBy, updatedDate) VALUES('$dutyLeaveCategory->categoryName', '$dutyLeaveCategory->parentCategoryId',$dutyLeaveCategory->leaveTypeId, '$dutyLeaveCategory->createdBy', utc_timestamp(), '$dutyLeaveCategory->updatedBy', utc_timestamp())"; | |
try | |
{ | |
return $this->executeQuery($sql); | |
} | |
catch (\Exception $e) | |
{ | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
} | |
/** | |
* update duty leave category | |
* @param DutyLeaveCategory $dutyLeaveCategory | |
* @throws ProfessionalException | |
* @return \com\linways\base\dto\MySqlResult | |
*/ | |
public function updateDutyLeaveCategory($dutyLeaveCategory) | |
{ | |
$dutyLeaveCategory = $this->realEscapeObject($dutyLeaveCategory); | |
$sql = "UPDATE dutyLeaveCategory SET categoryName = '$dutyLeaveCategory->categoryName', parentCatId = $dutyLeaveCategory->parentCategoryId, leaveTypeId = $dutyLeaveCategory->leaveTypeId ,updatedBy = $dutyLeaveCategory->updatedBy, updatedDate = utc_timestamp WHERE id = $dutyLeaveCategory->id"; | |
try { | |
return $this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
} | |
/** | |
* Delete duty leave category | |
* @param int $categoryId | |
* @throws ProfessionalException | |
* @return \com\linways\base\dto\MySqlResult | |
*/ | |
public function deleteDutyLeaveCategory($categoryId) | |
{ | |
$categoryId = $this->realEscapeString($categoryId); | |
$sql = "DELETE FROM dutyLeaveCategory WHERE id = $categoryId"; | |
try { | |
$this->executeQuery($sql); | |
$this->deleteCategoryByParentId($categoryId); | |
return ; | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
} | |
/** | |
* Get all duty leave category | |
* @throws ProfessionalException | |
* @return object|array|\com\linways\base\util\$objectList[] | |
*/ | |
public function getAllDutyLeaveCategory() | |
{ | |
$sql = "SELECT dlc.id, dlc.categoryName, dlc.parentCatId, dlc.leaveTypeId, lt.code, lt.name, dlc_parent.categoryName as parentCategory FROM dutyLeaveCategory dlc left join dutyLeaveCategory dlc_parent on dlc.parentCatId = dlc_parent.id left join student_leave_type lt on lt.id = dlc.leaveTypeId and lt.isActive=1 order by dlc.id"; | |
try { | |
$categoryDetails = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
return $categoryDetails; | |
} | |
/** | |
* Get duty leave category by id | |
* @param int $id | |
* @throws ProfessionalException | |
* @return object|NULL|\com\linways\base\util\$objectList[] | |
*/ | |
public function getDutyLeaveCategoryById($id) | |
{ | |
$id = $this->realEscapeString($id); | |
$sql = "SELECT dlc.id, dlc.categoryName, dlc.parentCatId, dlc.leaveTypeId, lt.code, lt.name, dlc_parent.categoryName as parentCategory FROM dutyLeaveCategory dlc left join dutyLeaveCategory dlc_parent on dlc.parentCatId = dlc_parent.id left join student_leave_type lt on lt.id = dlc.leaveTypeId and lt.isActive=1 WHERE dlc.id = $id"; | |
try { | |
$categoryDetails = $this->executeQueryForObject($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
return $categoryDetails; | |
} | |
/** | |
* Get duty leave category by parentId | |
* @param int $parentId | |
* @throws ProfessionalException | |
* @return object|NULL|\com\linways\base\util\$objectList[] | |
*/ | |
public function getDutyLeaveCategoryByParentId($parentId) | |
{ | |
$parentId = $this->realEscapeString($parentId); | |
$sql = "SELECT id, categoryName FROM dutyLeaveCategory WHERE parentCatId = $parentId"; | |
try { | |
$categoryDetails = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
return $categoryDetails; | |
} | |
/** | |
* Assign staff to dutyleave category | |
* @param int $categoryId | |
* @param array $staffIds | |
* @throws ProfessionalException | |
* @return object|NULL|\com\linways\base\util\$objectList[] | |
*/ | |
public function assignStaffToCategory($categoryId, $staffIds) | |
{ | |
$categoryId = $this->realEscapeString($categoryId); | |
$staffIds = $this->realEscapeArray($staffIds); | |
foreach ($staffIds as $staffId) | |
{ | |
$sql_values.= " ($categoryId, $staffId, '1', utc_timestamp(), '1', utc_timestamp()), "; | |
} | |
$sql_values = rtrim($sql_values, ", "); | |
$sql = "INSERT INTO dutyLeaveCategoryAssignedStaff (dutyLeaveCategoryId, staffId, createdBy, createdDate, updatedBy, updatedDate) VALUES $sql_values"; | |
try { | |
return $this->executeQueryForObject($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
} | |
/** | |
* Get category assigned staffs by categoryId | |
* @param int $categoryId | |
* @throws ProfessionalException | |
* @return object|array|\com\linways\base\util\$objectList[] | |
*/ | |
public function getCategoryAssignedStaffsByCategoryId($categoryId) | |
{ | |
$categoryId = $this->realEscapeString($categoryId); | |
$sql = "SELECT dlc.id AS categoryId, categoryName, parentCatId, sa.staffId, staffName FROM dutyLeaveCategory dlc LEFT JOIN dutyLeaveCategoryAssignedStaff cas ON dlc.id= cas.dutyLeaveCategoryId LEFT JOIN staffaccounts sa ON sa.staffID = cas.staffId WHERE dlc.id = $categoryId"; | |
try { | |
$staffIds = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
return $staffIds; | |
} | |
/** | |
* Delete category assigned staffs by category id | |
* @param int $categoryId | |
* @throws ProfessionalException | |
* @return \com\linways\base\dto\MySqlResult | |
*/ | |
public function deleteCategoryAssignedStaffsByCategoryId($categoryId) | |
{ | |
$categoryId = $this->realEscapeString($categoryId); | |
$sql = "DELETE FROM dutyLeaveCategoryAssignedStaff WHERE dutyLeaveCategoryId = $categoryId"; | |
try { | |
return $this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
} | |
/** | |
* Get DL rules by id | |
* @param int $id | |
* @throws ProfessionalException | |
* @return object|NULL|\com\linways\base\util\$objectList[] | |
*/ | |
public function getDLRulesById($id) | |
{ | |
$id = $this->realEscapeString($id); | |
$sql = "SELECT ruleName, ruleDefinition FROM DLRules WHERE id = $id"; | |
try { | |
$rules = $this->executeQueryForObject($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
return $rules; | |
} | |
/** | |
* Get all DL rules | |
* @throws ProfessionalException | |
* @return object|array|\com\linways\base\util\$objectList[] | |
*/ | |
public function getAllDLRules() | |
{ | |
$sql = "SELECT id, ruleName, ruleDefinition FROM DLRules"; | |
try { | |
$rules = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
return $rules; | |
} | |
/** | |
* Assign DL rules to category | |
* @param int $categoryId | |
* @param array $ruleIds | |
* @throws ProfessionalException | |
* @return object|NULL|\com\linways\base\util\$objectList[] | |
*/ | |
public function assignDLRulesToCategory($categoryId, $ruleIds) | |
{ | |
$categoryId = $this->realEscapeString($categoryId); | |
$ruleIds = $this->realEscapeArray($ruleIds); | |
foreach ($ruleIds as $ruleId) | |
{ | |
$sql_values.= " ($categoryId, $ruleId, '1', utc_timestamp(), '1', utc_timestamp()), "; | |
} | |
$sql_values = rtrim($sql_values, ", "); | |
$sql = "INSERT INTO dutyLeaveCategoryRule (dutyLeaveCategoryId, DLRulesId, createdBy, createdDate, updatedBy, updatedDate) VALUES $sql_values"; | |
try { | |
return $this->executeQueryForObject($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
} | |
/** | |
* Get DL rules assigned to category by categoryId | |
* @param int $categoryId | |
* @throws ProfessionalException | |
* @return object|array|\com\linways\base\util\$objectList[] | |
*/ | |
public function getDLRulesAssignedToCategoryByCategoryId($categoryId) | |
{ | |
$sql = "SELECT DLRulesId, ruleName, ruleDefinition FROM DLRules dlr left join dutyLeaveCategoryRule cr on cr.DLRulesId = dlr.id WHERE dutyLeaveCategoryId = $categoryId"; | |
try { | |
$rules = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
return $rules; | |
} | |
/** | |
* Get DL rules assigned by categoryId | |
* @param int $categoryId | |
* @throws ProfessionalException | |
* @return object|array|\com\linways\base\util\$objectList[] | |
*/ | |
public function getDLRulesAssignedByCategoryId($categoryId) | |
{ | |
$categoryId = $this->realEscapeString($categoryId); | |
$sql = "select dlr.id as ruleId, ruleName, ruleDefinition, DLRulesId, dutyLeaveCategoryId from DLRules dlr left join dutyLeaveCategoryRule cr on dlr.id = cr.DLRulesId and dutyLeaveCategoryId = $categoryId"; | |
try { | |
$ruleDetails = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
return $ruleDetails; | |
} | |
/** | |
* delete Assign DLRules To Category | |
* @param int $categoryId | |
* @throws ProfessionalException | |
* @return \com\linways\base\dto\MySqlResult | |
*/ | |
public function deleteAssignDLRulesToCategory($categoryId) | |
{ | |
$categoryId = $this->realEscapeString($categoryId); | |
$sql = "DELETE FROM dutyLeaveCategoryRule WHERE dutyLeaveCategoryId = $categoryId"; | |
try { | |
return $this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
} | |
/** | |
* Delete category by parentId | |
* @param int $parentId | |
* @throws ProfessionalException | |
* @return \com\linways\base\dto\MySqlResult | |
*/ | |
public function deleteCategoryByParentId($parentId) | |
{ | |
$parentId = $this->realEscapeString($parentId); | |
$sql = "DELETE FROM dutyLeaveCategory WHERE parentCatId = $parentId"; | |
try { | |
return $this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
} | |
/** | |
* get category details | |
* @param int $staffId | |
* @param int $leaveTypeId | |
* @throws ProfessionalException | |
* @return object|array|\com\linways\base\util\$objectList[] | |
*/ | |
public function getCategories($leaveTypeId, $staffId = null) | |
{ | |
$staffId = $this->realEscapeString($staffId); | |
$leaveTypeId = $this->realEscapeString($leaveTypeId); | |
$sql = "SELECT dlc.id, dlc.categoryName, dlc.parentCatId, dlp.categoryName as parentCategory from dutyLeaveCategory dlp inner join dutyLeaveCategory dlc on dlp.id = dlc.parentCatId left join dutyLeaveCategoryAssignedStaff cas on cas.dutyLeaveCategoryId= dlc.id where dlc.leaveTypeId = $leaveTypeId"; | |
if($staffId) | |
{ | |
$sql.=" and staffId = $staffId"; | |
} | |
try { | |
$categories = $this->executeQueryForList($sql, $this->mapper[DutyLeaveServiceMapper::GET_CATEGORY]); | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
return $categories; | |
} | |
/** | |
* Get leave type by id | |
* @param int $id | |
* @throws ProfessionalException | |
*/ | |
public function getLeaveTypeById($id) | |
{ | |
$id = $this->realEscapeString($id); | |
$sql = "SELECT * from student_leave_type WHERE id = $id and isActive=1"; | |
try { | |
$leaveType = $this->executeQueryForObject($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
return $leaveType; | |
} | |
/** | |
* Get staff assigned categories by staff | |
* @param int $staffId | |
* @throws ProfessionalException | |
* @return object|array|\com\linways\base\util\$objectList[] | |
*/ | |
public function getStaffAssignedCategoriesByStaffId($staffId) | |
{ | |
$staffId = $this->realEscapeString($staffId); | |
$sql = "select dlc.id, staffId, categoryName from dutyLeaveCategoryAssignedStaff cas inner join dutyLeaveCategory dlc on cas.dutyLeaveCategoryId = dlc.id where staffId = $staffId"; | |
try { | |
$categoryDetails = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
return $categoryDetails; | |
} | |
/** | |
* get staff assigned leave types by staffId | |
* @param int $staffId | |
* @throws ProfessionalException | |
* @return object|array|\com\linways\base\util\$objectList[] | |
*/ | |
public function getStaffAssignedLeaveTypeByStaffId($staffId) | |
{ | |
$staffId = $this->realEscapeString($staffId); | |
$sql = "select distinct slt.id, slt.code, slt.name, staffId from student_leave_type slt left join dutyLeaveCategory dlc on dlc.leaveTypeId=slt.id left join dutyLeaveCategoryAssignedStaff cas on cas.dutyLeaveCategoryId = dlc.id where staffId = $staffId and slt.isActive=1 order by slt.id"; | |
try { | |
$leaveTypes = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException( $e->getCode (), $e->getMessage ()); | |
} | |
return $leaveTypes; | |
} | |
} |