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 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 360
Template6FCMC
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 5
6972.00
0.00% covered (danger)
0.00%
0 / 360
 __construct
n/a
0 / 0
1
n/a
0 / 0
 getTemplateName
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 21
 processData
0.00% covered (danger)
0.00%
0 / 1
5112.00
0.00% covered (danger)
0.00%
0 / 256
 renderTemplate
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 47
 getsecondLanguageName
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 9
 getopenCourseName
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 27
<?php
//  SCEK College
namespace com\linways\ec\core\service\FinalConsolidatdMarksCardGenerator;
use com\linways\base\util\TwigRenderer;
use com\linways\ec\core\service\MarksCardService;
use com\linways\ec\core\service\CommonExamService;
use com\linways\core\ams\professional\util\PdfUtil;
use com\linways\core\ams\professional\util\CommonUtil;
use com\linways\ec\core\exception\ExamControllerException;
use com\linways\ec\core\service\FinalConsolidatedReportService;
use com\linways\ec\core\service\FinalConsolidatdMarksCardGenerator\FCMGenerator;
use com\linways\core\ams\professional\service\StudentService;
use com\linways\core\ams\professional\constant\examcontroller\CourseTypeConstants;
use com\linways\ec\core\service\ExamRegistrationService;
use com\linways\ec\core\request\SearchExamRegistrationRequest;
use com\linways\ec\core\service\ExamRegistrationBatchService;
use com\linways\ec\core\request\SearchExamRegistrationBatchRequest;
use com\linways\core\ams\professional\constant\ExamType;
use com\linways\core\ams\professional\service\AmsCustomFieldsService;
use com\linways\core\ams\professional\constant\AmsCustomFieldsEntities;
class Template6FCMC extends FCMGenerator
{
    public function __construct(){}
    
