Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 14 |
CRAP | |
0.00% |
0 / 194 |
| GradeService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 14 |
1482.00 | |
0.00% |
0 / 194 |
| __construct | n/a |
0 / 0 |
1 | n/a |
0 / 0 |
|||||
| __clone | n/a |
0 / 0 |
1 | n/a |
0 / 0 |
|||||
| getInstance | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 4 |
|||
| getExamGradingSchemeByCourseType | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
| addSubjectGradeSchemeMapping | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 15 |
|||
| getExamGradeSchemeBySubjectBatch | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| getExamSemesterGradeBySchemeId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
| getExamGradePointsBySchemeId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
| addSubjectGradeSchemeMappingBySubject | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 15 |
|||
| getExamGradingSchemeByCoursePattern | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 20 |
|||
| getExamSemesterGradeByBatch | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 19 |
|||
| updateSubjectGrades | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 19 |
|||
| updateSemGrades | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 14 |
|||
| getCgpaGrade | |
0.00% |
0 / 1 |
30.00 | |
0.00% |
0 / 19 |
|||
| getCgpaGradeDetails | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 13 |
|||
| getExamGradeByScheme | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 15 |
|||
| <?php | |
| namespace com\linways\core\ams\professional\service\examcontroller; | |
| use com\linways\core\ams\professional\service\BaseService; | |
| use com\linways\core\ams\professional\exception\ProfessionalException; | |
| use stdClass; | |
| class GradeService 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() { } | |
| // 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; | |
| } | |
| /** | |
| * @author Vishnu M | |
| */ | |
| public function getExamGradingSchemeByCourseType ( $courseTypeId ) { | |
| $courseTypeId = (int) $this->realEscapeString($courseTypeId); | |
| $gradingScheme = []; | |
| $sql = "SELECT schemeID, schemeName FROM exam_gradingscheme WHERE courseTypeID = '$courseTypeId' ORDER BY schemeName ASC "; | |
| try { | |
| $gradingScheme = $this->executeQueryForList($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $gradingScheme; | |
| } | |
| /** | |
| * Save Subject Grade scheme | |
| * @author Vishnu M | |
| */ | |
| public function addSubjectGradeSchemeMapping ( $courseTypeId, $batchStartYear, $semId, $gradingScheme, $subjectIdArray ) { | |
| $courseTypeId = (int) $this->realEscapeString($courseTypeId); | |
| $gradingScheme = (int) $this->realEscapeString($gradingScheme); | |
| $batchStartYear = (int) $this->realEscapeString($batchStartYear); | |
| $semId = (int) $this->realEscapeString($semId); | |
| $subjectIdArray = $this->realEscapeArray($subjectIdArray); | |
| $subjectIdString = implode(",", $subjectIdArray); | |
| $sql = "INSERT INTO exam_subject_grading_scheme (batch_id, subject_id, grade_scheme_id) | |
| SELECT DISTINCT sbs.batchID, sbs.subjectID, '$gradingScheme' AS gradeSchemeId FROM batches b INNER JOIN sbs_relation sbs ON (b.batchID = sbs.batchID) WHERE b.courseTypeID = '$courseTypeId' AND batchStartYear = '$batchStartYear' AND sbs.semID = '$semId' AND sbs.subjectID IN ($subjectIdString)"; | |
| try { | |
| $this->executeQuery($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return true; | |
| } | |
| public function getExamGradeSchemeBySubjectBatch ( $subjectId, $batchId ) { | |
| $subjectId = (int) $this->realEscapeString($subjectId); | |
| $batchId = (int) $this->realEscapeString($batchId); | |
| $gradingScheme = null; | |
| $sql = "SELECT egs.schemeID, egs.schemeName, egs.courseTypeID FROM exam_gradingscheme egs INNER JOIN exam_subject_grading_scheme esgs ON (egs.schemeID = esgs.grade_scheme_id) WHERE esgs.batch_id = '$batchId' AND esgs.subject_id = '$subjectId' "; | |
| try { | |
| $gradingScheme = $this->executeQueryForObject($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $gradingScheme; | |
| } | |
| public function getExamSemesterGradeBySchemeId ( $schemeId ) { | |
| $schemeId = (int) $this->realEscapeString($schemeId); | |
| $semesterGrades = null; | |
| $sql = "SELECT schemeID, gradePointFrom, gradePointTo, letterGrade, className FROM exam_semestergrade WHERE schemeID = '$schemeId' ORDER BY gradePointTo DESC "; | |
| try { | |
| $semesterGrades = $this->executeQueryForList($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $semesterGrades; | |
| } | |
| /** | |
| * Get all the grade points according to the schemeid | |
| * @param Integer $schemeId | |
| * @return Array $examGrades | |
| * @throws ProfessionalException | |
| * @author Vishnu M | |
| */ | |
| public function getExamGradePointsBySchemeId ( $schemeId ) { | |
| $schemeId = (int) $this->realEscapeString($schemeId); | |
| $examGrades = null; | |
| $sql = "SELECT percentFrom, percentTo, letterGrade, gradePoint, failStatus FROM exam_gradepoints WHERE schemeID = '$schemeId' ORDER BY percentTo DESC "; | |
| try { | |
| $examGrades = $this->executeQueryForList($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $examGrades; | |
| } | |
| public function addSubjectGradeSchemeMappingBySubject ( $subjectGradeScheme ) { | |
| $subjectGradeScheme = $this->realEscapeArray($subjectGradeScheme); | |
| try { | |
| $sql = "INSERT INTO exam_subject_grading_scheme (subject_id, batch_id, grade_scheme_id) VALUES "; | |
| if ( count ( $subjectGradeScheme ) ) { | |
| foreach ( $subjectGradeScheme as $gradeScheme ) { | |
| $values[] = "( ".$gradeScheme["subject"].", ".$gradeScheme["batch"].", ".$gradeScheme["gradeScheme"]." )"; | |
| } | |
| $sql .= implode ( ",", $values ); | |
| $sql .= " ON DUPLICATE KEY UPDATE grade_scheme_id = VALUES(grade_scheme_id) "; | |
| $this->executeQuery($sql); | |
| } | |
| } catch ( \Exception $e ) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * @author Vishnu M | |
| */ | |
| public function getExamGradingSchemeByCoursePattern ( $coursePatternId ) { | |
| $coursePatternId = (int) $this->realEscapeString($coursePatternId); | |
| $gradingScheme = []; | |
| $sql = "SELECT | |
| esg.semGradeID AS id, | |
| esg.className AS name | |
| FROM | |
| course_pattern cp | |
| INNER JOIN exam_gradingscheme egs ON | |
| cp.courseTypeID = egs.courseTypeID | |
| INNER JOIN exam_semestergrade esg ON | |
| esg.schemeID = egs.schemeID | |
| WHERE | |
| cp.patternID = $coursePatternId"; | |
| try { | |
| $gradingScheme = $this->executeQueryForList($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $gradingScheme; | |
| } | |
| /** | |
| * Get exam semester grades corresponds to a batch | |
| * @param $batchId | |
| * @return $examGrades | |
| * @author Vishnu M | |
| */ | |
| public function getExamSemesterGradeByBatch ( $batchId ) { | |
| $batchId = $this->realEscapeArray($batchId); | |
| $batchId = is_array($batchId) ? implode(",",$batchId) : $batchId; | |
| $examGrades = []; | |
| $sql = "SELECT DISTINCT | |
| esg.semGradeID AS id, | |
| esg.className AS name | |
| FROM | |
| exam_semestergrade esg | |
| INNER JOIN | |
| assignedSemesterGradeBatches asgb ON (esg.schemeID = asgb.exam_gradingscheme_id) | |
| WHERE | |
| asgb.batches_id IN ($batchId)"; | |
| try { | |
| $examGrades = $this->executeQueryForList($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $examGrades; | |
| } | |
| /* | |
| Method for updating subject grades | |
| @author Ranjith Balachandran | |
| */ | |
| public function updateSubjectGrades($gradePointId,$percentFrom,$percentTo,$letterGrade,$failStatus,$gradePoint,$className=null) | |
| { | |
| $sql = ''; | |
| $gradePointId = $this->realEscapeString($gradePointId); | |
| $percentFrom = $this->realEscapeString($percentFrom); | |
| $percentTo = $this->realEscapeString($percentTo); | |
| $letterGrade = $this->realEscapeString($letterGrade); | |
| $failStatus = $this->realEscapeString($failStatus); | |
| $gradePoint = $this->realEscapeString($gradePoint); | |
| $className = $className !== null ? $this->realEscapeString($className) : null; | |
| if ($className !== null) { | |
| $updateColumns = " , className = '$className' "; | |
| } | |
| try{ | |
| $sql = "UPDATE exam_gradepoints SET percentFrom = '$percentFrom', percentTo = '$percentTo' , letterGrade = '$letterGrade' , gradePoint = '$gradePoint' , failStatus = '$failStatus' $updateColumns WHERE gradePointID = $gradePointId"; | |
| $this->executeQuery($sql); | |
| }catch( \Exception $e){ | |
| throw new AutonomousException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /* | |
| Method for updating semester grades | |
| @author Ranjith Balachandran | |
| */ | |
| public function updateSemGrades($semGradeId,$gradePointFrom,$gradePointTo,$letterGrade,$className) | |
| { | |
| $sql = ''; | |
| $semGradeId = $this->realEscapeString($semGradeId); | |
| $gradePointFrom = $this->realEscapeString($gradePointFrom); | |
| $gradePointTo = $this->realEscapeString($gradePointTo); | |
| $letterGrade = $this->realEscapeString($letterGrade); | |
| $className = $this->realEscapeString($className); | |
| try{ | |
| $sql = "UPDATE exam_semestergrade SET gradePointFrom = '$gradePointFrom', gradePointTo = '$gradePointTo' , letterGrade = '$letterGrade' , className = '$className' WHERE semGradeID = $semGradeId"; | |
| $this->executeQuery($sql); | |
| }catch( \Exception $e){ | |
| throw new AutonomousException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * Get cgpa grade by cgpa,batchId | |
| * @param Integer $cgpa,$batchId | |
| * @return Array $grade | |
| * @author Sibin | |
| */ | |
| public function getCgpaGrade($cgpa,$batchId) | |
| { | |
| $batchId = (int)$this->realEscapeString($batchId); | |
| $cgpa = $this->realEscapeString($cgpa); | |
| $cgpaGradeDetails = []; | |
| $sql = "SELECT ecg.schemeID,ecg.percentFrom,ecg.percentTo,ecg.letterGrade,ecg.classname,ecg.failstatus from assignedCGPAGradeBatches acb | |
| INNER JOIN exam_cgpa_gradepoints ecg ON ecg.schemeID = acb.exam_cgpa_gradingscheme_id | |
| WHERE acb.batches_id ='$batchId' ORDER BY ecg.percentTo DESC"; | |
| try { | |
| $cgpaGradeDetails = $this->executeQueryForList($sql); | |
| foreach ($cgpaGradeDetails as $grade) { | |
| if ($grade->percentFrom <= $cgpa && $grade->percentTo >= $cgpa) { | |
| return $grade; | |
| } | |
| } | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return null; | |
| } | |
| /** | |
| * Get cgpa grade details by chpa,batchId | |
| * @param Integer $cgpa,$batchId | |
| * @return Array $grade | |
| * @author Sibin | |
| */ | |
| public function getCgpaGradeDetails($batchId) | |
| { | |
| $batchId = (int)$this->realEscapeString($batchId); | |
| $cgpaGradeDetails = []; | |
| $sql = "SELECT ecg.schemeID,ecg.percentFrom,ecg.percentTo,ecg.letterGrade,ecg.classname,ecg.failstatus from assignedCGPAGradeBatches acb | |
| INNER JOIN exam_cgpa_gradepoints ecg ON ecg.schemeID = acb.exam_cgpa_gradingscheme_id | |
| WHERE acb.batches_id ='$batchId' ORDER BY ecg.percentTo DESC"; | |
| try { | |
| $cgpaGradeDetails = $this->executeQueryForList($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $cgpaGradeDetails; | |
| } | |
| /** | |
| * Get cgpa grade details by scheme,courseType,percent | |
| * @param $request | |
| * @return $grade | |
| * @author Sibin | |
| */ | |
| public function getExamGradeByScheme($schemeId,$courseTypeId,$percent) | |
| { | |
| $schemeId = $this->realEscapeString($schemeId); | |
| $courseTypeId = $this->realEscapeString($courseTypeId); | |
| $percent = $this->realEscapeString($percent); | |
| $garde = new stdClass; | |
| $sql = "SELECT t1.letterGrade | |
| FROM exam_gradepoints t1, exam_gradingscheme t2 | |
| WHERE t2.courseTypeID = '$courseTypeId' AND t2.schemeID = '$schemeId' AND t2.schemeID = t1.schemeID AND t1.percentFrom <= '$percent' AND t1.percentTo >= '$percent'"; | |
| try { | |
| $garde = $this->executeQueryForObject($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $garde; | |
| } | |
| } |