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 / 15
CRAP
0.00% covered (danger)
0.00%
0 / 244
UniversityExamCoPoRuleService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 15
3306.00
0.00% covered (danger)
0.00%
0 / 244
 __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
 insertUniversityCoPoRules
0.00% covered (danger)
0.00%
0 / 1
42.00
0.00% covered (danger)
0.00%
0 / 18
 deleteCOPORulesOfUniversityExam
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 12
 getUniversityExamRules
0.00% covered (danger)
0.00%
0 / 1
342.00
0.00% covered (danger)
0.00%
0 / 71
 getDataForUniversityExamRules
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 19
 upsertUniversityAttainmentRules
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 10
 upsertUniversityAttainmentRulesForDepartment
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 10
 deleteUniversityAttainmentRule
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 9
 deleteUniversityAttainmentRuleForDepartment
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 9
 getRulesForUniversityAttainment
0.00% covered (danger)
0.00%
0 / 1
42.00
0.00% covered (danger)
0.00%
0 / 28
 getRulesForUniversityAttainmentForSubject
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 17
 getRulesForUniversityAttainmentForDepartment
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 15
 getEndSemesterExamDetails
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 16
<?php
namespace com\linways\core\ams\professional\service\nba;
use com\linways\core\ams\professional\util\CommonUtil;
use com\linways\core\ams\professional\service\BaseService;
use com\linways\core\ams\professional\service\BatchService;
use com\linways\core\ams\professional\service\DepartmentService;
use com\linways\core\ams\professional\exception\ProfessionalException;
use com\linways\core\ams\professional\dto\nba\NBASubjectAssessmentCoValue;
use com\linways\core\ams\professional\mapper\nba\UniversityExamCoPoRuleServiceMapper;
class UniversityExamCoPoRuleService 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 = UniversityExamCoPoRuleServiceMapper::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 [type] $rules
     * @return void
     */
    public function insertUniversityCoPoRules($rules)
    {
        $rules = $this->realEscapeArray($rules);
        if (!empty($rules)) {
            $rule = $rules[0];
            $this->deleteCOPORulesOfUniversityExam($rule->subjectId, $rule->batchId, $rule->semId);
        }
        $sql = "INSERT INTO `nba_university_exam_co_mapping_rules` (`co_id`, `po_id`, `value`, `from_percent`, `to_percent`, `distribution_type`, `subject_id`, `sem_id`, `batch_id`, `staff_id`, `created_by`, `created_date`, `updated_by`, `updated_date`) VALUES ";
        $values = [];
        foreach ($rules as $rule) {
            $values[] = "(".($rule->coId?$rule->coId:'NULL').", ".($rule->poId?$rule->poId:'NULL').", '$rule->value', '$rule->fromPercent', '$rule->toPercent', '$rule->distributionType', '$rule->subjectId', '$rule->semId', '$rule->batchId', '$rule->staffId', '$rule->createdBy', UTC_TIMESTAMP(), $rule->updatedBy, UTC_TIMESTAMP())";
        }
        $sql .= implode(',', $values);
        try {
            $this->executeQuery($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    public function deleteCOPORulesOfUniversityExam($subjectId, $batchId, $semId)
    {
        $subjectId = $this->realEscapeString($subjectId);
        $batchId = $this->realEscapeString($batchId);
        $semId = $this->realEscapeString($semId);
        $sql = "DELETE FROM nba_university_exam_co_mapping_rules WHERE subject_id = '$subjectId' AND batch_id = '$batchId' AND sem_id = '$semId'";
        try {
            $this->executeQuery($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return true;
    }
    public function getUniversityExamRules($batchId,$semId,$subjectId,$mapToCoCheck = null){
        $subjectId = $this->realEscapeString($subjectId);
        $batchId = $this->realEscapeString($batchId);
        $semId = $this->realEscapeString($semId);
        $mapToCoCheck = ($mapToCoCheck === null)? NULL: (int) $this->realEscapeString($mapToCoCheck);
        $sql = "";
        $percentList = [];
        $sql = "SELECT 
                    id,
                    co_id AS coId,
                    po_id AS poId,
                    value,
                    from_percent AS fromPercent,
                    to_percent AS toPercent,
                    concat(from_percent,'_', to_percent) as fromAndToPercent
                FROM
                    nba_university_exam_co_mapping_rules
                WHERE
                    batch_id = '$batchId' AND sem_id = '$semId'
                        AND subject_id = '$subjectId'";
        try{
           $responseList =  $this->executeQueryForList($sql, $this->mapper[UniversityExamCoPoRuleServiceMapper::GET_UNIVERSITY_RULES]);
        }catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        $mapToCo = true;
        if(( $mapToCoCheck !== null) && count($responseList)==0){
            if($mapToCoCheck===0){
                $mapToCo = false; 
            }elseif($mapToCoCheck===1){
                $mapToCo = true;
            }
        }
        foreach($responseList as $response){
            $percent = new \stdClass();
            
            if( $mapToCoCheck !== null){
                if(!empty($response->poList) && ($mapToCoCheck===0)){
                    $percent->fromPercent = $response->fromPercent;
                    $percent->toPercent = $response->toPercent;
                    $mapToCo = false;
                    $percent->mappings = CommonUtil::getObjectAttributeAsArrayFromObjectList($response->poList, 'id');
                }elseif(!empty($response->coList) && ($mapToCoCheck===1)){
                    $percent->fromPercent = $response->fromPercent;
                    $percent->toPercent = $response->toPercent;
                    $mapToCo = true;
                    $percent->mappings = CommonUtil::getObjectAttributeAsArrayFromObjectList($response->coList, 'id');
                }else{
                    if($mapToCoCheck===0){
                        $mapToCo = false; 
                    }elseif($mapToCoCheck===1){
                        $mapToCo = true;
                    }
                }   
            }else{
                $percent->fromPercent = $response->fromPercent;
                $percent->toPercent = $response->toPercent;
                if(!empty($response->poList)){
                    $mapToCo = false;
                    $percent->mappings = CommonUtil::getObjectAttributeAsArrayFromObjectList($response->poList, 'id');
                }elseif(!empty($response->coList)){
                    $mapToCo = true;
                    $percent->mappings = CommonUtil::getObjectAttributeAsArrayFromObjectList($response->coList, 'id');
                }
            }
            if (property_exists($percent, 'fromPercent')) {
                $percentList[] = $percent;
            }
        }
        $response->mapToCo = $mapToCo;
        $response->ruleList = $percentList;
        return $response;
    }
public function getDataForUniversityExamRules($batchId,$semId,$subjectId,$mapToCoCheck = null){
    $response = new \stdClass();
    if($mapToCoCheck===null){
        $rules = $this->getUniversityExamRules($batchId,$semId,$subjectId);
    }else{
        $rules = $this->getUniversityExamRules($batchId,$semId,$subjectId,$mapToCoCheck);
    }
    $response->mapToCo = $rules->mapToCo;
    $response->mapTo = "co";
    $response->rules = $rules->ruleList;
    if($response->mapToCo){
        $response->mapTo = "co";
    }else{
        $response->mapTo = "po";
    }
    
    $response->coList = NbaCoService::getInstance()->getAllCosBySubjectIdBatchIdAndSemId($subjectId, $batchId, $semId);
    $departmentId = BatchService::getInstance()->getBatchDetailsById($batchId)->deptId;
    $response->poList = NbaCoPoService::getInstance()->getProgramOutcomeListByBatchId($batchId);
    return $response;
}
/**
 * 
 *
 * @param [type] $universityAttainment
 * @return void
 */
public function upsertUniversityAttainmentRules($universityAttainment){
    $universityAttainment = $this->realEscapeObject($universityAttainment);
    $universityAttainment->rule = json_encode($universityAttainment->rule);
    $sql = "INSERT INTO `nba_university_attainment_rules` (`batch_id`, `sem_id`, `subject_id`, `rule`, `created_by`, `created_date`, `updated_by`, `updated_date`) VALUES ('$universityAttainment->batchId', '$universityAttainment->semId', '$universityAttainment->subjectId', '$universityAttainment->rule', '$universityAttainment->createdBy', UTC_TIMESTAMP(), '$universityAttainment->updatedBy', UTC_TIMESTAMP()) ON DUPLICATE KEY UPDATE rule='$universityAttainment->rule'";
    try {
        $this->executeQuery($sql);
    } catch (\Exception $e) {
        throw new ProfessionalException($e->getCode(), $e->getMessage());
    }
    return true;
}
/**
 * Undocumented function
 *
 * @param [type] $universityAttainment
 * @return void
 */
public function upsertUniversityAttainmentRulesForDepartment($universityAttainment){
    $universityAttainment = $this->realEscapeObject($universityAttainment);
    $universityAttainment->rule = json_encode($universityAttainment->rule);
    $sql = "INSERT INTO `nba_university_attainment_rules_for_department` (`department_id`, `enforce_rule`, `rule`, `created_by`, `created_date`, `updated_by`, `updated_date`) VALUES ('$universityAttainment->deptId', '$universityAttainment->enforceRule', '$universityAttainment->rule', '$universityAttainment->createdBy', UTC_TIMESTAMP(), '$universityAttainment->updatedBy', UTC_TIMESTAMP()) ON DUPLICATE KEY UPDATE rule='$universityAttainment->rule', enforce_rule='$universityAttainment->enforceRule'";
    try {
        $this->executeQuery($sql);
    } catch (\Exception $e) {
        throw new ProfessionalException($e->getCode(), $e->getMessage());
    }
    return true;
}
/**
 * Undocumented function
 *
 * @param [type] $request
 * @return void
 */
public function deleteUniversityAttainmentRule($request){
    $request = $this->realEscapeObject($request);
    $sql = "DELETE  FROM nba_university_attainment_rules WHERE batch_id = $request->batchId AND sem_id = $request->semId AND subject_id = $request->subjectId";
    try {
        $this->executeQuery($sql);
    } catch (\Exception $e) {
        throw new ProfessionalException($e->getCode(), $e->getMessage());
    }
    return true;
}
/**
 * Undocumented function
 *
 * @param [type] $request
 * @return void
 */
public function deleteUniversityAttainmentRuleForDepartment($request){
    $request = $this->realEscapeObject($request);
    $sql = "DELETE  FROM nba_university_attainment_rules_for_department WHERE department_id = $request->deptId ";
    try {
        $this->executeQuery($sql);
    } catch (\Exception $e) {
        throw new ProfessionalException($e->getCode(), $e->getMessage());
    }
    return true;
}
/**
 * Undocumented function
 *
 * @param [type] $batchId
 * @param [type] $semId
 * @param [type] $subjectId
 * @return void
 */
public function getRulesForUniversityAttainment($batchId, $semId, $subjectId)
{
    try{
        $deptId = DepartmentService::getInstance()->getDepartmentByBatchId($batchId)->deptID;
    }catch(\Exception $e){
        $deptId = null;
    }
    try{
        $ruleDetails = $this->getRulesForUniversityAttainmentForDepartment($deptId);
    }catch(\Exception $e){
        $ruleDetails = null;
    }
    if(empty($ruleDetails)){
        try{
            $ruleDetails = $this->getRulesForUniversityAttainmentForSubject($batchId, $semId, $subjectId);
            if(!empty($ruleDetails)){
                $ruleDetails->departmentRule = false;
            }
        }catch(\Exception $e){
            $ruleDetails = null;
        }
    }else{
        $ruleDetails->batchId = $batchId;
        $ruleDetails->semId = $semId;
        $ruleDetails->subjectId = $subjectId;
        $ruleDetails->departmentRule = true;
    }
    
    return $ruleDetails;
}
public function getRulesForUniversityAttainmentForSubject($batchId, $semId, $subjectId)
{
    $batchId = $this->realEscapeString($batchId);
    $semId = $this->realEscapeString($semId);
    $subjectId = $this->realEscapeString($subjectId);
    $ruleDetails = [];
    $sql = "";
    $sql = "SELECT rule, batch_id as batchId, sem_id as semId, subject_id as subjectId FROM nba_university_attainment_rules WHERE batch_id = '$batchId' AND sem_id = '$semId' AND subject_id = '$subjectId'";
    try {
        $ruleDetails = $this->executeQueryForObject($sql);
    } catch (\Exception $e) {
        throw new ProfessionalException($e->getCode(), $e->getMessage());
    }
    if (!empty($ruleDetails)) {
        $ruleDetails->rule = json_decode($ruleDetails->rule);
    }
    return $ruleDetails;
}
/**
 * Undocumented function
 *
 * @param [type] $deptId
 * @return void
 */
public function getRulesForUniversityAttainmentForDepartment($deptId)
{
    $deptId = $this->realEscapeString($deptId);
    $ruleDetails = [];
    $sql = "";
    $sql = "SELECT rule, department_id as deptId, enforce_rule as enforceRule FROM nba_university_attainment_rules_for_department WHERE department_id = '$deptId'";
    try {
        $ruleDetails = $this->executeQueryForObject($sql);
    } catch (\Exception $e) {
        throw new ProfessionalException($e->getCode(), $e->getMessage());
    }
    if (!empty($ruleDetails)) {
        $ruleDetails->rule = json_decode($ruleDetails->rule);
    }
    return $ruleDetails;
}
public function getEndSemesterExamDetails($batchId,$semId,$subjectId)
{
    $batchId = $this->realEscapeString($batchId);
    $semId = $this->realEscapeString($semId);
    $subjectId = $this->realEscapeString($subjectId);
    $sql = "SELECT distinct erb.examRegId as examRegId from exam_registration_batches erb left join exam_registration er on er.examregID = erb.examRegId where semID ='$semId' and batchID ='$batchId' and er.shortCourse = '0'";
    $examReg = $this->executeQueryForObject($sql);
    if(!empty($examReg) && !empty($examReg->examRegId)){
        $sql = "SELECT distinct examID as id,examName as name from exam where semID ='$semId' and batchID ='$batchId' and subjectID='$subjectId' and examregID='$examReg->examRegId'";
    }
    try {
        $exam = $this->executeQueryForList($sql);
    } catch (\Exception $e) {
        throw new ProfessionalException($e->getCode(), $e->getMessage());
    }
    return $exam;
}
}