Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 223 |
SubjectGroupMappingService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 9 |
1892.00 | |
0.00% |
0 / 223 |
saveSubjectGroupMapping | |
0.00% |
0 / 1 |
72.00 | |
0.00% |
0 / 23 |
|||
validateSaveSubjectGroupMapping | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 3 |
|||
insertSubjectGroupMapping | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 17 |
|||
updateSubjectGroupMapping | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 18 |
|||
deleteSubjectGroupMapping | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 18 |
|||
getAllSubjectDetails | |
0.00% |
0 / 1 |
110.00 | |
0.00% |
0 / 68 |
|||
getSubjectGroupMapping | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 19 |
|||
getAllSubjectGroups | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 15 |
|||
getSubjectGroupSubjectsByRequest | |
0.00% |
0 / 1 |
56.00 | |
0.00% |
0 / 42 |
<?php | |
namespace com\linways\ec\core\service; | |
use com\linways\base\util\MakeSingletonTrait; | |
use com\linways\base\util\SecurityUtils; | |
use com\linways\ec\core\constant\StatusConstants; | |
use com\linways\ec\core\exception\ExamControllerException; | |
class SubjectGroupMappingService extends BaseService{ | |
use MakeSingletonTrait; | |
/** | |
* Save Subject group Mapping | |
* @param $saveSubjectGroupArray | |
* @return $id | |
*/ | |
public function saveSubjectGroupMapping($saveSubjectGroupArray){ | |
$saveSubjectGroupArray = $this->realEscapeArray($saveSubjectGroupArray); | |
foreach($saveSubjectGroupArray as $saveSubjectGroup){ | |
$saveSubjectGroup->createdBy = $GLOBALS['userId'] ?? $saveSubjectGroup->createdBy; | |
$saveSubjectGroup->updatedBy = $GLOBALS['userId'] ?? $saveSubjectGroup->updatedBy; | |
try { | |
$this->validateSaveSubjectGroupMapping($saveSubjectGroup); | |
if (!empty($saveSubjectGroup->id)) { | |
$saveSubjectGroup->id = $this->updateSubjectGroupMapping($saveSubjectGroup); | |
} else { | |
$saveSubjectGroup->id = $this->insertSubjectGroupMapping($saveSubjectGroup); | |
} | |
} catch (\Exception $e) { | |
if ($e->getCode() !== ExamControllerException::INVALID_PARAMETERS && $e->getCode() !== ExamControllerException::EMPTY_PARAMETERS && $e->getCode() !== "DUPLICATE_ENTRY") { | |
throw new ExamControllerException($e->getCode(), "Failed to save subject group! Please try again"); | |
} else if ($e->getCode() === ExamControllerException::DUPLICATE_ENTRY) { | |
throw new ExamControllerException(ExamControllerException::DUPLICATE_ENTRY, "Cannot assign subject group.This subject group already assign in this batch"); | |
} else { | |
throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
} | |
} | |
} | |
return true; | |
} | |
/** | |
* validate Save Subject Group Mapping | |
* @param $saveSubjectGroup | |
* @return NULL | |
*/ | |
private function validateSaveSubjectGroupMapping($saveSubjectGroup){ | |
if (empty($saveSubjectGroup->groupId) || empty($saveSubjectGroup->academicPaperSubjectId) || empty($saveSubjectGroup->subjectGroupId)) | |
throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS, " empty parameter. can't save subject group! "); | |
} | |
/** | |
* insert Subject Group Mapping | |
* @param $saveSubjectGroup | |
* @return $id | |
*/ | |
private function insertSubjectGroupMapping($saveSubjectGroup){ | |
$properties = !empty($saveSubjectGroup->properties) ? "'" . json_encode($saveSubjectGroup->properties) . "'" : "NULL"; | |
$query = "INSERT INTO ec_subject_group_paper_subject_mapping | |
(groups_id,cm_academic_paper_subjects_id,subject_groups_id,properties,created_by,updated_by) | |
VALUES | |
('$saveSubjectGroup->groupId','$saveSubjectGroup->academicPaperSubjectId','$saveSubjectGroup->subjectGroupId',$properties,'$saveSubjectGroup->createdBy','$saveSubjectGroup->updatedBy') | |
ON DUPLICATE KEY | |
UPDATE | |
updated_by = VALUES(created_by), | |
subject_groups_id = VALUES(subject_groups_id), | |
properties = VALUES(properties)"; | |
try { | |
$saveSubjectGroup->id = $this->executeQuery($query,true)->id; | |
return $saveSubjectGroup->id; | |
} catch (\Exception $e) { | |
throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
} | |
} | |
/** | |
* update Subject Group Mapping | |
* @param $saveSubjectGroup | |
* @return $saveSubjectGroup->id | |
*/ | |
private function updateSubjectGroupMapping($saveSubjectGroup){ | |
$properties = !empty($saveSubjectGroup->properties) ? "'".json_encode($saveSubjectGroup->properties)."'" : "NULL"; | |
$query = "UPDATE | |
ec_subject_group_paper_subject_mapping | |
SET | |
groups_id = '$saveSubjectGroup->groupId', | |
cm_academic_paper_subjects_id = '$saveSubjectGroup->academicPaperSubjectId', | |
subject_groups_id = '$saveSubjectGroup->subjectGroupId', | |
properties = $properties, | |
updated_by = '$saveSubjectGroup->updatedBy' | |
WHERE | |
id = '$saveSubjectGroup->id'"; | |
try { | |
$this->executeQuery($query); | |
return $saveSubjectGroup->id; | |
} catch (\Exception $e) { | |
throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
} | |
} | |
/** | |
* Delete Subject Group Mapping | |
* @param String $id | |
* @return NULL | |
*/ | |
public function deleteSubjectGroupMapping($id){ | |
$id = $this->realEscapeString($id); | |
$staffId = $GLOBALS['userId']; | |
$subjectGroupMapping = new \stdClass(); | |
$subjectGroupMapping->id = $id; | |
$currentSubjectGroupMapping = reset($this->getSubjectGroupMapping($subjectGroupMapping)); | |
if(empty($currentSubjectGroupMapping)){ | |
throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS,"Can't delete ! subject group missing."); | |
} | |
$query = "DELETE FROM | |
ec_subject_group_paper_subject_mapping | |
WHERE | |
id = '$id'"; | |
try { | |
$this->executeQuery($query); | |
}catch (\Exception $e) { | |
throw new ExamControllerException(ExamControllerException::HAVE_RELATION,"Error deleting subject groups! Please try again"); | |
} | |
} | |
/** | |
* get All Subject Details | |
* @param $searchRequest | |
* @return $academicPapers | |
* @author Krishnajith | |
*/ | |
public function getAllSubjectDetails($searchRequest) { | |
$academicPapers = []; | |
$searchRequest = $this->realEscapeObject($searchRequest); | |
try{ | |
$orderBy = " ORDER BY sub.name ASC"; | |
$whereQuery = ""; | |
if(!empty($searchRequest->groupId)) { | |
$groupIdString = is_array($searchRequest->groupId) ? "'" . implode("','",$searchRequest->groupId) . "'" : "'".$searchRequest->groupId."'"; | |
$whereQuery .= " AND g.id IN ( $groupIdString )"; | |
} | |
if(!empty($searchRequest->programId)) { | |
$programIdString = is_array($searchRequest->programId) ? "'" . implode("','",$searchRequest->programId) . "'" : "'".$searchRequest->programId."'"; | |
$whereQuery .= " AND p.id IN ( $programIdString )"; | |
} | |
if(!empty($searchRequest->academicTermId)) { | |
$academicTermIdString = is_array($searchRequest->academicTermId) ? "'" . implode("','",$searchRequest->academicTermId) . "'" : "'".$searchRequest->academicTermId."'"; | |
$whereQuery .= " AND act.id IN ( $academicTermIdString )"; | |
} | |
$query = "SELECT DISTINCT | |
g.id AS groupId, | |
g.name AS groupName, | |
g.properties ->>'$.programId' AS programId, | |
aps.id AS academicPaperSubjectId, | |
aps.cm_academic_paper_id as academicPaperId, | |
ap.name as academicPaperName, | |
sub.id AS subjectId, | |
sub.name AS subjectName, | |
sub.code AS subjectCode, | |
act.name as academicTermName, | |
act.id as academicTermId, | |
esgpsm.id as subjectGroupMappingId, | |
esgpsm.subject_groups_id as subjectGroupId | |
FROM | |
`groups` g | |
INNER JOIN `program` p | |
ON p.id = g.properties->>'$.programId' | |
INNER JOIN groups_relations gr ON | |
gr.parent_groups_id = g.id | |
INNER JOIN `groups` sg ON | |
sg.id = gr.child_groups_id AND sg.type = 'SUBJECT' | |
INNER JOIN cm_academic_paper_subjects aps ON | |
aps.id = sg.paperSubjectId | |
INNER JOIN cm_academic_paper ap ON | |
aps.cm_academic_paper_id = ap.id | |
INNER JOIN academic_term act ON | |
act.id = sg.academic_term_id | |
INNER JOIN v4_ams_subject sub ON | |
sub.id = aps.ams_subject_id | |
LEFT JOIN ec_subject_group_paper_subject_mapping esgpsm ON | |
esgpsm.groups_id = g.id AND esgpsm.cm_academic_paper_subjects_id = aps.id | |
WHERE 1=1 "; | |
$subjectDetails = $this->executeQueryForList($query.$whereQuery.$orderBy); | |
} | |
catch (\Exception $e){ | |
throw new ExamControllerException($e->getCode(),$e->getMessage()); | |
} | |
foreach($subjectDetails as $academicPaper){ | |
$academicPapers[$academicPaper->academicPaperId]->id = $academicPaper->academicPaperId; | |
$academicPapers[$academicPaper->academicPaperId]->name = $academicPaper->academicPaperName; | |
$academicPapers[$academicPaper->academicPaperId]->subjectGroupId = $academicPaper->subjectGroupId; | |
$academicPapers[$academicPaper->academicPaperId]->subjects[$academicPaper->academicPaperSubjectId]= $academicPaper; | |
} | |
foreach($academicPapers as $academicPaper){ | |
$academicPaper->isExpand = false; | |
$academicPaper->subjects = array_values($academicPaper->subjects); | |
} | |
$academicPapers = array_values($academicPapers); | |
return $academicPapers; | |
} | |
/** | |
* get all subject groups | |
* @return $subjectGroups | |
*/ | |
public function getSubjectGroupMapping($searchRequest){ | |
$searchRequest = $this->realEscapeObject($searchRequest); | |
if(!empty($searchRequest->id)) { | |
$whereQuery .= " AND id = '$searchRequest->id' "; | |
} | |
try { | |
$query = "SELECT | |
DISTINCT | |
id, | |
groups_id, | |
cm_academic_paper_subjects_id, | |
subject_groups_id | |
FROM | |
ec_subject_group_paper_subject_mapping "; | |
$subjectGroups = $this->executeQueryForList($query); | |
} catch (\Exception $e) { | |
throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
} | |
return $subjectGroups; | |
} | |
/** | |
* get all subject groups | |
* @return $subjectGroups | |
*/ | |
public function getAllSubjectGroups(){ | |
try { | |
$query = "SELECT | |
DISTINCT | |
sg.id , | |
sg.name, | |
sg.code, | |
sg.properties | |
FROM | |
subjectGroups sg "; | |
$subjectGroups = $this->executeQueryForList($query); | |
} catch (\Exception $e) { | |
throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
} | |
return $subjectGroups; | |
} | |
/** | |
* get All Subject Details | |
* @param $searchRequest | |
* @return $academicPapers | |
* @author Krishnajith | |
*/ | |
public function getSubjectGroupSubjectsByRequest($searchRequest) { | |
$academicPapers = []; | |
$searchRequest = $this->realEscapeObject($searchRequest); | |
try{ | |
$whereQuery = ""; | |
if(!empty($searchRequest->groupId)) { | |
$groupIdString = is_array($searchRequest->groupId) ? "'" . implode("','",$searchRequest->groupId) . "'" : "'".$searchRequest->groupId."'"; | |
$whereQuery .= " AND esgpsm.groups_id IN ( $groupIdString )"; | |
} | |
if(!empty($searchRequest->subjectCategoryCode)) { | |
$whereQuery .= " AND sg.code = '$searchRequest->subjectCategoryCode'"; | |
} | |
if(!empty($searchRequest->academicTermId)) { | |
$academicTermIdString = is_array($searchRequest->academicTermId) ? "'" . implode("','",$searchRequest->academicTermId) . "'" : "'".$searchRequest->academicTermId."'"; | |
$whereQuery .= " AND eerb.academicTermId IN ( $academicTermIdString )"; | |
} | |
$query = "SELECT | |
esgpsm.id, | |
esgpsm.groups_id AS groupId, | |
esgpsm.cm_academic_paper_subjects_id AS paperSubjectId, | |
eerb.academicTermId, | |
esgpsm.subject_groups_id AS subjectGroupId | |
FROM | |
ec_subject_group_paper_subject_mapping esgpsm | |
INNER JOIN subjectGroups sg ON | |
sg.id = esgpsm.subject_groups_id | |
INNER JOIN ec_exam_registration_batch eerb ON | |
eerb.groups_id = esgpsm.groups_id | |
INNER JOIN ec_exam_registration eer ON | |
eer.id =eerb.ec_exam_registration_id | |
INNER JOIN ec_exam_registration_subject eers ON | |
eers.cm_academic_paper_subjects_id = esgpsm .cm_academic_paper_subjects_id AND | |
eers.ec_exam_registration_batch_id = eerb.id | |
WHERE | |
eer.`type` = 'REGULAR' AND | |
eer.trashed IS NULL"; | |
$subjectDetails = $this->executeQueryForList($query.$whereQuery); | |
} | |
catch (\Exception $e){ | |
throw new ExamControllerException($e->getCode(),$e->getMessage()); | |
} | |
return $subjectDetails; | |
} | |
} |