Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 21
CRAP
0.00% covered (danger)
0.00%
0 / 316
ConvocationService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 21
4290.00
0.00% covered (danger)
0.00%
0 / 316
 __construct
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 __clone
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 2
 getInstance
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 5
 addConvocation
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 30
 getConvocationById
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 10
 deleteConvocation
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 8
 searchConvocation
0.00% covered (danger)
0.00%
0 / 1
90.00
0.00% covered (danger)
0.00%
0 / 32
 getConvocationExamMonthYearById
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 10
 getConvocationBatches
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 10
 getConvocationStudentMarkDetailsById
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 10
 addConvocationStudentMarkDetails
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 32
 updateConvocationStudentMarkDetails
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 14
 deleteConvocationStudentMarkDetails
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 8
 searchConvocationStudentMarkDetails
0.00% covered (danger)
0.00%
0 / 1
42.00
0.00% covered (danger)
0.00%
0 / 24
 getConvocationHandleReport
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 14
 getConvocationReportEnable
0.00% covered (danger)
0.00%
0 / 1
90.00
0.00% covered (danger)
0.00%
0 / 30
 getConvocationByCourseTypeAndYear
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 15
 saveStudentDetailsInConvocationForm
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 13
 getStudentDetailsInConvocationForm
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 11
 getBatchExamRegistrationDetails
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 15
 getConvocationEnableDetailsByRequest
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 20
<?php 
    namespace com\linways\core\ams\professional\service\examcontroller;
    use com\linways\core\ams\professional\exception\ProfessionalException;
    use com\linways\core\ams\professional\mapper\examcontroller\ConvocationStudentMarkDetailsMapper;
    use com\linways\core\ams\professional\service\BaseService;
    use com\linways\core\ams\professional\constant\examcontroller\CourseTypeConstants;
    class ConvocationService 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 = ConvocationStudentMarkDetailsMapper::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;
        }
        /**
         * @param $convocation
         * @return Object
         * @throws ProfessionalException
         */
        public function addConvocation($convocation) {
            $convocation = $this->realEscapeObject($convocation);
            $sqlConvocation = "INSERT INTO convocation (name, code, conv_no, type, courseTypeId, month, year, created_by) 
            VALUES (
                    '$convocation->name',
                    '$convocation->code',
                    '$convocation->convocationNo',
                    '$convocation->type',
                    '$convocation->courseTypeId',
                    '$convocation->month',
                    '$convocation->year',
                    '$convocation->createdBy'
            )";
            try {
                $convocationId = $this->executeQueryForObject($sqlConvocation, TRUE);
                $values = null;
                if ( !empty ( $convocation->examMonthYear ) ) {
                    foreach ($convocation->examMonthYear as $examMonthYear) {
                        list($examMonth, $examYear, $isSupply ) = explode("-", $examMonthYear);
                        $values[] = "($convocationId$examMonth$examYear$isSupply)";
                    }
                }
                if ( !empty ( $values ) ) {
                    $sqlConvocationExamregs = "INSERT IGNORE INTO convocation_exam_month_year (convocation_id,exam_month, exam_year, is_supply) VALUES " . implode(",", $values);
                    $this->executeQuery($sqlConvocationExamregs);
                }
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $convocationId;
        }
        /**
         * Get convocation details by id
         * @param Integer $id
         * @throws ProfessionalException
         * @return Object $convocationDetails
         * @author Vishnu M
         */
        public function getConvocationById ( $id ) {
            $id = $this->realEscapeString($id);
            $convocationDetails = null;
            try {
                $sql = "SELECT id, name, code, conv_no AS convocationNo, type, courseTypeId, month, year FROM convocation WHERE id = '$id";
                $convocationDetails = $this->executeQueryForObject ( $sql );
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $convocationDetails;
        }
        
        /**
         * Delete convocation details
         * @param Integer $id
         * @throws ProfessionalException
         * @author Vishnu M
         */
        public function deleteConvocation ( $id ) {
            $id = $this->realEscapeString($id);
            try {
                $sql = "DELETE FROM convocation WHERE id = '$id";
                $this->executeQuery ( $sql );
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
        }
        /**
         * Search convocation details
         * @param ConvocationRequest $convocationRequest
         * @throws ProfessionalException
         * @return Array $convocationDetails
         * @author Vishnu M
         */
        public function searchConvocation ( $convocationRequest ) {
            $convocationRequest = $this->realEscapeObject($convocationRequest);
            $convocationDetails = null;
            $condition = null;
            if ( $convocationRequest->name ) {
                $condition .= " AND name = '$convocationRequest->name";
            }
            if ( $convocationRequest->code ) {
                $condition .= " AND code = '$convocationRequest->code";
            }
            if ( $convocationRequest->convocationNo ) {
                $condition .= " AND conv_no = '$convocationRequest->convocationNo";
            }
            if ( $convocationRequest->type ) {
                $condition .= " AND type = '$convocationRequest->type";
            }
            if ( $convocationRequest->courseTypeId ) {
                $condition .= " AND courseTypeId = '$convocationRequest->courseTypeId";
            }
            if ( $convocationRequest->month ) {
                $condition .= " AND month = '$convocationRequest->month";
            }
            if ( $convocationRequest->year ) {
                $condition .= " AND year = '$convocationRequest->year";
            }
            try {
                $sql = "SELECT id, name, code, conv_no AS convocationNo, type, courseTypeId, month, year FROM convocation WHERE id = id $condition ";
                $convocationDetails = $this->executeQueryForList ( $sql );
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $convocationDetails;
        }
        /**
         * @param $convocationId
         * @return array|Object
         * @throws ProfessionalException
         * @author Vishnu M
         */
        public function getConvocationExamMonthYearById ( $convocationId ) {
            $convocationId = $this->realEscapeString($convocationId);
            $convocationExamMonthYear = [];
            try {
                $sql = "SELECT convocation_id AS convocationId, exam_month AS examMonth, exam_year AS examYear, is_supply AS isSupply FROM convocation_exam_month_year WHERE convocation_id = '$convocationId";
                $convocationExamMonthYear = $this->executeQueryForList ( $sql );
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $convocationExamMonthYear;
        }
        /**
         * @param $convocationId
         * @param $patternCourseId
         * @return Object|null
         * @throws ProfessionalException
         */
        public function getConvocationBatches ( $convocationId, $patternCourseId ) {
            $sql = null;
            $convocationBatches = null;
            try {
                $sql = "SELECT b.batchID AS batchId, b.batchName FROM convocation c INNER JOIN batches b ON b.courseTypeID = c.courseTypeId AND b.batchEndYear <= c.year WHERE patterncourseID = '$patternCourseId' AND c.id = '$convocationId' and b.batchHide = 0";
                $convocationBatches = $this->executeQueryForList ( $sql );
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $convocationBatches;
        } 
        
        # Convocation Student Mark Details - Functions
        
        /**
         * Get convocation_student_mark_details details by id
         * @param Integer $id
         * @throws ProfessionalException
         * @return Object $convocationStudentMarkDetails
         * @author Vishnu M
         */
        public function getConvocationStudentMarkDetailsById ( $id ) {
            $id = $this->realEscapeString($id);
            $convocationStudentMarkDetails = null;
            try {
                $sql = "SELECT id, studentaccount_id AS studentId, semesters_id AS semId, obtained_mark AS obtainedMark, max_mark AS maxMark, last_exam_month AS lastExamMonth, last_exam_year AS lastExamYear FROM convocation_student_mark_details WHERE id = '$id";
                $convocationStudentMarkDetails = $this->executeQueryForObject ( $sql );
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $convocationStudentMarkDetails;
        }
        /**
         * Add convocation_student_mark_details details
         * @param ConvocationStudentMarkDetails $convocationStudentMarkDetails
         * @throws ProfessionalException
         * @return Object $convocation_student_mark_detailsDetails
         * @author Vishnu M
         */
        public function addConvocationStudentMarkDetails ( $convocationStudentMarkDetails ) {
            $convocationStudentMarkDetails = $this->realEscapeObject($convocationStudentMarkDetails);
            $id = null;
            try {
                $sql = "INSERT INTO convocation_student_mark_details ( 
                    studentaccount_id, 
                    semesters_id, 
                    obtained_mark, 
                    max_mark, 
                    last_exam_month, 
                    last_exam_year ) VALUES ( 
                    '".$convocationStudentMarkDetails->studentId."', 
                    '".$convocationStudentMarkDetails->semId."', 
                    '".$convocationStudentMarkDetails->obtainedMark."', 
                    '".$convocationStudentMarkDetails->maxMark."', 
                    '".$convocationStudentMarkDetails->lastExamMonth."', 
                    '".$convocationStudentMarkDetails->lastExamYear."' ) ON DUPLICATE KEY UPDATE
                    obtained_mark = VALUES (obtained_mark), 
                    max_mark = VALUES (max_mark), 
                    last_exam_month = VALUES (last_exam_month), 
                    last_exam_year = VALUES (last_exam_year)";
                $id = $this->executeQueryForObject ( $sql, TRUE );
                
                $student = $convocationStudentMarkDetails->student;
                $sql = "UPDATE studentaccount SET 
                          studentEmail = '".$student->studentEmail."', 
                          studentPhone = '".$student->studentPhone."'
                        WHERE studentID = '$convocationStudentMarkDetails->studentId";
                $this->executeQuery ( $sql );
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $id;
        }
        /**
         * Update convocation_student_mark_details details
         * @param ConvocationStudentMarkDetails $convocationStudentMarkDetails
         * @throws ProfessionalException
         * @author Vishnu M
         */
        public function updateConvocationStudentMarkDetails ( $convocationStudentMarkDetails ) {
            $convocationStudentMarkDetails = $this->realEscapeObject($convocationStudentMarkDetails);
            try {
                $sql = "UPDATE convocation_student_mark_details SET 
                    studentaccount_id = '$convocationStudentMarkDetails->studentId', 
                    semesters_id = '$convocationStudentMarkDetails->semId', 
                    obtained_mark = '$convocationStudentMarkDetails->obtainedMark', 
                    max_mark = '$convocationStudentMarkDetails->maxMark', 
                    last_exam_month = '$convocationStudentMarkDetails->lastExamMonth', 
                    last_exam_year = '$convocationStudentMarkDetails->lastExamYear' WHERE id = '$convocationStudentMarkDetails->id";
                $this->executeQuery ( $sql );
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
        }
        /**
         * Delete convocation_student_mark_details details
         * @param Integer $id
         * @throws ProfessionalException
         * @author Vishnu M
         */
        public function deleteConvocationStudentMarkDetails ( $id ) {
            $id = $this->realEscapeString($id);
            try {
                $sql = "DELETE FROM convocation_student_mark_details WHERE id = '$id";
                $this->executeQuery ( $sql );
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
        }
        /**
         * Search convocation_student_mark_details details
         * @param ConvocationStudentMarkDetailsRequest $convocationStudentMarkDetailsRequest
         * @throws ProfessionalException
         * @return Array $convocation_student_mark_detailsDetails
         * @author Vishnu M
         */
        public function searchConvocationStudentMarkDetails ( $convocationStudentMarkDetailsRequest ) {
            $convocationStudentMarkDetailsRequest = $this->realEscapeObject($convocationStudentMarkDetailsRequest);
            $convocationStudentMarkDetails = null;
            $condition = null;
            if ( $convocationStudentMarkDetailsRequest->studentId ) {
                $condition .= " AND studentaccount_id = '$convocationStudentMarkDetailsRequest->studentId";
            }
            if ( $convocationStudentMarkDetailsRequest->semId ) {
                $condition .= " AND semesters_id = '$convocationStudentMarkDetailsRequest->semId";
            }
            if ( $convocationStudentMarkDetailsRequest->lastExamMonth ) {
                $condition .= " AND last_exam_month = '$convocationStudentMarkDetailsRequest->lastExamMonth";
            }
            if ( $convocationStudentMarkDetailsRequest->lastExamYear ) {
                $condition .= " AND last_exam_year = '$convocationStudentMarkDetailsRequest->lastExamYear";
            }
            try {
                $sql = "SELECT id, studentaccount_id AS studentId, semesters_id AS semId, obtained_mark AS obtainedMark, max_mark AS maxMark, last_exam_month AS lastExamMonth, last_exam_year AS lastExamYear FROM convocation_student_mark_details WHERE id = id $condition ";
                $convocationStudentMarkDetails = $this->executeQueryForList ( $sql, $this->mapper
                [ConvocationStudentMarkDetailsMapper::GET_CONVOCATION_STUDENT_MARK_DETAILS] );
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $convocationStudentMarkDetails;
        }
        /**
         * @param $batchIdArr
         * @param $convocationId
         * @return Object|null
         * @throws ProfessionalException
         * @author Vishnu M
         */
        public function getConvocationHandleReport ( $batchIdArr, $convocationId ) {
            $convocationId = $this->realEscapeString($convocationId);
            $batchIdArr = $this->realEscapeArray($batchIdArr);
            $batchIds = implode(",", $batchIdArr);
            $reportDetails = null;
            $sql = null;
            try {
                $sql = "SELECT csmd.id, csmd.studentaccount_id AS studentId, sa.studentName, sa.regNo, sa.studentEmail, sa.batchID AS batchId, sa.studentPhone, csmd.semesters_id AS semId, csmd.obtained_mark AS obtainedMark, csmd.max_mark AS maxMark, csmd.last_exam_month AS lastExamMonth, csmd.last_exam_year AS lastExamYear  FROM convocation_student_mark_details csmd INNER JOIN studentaccount sa ON sa.studentID = csmd.studentaccount_id INNER JOIN convocation_exam_month_year cemy ON csmd.last_exam_month = cemy.exam_month AND csmd.last_exam_year = cemy.exam_year WHERE cemy.convocation_id = '$convocationId' AND sa.batchID IN ($batchIds)";
                
                $reportDetails = $this->executeQueryForList ( $sql, $this->mapper
                [ConvocationStudentMarkDetailsMapper::GET_CONVOCATION_STUDENT_MARK_DETAILS] );
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $reportDetails;
        }
        /** Convocation Report Enable for SJCC
         * @param $studentId
         * @return Object|null
         * @throws ProfessionalException
         * @author Sibin 
         */
        public function getConvocationReportEnable ($studentId) {
            $studentId = $this->realEscapeString($studentId);
            $sql = null;
            $convocationReportEnable = false;
            $studentDetails = null;
            try {
                if($studentId){
                    $sql = "SELECT ct.courseTypeID,ct.typeName,ct.typeDesc,ct.sec_lang,ct.markgrade,ct.extval_required,ct.course_Type as 'courseTypeMethod',ct.courseTypeFlag,ct.externalValuation,b.batchStartYear,b.patterncourseID
                                FROM
                                    batches b
                                INNER JOIN course_type ct ON
                                    ct.courseTypeID = b.courseTypeID
                                LEFT JOIN studentaccount sa ON
                                    sa.batchID = b.batchID
                                    WHERE sa.studentID='$studentId'";
                    $studentDetails = $this->executeQueryForObject($sql);
                    if(($studentDetails->courseTypeMethod == CourseTypeConstants::UG && $studentDetails->batchStartYear == 2017)){
                        $convocationReportEnable = true;
                    }
                    else if(($studentDetails->courseTypeMethod == CourseTypeConstants::UG && $studentDetails->batchStartYear == 2018)){
                        $convocationReportEnable = true;
                    }
                    else if(($studentDetails->courseTypeMethod == CourseTypeConstants::PG && $studentDetails->batchStartYear == 2019)){
                        $convocationReportEnable = true;
                    }
                }                
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $convocationReportEnable;
        }
        /** Convocation Report Enable for SJCC
         * @param $studentId
         * @return Object|null
         * @throws ProfessionalException
         * @author Sibin 
         */
        public function getConvocationByCourseTypeAndYear($courseTypeId,$year) {
            $courseTypeId = $this->realEscapeString($courseTypeId);
            $year = $this->realEscapeString($year);
            $sql = null;
            $convocation=null;
            try {
                if($courseTypeId && $year){
                    $sql = "SELECT id,name,code,conv_no,type,courseTypeId,month,year from convocation
                                WHERE courseTypeId='$courseTypeId' and year ='$year'";
                    $convocation = $this->executeQueryForObject($sql);
                }                
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $convocation;
        }
        /** save student details on convocation form
         * 
         * @throws ProfessionalException
         * @author Sibin 
         */
        public function saveStudentDetailsInConvocationForm($studentDetails) {
            $studentDetails = $this->realEscapeObject($studentDetails);
            $updateBy = $_SESSION['studentID'];
            $sql = null;
            try {
                $sql = "INSERT INTO convocationStudentDetails(studentId,category,studentAddress,studentPin,studentPhone,studentEmail,created_by,updated_by)
                            values('$studentDetails->id','$studentDetails->category','$studentDetails->additional_info_permanentAddress','$studentDetails->permanentZipCode','$studentDetails->studentPhone','$studentDetails->studentEmail','$updateBy','$updateBy')
                            ON DUPLICATE KEY UPDATE category = VALUES(category), studentAddress = VALUES(studentAddress), studentPin = VALUES(studentPin), studentPhone = VALUES(studentPhone),studentEmail = VALUES(studentEmail)";
                $this->executeQueryForObject($sql);                
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return true;
        }
        /** get saved student details on convocation form
         * @throws ProfessionalException
         * @author Sibin 
         */
        public function getStudentDetailsInConvocationForm($studentDetails) {
            $studentDetails = $this->realEscapeObject($studentDetails);
            $sql = null;
            $savedStudentDetails = null;
            try {
                $sql = "SELECT studentId,category,studentAddress,studentPin,studentPhone,studentEmail from convocationStudentDetails WHERE studentId = '$studentDetails->id'";
                $savedStudentDetails = $this->executeQueryForObject($sql);                
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $savedStudentDetails;
        }
         /** get batch exam registration detail
         * @throws ProfessionalException
         */
        public function getBatchExamRegistrationDetails($request) {
            $request = $this->realEscapeObject($request);
            $sql = null;
            try {
                if($request->isSupply){
                    $sql = "SELECT es.id , es.supplyDesc, es.semID from exam_supplementary es INNER JOIN supply_improve_batches sib ON (es.id = sib.exam_supplementary_id) WHERE sib.batchID =$request->batchId and es.examMonth ='$request->examMonth' and es.examYear ='$request->examYear'";
                }
                else{
                    $sql = "SELECT er.examregID , er.examregName, erb.semID from exam_registration er INNER JOIN exam_registration_batches erb ON (erb.examregID = er.examregID ) WHERE erb.batchID =$request->batchId and er.examMonth ='$request->examMonth' and er.examYear ='$request->examYear'";
                }
                $examRegistrations = $this->executeQueryForObject($sql);                
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $examRegistrations;
        }
        /** Convocation form  enable details
         * @param $studentId
         * @return Object|null
         * @throws ProfessionalException
         * @author Sibin 
         */
        public function getConvocationEnableDetailsByRequest ($request) {
            $request = $this->realEscapeObject($request);
            $sql = null;
            $studentDetails = null;
            try {
                if($request->studentId){
                    $sql = "SELECT ct.courseTypeID,ct.typeName,ct.typeDesc,ct.sec_lang,ct.markgrade,ct.extval_required,ct.course_Type as 'courseTypeMethod',ct.courseTypeFlag,ct.externalValuation,b.batchStartYear,b.patterncourseID
                                FROM
                                    batches b
                                INNER JOIN course_type ct ON
                                    ct.courseTypeID = b.courseTypeID
                                LEFT JOIN studentaccount sa ON
                                    sa.batchID = b.batchID
                                    WHERE sa.studentID='$request->studentId'";
                    $studentDetails = $this->executeQueryForObject($sql);
                }                
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $studentDetails;
        }
    }