Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 239 |
| CourseService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 12 |
992.00 | |
0.00% |
0 / 239 |
| __construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
| __clone | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
| getInstance | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 5 |
|||
| getCoursePatternByCourseTypeId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| getPatternDeptCoursesByCoursePatternId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| getCoursePatternByPatternId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| InitiateCourseRegistration | |
0.00% |
0 / 1 |
30.00 | |
0.00% |
0 / 68 |
|||
| CourseRegisteredDetails | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 18 |
|||
| updateVisiblity | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 22 |
|||
| updateCourseRegistration | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 14 |
|||
| getCourseRegistrationByBatchId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 27 |
|||
| completeCourseRegistration | |
0.00% |
0 / 1 |
56.00 | |
0.00% |
0 / 48 |
|||
| <?php | |
| namespace com\linways\core\ams\professional\service\examcontroller; | |
| use com\linways\core\ams\professional\exception\ProfessionalException; | |
| use com\linways\core\ams\professional\service\BaseService; | |
| use com\linways\core\ams\professional\service\InternalMarkService; | |
| use stdClass; | |
| class CourseService 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; | |
| } | |
| /** | |
| * @param Integer $courseTypeId | |
| * @return Object|null | |
| * @throws ProfessionalException | |
| * @author Vishnu M | |
| */ | |
| public function getCoursePatternByCourseTypeId($courseTypeId) { | |
| $courseTypeId = $this->realEscapeString($courseTypeId); | |
| $sql = null; | |
| $coursePattern = null; | |
| try { | |
| $sql = "SELECT patternID AS id, patternName AS name, patternDesc AS description, courseTypeID AS courseTypeId FROM course_pattern WHERE courseTypeID = '$courseTypeId' "; | |
| $coursePattern = $this->executeQueryForList($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $coursePattern; | |
| } | |
| /** | |
| * @param Integer $courseTypeId | |
| * @return Object|null | |
| * @throws ProfessionalException | |
| * @author Vishnu M | |
| */ | |
| public function getPatternDeptCoursesByCoursePatternId($coursePatternId) { | |
| $coursePatternId = $this->realEscapeString($coursePatternId); | |
| $sql = null; | |
| $patternDeptCourses = null; | |
| try { | |
| $sql = "SELECT patterncourseID AS id, patterncourseName AS name, patternID AS patternId, deptID AS deptId, patterncourseCode AS code, patternAbbreviation FROM pattern_deptcourses WHERE patternID = '$coursePatternId' "; | |
| $patternDeptCourses = $this->executeQueryForList($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $patternDeptCourses; | |
| } | |
| /** | |
| * @param Integer $patternId | |
| * @return Array|null | |
| * @throws ProfessionalException | |
| */ | |
| public function getCoursePatternByPatternId($patternId) { | |
| $patternId = $this->realEscapeString($patternId); | |
| $sql = null; | |
| $coursePattern = null; | |
| try { | |
| $sql = "SELECT patternID AS id, patternName AS name, patternDesc AS description, courseTypeID AS courseTypeId FROM course_pattern WHERE patternID = '$patternId' "; | |
| $coursePattern = $this->executeQueryForObject($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $coursePattern; | |
| } | |
| /** | |
| * @param Integer $patternId | |
| * @return Object|null | |
| * @throws ProfessionalException | |
| */ | |
| public function InitiateCourseRegistration($batchID,$semID,$fromDate,$toDate) { | |
| $batchID = $this->realEscapeString($batchID); | |
| $semID = $this->realEscapeString($semID); | |
| $fromDate = $this->realEscapeString($fromDate); | |
| $toDate = $this->realEscapeString($toDate); | |
| $sql = null; | |
| $sql = "SELECT id FROM course_registration WHERE batchID = '$batchID' AND semID = '$semID'"; | |
| $alreadyExists = $this->executeQueryForList($sql); | |
| if(count($alreadyExists) > 0) | |
| { | |
| $isUpdated = $this->updateCourseRegistration($batchID,$semID,$fromDate,$toDate); | |
| if($isUpdated){ | |
| return true; | |
| } | |
| else{ | |
| return false; | |
| } | |
| } | |
| try { | |
| $students = []; | |
| $sql = "SELECT studentID FROM studentaccount WHERE batchID = ".$batchID; | |
| $studentsArr = InternalMarkService::getInstance()->getStudentByBatchSem($batchID); | |
| // $studentsArr = $this->executeQueryForList($sql); | |
| foreach($studentsArr as $st) | |
| { | |
| $stud = new stdClass(); | |
| $stud->id = $st->studentID; | |
| $stud->attended = false; | |
| $stud->dateAndTime = ""; | |
| $students[] = $stud; | |
| } | |
| $studentCount = count($students); | |
| $studentAttended = 0; | |
| $recordToSave = new stdClass(); | |
| $recordToSave->students = $students; | |
| $recordToSave->studentCount = $studentCount; | |
| $recordToSave->studentAttended = $studentAttended; | |
| $recordToSave->dateAndTime = date("Y-m-d H:i:s"); | |
| $recordToSave = json_encode($recordToSave); | |
| $sql = "INSERT | |
| INTO | |
| course_registration (semID, | |
| batchID, | |
| isActive, | |
| fromDate, | |
| toDate, | |
| studentsConfirmed, | |
| isConfirmed, | |
| created_by, | |
| created_date, | |
| updated_by, | |
| updated_date)"; | |
| $sql .=" VALUES('$semID', | |
| '$batchID', | |
| '1', | |
| '$fromDate', | |
| '$toDate', | |
| '$recordToSave', | |
| '0',". | |
| $_SESSION['adminID'].", | |
| 'NOW()', | |
| ".$_SESSION['adminID'].", | |
| 'NOW()')"; | |
| $this->executeQuery($sql); | |
| $courseDetails = $this->CourseRegisteredDetails($batchID,$semID); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $courseDetails; | |
| } | |
| public function CourseRegisteredDetails($batchID,$semID) | |
| { | |
| $batchID = $this->realEscapeString($batchID); | |
| $semID = $this->realEscapeString($semID); | |
| $sql = null; | |
| $courseDetails = null; | |
| try { | |
| $sql = "SELECT id, | |
| fromDate, | |
| toDate, | |
| studentsConfirmed, | |
| isActive | |
| FROM course_registration WHERE batchID = '$batchID' AND semID = '$semID'"; | |
| $courseDetails = $this->executeQueryForObject($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $courseDetails; | |
| } | |
| public function updateVisiblity($batchID,$semID) | |
| { | |
| $batchID = $this->realEscapeString($batchID); | |
| $sql = null; | |
| try { | |
| $sql = "SELECT isActive FROM course_registration WHERE batchID = '$batchID' AND semID = '$semID' "; | |
| $status = $this->executeQueryForObject($sql); | |
| if($status->isActive == '1') | |
| { | |
| $sql = "UPDATE course_registration SET isActive = '0' WHERE batchID = '$batchID' AND semID = '$semID' "; | |
| $this->executeQuery($sql); | |
| } | |
| else | |
| { | |
| $sql = "UPDATE course_registration SET isActive = '1' WHERE batchID = '$batchID' AND semID = '$semID' "; | |
| $this->executeQuery($sql); | |
| } | |
| $courseDetails = $this->CourseRegisteredDetails($batchID,$semID); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $courseDetails; | |
| } | |
| public function updateCourseRegistration($batchID,$semID,$fromDate,$toDate) | |
| { | |
| $batchID = $this->realEscapeString($batchID); | |
| $semID = $this->realEscapeString($semID); | |
| $fromDate = $this->realEscapeString($fromDate); | |
| $toDate = $this->realEscapeString($toDate); | |
| $sql = null; | |
| try { | |
| $sql = "UPDATE course_registration SET fromDate = '$fromDate',toDate = '$toDate' WHERE batchID = '$batchID' and semID = '$semID'"; | |
| $this->executeQuery($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return true; | |
| } | |
| public function getCourseRegistrationByBatchId($batchID,$semID) | |
| { | |
| $batchID = $this->realEscapeString($batchID); | |
| $semID = $this->realEscapeString($semID); | |
| $currentDate = date('Y-m-d')." 00:00:00"; | |
| try { | |
| $sql = "SELECT semID, | |
| batchID, | |
| isActive, | |
| fromDate, | |
| toDate, | |
| studentsConfirmed, | |
| isConfirmed, | |
| created_by, | |
| created_date, | |
| updated_by, | |
| updated_date | |
| FROM course_registration | |
| WHERE batchID = '$batchID' AND | |
| semID = '$semID' AND | |
| isActive ='1' AND | |
| '$currentDate' BETWEEN fromDate AND toDate"; | |
| $batchData = $this->executeQueryForObject($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return$batchData; | |
| } | |
| public function completeCourseRegistration($studentID) | |
| { | |
| try | |
| { | |
| $studentID = $this->realEscapeString($studentID); | |
| $sql = "SELECT ba.batchID,s.semID from studentaccount sa INNER JOIN batches ba on ba.batchID = sa.batchID INNER JOIN semesters s on ba.semID = s.semID WHERE studentID = '$studentID'"; | |
| $res = $this->executeQueryForObject($sql); | |
| $batchID = $res->batchID; | |
| $semID = $res->semID; | |
| $data = $this->getCourseRegistrationByBatchId($batchID,$semID); | |
| if($data) | |
| { | |
| $studentsData = json_decode($data->studentsConfirmed); | |
| $students = $studentsData->students; | |
| $studentAttended = (int)$studentsData->studentAttended; | |
| $studentCount = $studentsData->studentCount; | |
| if(count($students)>0) | |
| { | |
| foreach($students as $student) | |
| { | |
| if($student->id == $studentID) | |
| { | |
| if($student->attended) | |
| { | |
| $student->attended = true; | |
| $student->dateAndTime = date("Y-m-d H:i:s"); | |
| } | |
| else{ | |
| $student->attended = true; | |
| $studentAttended++; | |
| $student->dateAndTime = date("Y-m-d H:i:s"); | |
| } | |
| } | |
| } | |
| $studentsConfirmed = new stdClass(); | |
| $studentsConfirmed->students = $students; | |
| $studentsConfirmed->studentAttended = $studentAttended; | |
| $studentsConfirmed->studentCount = $studentCount; | |
| $recordToUpdate = json_encode($studentsConfirmed); | |
| $sql = "UPDATE course_registration SET studentsConfirmed = '$recordToUpdate' WHERE batchID = '$batchID' and semID = '$semID'"; | |
| $this->executeQuery($sql); | |
| } | |
| } | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| return false; | |
| } | |
| return true; | |
| } | |
| } |