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 / 10
CRAP
0.00% covered (danger)
0.00%
0 / 427
RankReportService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 10
1980.00
0.00% covered (danger)
0.00%
0 / 427
 __construct
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 2
 __clone
n/a
0 / 0
1
n/a
0 / 0
 getInstance
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 5
 getRankReportById
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 10
 addRankReport
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 19
 updateRankReport
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 12
 deleteRankReport
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 8
 searchRankReport
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 20
 getRankReportExamDetails
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 100
 getSubjectToppersExamDetails
0.00% covered (danger)
0.00%
0 / 1
132.00
0.00% covered (danger)
0.00%
0 / 124
 getSubjectToppersExamDetailsWithoutSbs
0.00% covered (danger)
0.00%
0 / 1
182.00
0.00% covered (danger)
0.00%
0 / 127
<?php
    namespace com\linways\core\ams\professional\service\examcontroller;
    use com\linways\core\ams\professional\mapper\examcontroller\ConsolidatedMarkReportServiceMapper;
    use com\linways\core\ams\professional\service\BaseService;
    use com\linways\core\ams\professional\exception\ProfessionalException;
    use com\linways\core\ams\professional\request\examcontroller\RankReportRequest;
    class RankReportService extends BaseService {
        // Condition 1 - Presence of a static member variable
        private static $_instance = null;
        
        // Condition 2 - Locked down the constructor
        private function __construct() {
            $this->mapper = ConsolidatedMarkReportServiceMapper::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;
        }
    
    
        /**
         * Get rank_report details by id
         * @param Integer $id
         * @throws ProfessionalException
         * @return Object $rankReportDetails
         * @author Vishnu M
         */
        public function getRankReportById ( $id ) {
            $id = $this->realEscapeString($id);
            $rankReportDetails = null;
            try {
                $sql = "SELECT id, name, course_type_id AS courseTypeId, year FROM rank_report WHERE id = '$id";
                $rankReportDetails = $this->executeQueryForObject ( $sql );
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $rankReportDetails;
        }
        /**
         * Add rank_report details
         * @param RankReport $rankreport
         * @throws ProfessionalException
         * @return Object $rankReportDetails
         * @author Vishnu M
         */
        public function addRankReport ( $rankreport ) {
            $rankreport = $this->realEscapeObject($rankreport);
            $id = null;
            try {
                $sql = "INSERT INTO rank_report ( 
                    name, 
                    course_type_id, 
                    year,
                    created_by) VALUES ( 
                    '".$rankreport->name."', 
                    '".$rankreport->courseTypeId."', 
                    '".$rankreport->year."',
                    '".$rankreport->createdBy."'
                     )";
                $id = $this->executeQueryForObject ( $sql, TRUE );
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $id;
        }
        /**
         * Update rank_report details
         * @param RankReport $rankreport
         * @throws ProfessionalException
         * @author Vishnu M
         */
        public function updateRankReport ( $rankreport ) {
            $rankreport = $this->realEscapeObject($rankreport);
            try {
                $sql = "UPDATE rank_report SET 
                    name = '$rankreport->name', 
                    course_type_id = '$rankreport->courseTypeId', 
                    year = '$rankreport->year',
                    updated_by = '$rankreport->createdBy' WHERE id = '$rankreport->id";
                $this->executeQuery ( $sql );
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
        }
        /**
         * Delete rank_report details
         * @param Integer $id
         * @throws ProfessionalException
         * @author Vishnu M
         */
        public function deleteRankReport ( $id ) {
            $id = $this->realEscapeString($id);
            try {
                $sql = "DELETE FROM rank_report WHERE id = '$id";
                $this->executeQuery ( $sql );
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
        }
        /**
         * Search rank_report details
         * @param RankReportRequest $rankReportRequest
         * @throws ProfessionalException
         * @return Array $rankReportDetails
         * @author Vishnu M
         */
        public function searchRankReport ( $rankReportRequest ) {
            $rankReportRequest = $this->realEscapeObject($rankReportRequest);
            $rankReportDetails = null;
            $condition = null;
            
            if ( $rankReportRequest->name ) {
                $condition .= " AND name = '$rankReportRequest->name";
            }
            if ( $rankReportRequest->courseTypeId ) {
                $condition .= " AND course_type_id = '$rankReportRequest->courseTypeId";
            }
            if ( $rankReportRequest->year ) {
                $condition .= " AND year = '$rankReportRequest->year";
            }
            try {
                $sql = "SELECT id, name, course_type_id AS courseTypeId, year FROM rank_report WHERE id > 0 $condition ";
                $rankReportDetails = $this->executeQueryForList ( $sql );
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $rankReportDetails;
        }
        /**
         * @param $rankReportRequest
         * @return Object|null
         * @throws ProfessionalException
         * @author Vishnu M
         */
        public function getRankReportExamDetails ( $rankReportRequest ) {
            $rankReportRequest = $this->realEscapeObject($rankReportRequest);
            $rankReportId = $rankReportRequest->rankReportId;
            $condition = null;
            if ( $rankReportRequest->rankReportSubjectGroupId ) {
                $condition .= " AND rrsgm.rank_report_subject_group_id = '$rankReportRequest->rankReportSubjectGroupId";
            }
            
            $rankReportDetails = null;
            $sql = null;
            try {
                $sql = "SELECT 
                    sa.studentID,
                    sa.studentName,
                    sa.regNo,
                    sa.rollNo,
                    sa.admissionNo,
                    b.batchID,
                    b.batchName,
                    b.deptID,
                    b.totalSemester,
                    b.final_semester,
                    b.batchStartYear,
                    b.batchEndYear,
                    b.courseTypeID,
                    e.examID,
                    e.subjectID,
                    e.examregID,
                    e.semID,
                    sem.orderNo,
                    eme.id AS markId,
                    eme.mark AS externalMark,
                    e.examTotalMarks AS externalMax,
                    im.internalMarkID,
                    im.internalMarks AS internalMark,
                    ims.maxInternalMarks AS internalMax,
                    esc.isInternal,
                    esc.isExternal,
                    esc.excludeSubjectFromTotal,
                    esc.subjectType,
                    IF (ees.id, 1, 0) AS isExempted,
                    rrsgm.subjects_id AS subjectID,
                    rrsgm.semesters_id AS semID
                FROM
                    rank_report rr
                        INNER JOIN
                    batches b ON (rr.course_type_id = b.courseTypeID
                        AND rr.year = b.batchStartYear)
                        INNER JOIN
                    rank_report_subject_group_mapping rrsgm ON (rr.id = rank_report_id)
                        INNER JOIN
                    exam_reg_studentsubject erss ON (rrsgm.subjects_id = erss.subjectID)
                        INNER JOIN
                    sbs_relation sbs ON (sbs.batchID = b.batchID
                        AND sbs.subjectID = rrsgm.subjects_id
                        AND sbs.semID = rrsgm.semesters_id)
                        INNER JOIN
                    semesters sem ON sbs.semID = sem.semID
                        INNER JOIN
                    exam_reg_studentchallan ersc ON (ersc.studentID = erss.studentID
                        AND erss.examregID = ersc.examregID)
                        INNER JOIN
                    exam e ON (e.subjectID = rrsgm.subjects_id
                        AND e.semID = rrsgm.semesters_id
                        AND e.batchID = b.batchID
                        AND ersc.examregID = e.examregID)
                        INNER JOIN
                    studentaccount sa ON (ersc.studentID = sa.studentID
                        AND b.batchID = sa.batchID)
                        INNER JOIN
                    exammarks_external eme ON (eme.examID = e.examID
                        AND eme.studentID = sa.studentID)
                        INNER JOIN
                    exam_subjectcredit esc ON (esc.subjectID = rrsgm.subjects_id
                        AND esc.batchID = e.batchID
                        AND esc.semID = e.semID)
                        LEFT JOIN
                    internal_marks im ON (im.subjectID = rrsgm.subjects_id
                        AND im.studentID = sa.studentID
                        AND im.batchID = e.batchID
                        AND im.semID = e.semID)
                        LEFT JOIN
                    internal_marks_settings ims ON (ims.subjectID = rrsgm.subjects_id
                        AND ims.batchID = e.batchID
                        AND ims.semID = e.semID)
                        LEFT JOIN
                    exam_exempted_students ees ON ees.exam_id = e.examID
                        AND ees.studentaccount_id = sa.studentID
                        LEFT JOIN 
                    failed_students fs ON fs.studentID = sa.studentID
                        AND FIND_IN_SET(e.semID, fs.hisSemestersInThisbatch)
                WHERE
                    ersc.paid = 1 AND rr.id = '$rankReportId'
                    $condition
                ORDER BY sa.regNo ASC";
                
                $rankReportDetails = $this->executeQueryForList($sql, $this->mapper 
                [ConsolidatedMarkReportServiceMapper::GET_REGULAR_EXAM_MARK_DETAILS]);
                
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $rankReportDetails;
        }
        /**
         * @param $subjectToppersRequest
         * @return Object|null
         * @throws ProfessionalException
         * @author Vishnu M
         */
        public function getSubjectToppersExamDetails ( $subjectToppersRequest ) {
            $subjectToppersRequest = $this->realEscapeObject($subjectToppersRequest);
            $condition = null;
            if ( $subjectToppersRequest->rankReportId ) {
                $condition .= " AND rrsgm.rank_report_id = '$subjectToppersRequest->rankReportId";
            }
            if ( $subjectToppersRequest->rankReportSubjectGroupId ) {
                $condition .= " AND rrsgm.rank_report_subject_group_id = '$subjectToppersRequest->rankReportSubjectGroupId";
            }
            if ($subjectToppersRequest->gender) {
                $condition .= " AND sa.studentGender LIKE '$subjectToppersRequest->gender";
            }
            if ($subjectToppersRequest->seatReservationId) {
                // reservID in studentaccount Table
                $seatReservationIdString = is_array($subjectToppersRequest->seatReservationId) ? implode(',', $subjectToppersRequest->seatReservationId) : $subjectToppersRequest->seatReservationId;
                $condition .= " AND sa.reservID IN ($seatReservationIdString";
            }
            if ($subjectToppersRequest->religionId) {
                $religionIdString = is_array($subjectToppersRequest->religionId) ? implode(',', $subjectToppersRequest->religionId) : $subjectToppersRequest->religionId;
                $condition .= " AND sa.religion IN ($religionIdString";
            }
            if ($subjectToppersRequest->campusTypeId) {
                $campusTypeIdString = is_array($subjectToppersRequest->campusTypeId) ? implode(',', $subjectToppersRequest->campusTypeId) : $subjectToppersRequest->campusTypeId;
                $condition .= " AND sa.campus_type_id IN ($campusTypeIdString";
            }
            
            $sql = null;
            $subjectTopperDetails = null;
            try {
                $sql = "
                SELECT 
                    sa.studentID,
                    sa.studentName,
                    sa.regNo,
                    sa.rollNo,
                    sa.admissionNo,
                    b.batchID,
                    b.batchName,
                    b.deptID,
                    b.totalSemester,
                    b.final_semester,
                    b.batchStartYear,
                    b.batchEndYear,
                    b.courseTypeID,
                    e.examID,
                    e.subjectID,
                    e.examregID,
                    e.semID,
                    sem.orderNo,
                    eme.id AS markId,
                    eme.mark AS externalMark,
                    e.examTotalMarks AS externalMax,
                    im.internalMarkID,
                    im.internalMarks AS internalMark,
                    ims.maxInternalMarks AS internalMax,
                    esc.isInternal,
                    esc.isExternal,
                    esc.excludeSubjectFromTotal,
                    esc.subjectType,
                    IF (ees.id, 1, 0) AS isExempted,
                    rrsgm.subjects_id AS subjectID,
                    rrsgm.semesters_id AS semID
                FROM
                    exam_registration er
                        INNER JOIN
                    exam_registration_batches erb ON (er.examregID = erb.examregID)
                        INNER JOIN
                    rank_report_subject_group_mapping rrsgm ON (rrsgm.semesters_id = erb.semID)
                        INNER JOIN
                    rank_report_subject_group rrsg ON (rrsg.id = rrsgm.rank_report_subject_group_id)
                        INNER JOIN
                    sbs_relation sbs ON (sbs.batchID = erb.batchID
                        AND sbs.semID = erb.semID
                        AND sbs.subjectID = rrsgm.subjects_id
                        AND sbs.semID = rrsgm.semesters_id)
                        INNER JOIN
                    batches b ON (b.batchID = erb.batchID
                        AND b.batchID = sbs.batchID)
                        INNER JOIN
                    semesters sem ON (sem.semID = sbs.semID)
                        INNER JOIN
                    exam_reg_studentchallan ersc ON (ersc.examregID = er.examregID
                        AND paid = 1)
                        INNER JOIN
                    exam_reg_studentsubject erss ON (ersc.studentID = erss.studentID
                        AND erss.examregID = er.examregID
                        AND erss.subjectID = rrsgm.subjects_id)
                        INNER JOIN
                    exam e ON (e.subjectID = erss.subjectID
                        AND e.batchID = erb.batchID
                        AND e.semID = erb.semID
                        AND e.examregID = er.examregID)
                        INNER JOIN
                    studentaccount sa ON (sa.studentID = ersc.studentID)
                        INNER JOIN
                    exammarks_external eme ON (eme.examID = e.examID
                        AND eme.studentID = sa.studentID)
                        INNER JOIN
                    exam_subjectcredit esc ON (esc.subjectID = rrsgm.subjects_id
                        AND esc.batchID = e.batchID
                        AND esc.semID = e.semID)
                        LEFT JOIN
                    internal_marks im ON (im.subjectID = rrsgm.subjects_id
                        AND im.studentID = sa.studentID
                        AND im.batchID = e.batchID
                        AND im.semID = e.semID)
                        LEFT JOIN
                    internal_marks_settings ims ON (ims.subjectID = rrsgm.subjects_id
                        AND ims.batchID = e.batchID
                        AND ims.semID = e.semID)
                        LEFT JOIN
                    exam_exempted_students ees ON ees.exam_id = e.examID
                        AND ees.studentaccount_id = sa.studentID
                        LEFT JOIN 
                    failed_students fs ON fs.studentID = sa.studentID
                        AND FIND_IN_SET(e.semID, fs.hisSemestersInThisbatch)
                WHERE
                    er.examregID = '$subjectToppersRequest->examRegId' AND erb.semID = '$subjectToppersRequest->semId'
                    $condition
                ORDER BY rrsg.name ASC, sa.regNo ASC, sem.semID ASC, esc.subjectOrder ASC, fs.failedInSemester ASC";
                $subjectTopperDetails = $this->executeQueryForList($sql, $this->mapper
                [ConsolidatedMarkReportServiceMapper::GET_REGULAR_EXAM_MARK_DETAILS]);
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $subjectTopperDetails;
        }
        /**
         * @param $subjectToppersRequest
         * @return Object|null
         * @throws ProfessionalException
         * @author Sibin
         */
        public function getSubjectToppersExamDetailsWithoutSbs ( $subjectToppersRequest ) {
            $subjectToppersRequest = $this->realEscapeObject($subjectToppersRequest);
            $condition = null;
            if ( $subjectToppersRequest->rankReportId ) {
                $condition .= " AND rrsgm.rank_report_id = '$subjectToppersRequest->rankReportId";
            }
            if ( $subjectToppersRequest->rankReportSubjectGroupId ) {
                $condition .= " AND rrsgm.rank_report_subject_group_id = '$subjectToppersRequest->rankReportSubjectGroupId";
            }
            if ($subjectToppersRequest->gender) {
                $condition .= " AND sa.studentGender LIKE '$subjectToppersRequest->gender";
            }
            if ($subjectToppersRequest->seatReservationId) {
                // reservID in studentaccount Table
                $seatReservationIdString = is_array($subjectToppersRequest->seatReservationId) ? implode(',', $subjectToppersRequest->seatReservationId) : $subjectToppersRequest->seatReservationId;
                $condition .= " AND sa.reservID IN ($seatReservationIdString";
            }
            if ($subjectToppersRequest->religionId) {
                $religionIdString = is_array($subjectToppersRequest->religionId) ? implode(',', $subjectToppersRequest->religionId) : $subjectToppersRequest->religionId;
                $condition .= " AND sa.religion IN ($religionIdString";
            }
            if ($subjectToppersRequest->campusTypeId) {
                $campusTypeIdString = is_array($subjectToppersRequest->campusTypeId) ? implode(',', $subjectToppersRequest->campusTypeId) : $subjectToppersRequest->campusTypeId;
                $condition .= " AND sa.campus_type_id IN ($campusTypeIdString";
            }
            if($subjectToppersRequest->studentId){
                $condition .= " AND sa.studentId IN ($subjectToppersRequest->studentId";
            }
            if($subjectToppersRequest->subjectIds){
                $condition .= " AND e.subjectID IN ($subjectToppersRequest->subjectIds";
            }
            
            $sql = null;
            $subjectTopperDetails = null;
            try {
                $sql = "
                SELECT 
                    sa.studentID,
                    sa.studentName,
                    sa.regNo,
                    sa.rollNo,
                    sa.admissionNo,
                    b.batchID,
                    b.batchName,
                    b.deptID,
                    b.totalSemester,
                    b.final_semester,
                    b.batchStartYear,
                    b.batchEndYear,
                    b.courseTypeID,
                    e.examID,
                    e.subjectID,
                    e.examregID,
                    e.semID,
                    sem.orderNo,
                    eme.id AS markId,
                    eme.mark AS externalMark,
                    e.examTotalMarks AS externalMax,
                    im.internalMarkID,
                    im.internalMarks AS internalMark,
                    ims.maxInternalMarks AS internalMax,
                    esc.isInternal,
                    esc.isExternal,
                    esc.excludeSubjectFromTotal,
                    esc.subjectType,
                    IF (ees.id, 1, 0) AS isExempted,
                    rrsgm.subjects_id AS subjectID,
                    rrsgm.semesters_id AS semID
                FROM
                    exam_registration er
                        INNER JOIN
                    exam_registration_batches erb ON (er.examregID = erb.examregID)
                        INNER JOIN
                    rank_report_subject_group_mapping rrsgm ON (rrsgm.semesters_id = erb.semID)
                        INNER JOIN
                    rank_report_subject_group rrsg ON (rrsg.id = rrsgm.rank_report_subject_group_id)
                        INNER JOIN
                    exam_subjectcredit esc ON (esc.batchID = erb.batchID
                        AND esc.semID = erb.semID
                        AND esc.subjectID = rrsgm.subjects_id
                        AND esc.semID = rrsgm.semesters_id)
                        INNER JOIN
                    batches b ON (b.batchID = erb.batchID
                        AND b.batchID = esc.batchID)
                        INNER JOIN
                    semesters sem ON (sem.semID = esc.semID)
                        INNER JOIN
                    exam_reg_studentchallan ersc ON (ersc.examregID = er.examregID
                        AND paid = 1)
                        INNER JOIN
                    exam_reg_studentsubject erss ON (ersc.studentID = erss.studentID
                        AND erss.examregID = er.examregID
                        AND erss.subjectID = rrsgm.subjects_id)
                        INNER JOIN
                    exam e ON (e.subjectID = erss.subjectID
                        AND e.batchID = erb.batchID
                        AND e.semID = erb.semID
                        AND e.examregID = er.examregID)
                        INNER JOIN
                    studentaccount sa ON (sa.studentID = ersc.studentID)
                        LEFT JOIN
                    exammarks_external eme ON (eme.examID = e.examID
                        AND eme.studentID = sa.studentID)
                        LEFT JOIN
                    internal_marks im ON (im.subjectID = rrsgm.subjects_id
                        AND im.studentID = sa.studentID
                        AND im.batchID = e.batchID
                        AND im.semID = e.semID)
                        LEFT JOIN
                    internal_marks_settings ims ON (ims.subjectID = rrsgm.subjects_id
                        AND ims.batchID = e.batchID
                        AND ims.semID = e.semID)
                        LEFT JOIN
                    exam_exempted_students ees ON ees.exam_id = e.examID
                        AND ees.studentaccount_id = sa.studentID
                        LEFT JOIN 
                    failed_students fs ON fs.studentID = sa.studentID
                        AND FIND_IN_SET(e.semID, fs.hisSemestersInThisbatch)
                WHERE
                    er.examregID = '$subjectToppersRequest->examRegId' AND erb.semID = '$subjectToppersRequest->semId'
                    AND e.batchID = IF (fs.previousBatch, fs.previousBatch, sa.batchID)
                    $condition
                ORDER BY rrsg.name ASC, sa.regNo ASC, sem.semID ASC, esc.subjectOrder ASC, fs.failedInSemester ASC";
                $subjectTopperDetails = $this->executeQueryForList($sql, $this->mapper
                [ConsolidatedMarkReportServiceMapper::GET_REGULAR_EXAM_MARK_DETAILS]);
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            return $subjectTopperDetails;
        }
    }
?>