    protected function getTemplateName($request){
        $query = "SELECT
            ct.course_Type AS courseType,
            g.properties->>'$.startYear' AS batchStartYear
        FROM
            `groups` g
        INNER JOIN program p ON
            p.id = CAST(g.properties->>'$.programId' AS CHAR)
        INNER JOIN course_type ct ON
            ct.courseTypeID = p.course_type_id
        WHERE g.id IN ('$request->groupId')";
        $courseDetails = $this->executeQueryForObject($query);
        $courseType = $courseDetails->courseType;
        $batchStartYear = $courseDetails->batchStartYear;
        if ($courseType == "UG") {
            $templateName = "Template6FCMC_BTECH";
        }
        else{
            $templateName = 'Template6FCMC';
        }
        return $templateName;
    }
     /**
     * Process Student data college base
     * @param $request
     */
    protected function processData($request){
        // to fetch all Special exam assigned for this batch
        $requestForSpecialExam = new \stdClass;
        $requestForSpecialExam->isSpecialExamRegistration = true;
        $requestForSpecialExam->groupId = $request->groupId;
        $allSupplementaryExamRegistrations = (array) ExamRegistrationService::getInstance()->searchExamRegistrationByOtherDetails($requestForSpecialExam);
        $allSupplementaryExamRegistrationIds = array_column($allSupplementaryExamRegistrations,'id');
        // get all students credit points
        $requestForActivityPoints = new \stdClass;
        $requestForActivityPoints->groupId = $request->groupId;
        $requestForActivityPoints->studentId = $request->studentId;
        $studentActivityPoints = CommonExamService::getInstance()->getStudentsActivityPoints($requestForActivityPoints);
        $response = new \stdClass;
        $searchRequest = new \stdClass;
        $request->excludeMinorHonor = 1;
        $response->studentData = reset(MarksCardService::getInstance()->getConsoliidatedMarksCardData($request))->students;
        uasort($response->studentData, function ($a, $b) {
            return $a->regNo > $b->regNo;
        });
        // to fetch Mionor Subject Details
        $request->excludeMinorHonor = false;
        $request->consoiderHonoursSubjects = false;
        $request->consoiderMinorSubjects = 1;
        $response->minorStudentData = reset(MarksCardService::getInstance()->getConsoliidatedMarksCardData($request))->students;
        // to fetch Honour Subject Details
        $request->excludeMinorHonor = false;
        $request->consoiderMinorSubjects = false;
        $request->consoiderHonoursSubjects = 1;
        $response->honoursStudentData = reset(MarksCardService::getInstance()->getConsoliidatedMarksCardData($request))->students;
        $courseType = reset($response->studentData)->courseType;
        $batchStartYear = reset($response->studentData)->admissionYear;
        foreach ($response->studentData as $studentId => $student){
            $student->studentImage  = StudentService::getInstance()->getStudentProfilePic($student->studentId)->docpath;
            $student->dobFullName = $student->dob ?  date('d-F-Y',strtotime($student->dob)) : '';
            $student->dob  = $student->dob ?  date("d/m/Y", strtotime($student->dob)) : '';
            $batchDetails = json_decode($student->properties);
            $student->courseCompleteWithinYear = 1;
            $finalSem = $batchDetails->finalTermId;
            $student->finalSem = $batchDetails->finalTermId;
            // this case to check if student attempt supply after last semester regular exam then not eligible minor
            $student->lastAcademicTerm = reset(array_filter( $student->academicTerms ,function($value)use($finalSem){
                return $value->termId == $finalSem;
            }));
            $student->finalTermRegularExamHistory = reset(array_filter($student->lastAcademicTerm->markHistory,function($value){
                return $value->historyType == 'REGULAR';
            }));
            $student->finalTermRegularExamMonthYear = !empty($student->finalTermRegularExamHistory ) ? date('Y-m',strtotime($student->finalTermRegularExamHistory->examYear."-". $student->finalTermRegularExamHistory->examMonth."-01")) : NULL;
            $student->latestExamMonthYear = $student->markDetails->latestExamMonth ?  date("Y-m", strtotime($student->markDetails->latestExamYear."-".$student->markDetails->latestExamMonth."-01")) : NULL;
            foreach ($student->academicTerms as $key => $semMark){
                $totalMarkMinimum = 0;
                $semesterNames = CommonExamService::getInstance()->getDifferentSemesterName($semMark->termName);
                $semMark->semInRomanLetter = $semesterNames->romanLetter;
                $semMark->semInFullName = $semesterNames->fullName;
                if ($semMark->failedStatus != 'FAILED') {
                    $sgpa = round($semMark->sgpa, 2);
                    $sgpa = sprintf('%0.2f', $sgpa);
                }
            
                $semMark->sgpa = $sgpa;
                uasort($semMark->subject, function ($a, $b) {
                    return $a->subjectOrder > $b->subjectOrder;
                });
            }
            $student->minorSubjects = [];
            $student->honoursSubjects = [];
            $student->isPassAllMinorSubjects = true;
            $student->studentMinorCredits = 0;
            $student->studentHonoursCredits = 0;
            $minorDetails = $response->minorStudentData[$studentId];
            $student->isPassAllHonourSubjects = true;
            $honoursDetails = $response->honoursStudentData[$studentId];
            // check conditions for eligible minor certificate and eligible minor subjects
            // if the certificate is verified then that subject become passed (Grade P )in case of MOOC subject 
            // if student attempt supply after last semester regular exam then not eligible minor
            foreach ($minorDetails->academicTerms as $minorTermId) {
                foreach ($minorTermId->subjects as $minorSubject) {
                    if($minorSubject->isMoocSubject == '1'){
                        if($minorSubject->moocVerificationStatus == 'APPROVED'){
                            $minorSubject->examMonthYearFormat2 = date('M Y',strtotime($minorSubject->markDetails->latestExamYear."-".$minorSubject->markDetails->latestExamMonth."-01"));
                            $minorSubject->credit = $minorSubject->markDetails->credit;
                            $student->studentMinorCredits =  $student->studentMinorCredits + (float)$minorSubject->credit;
                            $minorSubject->isMooc = $minorSubject->isMoocSubject == '1' ? 1 : 0; 
                            $minorSubject->grade = "P";
                            $minorSubject->failedStatus = "PASSED";
                            $student->minorSubjects[] = $minorSubject;
                        }
                        else{
                            $student->isPassAllMinorSubjects = false;
                        }
                    }
                    else{
                        if($minorSubject->failedStatus == 'FAILED'){
                            $student->isPassAllMinorSubjects = false;
                        }
                        else{
                            $minorSubject->examMonthYearFormat2 = date('M Y',strtotime($minorSubject->markDetails->latestExamYear."-".$minorSubject->markDetails->latestExamMonth."-01"));
                            $minorSubject->credit = $minorSubject->markDetails->credit;
                            $student->studentMinorCredits =  $student->studentMinorCredits + (float)$minorSubject->credit;
                            $minorSubject->isMooc = $minorSubject->isMoocSubject == '1' ? 1 : 0; 
                            $student->minorSubjects[] = $minorSubject;
                        }
                    }
                }
            }
            if(!empty($student->finalTermRegularExamMonthYear) && !empty($student->latestExamMonthYear)){
                if($student->finalTermRegularExamMonthYear < $student->latestExamMonthYear){
                    $student->isPassAllMinorSubjects = false;
                }
            }
            // check conditions for eligible honours certificate and eligible honours subjects
            // check all with exclude mooc subject having gradepont greate than or egual to 6.5 then will be pass otherwise not eligible for Honours degree 
            // if subject is passed then get credit of the subject
            // if the certificate is verified then that subject become passed (Grade P ) in case of MOOC subject 
            // 6.5 -> grade pont of C grade (as per college rule)  
            foreach ($honoursDetails->academicTerms as $honoursTermId) {
                foreach ($honoursTermId->subjects as $honoursSubject) {
                    if($honoursSubject->isMoocSubject == '1'){
                        if($honoursSubject->moocVerificationStatus == 'APPROVED'){
                            $honoursSubject->examMonthYearFormat2 = date('M Y',strtotime($honoursSubject->markDetails->latestExamYear."-".$honoursSubject->markDetails->latestExamMonth."-01"));
                            $honoursSubject->credit = $honoursSubject->markDetails->credit;
                            $student->studentHonoursCredits =  $student->studentHonoursCredits + (float)$honoursSubject->credit;
                            $honoursSubject->isMooc = $honoursSubject->isMoocSubject == '1' ? 1 : 0; 
                            $honoursSubject->grade = "P";
                            $honoursSubject->failedStatus = "PASSED";
                            $student->honoursSubjects[] = $honoursSubject;
                        }
                        else{
                            $student->isPassAllHonourSubjects = false;
                        }
                    }
                    else{
                        if((float)$honoursSubject->markDetails->gradePoint >= 6.5){
                            $honoursSubject->examMonthYearFormat2 = date('M Y',strtotime($honoursSubject->markDetails->latestExamYear."-".$honoursSubject->markDetails->latestExamMonth."-01"));
                            $honoursSubject->credit = $honoursSubject->markDetails->credit;
                            $student->studentHonoursCredits =  $student->studentHonoursCredits + (float)$honoursSubject->credit;
                            $student->honoursSubjects[] = $honoursSubject;
                        }
                        else{
                            $student->isPassAllHonourSubjects = false;
                            if($honoursSubject->failedStatus == "PASSED"){
                                $honoursSubject->examMonthYearFormat2 = date('M Y',strtotime($honoursSubject->markDetails->latestExamYear."-".$honoursSubject->markDetails->latestExamMonth."-01"));
                                $honoursSubject->credit = $honoursSubject->markDetails->credit;
                                $student->studentHonoursCredits =  $student->studentHonoursCredits + (float)$honoursSubject->credit;
                                $student->honoursSubjects[] = $honoursSubject;
                            }
                        }
                    }
                }
            }
           
        }
        foreach ($response->studentData as $studentId => $student) {
            $student->nonAcademicsCredits = 0;
            $student->totalEarnedCredit = 0; 
            if(!empty($studentActivityPoints[$student->studentId])){
                if($studentActivityPoints[$student->studentId]->activityPoint >= 100){
                    $student->nonAcademicsCredits = '2.00';
                    $student->totalEarnedCredit = 2; 
                }
            }
            $customFields = AmsCustomFieldsService::getInstance()->getAmsCustomFieldValue(AmsCustomFieldsEntities::STUDENT, $student->studentId, []);
            if( $customFields ){
                $student->ktuCode = CommonExamService::getInstance()->getCustomFieldObjectList($customFields)->studentData->KTU_CODE;
            }
            
            $student->lastExamMonthYear = $student->markDetails->latestExamMonth ?  date("F Y", strtotime("01-". $student->markDetails->latestExamMonth."-".$student->markDetails->latestExamYear)) : "";
            $student->credit = $student->markDetails->credit;
            $student->roundOff = 2;
            $student->cgpa = round($student->markDetails->rawCgpa, $student->roundOff);
            $student->class = $student->markDetails->class;
            $student->cgpaInWords = CommonUtil::convertNumberToWords($student->cgpa);
            $student->cgpa = sprintf('%0.2f', $student->cgpa);
            $student->creditInWords = CommonUtil::convertNumberToWords($student->markDetails->credit);
            foreach ($student->academicTerms as $term) {
                $term->credit = $term->markDetails->credit;
                $additionalCreditRequest = new \stdClass;
                $additionalCreditRequest->studentId  = $student->studentId;
                $additionalCreditRequest->academicTermId  = $term->termId;
                $additionalCreditRequest->groupId  = $student->groupsId;
                $additionalCreditRequest->creditType = "CREDIT_TRANSFERED";
                $additionalCredit = CommonExamService::getInstance()->getStudentAdditionalCredits($additionalCreditRequest);
                $term->semCredit = 0; 
                $term->transferredCredit = (int)$additionalCredit->credit ? $additionalCredit->credit : 0;
                $term->semCredit += $term->transferredCredit; 
                $student->totalEarnedCredit += $term->transferredCredit; 
                foreach ($term->subjects as $subject) {
                    $subject->examMonthYear = date('F Y',strtotime($subject->markDetails->latestExamYear."-".$subject->markDetails->latestExamMonth."-01"));
                    $subject->examMonthYearFormat2 = date('M Y',strtotime($subject->markDetails->latestExamYear."-".$subject->markDetails->latestExamMonth."-01"));
                    $subject->credit = $subject->markDetails->credit;
                    $subject->isElective =  $subject->subjectCategoryCode == 'ELECTIVE' ? 1 : 0;
                    if(  $subject->failedStatus == "PASSED" ){
                        $term->semCredit += $subject->credit;
                        $student->totalEarnedCredit += $subject->credit;
                    }
                    if($subject->markDetails->excludeSubjectFromTotal == '1'){
                        $subject->grade = $subject->failedStatus == "PASSED" ? 'P' : 'F' ;
                    }
                }
            }
            //For QR code generation
            if($student->failedStatus == 'FAILED'){
                $student->qrData =  $student->regNo . " | " . $student->name;
            }else{
                $student->qrData =  $student->regNo . " | " . $student->name . " | CGPA - " . $student->cgpa;
            }
            if( $student->isPassAllMinorSubjects){
                if(empty($student->minorSubjects)){
                    $student->isPassAllMinorSubjects = false;
                }
                elseif($student->studentMinorCredits < 20){
                    $student->isPassAllMinorSubjects = false;
                }
            }
            if( $student->isPassAllHonourSubjects){
                // ---------------- Check Honour Passing Criteria --------------------
                // 1.Currently Pass OverAll Subject And get cgpa >= 8.5
                // 2.Pass All Subjects in honurs with credit atleast 20
                // 3.No backlogs (Supply) not consider backlog as special and revaluation
                if(empty($student->honoursSubjects)){
                    $student->isPassAllHonourSubjects = false;
                }
                elseif($student->studentHonoursCredits < 20){
                    $student->isPassAllHonourSubjects = false;
                }
                else if($student->failedStatus == 'FAILED' || ($student->cgpa < 8.5)){
                    $student->isPassAllHonourSubjects = false;
                }
                else{
                    foreach ($student->academicTerms as $term) {
                        foreach ($term->subjects as $subject) {
                            if(count($subject->markHistory) >= 2 && !empty($allSupplementaryExamRegistrationIds)){
                                $specialExamSubject = reset(array_filter($subject->markHistory,function($value)use($allSupplementaryExamRegistrationIds){
                                    return in_array($value->examRegistrationId, $allSupplementaryExamRegistrationIds);
                                }));
                                $revaluationExamHistory = reset(array_filter($subject->markHistory,function($value)use($allSupplementaryExamRegistrationIds){
                                    return $value->examMarkType == 'REVALUATION';
                                }));
                                if(!empty($specialExamSubject)){
                                    $subject->markHistory = array_filter($subject->markHistory,function($value)use($allSupplementaryExamRegistrationIds){
                                        return $value->examMarkType != 'REGULAR';
                                    });
                                }
                                if(!empty($revaluationExamHistory)){
                                    $subject->markHistory = array_filter($subject->markHistory,function($value)use($allSupplementaryExamRegistrationIds){
                                        return $value->examMarkType != 'REGULAR';
                                    });
                                }
                                if (count($subject->markHistory) >= 2) {
                                    $student->isPassAllHonourSubjects = false;
                                    break;
                                } 
                            }
                        }
                    }
                }
            }
            if ( $request->filterSettings['showMinorMarksCard'] && $request->filterSettings['showHonoursMarksCard']){
                if(empty($student->minorSubjects) || empty($student->honoursSubjects) || !$student->isPassAllHonourSubjects || !$student->isPassAllMinorSubjects){
                    unset($response->studentData[$studentId]);
                }
            }
            else if ( $request->filterSettings['showMinorMarksCard'] ){
                if( empty($student->minorSubjects)  || !$student->isPassAllMinorSubjects || !empty($student->honoursSubjects)){
                    unset($response->studentData[$studentId]);
                }
            }
            else if ( $request->filterSettings['showHonoursMarksCard'] ){
                if( empty($student->honoursSubjects) || !$student->isPassAllHonourSubjects || !empty($student->minorSubjects)){
                    unset($response->studentData[$studentId]);
                }
            }
        }
        if(empty($response->studentData)){
            throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No Details Found");
        }
        $response->showHonoursMarksCard = $request->filterSettings['showHonoursMarksCard'];
        $response->showMinorMarksCard = $request->filterSettings['showMinorMarksCard'];
        $response->disableCollegeRegisterNumber = false;
        if($batchStartYear >= '2023'){
            $response->disableCollegeRegisterNumber = true;
        }
        $response->collegeData = CommonExamService::getInstance()->getCollegeDetails();
        $response->dateOfIssue = $request->filterSettings['markListDate']?: date("d-m-Y");
        $response->dateOfIssueWithMonthName = $request->filterSettings['markListDate'] ? date('d-F-Y',strtotime($request->filterSettings['markListDate'])) : date("d-F-Y");
        return $response;
    }
     /**
     * Render Program Result
     * @param $templateName
     * @param Object $data
     * @return Object
     */
    protected function renderTemplate($templateName, $data){
        if(empty($data)){
            throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No Details Found");
        }
        else{
            $responseHtml = TwigRenderer::renderTemplateFileToHtml(realpath(DOCUMENT_ROOT."../examcontroller-api/src/com/linways/web/templates/FinalConsolidatedMarksCard/Template6/$templateName.twig"), [ 'data'=>$data ]);
            $prtContent = NULL;
            $prtContent .= '<html><head>';
            $prtContent .= "<style>
                
                </style>";
            $prtContent .= '</head><title>Consolidated Marks Card</title><body>';
            $prtContent .= $responseHtml;
            $prtContent .= '</body></html>';
            if ( $templateName == "Template6FCMC_BTECH" ){
                $width = 420;
                $height = 297;
                $options = array(
                    'page-width'     => $width."mm",
                    'page-height'    => $height."mm",
                    'dpi'            => 490,
                    'margin-top' => "17mm",
                    'margin-left' => "15mm",
                    'margin-right' => "15mm",
                    'margin-bottom' => "50mm",
                    // 'binary' => "/usr/local/bin/wkhtmltopdf", // For Mac
                    'user-style-sheet' => realpath(DOCUMENT_ROOT . "/libcommon/bootstrap/css/bootstrap.min.css")
                );
            }
            else{
                $width = 297;
                $height = 420;
                $options = array(
                    'page-width'     => $width."mm",
                    'page-height'    => $height."mm",
                    'dpi'            => 490,
                    'margin-top' => "10mm",
                    'margin-left' => "10mm",
                    'margin-right' => "10mm",
                    'margin-bottom' => "10mm",
                    'orientation'=> "landscape",
                    // 'binary' => "/usr/local/bin/wkhtmltopdf", // For Mac
                    'user-style-sheet' => realpath(DOCUMENT_ROOT . "/libcommon/bootstrap/css/bootstrap.min.css")
                );
            }
          
            $finalCMC = new \stdClass;
            $finalCMC->htmlData = $responseHtml;
            $finalCMC->printData = PdfUtil::renderPdf($prtContent, $options);
        return  $finalCMC;
        }
       
    }
    private function getsecondLanguageName($studentId)
    {
        try {
            $query = "SELECT t1.secondLangaugeName FROM secondLangauge t1,studentaccount t2 WHERE t1.secondlangaugeID = t2.secondlangaugeID AND t2.studentID = ".$studentId."";
    
            $displayName = $this->executeQueryForObject($query)->secondLangaugeName;;
        } catch (\Exception $e) {
            throw $e;
        }
        return $displayName;
    }
    private function getopenCourseName($studentID)
    {
        try {
            $sql_check33 = "SELECT t1.pseudosubjectID FROM pseudosubjects t1,pseudosubjects_students t2 WHERE t1.pseudosubjectID = t2.pseudosubjectID AND t2.studentID = ".$studentID." AND t1.isOpencourse = 1";
    
            $pseudosubjectID = $this->executeQueryForObject($sql_check33)->pseudosubjectID;
    
            if($pseudosubjectID)
            {
                $query1 = "SELECT t1.subjectID FROM sbs_relation t1,pseudosubjects_sbs t2 WHERE t1.sbsID = t2.sbsID AND t2.pseudosubjectID = ".$pseudosubjectID."";
    
                $subjectID = $this->executeQueryForObject($query1)->subjectID;
    
                if($subjectID)
                {
                    $sql ="SELECT code as subjectName, name as subjectDesc from v4_ams_subject where id=\"".$subjectID."\"";
                
                    $subjectDesc = $this->executeQueryForObject($sql)->subjectDesc;    
                }
                else
                {
                    $subjectDesc = '-'; 
                }
    
            }
            else
            {
                $subjectDesc = '-'; 
            }
        } catch (\Exception $e) {
            throw $e;
        }
        return $subjectDesc;
    }
}