| Code Coverage | ||||||||||
| Classes and Traits | Functions and Methods | Lines | ||||||||
| Total |  | 0.00% | 0 / 1 |  | 0.00% | 0 / 19 | CRAP |  | 0.00% | 0 / 274 | 
| PoGroupService |  | 0.00% | 0 / 1 |  | 0.00% | 0 / 19 | 2550.00 |  | 0.00% | 0 / 274 | 
| __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 | |||
| createNewPoGroup |  | 0.00% | 0 / 1 | 6.00 |  | 0.00% | 0 / 12 | |||
| updatePoGroup |  | 0.00% | 0 / 1 | 6.00 |  | 0.00% | 0 / 10 | |||
| deletePoGroupById |  | 0.00% | 0 / 1 | 6.00 |  | 0.00% | 0 / 10 | |||
| addPoToPoGroup |  | 0.00% | 0 / 1 | 6.00 |  | 0.00% | 0 / 11 | |||
| checkIfPoAlreadyAddedToPo |  | 0.00% | 0 / 1 | 12.00 |  | 0.00% | 0 / 13 | |||
| addBatchToPoGroup |  | 0.00% | 0 / 1 | 6.00 |  | 0.00% | 0 / 11 | |||
| addBatchListToPoGroup |  | 0.00% | 0 / 1 | 12.00 |  | 0.00% | 0 / 15 | |||
| removeBatchFromPoGroup |  | 0.00% | 0 / 1 | 6.00 |  | 0.00% | 0 / 11 | |||
| removeAllBatchFromPoGroup |  | 0.00% | 0 / 1 | 6.00 |  | 0.00% | 0 / 11 | |||
| searchPoGroup |  | 0.00% | 0 / 1 | 90.00 |  | 0.00% | 0 / 57 | |||
| getBatchDetailsByGroupIds |  | 0.00% | 0 / 1 | 6.00 |  | 0.00% | 0 / 18 | |||
| getBatchDetailsByGroupId |  | 0.00% | 0 / 1 | 6.00 |  | 0.00% | 0 / 17 | |||
| getGroupDetailsById |  | 0.00% | 0 / 1 | 6.00 |  | 0.00% | 0 / 11 | |||
| getPoListByGroupId |  | 0.00% | 0 / 1 | 42.00 |  | 0.00% | 0 / 18 | |||
| getGroupDetailsByBatchId |  | 0.00% | 0 / 1 | 6.00 |  | 0.00% | 0 / 18 | |||
| getBatchesListForAddingToGroup |  | 0.00% | 0 / 1 | 12.00 |  | 0.00% | 0 / 21 | |||
| <?php | |
| namespace com\linways\core\ams\professional\service\nba; | |
| use com\linways\core\ams\professional\service\BaseService; | |
| use com\linways\core\ams\professional\exception\ProfessionalException; | |
| use com\linways\core\ams\professional\mapper\nba\PoGroupServiceMapper; | |
| use com\linways\core\ams\professional\request\nba\SearchPoGroupRequest; | |
| class PoGroupService 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 = PoGroupServiceMapper::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; | |
| } | |
| /** | |
| * Undocumented function | |
| * | |
| * @param PoGroup $poGroup | |
| * @return void | |
| */ | |
| public function createNewPoGroup($poGroup) | |
| { | |
| $poGroup = $this->realEscapeObject($poGroup); | |
| $sql = ""; | |
| $id = null; | |
| $sql = "INSERT INTO nba_po_group(name, description, dept_id, created_by, created_date, updated_by, updated_date) VALUES('$poGroup->name', '$poGroup->description', '$poGroup->deptId', $poGroup->createdBy, UTC_TIMESTAMP(), $poGroup->updatedBy, UTC_TIMESTAMP())"; | |
| try { | |
| $id = $this->executeQuery($sql, true); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $id; | |
| } | |
| /** | |
| * Undocumented function | |
| * | |
| * @param PoGroup $poGroup | |
| * @return void | |
| */ | |
| public function updatePoGroup($poGroup){ | |
| $poGroup = $this->realEscapeObject($poGroup); | |
| $sql = ""; | |
| $sql = "UPDATE nba_po_group SET name = '$poGroup->name', description= '$poGroup->description', updated_by = '$poGroup->updatedBy' WHERE id = $poGroup->id"; | |
| try { | |
| $this->executeQuery($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $poGroup; | |
| } | |
| /** | |
| * Undocumented function | |
| * | |
| * @param integer $groupId | |
| * @return void | |
| */ | |
| public function deletePoGroupById($groupId){ | |
| $groupId = $this->realEscapeString($groupId); | |
| $sql = ""; | |
| $sql = "DELETE FROM nba_po_group WHERE id = '$groupId'"; | |
| try { | |
| $this->executeQuery($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return true; | |
| } | |
| /** | |
| * Undocumented function | |
| * | |
| * @param [type] $poList | |
| * @return void | |
| */ | |
| public function addPoToPoGroup($poGroupToPoMapping){ | |
| $poGroupToPoMapping = $this->realEscapeObject($poGroupToPoMapping); | |
| $sql = ""; | |
| $id = null; | |
| $sql = "INSERT INTO nba_po_group_to_po_mapping(po_id, nba_po_group_id, created_by, created_date, updated_by, updated_date) VALUES($poGroupToPoMapping->poId, $poGroupToPoMapping->groupId, $poGroupToPoMapping->createdBy, UTC_TIMESTAMP(), $poGroupToPoMapping->updatedBy, UTC_TIMESTAMP())"; | |
| try{ | |
| $id = $this->executeQueryForObject($sql, true); | |
| }catch(\Exception $e){ | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $id; | |
| } | |
| /** | |
| * Return true if the given group contains a po | |
| * | |
| * @param [PoGroupToPoMapping] $poGroup | |
| * @return void | |
| */ | |
| public function checkIfPoAlreadyAddedToPo($poGroupToPoMapping){ | |
| $sql = ""; | |
| $id = null; | |
| $sql = "SELECT id FROM nba_po_group_to_po_mapping WHERE po_id = $poGroupToPoMapping->poId"; | |
| try{ | |
| $id = $this->executeQueryForObject($sql); | |
| }catch(\Exception $e){ | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| if(!empty($id)){ | |
| return true; | |
| } | |
| return false; | |
| } | |
| /** | |
| * Undocumented function | |
| * | |
| * @param PoGroupToBatchMapping $batchesList | |
| * @return void | |
| */ | |
| public function addBatchToPoGroup($batchMapping){ | |
| $batchMapping = $this->realEscapeObject($batchMapping); | |
| $sql = ""; | |
| $id = null; | |
| $sql = "INSERT INTO nba_po_group_to_batches_mapping(nba_po_group_id, batch_id, created_by, created_date, updated_by, updated_date) VALUES('$batchMapping->groupId', '$batchMapping->batchId', '$batchMapping->createdBy', UTC_TIMESTAMP(), '$batchMapping->updatedBy', UTC_TIMESTAMP())"; | |
| try{ | |
| $id = $this->executeQueryForObject($sql, true); | |
| }catch(\Exception $e){ | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $id; | |
| } | |
| /** | |
| * Undocumented function | |
| * | |
| * @param [PoGroupToBatchMapping] $batchesList | |
| * @return void | |
| */ | |
| public function addBatchListToPoGroup($batchMappingList){ | |
| $batchMappingList = $this->realEscapeObject($batchMappingList); | |
| $sql = ""; | |
| $values = []; | |
| $sql = "INSERT INTO nba_po_group_to_batches_mapping(nba_po_group_id, batch_id, created_by, created_date, updated_by, updated_date) VALUES "; | |
| $values = []; | |
| foreach($batchMappingList as $batchMapping){ | |
| $values[] = "('$batchMapping->groupId', '$batchMapping->batchId', '$batchMapping->createdBy', UTC_TIMESTAMP(), '$batchMapping->updatedBy', UTC_TIMESTAMP())"; | |
| } | |
| $sql .= implode(',', $values); | |
| try{ | |
| $this->executeQuery($sql); | |
| }catch(\Exception $e){ | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| /** | |
| * Undocumented function | |
| * | |
| * @param [PoGroupToBatchMapping] $batchMapping | |
| * @return void | |
| */ | |
| public function removeBatchFromPoGroup($batchMapping){ | |
| $batchMapping = $this->realEscapeObject($batchMapping); | |
| $sql = ""; | |
| $values = []; | |
| $sql = "DELETE FROM nba_po_group_to_batches_mapping WHERE nba_po_group_id = $batchMapping->groupId AND batch_id = $batchMapping->batchId"; | |
| try{ | |
| $this->executeQuery($sql); | |
| }catch(\Exception $e){ | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return true; | |
| } | |
| /** | |
| * Undocumented function | |
| * | |
| * @param [PoGroupToBatchMapping] $batchMapping | |
| * @return void | |
| */ | |
| public function removeAllBatchFromPoGroup($batchMapping){ | |
| $batchMapping = $this->realEscapeObject($batchMapping); | |
| $sql = ""; | |
| $values = []; | |
| $sql = "DELETE FROM nba_po_group_to_batches_mapping WHERE nba_po_group_id = $batchMapping->groupId"; | |
| try{ | |
| $this->executeQuery($sql); | |
| }catch(\Exception $e){ | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return true; | |
| } | |
| /** | |
| * Undocumented function | |
| * | |
| * @param SearchPoGroupRequest $request | |
| * @return void | |
| */ | |
| public function searchPoGroup($request){ | |
| $request = $this->realEscapeObject($request); | |
| $ids = implode("','", $request->groupIds); | |
| $sql = "SELECT | |
| npg.id AS npg_id, | |
| npg.name AS npg_name, | |
| npg.description AS npg_description, | |
| npgm.id AS npgm_id, | |
| npgm.nba_po_group_id AS npgm_nba_po_group_id, | |
| bat.batchID AS batchId, | |
| bat.batchName, | |
| bat.batchDesc, | |
| bat.semID as semId, | |
| po.id AS poId, | |
| po.poCode, | |
| po.poName, | |
| po.poDesc, | |
| po.order_no, | |
| po.isPSO | |
| FROM | |
| nba_po_group npg | |
| LEFT JOIN | |
| nba_po_group_to_po_mapping npgm ON npgm.nba_po_group_id = npg.id | |
| LEFT JOIN | |
| nba_po_group_to_batches_mapping npbm ON npbm.nba_po_group_id = npg.id | |
| LEFT JOIN | |
| batches bat ON bat.batchID = npbm.batch_id | |
| LEFT JOIN | |
| nba_program_outcome po ON po.id = npgm.po_id WHERE npg.id IS NOT NULL "; | |
| $groupList = []; | |
| if(!empty($request->createdBy)){ | |
| $sql .= "AND npg.created_by = $request->createdBy"; | |
| } | |
| if(!empty($request->groupId)){ | |
| $sql .= "AND npg.id = $request->groupId"; | |
| } | |
| if(!empty($request->groupIds)){ | |
| $sql .= "AND npg.id in ('".$ids."')"; | |
| } | |
| if(!empty($request->deptId)){ | |
| $sql .= "AND npg.dept_id = $request->deptId"; | |
| } | |
| if(!empty($request->isSeparatePso)){ | |
| if($request->isSeparatePso == 1){ | |
| $sql .= "AND po.isPSO=0"; | |
| } | |
| if($request->isSeparatePso == 2){ | |
| $sql .= "AND po.isPSO=1"; | |
| } | |
| } | |
| $sql .= " ORDER BY npg.id, po.order_no"; | |
| try{ | |
| $groupList = $this->executeQueryForList($sql, $this->mapper[PoGroupServiceMapper::SEARCH_PO_GROUP]); | |
| }catch(\Exception $e){ | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $groupList; | |
| } | |
| public function getBatchDetailsByGroupIds($groupIds){ | |
| $sql = ""; | |
| $groupIds = $this->realEscapeArray($groupIds); | |
| $ids = implode("','", $groupIds); | |
| $sql = "SELECT | |
| nbm.nba_po_group_id, nbm.batch_id as batchId, batches.batchName, batches.semID as semId | |
| FROM | |
| nba_po_group_to_batches_mapping nbm | |
| INNER JOIN | |
| batches ON (batches.batchID = nbm.batch_id) | |
| WHERE | |
| nbm.nba_po_group_id IN ('".$ids."')"; | |
| try{ | |
| $batchesByGroupIds = $this->executeQueryForList($sql); | |
| }catch(\Exception $e){ | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $batchesByGroupIds; | |
| } | |
| public function getBatchDetailsByGroupId($groupId){ | |
| $sql = ""; | |
| $groupId = $this->realEscapeString($groupId); | |
| $sql = "SELECT | |
| nbm.nba_po_group_id, nbm.batch_id as batchId, batches.batchName, batches.semID as semId | |
| FROM | |
| nba_po_group_to_batches_mapping nbm | |
| INNER JOIN | |
| batches ON (batches.batchID = nbm.batch_id) | |
| WHERE | |
| nbm.nba_po_group_id = $groupId "; | |
| try{ | |
| $batchesByGroupIds = $this->executeQueryForList($sql); | |
| }catch(\Exception $e){ | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $batchesByGroupIds; | |
| } | |
| /** | |
| * Undocumented function | |
| * | |
| * @param integer $groupId | |
| * @return void | |
| */ | |
| public function getGroupDetailsById($groupId){ | |
| $sql = ""; | |
| $groupDetails = null; | |
| $groupId = $this->realEscapeString($groupId); | |
| $sql = "SELECT id, name, description, dept_id as deptId FROM nba_po_group WHERE id = $groupId "; | |
| try{ | |
| $groupDetails = $this->executeQueryForObject($sql); | |
| }catch(\Exception $e){ | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $groupDetails; | |
| } | |
| /** | |
| * Undocumented function | |
| * | |
| * @param integer $groupId | |
| * @return void | |
| */ | |
| public function getPoListByGroupId($groupId, $includePo = true, $includePso = true){ | |
| $sql = ""; | |
| $poList = []; | |
| $groupId = $this->realEscapeString($groupId); | |
| $sql = "SELECT po.id, po.poName as name, po.poDesc as description, po.poCode as code, po.isPSO, po.order_no as orderNo FROM nba_program_outcome po INNER JOIN nba_po_group_to_po_mapping npm ON npm.po_id = po.id WHERE npm.nba_po_group_id = '$groupId' "; | |
| if($includePo && !$includePso){ | |
| $sql .= " AND po.isPso = 0 "; | |
| } | |
| if(!$includePo && $includePso){ | |
| $sql .= " AND po.isPso = 1 "; | |
| } | |
| $sql .= " ORDER BY po.order_no"; | |
| try{ | |
| $poList = $this->executeQueryForList($sql); | |
| }catch(\Exception $e){ | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $poList; | |
| } | |
| /** | |
| * Undocumented function | |
| * | |
| * @param integer $batchId | |
| * @return void | |
| */ | |
| public function getGroupDetailsByBatchId($batchId){ | |
| $sql = ""; | |
| $batchId = $this->realEscapeString($batchId); | |
| $group = null; | |
| $sql = "SELECT | |
| npg.id, npg.name, npg.description, npg.dept_id | |
| FROM | |
| nba_po_group npg | |
| INNER JOIN | |
| nba_po_group_to_batches_mapping nbm ON nbm.nba_po_group_id = npg.id | |
| WHERE | |
| nbm.batch_id = '$batchId'"; | |
| try{ | |
| $group = $this->executeQueryForObject($sql); | |
| }catch(\Exception $e){ | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $group; | |
| } | |
| /** | |
| * Undocumented function | |
| * | |
| * @param GetBatchesListForPoGroupRequest $request | |
| * @return void | |
| */ | |
| public function getBatchesListForAddingToGroup($request){ | |
| $sql = ""; | |
| $batchList = []; | |
| $request = $this->realEscapeObject($request); | |
| $sql = " SELECT batchID as id, | |
| batchName as name, | |
| batchDesc as description, | |
| batchStartYear as startYear, | |
| batchEndYear as endYear, | |
| batchCreateTime as createdDate, | |
| semID as currentSemId | |
| FROM batches WHERE deptID = '$request->deptId' AND batchID NOT IN (SELECT DISTINCT batch_id FROM nba_po_group_to_batches_mapping WHERE nba_po_group_id <>'$request->groupId')"; | |
| if(!empty($request->batchName)){ | |
| $sql .= " AND (batchName LIKE '%$request->batchName%' OR batchDesc LIKE '%$request->batchName%')"; | |
| } | |
| try{ | |
| $batchList = $this->executeQueryForList($sql); | |
| }catch(\Exception $e){ | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $batchList; | |
| } | |
| } |