Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 231 |
BatchPaperSubjectService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 9 |
1560.00 | |
0.00% |
0 / 231 |
__construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
insertBatchPaperSubject | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 14 |
|||
updateBatchPaperSubject | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 18 |
|||
deleteBatchPaperSubject | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 18 |
|||
restoreStream | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 18 |
|||
searchStream | |
0.00% |
0 / 1 |
72.00 | |
0.00% |
0 / 40 |
|||
getStreamDetails | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 24 |
|||
getAllSubjectsByGroupIdAndSemId | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 35 |
|||
searchBatchPaperSubject | |
0.00% |
0 / 1 |
132.00 | |
0.00% |
0 / 62 |
<?php | |
namespace com\linways\core\ams\professional\service\academic; | |
use com\linways\base\util\SecurityUtils; | |
use com\linways\base\util\MakeSingletonTrait; | |
use com\linways\core\ams\professional\service\BaseService; | |
use com\linways\core\ams\professional\exception\ProfessionalException; | |
use com\linways\core\ams\professional\mapper\academic\BatchPaperSubjectServiceMapper; | |
use com\linways\core\ams\professional\request\academic\BatchPaperSubjectServiceRequest; | |
use com\linways\core\ams\professional\constant\academic\StatusConstants; | |
use com\linways\core\ams\professional\dto\api\BatchPaperSubject; | |
use com\linways\core\ams\professional\mapper\academic\StreamServiceMapper; | |
use com\linways\core\ams\professional\request\academic\SearchBatchPaperSubjectRequest; | |
use com\linways\core\ams\professional\request\academic\SearchStreamRequest; | |
class BatchPaperSubjectService extends BaseService | |
{ | |
use MakeSingletonTrait; | |
private function __construct() { | |
$this->mapper = BatchPaperSubjectServiceMapper::getInstance()->getMapper(); | |
} | |
/** | |
* Insert Stream | |
* @param BatchPaperSubject $batchpapersubject | |
* @return String $id | |
*/ | |
public function insertBatchPaperSubject(BatchPaperSubject $batchpapersubject) | |
{ | |
$properties = !empty($batchpapersubject->properties) ? "'" . json_encode($batchpapersubject->properties) . "'" : "NULL"; | |
$id = SecurityUtils::getRandomString(); | |
$query = "INSERT INTO `batch_paper_subject` | |
(`id`,`group_id`,`paper_subject_id`,`properties`,`created_by`,`updated_by`) | |
VALUES | |
('$id','$batchpapersubject->groupId','$batchpapersubject->paperSubjectId',$properties,'$batchpapersubject->createdBy','$batchpapersubject->updatedBy')"; | |
try { | |
$this->executeQuery($query); | |
return $id; | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
} | |
} | |
/** | |
* Update Stream | |
* @param BatchPaperSubject $batchpapersubject | |
* @return String $batchpapersubject->id | |
*/ | |
public function updateBatchPaperSubject(BatchPaperSubject $batchpapersubject) | |
{ | |
$properties = !empty($batchpapersubject->properties) ? "'".json_encode($batchpapersubject->properties)."'" : "NULL"; | |
$query = "UPDATE | |
`batch_paper_subject` | |
SET | |
`group_id` = '$batchpapersubject->groupId', | |
`paper_subject_id` = '$batchpapersubject->paperSubjectId', | |
`properties` = $properties, | |
`updated_by` = '$batchpapersubject->updatedBy' | |
WHERE | |
`id` = '$batchpapersubject->id'"; | |
try { | |
$this->executeQuery($query); | |
return $batchpapersubject->id; | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
} | |
} | |
/** | |
* Delete Stream (Soft Delete) | |
* @param String $id | |
* @return NULL | |
*/ | |
public function deleteBatchPaperSubject($id) | |
{ | |
$id = $this->realEscapeString($id); | |
$updatedBy = $GLOBALS['userId']; | |
if(empty($id)) | |
throw new ProfessionalException(ProfessionalException::EMPTY_PARAMETERS,"BatchPaperSubject is invalid! Please enter a valid BatchPaperSubject"); | |
$query = "UPDATE | |
`batch_paper_subject` | |
SET | |
`trashed` = UTC_TIMESTAMP(), | |
`updated_by` = '$updatedBy' | |
WHERE | |
id = '$id'"; | |
try { | |
$this->executeQuery($query); | |
} catch (\Exception $e) { | |
throw new ProfessionalException(ProfessionalException::ERROR_DELETING,"Error deleting BatchPaperSubject! Please try again"); | |
} | |
} | |
/** | |
* Restore Stream | |
* @param String $id | |
* @return NULL | |
*/ | |
public function restoreStream($id) | |
{ | |
$id = $this->realEscapeString($id); | |
$updatedBy = $GLOBALS['userId']; | |
if(empty($id)) | |
throw new ProfessionalException(ProfessionalException::EMPTY_PARAMETERS,"Stream is invalid! Please enter a valid stream"); | |
$query = "UPDATE | |
`stream` | |
SET | |
`trashed` = NULL, | |
`updated_by` = '$updatedBy' | |
WHERE | |
`id` = '$id'"; | |
try { | |
$this->executeQuery($query); | |
} catch (\Exception $e) { | |
throw new ProfessionalException(ProfessionalException::ERROR_RESTORING,"Error restoring academic term! Please try again"); | |
} | |
} | |
/** | |
* Search Academic term Details | |
* @param SearchStreamRequest $request | |
* @return Stream | |
*/ | |
public function searchStream(SearchStreamRequest $request) | |
{ | |
$request = $this->realEscapeObject($request); | |
$whereQuery = ""; | |
$limitQuery = ""; | |
if(!empty($request->id)) { | |
$whereQuery .= " AND st.id='$request->id' "; | |
} | |
if($request->trashed === StatusConstants::ACTIVE) { | |
$whereQuery .= " AND st.trashed IS NULL "; | |
} | |
if($request->trashed === StatusConstants::TRASHED) { | |
$whereQuery .= " AND st.trashed IS NOT NULL "; | |
} | |
if(!empty($request->name)) { | |
$whereQuery .= " AND st.name LIKE '%$request->name%' "; | |
} | |
if($request->startIndex !== "" && $request->endIndex !== "") | |
{ | |
$limitQuery .= " LIMIT $request->startIndex,$request->endIndex"; | |
} | |
$query = "SELECT | |
st.id, | |
st.name, | |
st.properties, | |
st.trashed, | |
st.created_by, | |
st.created_date, | |
st.updated_by, | |
st.updated_date | |
FROM | |
`stream` st | |
WHERE | |
1 = 1"; | |
try { | |
$streams = $this->executeQueryForList($query.$whereQuery.$limitQuery, $this->mapper[StreamServiceMapper::SEARCH_STREAMS]); | |
} catch (\Exception $e) { | |
throw new ProfessionalException(ProfessionalException::ERROR_FETCHING,"Cannot fetch stream details! Please try again."); | |
} | |
return $streams; | |
} | |
/** | |
* get Academic term by id | |
* @param String $id | |
* @return Stream | |
*/ | |
public function getStreamDetails($id) | |
{ | |
$id = $this->realEscapeObject($id); | |
if(empty($id)) | |
throw new ProfessionalException(ProfessionalException::EMPTY_PARAMETERS,"Stream is invalid! Please enter a valid stream"); | |
$query = "SELECT | |
st.id, | |
st.name, | |
st.properties, | |
st.trashed, | |
st.created_by, | |
st.created_date, | |
st.updated_by, | |
st.updated_date | |
FROM | |
`stream` st | |
WHERE | |
`id` = '$id'"; | |
try { | |
$stream = $this->executeQueryForObject($query,false, $this->mapper[StreamServiceMapper::SEARCH_STREAMS]); | |
} catch (\Exception $e) { | |
throw new ProfessionalException(ProfessionalException::ERROR_FETCHING,"Cannot fetch stream details! Please try again"); | |
} | |
return $stream; | |
} | |
public function getAllSubjectsByGroupIdAndSemId($groupId = null,$academicTermId = null) | |
{ | |
$whereQuery = ""; | |
if(!empty($groupId)) { | |
$whereQuery .= " AND bps.groups_id = '$groupId' "; | |
} | |
if(!empty($academicTermId)) { | |
$whereQuery .= " AND sats.academic_term_id='$academicTermId'"; | |
} | |
$query = "SELECT | |
distinct aps.id as id, | |
s.subjectDesc as name | |
FROM | |
batch_paper_subject bps | |
INNER JOIN | |
cm_academic_paper_subjects aps ON bps.cm_academic_paper_subjects_id = aps.id | |
INNER JOIN | |
subjects s ON aps.subject_id = s.subjectID | |
INNER JOIN | |
cm_academic_paper ap ON aps.cm_academic_paper_id = ap.id | |
INNER JOIN | |
cm_syllabus_academic_term_settings sats ON sats.id = ap.cm_syllabus_academic_term_settings_id AND sats.trashed IS NULL | |
INNER JOIN | |
academic_term at ON at.id = sats.academic_term_id AND at.trashed IS NULL | |
WHERE | |
1 = 1"; | |
try | |
{ | |
$subjectList = $this->executeQueryForList($query.$whereQuery); | |
} | |
catch (\Exception $e) | |
{ | |
throw new ProfessionalException(ProfessionalException::ERROR_FETCHING_SUBJECTS,"Cannot fetch Subjects! Please try again"); | |
} | |
return $subjectList; | |
} | |
/** | |
* Search Batch Paper Subject Details | |
* @param SearchBatchPaperSubjectRequest $request | |
* @return batchpapersubject | |
*/ | |
public function searchBatchPaperSubject(SearchBatchPaperSubjectRequest $request) | |
{ | |
$request = $this->realEscapeObject($request); | |
$whereQuery = ""; | |
$limitQuery = ""; | |
if(!empty($request->id)) { | |
$whereQuery .= " AND bps.id='$request->id' "; | |
} | |
if (!empty($request->groupsIds) && count($request->groupsIds) > 0) { | |
$result = "'" . implode ( "', '", $request->groupsIds ) . "'"; | |
$whereQuery .= " AND bps.groups_id IN ($result) "; | |
} | |
if (!empty($request->academicPaperSubjectsIds) && count($request->academicPaperSubjectsIds) > 0) { | |
$result = "'" . implode ( "', '", $request->academicPaperSubjectsIds ) . "'"; | |
$whereQuery .= " AND bps.cm_academic_paper_subjects_id IN ($result) "; | |
} | |
if($request->trashed === StatusConstants::ACTIVE) { | |
$whereQuery .= " AND bps.trashed IS NULL "; | |
} | |
if($request->trashed === StatusConstants::TRASHED) { | |
$whereQuery .= " AND bps.trashed IS NOT NULL "; | |
} | |
if($request->startIndex !== "" && $request->endIndex !== "") { | |
$limitQuery .= " LIMIT $request->startIndex,$request->endIndex"; | |
} | |
$query = "SELECT | |
bps.id, | |
bps.groups_id, | |
bps.cm_academic_paper_subjects_id, | |
bps.properties, | |
bps.trashed, | |
bps.created_by, | |
bps.created_date, | |
bps.updated_by, | |
bps.updated_date, | |
g.name AS `GroupName`, | |
g.type AS `GroupType`, | |
g.identifying_context, | |
g.properties AS `GroupProperties`, | |
aps.paper_id, | |
aps.subject_id, | |
aps.properties AS `academicPaperSubjectsProperties`, | |
ap.name AS `academicPaperName`, | |
ap.type AS `academicPaperType`, | |
ap.academic_term_id, | |
ap.properties AS `academicPaperProperties` | |
FROM | |
`batch_paper_subject` bps | |
INNER JOIN `groups` g ON | |
g.id = bps.groups_id | |
INNER JOIN `cm_academic_paper_subjects` aps ON | |
aps.id = bps.cm_academic_paper_subjects_id | |
INNER JOIN `cm_academic_paper` ap ON | |
ap.id = aps.paper_id | |
WHERE | |
1 = 1"; | |
try { | |
$batchpapersubject = $this->executeQueryForList($query.$whereQuery.$limitQuery, $this->mapper[BatchPaperSubjectServiceMapper::SEARCH_BATCH_PAPER_SUBJECT]); | |
} catch (\Exception $e) { | |
throw new ProfessionalException(ProfessionalException::ERROR_FETCHING,"Cannot fetch batch paper subject details! Please try again."); | |
} | |
return $batchpapersubject; | |
} | |
} |