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 / 81
CRAP
0.00% covered (danger)
0.00%
0 / 1433
EvaluationService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 81
94556.00
0.00% covered (danger)
0.00%
0 / 1433
 __construct
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 2
 __clone
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 1
 getInstance
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 4
 getEvaluationDetails
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 18
 staffAssignedToThisEvaluation
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 15
 addStaffToEvaluation
0.00% covered (danger)
0.00%
0 / 1
272.00
0.00% covered (danger)
0.00%
0 / 38
 getStudentSuggestions
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 17
 getStaffDisplayDetails
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 17
 getBatchDisplayDetails
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 15
 deleteAssignedStaffDetailsBySemId
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 13
 studentPerformedEvaluationOrNot
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 18
 getAllEvaluationDetails
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 16
 getStudentDetails
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 22
 getEvaluationBatchIDs
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 14
 getStudentKeyDetails
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 24
 getUserTypeOfEvaluation
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 13
 getAllUserTypesOfEvaluation
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 9
 allowHodStaffView
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 20
 searchCollegeEvaluation
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 9
 searchFacultyEvaluation
0.00% covered (danger)
0.00%
0 / 1
182.00
0.00% covered (danger)
0.00%
0 / 39
 getNumberOfQuestionsInAnEvaluation
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 10
 getCommentOfAnEvaluation
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 10
 getTotalNumberOfAnsweresOfAnEvaluation
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 19
 getEvaluationAttendedStudentCount
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 18
 addCommentToAnEvaluation
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 11
 evaluationHasMinimumStudentAttendancePercentage
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 16
 getAllEvaluationTypeIdsWhoseEvaluationAttendanceIsLessThanMinimumAttendancePercentageForAllBatchesAndSemesters
0.00% covered (danger)
0.00%
0 / 1
56.00
0.00% covered (danger)
0.00%
0 / 38
 getAllBatchesAndSemestersWhoseEvaluationAttendanceIsLessThanMinimumAttendancePercentage
0.00% covered (danger)
0.00%
0 / 1
42.00
0.00% covered (danger)
0.00%
0 / 34
 getStaffListForAddingToEvaluation
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 15
 getSbsIdsOfEvaluationAttendedStaffs
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 12
 getSbsIdsOfStaffAlreadyAddedToAnEvaluation
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 12
 getEvaluationDetailsOfAStaff
0.00% covered (danger)
0.00%
0 / 1
56.00
0.00% covered (danger)
0.00%
0 / 27
 getFeedbacksOfAStaffInABatch
0.00% covered (danger)
0.00%
0 / 1
42.00
0.00% covered (danger)
0.00%
0 / 11
 getMaxAnswersInEvaluationGroup
0.00% covered (danger)
0.00%
0 / 1
72.00
0.00% covered (danger)
0.00%
0 / 40
 getAllStaffEvaluation
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 11
 getAllEvaluation
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 8
 getDepartmentsByEvaluatioID
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 11
 getDepartmentsByEvaluatioIDs
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 11
 getBatchesByEvaluatioID
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 10
 getBatchesByEvaluatioIDs
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 10
 getSubjectsByEvaluatioID
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 13
 getSubjectsByEvaluatioIDs
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 13
 getStaffsByEvaluatioID
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 15
 getStaffsByEvaluatioIDs
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 15
 getSbsIDByEvaluationID
0.00% covered (danger)
0.00%
0 / 1
42.00
0.00% covered (danger)
0.00%
0 / 17
 getSbsIDByEvaluationIDs
0.00% covered (danger)
0.00%
0 / 1
56.00
0.00% covered (danger)
0.00%
0 / 21
 getCountOfStudentNeedToBeAttended
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 30
 getCountOfStudentNeedToBeAttendedInMultipleBatchesBySbsIDs
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 31
 getCountOfEvaluationAttentedStudents
0.00% covered (danger)
0.00%
0 / 1
42.00
0.00% covered (danger)
0.00%
0 / 41
 getStaffDetailsFromSbsRelation
0.00% covered (danger)
0.00%
0 / 1
56.00
0.00% covered (danger)
0.00%
0 / 31
 getStudentStaffEvaluationStatus
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 52
 getStaffEvaluationByStudentId
0.00% covered (danger)
0.00%
0 / 1
90.00
0.00% covered (danger)
0.00%
0 / 23
 getStaffsEvaluationDetailsByRequest
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 17
 lockEvaluationbyId
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 10
 unlockEvaluationbyId
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 10
 addSelectedStudentsToStaffEval
0.00% covered (danger)
0.00%
0 / 1
56.00
0.00% covered (danger)
0.00%
0 / 30
 checkStudentExistBySbsIdAndStudentId
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 16
 getAllStudentsInStaffEvaluationStudent
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 18
 deleteStudentsInStaffEvaluationStudent
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 15
 getStaffEvalStaffSbsList
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 13
 getAllSections
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 18
 updateEvaluationQuestionsSection
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 8
 getEvaluationQuestionSections
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 7
 findQuestionSectionId
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 9
 getQuestion
0.00% covered (danger)
0.00%
0 / 1
72.00
0.00% covered (danger)
0.00%
0 / 25
 checkEvaluationHaveMultiChoiceQuestion
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 10
 getAllSectionsForReport
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 24
 getAllStaffsEvaluationDetailsByRequest
0.00% covered (danger)
0.00%
0 / 1
210.00
0.00% covered (danger)
0.00%
0 / 21
 getEvaluationQuestions
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 8
 getEvaluationData
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 10
 createStaffEvaluation
0.00% covered (danger)
0.00%
0 / 1
42.00
0.00% covered (danger)
0.00%
0 / 35
 executeQueriesByString
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 10
 deleteEvaluation
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 20
 getAllEvaluations
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 21
 getSbsAndBatchDetailsByBatchAndEvalTypeID
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 18
 getEvaluationDetailsForBulkPrint
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 10
 getSbsDetailsForBulkPrint
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 9
 getQuestionsOfEvaluationForBulkPrint
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 9
 getStudentAnswerCount
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 12
 getAnswerForQuestion
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 11
 getEvaluationsByDeptBatchSem
0.00% covered (danger)
0.00%
0 / 1
42.00
0.00% covered (danger)
0.00%
0 / 49
<?php
namespace com\linways\core\ams\professional\service;
use com\linways\core\ams\professional\service\StudentService;
use com\linways\core\ams\professional\exception\ProfessionalException;
use com\linways\core\ams\professional\request\SearchFacultyEvaluation;
use com\linways\core\ams\professional\request\GetEvaluationAttendedStudentCount;
use com\linways\core\ams\professional\mapper\StaffEvaluationMapper;
use stdClass;
class EvaluationService extends BaseService
{
    private static $_instance = null;
    
    // /Condition 2 - Locked down the constructor
    private function __construct() {
        $this->mapper = StaffEvaluationMapper::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;
    }
    
    /**
     * Method for getting evaluation name
     * @input $evalId
     * @author Ranjith Balachandran
     */
    
    public function getEvaluationDetails ( $evalId ) {
        $evaluationDetails = null;
        $evalId = $this->realEscapeString($evalId);
        $sql = "SELECT eval_typeID, eval_name AS evaluationName,
                                                 instruction,
                                                  question_per_page,
                                                   student_suggestion,
                                                    evalStartDate,
                                                     evalEndDate,
                                                      loginType,
                                                       staffeval_type,
                                                        is_mandatory as isMandatory, minimum_student_attendance_percentage as           minimumAttendancePercentage FROM staffeval_type WHERE eval_typeID = ".$evalId."";
        
        try {
            $evaluationDetails = $this->executeQueryForObject( $sql );
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        return $evaluationDetails;
    }
    
    /**
     * Method to check whether staffs are added to this evaluation
     * @input $evalId,$semId,$sbsId,$batchId
     * @author Ranjith Balachandran
     */
    
    public function staffAssignedToThisEvaluation($evalId,$semId,$sbsId,$batchId)
    {
        $staffAssignedOrNot = null;
        
        $evalId = $this->realEscapeString($evalId);
        $semId = $this->realEscapeString($semId);
        $sbsId = $this->realEscapeString($sbsId);
        $batchId = $this->realEscapeString($batchId);
        
        try {
            $sql = "SELECT sesl.eval_typeID as evalId,sesl.sbsID as sbsId, sesl.batchID as batchId, sesl.semID as semId FROM staffeval_stafflist sesl WHERE sesl.eval_typeID = $evalId AND sesl.semID = $semId AND sesl.sbsID = $sbsId AND sesl.batchID = $batchId";
            $staffAssignedOrNot = $this->executeQueryForObject( $sql );
            
        }catch (\Exception $e)
        {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        return $staffAssignedOrNot;
    }
    
    /**
     * Method for adding staffs for evaluation
     * @input $myData,$semId,$evalId
     * @author Ranjith Balachandran
     */
    
    public function addStaffToEvaluation($myData,$semId,$evalId,$batchIds){
        $sql = '';
        $semId = $this->realEscapeString($semId);
        $evalId = $this->realEscapeString($evalId);
        $myData = $this->realEscapeArray($myData);
        $batchIds = $this->realEscapeString($batchIds);
        $allSbs = array_map(function($obj) { return $obj->sbsId; },array_filter($myData, function($data){return !(int)$data->subbatchId;}));
        $subBatchSbs = array_filter($myData, function($data){return (int)$data->subbatchId;});
        if(empty($batchIds) || !(int)$evalId || !(int)$semId){
            throw new ProfessionalException(ProfessionalException::EMPTY_PARAMETERS,"Invalid params! Please try again");
        }
        $this->deleteAssignedStaffDetailsBySemId($semId, $evalId,$batchIds);
        $sql = "INSERT INTO staffeval_stafflist (sbsID,batchID,semID,eval_typeID,subbatchID)
        SELECT sbsID, batchID, semID, '".$evalId."', 0 
        FROM (SELECT sbs.sbsID,sbs.batchID,sbs.semID,ss.sbsID AS sbsIdsList FROM sbs_relation sbs
        LEFT JOIN staffeval_stafflist ss ON ss.batchID = sbs.batchID AND ss.semID = sbs.semID AND ss.sbsID = sbs.sbsID AND ss.eval_typeID = '".$evalId."'
        WHERE sbs.sbsID IN (".implode(',',$allSbs).")) as t 
        WHERE t.sbsIdsList is null;";
        try {        
            $this->executeQuery($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        foreach ($subBatchSbs as $firstArr){
            $sbsId = $firstArr->sbsId;
            $batchId = $firstArr->batchId;
            $subbatchId = $firstArr->subbatchId?$firstArr->subbatchId:0;
            if(((int) $evalId && (int) $semId && (int) $sbsId && (int) $batchId)){
                $staffAssignedOrNot = $this->staffAssignedToThisEvaluation($evalId,$semId,$sbsId,$batchId,$subbatchId);
                if(empty($staffAssignedOrNot->evalId) && empty($staffAssignedOrNot->sbsId) && empty($staffAssignedOrNot->batchId) && empty($staffAssignedOrNot->semId))
                {
                    $sql = "INSERT INTO staffeval_stafflist (sbsID,batchID,semID,eval_typeID,subbatchID) VALUES (".$sbsId.",".$batchId.",".$semId.",".$evalId.",\"$subbatchId\")";
                    try {
                        $this->executeQuery($sql);
                    } catch (\Exception $e) {
                        throw new ProfessionalException($e->getCode(),$e->getMessage());
                    }
                }
            }
        }
        
    }
    
    /**
     * Undocumented function
     *
     * @param [type] $staffId
     * @param [type] $evalTypeId
     * @return void
     */
    public function getStudentSuggestions($staffId, $evalTypeId){
        $staffId = $this->realEscapeString($staffId);
        $evalTypeId = $this->realEscapeString($evalTypeId);
        $suggestionList = [];
        $sql = "SELECT 
                    commentID as id, comments as suggestion
                FROM
                    staffeval_student_suggestions
                WHERE
                    staffID = '$staffId'
                        AND eval_typeID = '$evalTypeId'";
        try {
            $suggestionList = $this->executeQueryForList($sql);
        } catch (\Exception $th) {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        return $suggestionList;
    }
    /**
     * Method for diplaying staff details in staff evaluation
     * @input $semId,$batchId,$staffId,$evalId,$sbsId
     * @author Ranjith Balachandran
     */
    
    public function getStaffDisplayDetails($semId,$batchId,$staffId,$evalId,$sbsId)
    {
        $sql = '';
        $staffDisplayDetails = [];
        $semId = $this->realEscapeString($semId);
        $batchId = $this->realEscapeString($batchId);
        $staffId = $this->realEscapeString($staffId);
        $evalId = $this->realEscapeString($evalId);
        $sbsId = $this->realEscapeString($sbsId);
        try {
           $sql = "SELECT sesl.sbsID as sbsId,sesl.subbatchID FROM sbs_relation sr INNER JOIN staffeval_stafflist sesl ON sr.sbsID = sesl.sbsID AND sr.batchID = sesl.batchID AND sr.semID = sesl.semID WHERE sr.batchID = $batchId AND sr.semID = $semId AND sr.staffID = $staffId AND sesl.eval_typeID = $evalId AND sesl.sbsID = $sbsId";
            $staffDisplayDetails = $this->executeQueryForObject($sql);
        }catch (\Exception $e)
        {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        return $staffDisplayDetails;
    }
    
    /**
     * Method for diplaying batch details in staff evaluation
     * @input $semId,$batchId,$evalId
     * @author Ranjith Balachandran
     */
    
    public function getBatchDisplayDetails($semId,$batchId,$evalId)
    {
        $sql = '';
        
        $batchDisplayDetails = [];
        
        $semId = $this->realEscapeString($semId);
        $batchId = $this->realEscapeString($batchId);
        $evalId = $this->realEscapeString($evalId);
        
        try {
            $sql = "SELECT b.batchID as batchId FROM batches b INNER JOIN staffeval_stafflist sesl ON b.batchID = sesl.batchID WHERE sesl.batchID = $batchId AND sesl.eval_typeID = $evalId AND sesl.semID = $semId";
            $batchDisplayDetails = $this->executeQueryForObject($sql);
        }catch (\Exception $e)
        {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        
        return $batchDisplayDetails;
    }
    
    /**
     * Method for deleting assigned staff details in staff evaluation by semId
     * @input $semId,$evalId
     * @author Ranjith Balachandran
     */
    
    public function deleteAssignedStaffDetailsBySemId($semId,$evalId,$batchIds)
    {
        $sql = '';
        
        $semId = $this->realEscapeString($semId);
        $evalId = $this->realEscapeString($evalId);
        $batchIds = $this->realEscapeString($batchIds);
        
        try {
            $sql = "DELETE FROM staffeval_stafflist WHERE eval_typeID = $evalId AND semID = $semId AND batchID IN ($batchIds)";
            $this->executeQuery($sql);
            
        }catch (\Exception $e)
        {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
       
    }
    
    /**
     * Method for checking whether student performed evaluation or not
     * @input $evalId,$loginMethod
     * @author Ranjith Balachandran  
     */
    public function studentPerformedEvaluationOrNot ( $evalId, $loginMethod ) {
        $sql = '';
        
        $studentPerformedEvaluation = null;
        
        $evalId = $this->realEscapeString($evalId);
        $loginMethod = $this->realEscapeString($loginMethod);
        
        if($loginMethod == 1) {
            $sql = "SELECT studentID FROM staffeval_studentanswer_sbsids WHERE eval_typeID = ".$evalId."";
        }
        elseif($loginMethod == 2) {
            $sql = "SELECT sbsID FROM staffeval_studentanswers WHERE eval_typeID = ".$evalId."";
        }
        
        try {
            $studentPerformedEvaluation = $this->executeQueryForObject($sql);
        }
        catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        
        return $studentPerformedEvaluation;
    }
    public function getAllEvaluationDetails($batchID)
    {
        $batchID=$this->realEscapeString($batchID);
        $query="select distinct st.eval_typeID,st.eval_name from staffeval_type st ";
        if($batchID)
        {
        $query.="inner join staffeval_stafflist ss on st.eval_typeID=ss.eval_typeID and ss.batchID=$batchID";
        }
        // To Order Evaluvations 
        $query .= " ORDER BY st.eval_typeID DESC";
        try{
            $response=$this->executeQueryForList($query);
        }catch(\Exception $e)
        {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        return $response;
    }
    public function getStudentDetails($evalTypeID,$fullPerform,$batchID)
    {
        $evalTypeID=$this->realEscapeString($evalTypeID);
        $fullPerform=$this->realEscapeString($fullPerform);
        $batchID=$this->realEscapeString($batchID);
        $query="select sa.studentID,sa.studentName,sa.regNo,sa.admissionNo,b.batchName from studentaccount sa inner join staffeval_savestudent sss on sa.studentID=sss.studentaccount_id inner join batches b on sa.batchID=b.batchID where sss.staffeval_type_id=$evalTypeID and sss.fullPerform=$fullPerform ";
        if($batchID)
        {
        $query.="and sss.batches_id=$batchID ";
        }
        $query.="order by sa.regNo";
        try{
            $response=$this->executeQueryForList($query);
        }catch(\Exception $e)
        {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        if(empty($response))
        {
            throw new ProfessionalException(ProfessionalException::ARRAY_EMPTY,"No Records Found");
        }
        return $response;
    }
    /**
     * get batches assigned for faculty evaluation
     * @author Aswin
     * @param  $eval_type_id
     * @throws ProfessionalException
     * @return object|array|\com\linways\base\util\$objectList[]
     */
    public function getEvaluationBatchIDs($eval_type_id)
    {
        $eval_type_id=$this->realEscapeString($eval_type_id);
        $query="SELECT ss.batches_id as batchID,IF(COUNT(ssa.sbsID),1,0) AS performed FROM staffeval_savestudent ss 
            LEFT JOIN staffeval_studentanswers ssa ON ssa.batchID = ss.batches_id AND ss.staffeval_type_id = ssa.eval_typeID
            WHERE ss.staffeval_type_id = '".$eval_type_id."'
            GROUP BY ss.batches_id;";
        try {
            $response=$this->executeQueryForList($query);
        }
        catch(\Exception $e) {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        return $response;
    }
    public function getStudentKeyDetails ( $key ) {
        $keyDetails = null;
        $key = $this->realEscapeString($key);
        $sql = "SELECT 
        sk.batchID,
        sk.semID,
        sk.eval_typeID,
        sk.code,
        sk.code_status,
        sk.test_attempts,
        st.eval_name,
        st.is_locked
    FROM
        staffeval_studentkeys sk
            INNER JOIN
        staffeval_type st ON sk.eval_typeID = st.eval_typeID
            AND code = '".$key."'";
        try {
            $keyDetails = $this->executeQueryForObject($sql);
        }
        catch(\Exception $e) {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        return $keyDetails;
    }
    public function getUserTypeOfEvaluation($batchID, $evalID){
        $batchID = $this->realEscapeString($batchID);
        $evalID = $this->realEscapeString($evalID);
        
        $sql = "SELECT eb.userType FROM evaluation ev INNER JOIN evaluation_batches eb ON eb.evaluationID = ev.id AND ev.id = $evalID AND eb.batchID = $batchID";
        
        try{
            $userType = $this->executeQueryForObject($sql);
        }catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        if(!empty($userType)){
            return $userType->userType;
        }
        return null;
    }
    /**
     * Undocumented function
     *
     * @param [type] $evalID
     * @return void
     */
    public function getAllUserTypesOfEvaluation($evalID){
        $evalID = $this->realEscapeString($evalID);
        $sql = "SELECT DISTINCT eb.userType as name FROM evaluation ev INNER JOIN evaluation_batches eb ON eb.evaluationID = ev.id AND ev.id = $evalID";
        try{
            $userTypeList = $this->executeQueryForList($sql);
        }catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return $userTypeList;
    }
    /**
     * Allow HOD / staff to view the evaluation results in their login
     * @param String $allowView
     * @param Int $status
     * @param Int $batchId
     * @param Int $evalTypeId
     * @return boolean
     * @author Vishnu M  
     */
    public function allowHodStaffView ( $allowView, $status, $batchId, $evalTypeId )
    {
        $sql = "";
        $allowView = $this->realEscapeString($allowView);        
        $status = $this->realEscapeString($status);        
        $batchId = $this->realEscapeString($batchId);
        $evalTypeId = $this->realEscapeString($evalTypeId);
        if ( $allowView == "HOD" ) {
            $sql = "UPDATE staffeval_studentanswers SET allow_HOD = ".$status." WHERE batchID = ".$batchId." AND eval_typeID = ".$evalTypeId."";
        } 
        else if ( $allowView == "STAFF" ) {
            $sql = "UPDATE staffeval_studentanswers SET allow_staff = ".$status." WHERE batchID = ".$batchId." AND eval_typeID = ".$evalTypeId."";
        }
        try{
            $this->executeQuery($sql);
        }
        catch ( \Exception $e ) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return true;
    }
    
    /**
     *  
     * @param SearchFacultyEvaluation $request
     * @return void
     */
    public function searchCollegeEvaluation($request){
        $sql = "";
        $sql = "SELECT DISTINCT eval.id, eval.name, eval.expiryDate FROM evaluation eval INNER JOIN evaluation_batches ebatch ON (eval.id = ebatch.evaluationID) WHERE ebatch.userType = '".$request->userType."' AND eval.isLocked = 0 AND eval.expiryDate >= '".date("Y-m-d")."' AND ebatch.batchID = ".$request->batchId." AND eval.is_mandatory = '$request->isMandatory' AND ".$request->studentId." NOT IN ( SELECT studentID FROM evaluation_answer WHERE evaluationID = eval.id AND ".($request->userType == 'Parent'?' userType=\'Parent\'':'(userType=\'Student\' OR userType IS NULL) ').") ORDER BY eval.id DESC";
        try{
            $evaluationList = $this->executeQueryForList($sql);
        }catch ( \Exception $e ) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return $evaluationList;
    }
    
    /**
     * Undocumented function
     *
     * @param SearchFacultyEvaluation $request
     * @return void
     */
    public function searchFacultyEvaluation($request)
    {
        $sql = "";
        $request = $this->realEscapeObject($request);
        $sql = "SELECT st.eval_typeID as evalTypeId, st.eval_name as evalName, ss.batches_id as batchId, ss.studentaccount_id as studentId FROM staffeval_type st INNER JOIN staffeval_savestudent ss ON st.eval_typeID = ss.staffeval_type_id WHERE 1=1 ";
        if(!empty($request->evalTypeId)){
            $sql .= " AND st.eval_typeID='$request->evalTypeId'";
        }
        if(!empty($request->evalStartDate)){
            $sql .= " AND st.evalStartDate <= '".date('Y-m-d',strtotime($request->evalStartDate))."'";
        }
        if(!empty($request->evalEndDate)){
            $sql .= " AND st.evalEndDate >= '".date('Y-m-d',strtotime($request->evalEndDate))."'";
        }
        if(!empty($request->loginType)){
            $sql .= " AND st.loginType = '$request->loginType'";
        }
        if(!empty($request->staffEvalType)){
            $sql .= " AND st.staffeval_type = '$request->staffEvalType'";
        }
        if(!empty($request->batchId)){
            $sql .= " AND ss.batches_id = '$request->batchId'";
        }
        if(!empty($request->studentId)){
            $sql .= " AND ss.studentaccount_id = '$request->studentId'";
        }
        if(!empty($request->isMandatory) || $request->isMandatory == 0){
            $sql .= " AND st.is_mandatory = '$request->isMandatory'";
        }
        if(!empty($request->fullPerform) || $request->fullPerform == 0 ){
            $sql .= " AND ss.fullPerform = '$request->fullPerform'";
        }
        try{
            $evaluationList = $this->executeQueryForList($sql);
        }
        catch ( \Exception $e ) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return $evaluationList;
    }
    /**
     * Undocumented function
     * @param [type] $evalTypeId
     * @return void
     */
    public function getNumberOfQuestionsInAnEvaluation($evalTypeId){
        $evalTypeId = $this->realEscapeString($evalTypeId);
        $count = null;
        $sql = "SELECT count(stq.questionID) as totalRecords from staffeval_type_questions stq INNER JOIN staffeval_questions sq ON stq.questionID = sq.questionID and stq.eval_typeID='$evalTypeId'";
        try{
            $count = $this->executeQueryForObject($sql)->totalRecords;
        }catch ( \Exception $e ) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return $count;
    }
    /**
     * Undocumented function
     *
     * @param FacultyEvaluationCommentsFromHod $request
     * @return void
     */
    public function getCommentOfAnEvaluation($request){
        $request = $this->realEscapeObject($request);
        $sql = "";
        $sql = "SELECT comment FROM staffeval_comments_from_hod WHERE eval_type_id = '$request->evalTypeId' AND batch_id = '$request->batchId' AND sem_id = '$request->semId' AND sbs_id = '$request->sbsId'";
        try{
            $comment = $this->executeQueryForObject($sql);
        }catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return $comment;
    }
    /**
     * @param [type] $request
     * @return void
     */
    public function getTotalNumberOfAnsweresOfAnEvaluation($request){
        $request = $this->realEscapeObject($request);
        $sql = "";
        $sql = "SELECT sum(answer_count) as totalRecords from staffeval_studentanswers where batchID = '$request->batchId' and semID = '$request->semId' and eval_typeID = '$request->evalTypeId'";
        try{
            $answerCount = $this->executeQueryForObject($sql)->totalRecords;
        }catch ( \Exception $e ) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        $sql = "SELECT count(distinct sbsID) as totalRecords from staffeval_studentanswers where batchID = '$request->batchId' and semID = '$request->semId' and eval_typeID = '$request->evalTypeId'";
        try{
            $sbsCount = $this->executeQueryForObject($sql)->totalRecords;
        }catch ( \Exception $e ) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        if($sbsCount == 0){
            return 0;
        }
        return $answerCount/$sbsCount;
    }
    /**
     * Returns count of students who completed whole evaluation by batch
     * @param GetEvaluationAttendedStudentCount $request
     * @return studentCount
     */
    public function getEvaluationAttendedStudentCount($request){
        $request = $this->realEscapeObject($request);
        $studentCount = 0;
        $evaluationLoginType = (int)$this->getEvaluationDetails($request->evalTypeId)->loginType;
        if($evaluationLoginType == 1) // Secret key
        {
            $sql = "SELECT COUNT(code) as studentCount from staffeval_studentkeys where eval_typeID = $request->evalTypeId and code_status = 1 and batchID = $request->batchId and semId=$request->semId";
        }
        else // if($evaluationLoginType == 2) Student Login
        {
            $sql = "SELECT COUNT(id) as studentCount from staffeval_savestudent evl where staffeval_type_id = $request->evalTypeId and fullperform = 1 and batches_id = $request->batchId";
        }
        try{
            $studentCount = $this->executeQueryForObject($sql)->studentCount;
        }catch ( \Exception $e ) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        
        return $studentCount;
    }
     /**
     * @param FacultyEvaluationCommentsFromHod $comment
     * @return void
     */
    public function addCommentToAnEvaluation($comment){
        $sql = "";
        $comment = $this->realEscapeObject($comment);
        $comment->comment = trim($comment->comment);
        $sql = "INSERT INTO `staffeval_comments_from_hod` (`eval_type_id`, `batch_id`, `sem_id`, `sbs_id`, `comment`, `created_by`, `created_date`, `updated_by`, `updated_date`) VALUES ('$comment->evalTypeId', '$comment->batchId', '$comment->semId', '$comment->sbsId', '$comment->comment', '$comment->createdBy', UTC_TIMESTAMP(), '$comment->updatedBy', UTC_TIMESTAMP()) ON DUPLICATE KEY UPDATE comment = '$comment->comment'";
        try {
            $comment->id = $this->executeQueryForObject($sql, true);
        } catch (\Exception $th) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return $comment;
    }
    /**
     * Undocumented function
     * @param [type] $request
     * @return void
     */
    public function evaluationHasMinimumStudentAttendancePercentage($request){
        
        $minumumAttendancePercentage = (float)$this->getEvaluationDetails($request->evalTypeId)->minimumAttendancePercentage;
        $totalStudentsOfABatch = (int)StudentService::getInstance()->getStudentsCountByBatch($request->batchId);
        $noOfStudentsAttendedEvaluation = $this->getEvaluationAttendedStudentCount($request);
        if(empty($minumumAttendancePercentage)){
            return true;
        }
        if($noOfStudentsAttendedEvaluation == 0){
            $attendancePercentage = 0;
        }else{
            $attendancePercentage = ($noOfStudentsAttendedEvaluation/$totalStudentsOfABatch)*100;
        }
        if($attendancePercentage >= $minumumAttendancePercentage){
            return true;
        }
        return false;
    }
    public function getAllEvaluationTypeIdsWhoseEvaluationAttendanceIsLessThanMinimumAttendancePercentageForAllBatchesAndSemesters($staffId, $evalTypeId = null){
        $batchesAndSemesters = [];
        $sql = "SELECT DISTINCT
        t1.eval_typeID as evalTypeId, t3.staffID, t2.eval_name, t1.batchID as batchId, t1.semID as semId
    FROM
        staffeval_stafflist t1,
        staffeval_type t2,
        sbs_relation t3
    WHERE
        t3.staffID = '$staffId'
            AND t1.eval_typeID = t2.eval_typeID
            AND t1.sbsID = t3.sbsID";
            if(!empty($evalTypeId)){
                $sql .= " AND t1.eval_typeID = $evalTypeId";
            }
        try{
            $batchesAndSemesters = $this->executeQueryForList($sql);
        }catch ( \Exception $e ) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        foreach($batchesAndSemesters as $key => $batchAndSemester){
            $request = new GetEvaluationAttendedStudentCount();
            $request->batchId = $batchAndSemester->batchId;
            $request->semId = $batchAndSemester->semId;
            $request->evalTypeId = $batchAndSemester->evalTypeId;
            try{
                if(!$this->evaluationHasMinimumStudentAttendancePercentage($request)){
                    unset($batchesAndSemesters[$key]);
                }
            }catch(\Exception $e){
                continue;
            }
        }
        
        $responseArray = [];
        foreach($batchesAndSemesters as $batchAndSemester){
            $responseArray[] = $batchAndSemester->evalTypeId;
        }
        return $responseArray;
    }
    /**
     *
     * @param [type] $evalTypeId
     * @param [type] $staffId
     * @return void
     */
    public function getAllBatchesAndSemestersWhoseEvaluationAttendanceIsLessThanMinimumAttendancePercentage($staffId, $evalTypeId = null){
        $batchesAndSemesters = [];
        $sql = "SELECT DISTINCT
        t1.eval_typeID as evalTypeId, t3.staffID, t2.eval_name, t1.batchID as batchId, t1.semID as semId
    FROM
        staffeval_stafflist t1,
        staffeval_type t2,
        sbs_relation t3
    WHERE
        t3.staffID = '$staffId'
            AND t1.eval_typeID = t2.eval_typeID
            AND t1.sbsID = t3.sbsID";
            if(!empty($evalTypeId)){
                $sql .= " AND t1.eval_typeID = $evalTypeId";
            }
        try{
            $batchesAndSemesters = $this->executeQueryForList($sql);
        }catch ( \Exception $e ) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        foreach($batchesAndSemesters as $key => $batchAndSemester){
            $request = new GetEvaluationAttendedStudentCount();
            $request->batchId = $batchAndSemester->batchId;
            $request->semId = $batchAndSemester->semId;
            $request->evalTypeId = $batchAndSemester->evalTypeId;
            try{
                if($this->evaluationHasMinimumStudentAttendancePercentage($request)){
                    unset($batchesAndSemesters[$key]);
                }
            }catch(\Exception $e){
                continue;
            }
        }
        return $batchesAndSemesters;
    }
    /**
     * Undocumented function
     *
     * @param [type] $batchId
     * @param [type] $semId
     * @param [type] $subjectCategories
     * @return void
     */
    function getStaffListForAddingToEvaluation($batchId, $semId, $subjectCategories)
    {
        $batchId = $this->realEscapeString($batchId);
        $semId = $this->realEscapeString($semId);
        $subjectCategories = $this->realEscapeArray($subjectCategories);
        $sql = "select t1.sbsID, t1.staffID, t1.batchID, t1.subjectID, t2.staffName, t3.batchName, t4.subjectName from sbs_relation t1 INNER JOIN  staffaccounts t2 ON t2.staffID=t1.staffID  AND t1.batchID='$batchId' AND t1.semID='$semId' INNER JOIN batches t3 ON t3.batchID = t1.batchID INNER JOIN subjects t4 ON t4.subjectID = t1.subjectID ";
        if(!empty($subjectCategories)){
            $sql .= " INNER JOIN subject_category sc ON sc.subjectcatID = t4.subjectcatID AND sc.subjectcatID IN (".implode(',', $subjectCategories).")";
        }
        try {
            $staffList = $this->executeQueryForList($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return $staffList;
    }
    public function getSbsIdsOfEvaluationAttendedStaffs($batchId, $semId, $evalTypeId){
        $sbsids=" ";
        $sql="SELECT GROUP_CONCAT(sbsID) as sbsList FROM staffeval_studentanswers WHERE batchID=\"$batchId\" AND semID=\"$semId\" AND eval_typeID=\"$evalTypeId\" ";
        
        try {
            $sbsList = $this->executeQueryForObject($sql)->sbsList;
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        if($sbsList){
            $sbsList = explode(',', $sbsList);
        }
        return $sbsList;
    }
    public function getSbsIdsOfStaffAlreadyAddedToAnEvaluation($batchId, $semId, $evalTypeId){
        $sbsids=" ";
        $sql="SELECT GROUP_CONCAT(sbsID) as sbsList FROM staffeval_stafflist WHERE batchID=\"$batchId\" AND semID=\"$semId\" AND eval_typeID=\"$evalTypeId\" ";
        
        try {
            $sbsList = $this->executeQueryForObject($sql)->sbsList;
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        if($sbsList){
            $sbsList = explode(',', $sbsList);
        }
        return $sbsList;
    }
    
    public function getEvaluationDetailsOfAStaff($request) {
        $request = $this->realEscapeObject($request);
        $condition = "";
        // and sevlstd.sbsID=$request->sbsID and sevlstd.batchID=$request->batchID and sevlstd.semID=$request->semID
        $condition .= $request->sbsIDs?" and slist.sbsID in ($request->sbsIDs":" and slist.sbsID=$request->sbsID ";
        $condition .= $request->batchIDs?" and slist.batchID in ($request->batchIDs":"";
        $condition .= $request->needMultiChoiceQuestion?" and sq.is_multiple_choice_question = '1' ":" and sq.is_multiple_choice_question = '0' ";
        if(empty($request->batchIDs))
        {
            $condition .= $request->batchID?" and slist.batchID = '$request->batchID":"";
        }
        
        $sql = "
            SELECT slist.sbsID,sevlt.eval_typeID,sevlt.loginType, sevlt.eval_name, sevlt.staffeval_type, sevlt.evalStartDate, sevlt.evalEndDate, stq.questionID, sq.question, sa.answerID, sa.answer, sa.point,sum(sevlstd.answer_count) as answer_count, sec.id as sectionId, sec.code as section_code, stq.question_order 
            FROM 
                staffeval_type sevlt 
                INNER JOIN staffeval_type_questions stq on sevlt.eval_typeID = stq.eval_typeID
                INNER JOIN staffeval_question_sections sec on sec.id = stq.section_id
                INNER JOIN staffeval_questions sq on sq.questionID = stq.questionID
                INNER JOIN staffeval_answers sa on sa.questionID = stq.questionID
                INNER JOIN staffeval_stafflist slist on slist.eval_typeID = sevlt.eval_typeID 
                LEFT JOIN staffeval_studentanswers sevlstd on sevlstd.eval_typeID = sevlt.eval_typeID and sevlstd.questionID = stq.questionID 
                    and sevlstd.answerID = sa.answerID and sevlstd.eval_typeID=sevlt.eval_typeID and sevlstd.sbsID = slist.sbsID and sevlstd.batchID = slist.batchID 
                    WHERE sevlt.eval_typeID = $request->evalTypeId $condition group by sa.answerID order by sec.properties->'$.order',stq.question_order, stq.questionID, sa.point;";
        try {
            return $this->executeQueryForList($sql, $this->mapper[StaffEvaluationMapper::GET_STAFF_EVALUATION_DETAILS]);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    
    
    public function getFeedbacksOfAStaffInABatch($request) {
        $request = $this->realEscapeObject($request);
        $condition = "";
        $condition .= $request->batchIDs?" and batchID in ($request->batchIDs":($request->batchID?" and batchID = '$request->batchID":"");
        $condition .= $request->sbsIDs?" and sbsID in ($request->sbsIDs":($request->sbsID?" and sbsID=$request->sbsID ":"");
        $sql = "select comments,extra_sugg_question_no from staffeval_student_suggestions where staffID = '$request->staffID$condition and eval_typeID='$request->evalTypeId';";
        try {
            return $this->executeQueryForList($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    
    public function getMaxAnswersInEvaluationGroup($evaluationDetails)
    {
        $evaluationSectionDetails = [];
        $evaluationSectionDetails["answer"]->maxAnswerNumber = 0;
        $evaluationSectionDetails["students"]->studentCount = 0;
        if($evaluationDetails)
        {
            foreach ($evaluationDetails as $evaluation)
            {
                foreach ($evaluation->sections as $section)
                {
                    foreach ($section->questions as $questions)
                    {
                        $answerNumber = 0;
                        $EvaluatedStudents = 0;
                        foreach ($questions->answers as $answers)
                        {
                            $evaluationSectionDetails[$section->code]->answers[$questions->id][$answers->answer][(float)$answers->point]=$answers->studentAnswerCount;
                            $answerNumber++;
                            
                            $evaluationSectionDetails[$section->code]->answerPatterns[$answers->answer.",".(float)$answers->point] = (float)$answers->point;
                            
                            $EvaluatedStudents += $answers->studentAnswerCount;
                        }
                        $evaluationSectionDetails[$section->code]->maxQuestionNumber = count($evaluationSectionDetails[$section->code]->answerPatterns);
                        if($evaluationSectionDetails["answer"]->maxAnswerNumber < count($evaluationSectionDetails[$section->code]->answerPatterns))
                        {
                            $evaluationSectionDetails["answer"]->maxAnswerNumber = count($evaluationSectionDetails[$section->code]->answerPatterns);
                        }
                        if($evaluationSectionDetails["students"]->studentCount < $EvaluatedStudents)
                        {
                            $evaluationSectionDetails["students"]->studentCount = $EvaluatedStudents;
                        }
                    }
                }
            }
            return $evaluationSectionDetails;
        }
        else
        {
            return false;
        }
    }
    public function getAllStaffEvaluation($batchID,$semID,$sbsID)
    {
        $sql = "SELECT distinct sevlt.eval_typeID , sevlt.eval_name
                FROM staffeval_type sevlt 
                LEFT JOIN staffeval_studentanswers sevlstd on sevlstd.eval_typeID = sevlt.eval_typeID and sevlstd.batchID=$batchID 
                and sevlstd.semID=$semID and sevlstd.sbsID = $sbsID group by eval_typeID;";
        try {
            return $this->executeQueryForList($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    
    public function getAllEvaluation()
    {
        $sql = "SELECT eval_typeID, eval_name, instruction, question_per_page, student_suggestion, createdBy, createdDate, updatedBy, updatedDate, evalStartDate, evalEndDate, loginType, staffeval_type, default_result_view, is_mandatory, minimum_student_attendance_percentage from staffeval_type ORDER BY eval_typeID DESC;";
        try {
            return $this->executeQueryForList($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    
    public function getDepartmentsByEvaluatioID($evalTypeId)
    {
        $sql = "SELECT distinct dept.deptID,dept.deptName from batches bat
                inner join staffeval_stafflist slist on slist.batchID = bat.batchID
                inner join department dept on dept.deptID = bat.deptID
                where slist.eval_typeID = $evalTypeId;";
        try {
            return $this->executeQueryForList($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    public function getDepartmentsByEvaluatioIDs($evalTypeId)
    {
        $sql = "SELECT distinct dept.deptID,dept.deptName from batches bat
                inner join staffeval_stafflist slist on slist.batchID = bat.batchID
                inner join department dept on dept.deptID = bat.deptID
                where slist.eval_typeID in ($evalTypeId)";
        try {
            return $this->executeQueryForList($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    public function getBatchesByEvaluatioID($deptID , $evalTypeId)
    {
        $sql = "SELECT distinct bat.batchID,bat.batchName from staffeval_stafflist slist 
                inner join batches bat on slist.batchID = bat.batchID  
                where slist.eval_typeID = $evalTypeId and bat.deptID = $deptID;";
        try {
            return $this->executeQueryForList($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    public function getBatchesByEvaluatioIDs($deptID , $evalTypeId)
    {
        $sql = "SELECT distinct bat.batchID,bat.batchName from staffeval_stafflist slist 
                inner join batches bat on slist.batchID = bat.batchID  
                where slist.eval_typeID in ($evalTypeId) and bat.deptID in ($deptID)";
        try {
            return $this->executeQueryForList($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    
    public function getSubjectsByEvaluatioID($batchIDs ,$evalTypeId ,$deptID)
    {
        $condition = $batchIDs?" and sbs.batchID in ($batchIDs":$batchIDs;
        $sql = "SELECT distinct sub.subjectID, sub.subjectName, sub.subjectDesc from staffeval_stafflist slist 
                inner join sbs_relation sbs on sbs.sbsID = slist.sbsID
                inner join subjects sub on sub.subjectID = sbs.subjectID
                inner join batches bat on bat.batchID = sbs.batchID
                where slist.eval_typeID = $evalTypeId $condition and bat.deptID = $deptID;";
        try {
            return $this->executeQueryForList($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    public function getSubjectsByEvaluatioIDs($batchIDs ,$evalTypeId ,$deptID)
    {
        $condition = $batchIDs?" and sbs.batchID in ($batchIDs":$batchIDs;
        $sql = "SELECT distinct sub.subjectID, sub.subjectName, sub.subjectDesc from staffeval_stafflist slist 
                inner join sbs_relation sbs on sbs.sbsID = slist.sbsID
                inner join subjects sub on sub.subjectID = sbs.subjectID
                inner join batches bat on bat.batchID = sbs.batchID
                where slist.eval_typeID in  ($evalTypeId$condition and bat.deptID in ($deptID)";
        try {
            return $this->executeQueryForList($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    
    public function getStaffsByEvaluatioID($batchIDs ,$evalTypeId ,$subjectID, $deptID = NULL)
    {
        $condition = $batchIDs?" and sbs.batchID in ($batchIDs":"";
        $condition .= $deptID?" and staff.deptID = $deptID ":"";
        $condition .= $subjectID?" and sub.subjectID = $subjectID ":"";
        $sql = "SELECT distinct staff.staffID,staff.staffName from staffeval_stafflist slist
                inner join sbs_relation sbs on slist.sbsID = sbs.sbsID
                inner join staffaccounts staff on staff.staffID = sbs.staffID
                inner join subjects sub on sub.subjectID = sbs.subjectID
                where slist.eval_typeID=$evalTypeId $condition;";
        try {
            return $this->executeQueryForList($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    public function getStaffsByEvaluatioIDs($batchIDs ,$evalTypeId ,$subjectID, $deptID = NULL)
    {
        $condition = $batchIDs?" and sbs.batchID in ($batchIDs":"";
        $condition .= $deptID?" and staff.deptID in ($deptID":"";
        $condition .= $subjectID?" and sub.subjectID in ($subjectID":"";
        $sql = "SELECT distinct staff.staffID,staff.staffName from staffeval_stafflist slist
                inner join sbs_relation sbs on slist.sbsID = sbs.sbsID
                inner join staffaccounts staff on staff.staffID = sbs.staffID
                inner join subjects sub on sub.subjectID = sbs.subjectID
                where slist.eval_typeID in ($evalTypeId$condition;";
        try {
            return $this->executeQueryForList($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    
    public function getSbsIDByEvaluationID($batchIDs ,$staffID ,$evalTypeID ,$subjectID, $deptID = NULL)
    {
        $condition = $batchIDs?" and slist.batchID in ($batchIDs)":"";
        $condition .= $deptID ? " and st.deptID = $deptID ":"";
        $condition .= $subjectID ? " and subjectID = $subjectID ":"";
        $sql = "select GROUP_CONCAT(sbs.sbsID) as sbsIDs
                from staffeval_stafflist slist
                inner join sbs_relation sbs on sbs.sbsID=slist.sbsID
                inner join staffaccounts st on st.staffID = sbs.staffID 
                where slist.eval_typeID = $evalTypeID and sbs.staffID = $staffID  $condition ";
        $sql .= $subjectID? " group by sbs.subjectID; ":" ;";
        try {
            $sbsIDsObject = $this->executeQueryForObject($sql);
            return $sbsIDsObject->sbsIDs;
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    public function getSbsIDByEvaluationIDs($batchIDs ,$staffID ,$evalTypeID ,$subjectID, $deptID = NULL)
    {
        $condition = $batchIDs?" and slist.batchID in ($batchIDs)":"";
        $condition .= $deptID ? " and st.deptID in ($deptID":"";
        $condition .= $subjectID ? " and subjectID in  ($subjectID":"";
        $sql = "SELECT GROUP_CONCAT(sbs.sbsID) as sbsIDs
                from staffeval_stafflist slist
                inner join sbs_relation sbs on sbs.sbsID=slist.sbsID
                inner join staffaccounts st on st.staffID = sbs.staffID 
                where slist.eval_typeID in ($evalTypeID) and sbs.staffID in ( $staffID)  $condition ";
        $sql .= $subjectID? " group by sbs.subjectID; ":" ;";
        try {
            $sbsIds = [];
            $sbsIDsObject = $this->executeQueryForList($sql);
            foreach ($sbsIDsObject as $value) {
                $sbsIds[]= $value->sbsIDs;
            }
            return implode(",",$sbsIds);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    
    public function getCountOfStudentNeedToBeAttended($sbsIDs,$evalTypeId,$batchId)
    {
        $sbsIDs = implode(',',$sbsIDs);
        try {
            $sql = "select * from staffeval_stafflist ss
            left join subbatch_sbs ssbs on ssbs.sbsID = ss.sbsID 
            where ss.eval_typeID = $evalTypeId and ss.sbsID in ($sbsIDs) and ssbs.sbsID is null;";
            $subbatchDetails = $this->executeQueryForList($sql);
            $studentCount = 0;
            if(!empty($subbatchDetails))
            {
                $sql = "select count(DISTINCT studentID) as studentCount from studentaccount where batchID = ".$batchId;
                $studentCount = $this->executeQueryForObject($sql)->studentCount;
            }
            else 
            {
                $sql = "SELECT COUNT(DISTINCT sts.studentID) as studentCount FROM staffeval_stafflist ss
                            INNER JOIN subbatch_sbs ssbs ON ssbs.sbsID = ss.sbsID AND (FIND_IN_SET(ssbs.subbatchID,ss.subbatchID) OR ss.subbatchID = 0 OR ss.subbatchID IS NULL)
                            INNER JOIN subbatch_student sts ON ssbs.subbatchID = sts.subbatchID
                            INNER JOIN studentaccount std ON std.studentID = sts.studentID AND std.batchID = ss.batchID
                        WHERE
                            ss.sbsID IN ($sbsIDs)
                            AND ss.eval_typeID = $evalTypeId
                            AND std.batchID = $batchId;";
                $studentCount = $this->executeQueryForObject($sql)->studentCount;
            }
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return $studentCount;
    }
    
    public function getCountOfStudentNeedToBeAttendedInMultipleBatchesBySbsIDs($sbsIDs,$evalTypeId)
    {
        $sbsIDs = implode(',',$sbsIDs);
        $sql = "SELECT COUNT(DISTINCT studentID) AS studentCount
        FROM (
            SELECT DISTINCT std.studentID AS studentID
                FROM
                sbs_relation sbs
            INNER JOIN staffeval_stafflist stl ON stl.sbsID = sbs.sbsID
            INNER JOIN studentaccount std ON std.batchID = sbs.batchID
            LEFT JOIN subbatch_sbs ssbs ON ssbs.sbsID = sbs.sbsID
            WHERE
                ssbs.sbsID IS NULL AND sbs.sbsID IN ($sbsIDs) AND stl.eval_typeID = $evalTypeId
        UNION 
            SELECT DISTINCT sss.studentID AS studentID
            FROM
                sbs_relation sbs
            INNER JOIN subbatch_sbs ss ON ss.sbsID = sbs.sbsID
            INNER JOIN staffeval_stafflist stl ON stl.sbsID = ss.sbsID AND (FIND_IN_SET(ss.subbatchID, stl.subbatchID) OR stl.subbatchID = 0 OR stl.subbatchID IS NULL)
            INNER JOIN subbatch_student sss ON sss.subbatchID = ss.subbatchID
            INNER JOIN studentaccount std ON std.studentID = sss.studentID
                AND std.batchID = sbs.batchID
            WHERE
                ss.sbsID IN ($sbsIDs)
                AND stl.eval_typeID = $evalTypeId) AS student;";
        try{
            $studentCount = $this->executeQueryForObject($sql)->studentCount;
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return $studentCount;
    }
    public function getCountOfEvaluationAttentedStudents($request) 
    {
        $request = $this->realEscapeObject($request);
        $condition = "";
        $condition .= $request->semID?" and slist.semID = $request->semID ":"";
        $condition .= $request->batchID?" and slist.batchID = $request->batchID ":"";
        $condition .= $request->evalTypeId?" and slist.eval_typeID = $request->evalTypeId ":"";
        try 
        {        
            if($condition)
            {
                $sql="SELECT group_concat( distinct slist.sbsID) as sbsID,slist.batchID,slist.semID,slist.eval_typeID,slist.subbatchID, bat.batchName, evl.eval_name, evl.loginType, temp1.studentCount as studentAttented, temp1.evaluationDone, stans.allow_HOD, stans.allow_staff
                FROM staffeval_stafflist slist
                INNER JOIN batches bat ON slist.batchID = bat.batchID
                INNER JOIN staffeval_type evl ON evl.eval_typeID = slist.eval_typeID
                INNER JOIN staffeval_studentanswers stans ON stans.eval_typeID = slist.eval_typeID AND slist.sbsID = stans.sbsID
                LEFT JOIN (SELECT et.eval_typeID, et.eval_name, et.loginType,
                    CASE WHEN et.loginType = 1 THEN COUNT(distinct stk.code) WHEN et.loginType = 2 THEN COUNT(distinct sts.studentaccount_id) END AS studentCount,
                    CASE WHEN et.loginType = 1 THEN stk.batchID WHEN et.loginType = 2 THEN sts.batches_id END AS batchID,
                    CASE WHEN et.loginType = 1 THEN stk.code_status WHEN et.loginType = 2 THEN sts.fullPerform END AS evaluationDone
                    FROM staffeval_type et
                    LEFT JOIN staffeval_studentkeys stk ON stk.eval_typeID = et.eval_typeID AND stk.code_status = 1
                    LEFT JOIN staffeval_savestudent sts ON sts.staffeval_type_id = et.eval_typeID AND sts.fullPerform = 1
                        LEFT JOIN studentaccount stssts on stssts.studentID = sts.studentaccount_id and stssts.batchID = sts.batches_id 
                    where (et.loginType = 1 and stssts.studentID is null) or (et.loginType = 2 and stssts.studentID is not null)
                    GROUP BY et.eval_typeID , IFNULL(stk.batchID, sts.batches_id)
                    ORDER BY et.eval_typeID) temp1 ON slist.batchID = temp1.batchID AND slist.eval_typeID = temp1.eval_typeID
                WHERE 1=1 $condition 
                GROUP BY slist.eval_typeID , slist.batchID
                ORDER BY slist.batchID DESC";
                return $this->executeQueryForList($sql);
            }
            else 
            {
                return false;
            }
        }
        catch (\Exception $e) 
        {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    public function getStaffDetailsFromSbsRelation($semId, $batchIds, $evalType, $subjectCategories = null)
    {
        $staffDetails = [];
        $evalType = strtoupper($evalType);
        $semId = $this->realEscapeString($semId);
        if (gettype($batchIds) == "array") {
            $batchIds = implode(',', $batchIds);
        }
        $batchIds = $this->realEscapeString($batchIds);
        $subjectCategories = $this->realEscapeArray($subjectCategories);
        $condition = "";
        if (!empty($subjectCategories)) {
            $condition = " INNER JOIN subject_category sc ON sc.subjectcatID = s.subjectcatID AND sc.subjectcatID IN (" . implode(',', $subjectCategories) . ")";
        }
        try {
            switch ($evalType) {
                case "FACULTY":
                    $sql = "SELECT sa.staffID as staffId,sa.staffName as staffName, s.subjectDesc as subjectDesc,s.subjectName as subjectName,b.batchName,sr.sbsID as sbsId,b.batchID as batchId FROM staffaccounts sa INNER JOIN sbs_relation sr ON sa.staffID = sr.staffID INNER JOIN subjects s ON s.subjectID = sr.subjectID $condition INNER JOIN batches b ON b.batchID = sr.batchID WHERE sr.batchID IN (" . $batchIds . ") AND sr.semID = $semId group by sa.staffID,b.batchID ORDER BY sa.staffID,b.batchID ASC";
                    break;
                case "COURSE":
                    $sql = "SELECT sa.staffID as staffId,sa.staffName as staffName, s.subjectDesc as subjectDesc,s.subjectName as subjectName,b.batchName,sr.sbsID as sbsId,b.batchID as batchId FROM staffaccounts sa INNER JOIN sbs_relation sr ON sa.staffID = sr.staffID INNER JOIN subjects s ON s.subjectID = sr.subjectID $condition INNER JOIN batches b ON b.batchID = sr.batchID WHERE sr.batchID IN (" . $batchIds . ") AND sr.semID = $semId group by sbs.subjectID,b.batchID ORDER BY sbs.subjectID,b.batchID ASC";
                    break;
                case "BOTH":
                    $sql = "SELECT sa.staffID as staffId,sa.staffName as staffName, s.subjectDesc as subjectDesc,s.subjectName as subjectName,b.batchName,sr.sbsID as sbsId,b.batchID as batchId FROM staffaccounts sa INNER JOIN sbs_relation sr ON sa.staffID = sr.staffID INNER JOIN subjects s ON s.subjectID = sr.subjectID $condition INNER JOIN batches b ON b.batchID = sr.batchID WHERE sr.batchID IN (" . $batchIds . ") AND sr.semID = $semId ORDER BY b.batchID ASC";
                    break;
            }
            $staffDetails = $this->executeQueryForList($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return $staffDetails;
    }
    /**
     * get staff evaluation status done by student
     *
     * @param int $semId
     * @param int $batchIds
     * @param int $studentId
     * @return Object
     */
    public function getStudentStaffEvaluationStatus($semId, $batchId, $studentId)
    {
        $semId = $this->realEscapeString($semId);
        $batchId = $this->realEscapeString($batchId);
        $studentId = $this->realEscapeString($studentId);
        $sql = "";
        try {
            $sqlEvalIds = "SELECT
                DISTINCT sevt.eval_typeID AS id,
                sevt.eval_name AS name,
                sevt.evalStartDate,
                sevt.evalEndDate,
                sevt.loginType
            FROM
                staffeval_studentanswers sesa
                INNER JOIN staffeval_type sevt ON sevt.eval_typeID = sesa.eval_typeID
            WHERE
                sesa.batchID = $batchId
                AND sesa.semID = $semId";
            $evalObj = $this->executeQueryForObject($sqlEvalIds);
            if ($evalObj->loginType == 2) {
                $evalObj->isKeyGenaratedValuation = false;
                $sql = "SELECT
                    sess.fullPerform
                FROM
                    staffeval_type sevt
                INNER JOIN staffeval_savestudent sess ON
                    sess.staffeval_type_id = sevt.eval_typeID
                WHERE
                    sess.studentaccount_id = $studentId
                    AND sess.batches_id = $batchId
                    AND sess.staffeval_type_id IN ($evalObj->id)";
                
                $evaluationDetails = $this->executeQueryForObject($sql);
                if ($evaluationDetails->fullPerform == 1) {
                    $evalObj->isComplete = true;
                }
                else{
                    $evalObj->isComplete = false;
                }
            }
            else if(!empty($evalObj)){
                $evalObj->isKeyGenaratedValuation = true;
                $evalObj->isComplete = true;
            }
            else {
                $evalObj->isKeyGenaratedValuation = false;
                $evalObj->isComplete = false;
            }
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return $evalObj;
    }
    
    /**
     * list all evaluation for student
     * check student finished evaluations
     * @param $request
     * @return Object StaffEvaluationList
     */
    public function getStaffEvaluationByStudentId($request)
    {
        $condition = "";
        $condition .= $request->validateWithCurrentDate? " AND NOW() >= stt.evalStartDate AND NOW() <= stt.evalEndDate " : "" ;
        $condition .= $request->fullPerform === '0' || $request->fullPerform === '1'? " AND stsa.fullPerform = ".(int)$request->fullPerform : "" ;
        $condition .= (int)$request->loginType?" AND stt.loginType = $request->loginType ":"";
        $condition .= $request->isMandatory === '0' || $request->isMandatory === '1'? " AND stt.is_mandatory = ".(int)$request->isMandatory : "" ;
        $condition .= $request->isLocked == '0'? " AND stt.is_locked = 0 ":"";
        $sql = "SELECT stt.eval_typeID,stt.eval_name, stt.loginType, stt.evalStartDate,stt.evalEndDate,stsa.fullPerform, stt.is_locked, stt.staffeval_type
        FROM staffeval_type stt
            INNER JOIN staffeval_stafflist stsl ON stsl.eval_typeID = stt.eval_typeID
            INNER JOIN studentaccount std ON std.batchID = stsl.batchID
            LEFT JOIN staffeval_savestudent stsa on stsa.studentaccount_id = std.studentID and stsa.staffeval_type_id = stt.eval_typeID and stsa.batches_id = stsl.batchID 
            LEFT JOIN subbatch_sbs ssbs ON ssbs.sbsID = stsl.sbsID AND ((FIND_IN_SET(ssbs.subbatchID, stsl.subbatchID)) OR (stsl.subbatchID = 0 OR stsl.subbatchID IS NULL))
            LEFT JOIN subbatch_student stsd ON stsd.subbatchID = ssbs.subbatchID AND stsd.studentID = std.studentID
        WHERE std.studentID = $request->studentId AND stsl.batchID = $request->batchId AND ((ssbs.sbsID IS NULL AND stsd.subbatchID IS NULL) OR (ssbs.sbsID IS NOT NULL AND stsd.subbatchID IS NOT NULL))
        $condition
        GROUP BY stt.eval_typeID;";
        try{
            return $this->executeQueryForList($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    public function getStaffsEvaluationDetailsByRequest($request)
    {
        $request->staffID?$where[]=" sst.staffID = $request->staffID ":"";
        $request->sbsID?$where[] = " sst.sbsID = $request->sbsID ":"";
        $sql = "SELECT 
            sst.sbsID, sst.eval_typeID, st.eval_name, bat.batchName, bat.deptID, sbs.batchID, sbs.staffID, sbs.subjectID, sbs.semID
            FROM staffeval_type st
            INNER JOIN staffeval_studentanswers sst ON sst.eval_typeID = st.eval_typeID
            INNER JOIN sbs_relation sbs ON sbs.sbsID = sst.sbsID
            INNER JOIN batches bat ON bat.batchID = sst.batchID
            ".($where?" WHERE ".implode(' AND ',$where):"")."
            GROUP BY st.eval_typeID , sst.sbsID";
        try{
            return $this->executeQueryForList($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    } 
    /**
     * Method to Lock a evaluation by id
     * @param id
     * @return Boolean
     * @throws ProfessionalException
     */
    public function lockEvaluationbyId($id){
        $sql = "UPDATE `staffeval_type` SET `is_locked`='1' WHERE `eval_typeID`='$id";
        try{
            $this->executeQueryForObject($sql, true);
            return true;
        }
        catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return false;
    }
    /**
     * Method to unLock a evaluation by id
     * @param id
     * @return Boolean
     * @throws ProfessionalException
     */
    public function unlockEvaluationbyId($id){
        $sql = "UPDATE `staffeval_type` SET `is_locked`='0' WHERE `eval_typeID`='$id";
        try{
            $this->executeQueryForObject($sql, true);
            return true;
        }
        catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return false;
    }
    /**
     * Method to insert data into staffEval_studentList
     * @param Object $request
     * @return Boolean
     * @throws ProfessionalException
     */
    public function addSelectedStudentsToStaffEval($request){
        
        try{
            if($request->studentIds){
                foreach($request->studentIds as $studentID){
                    $result = EvaluationService::getInstance()->checkStudentExistBySbsIdAndStudentId($request->sbsID, $studentID, $request->evalId);
                    if(!$result){
                        $sql = " INSERT INTO `staffEval_studentList` (`evaluationID`, `sbsID`, `subjectID`, `studentID`, `batchID`, `created_by`)
                            VALUES ('$request->evalId', '$request->sbsID', '$request->subjectID', '$studentID', '$request->batchID', '$request->adminID'); ";
                    $resultStdAdded = $this->executeQueryForList($sql);
                    }
                    else{
                        continue;
                    }
                    
                }
            }
            
            if($request->unselectedStdnList){ //remove students
                $sql = '';
                $studentIds = '';
                foreach($request->unselectedStdnList as $studentID){
                    $sql = " DELETE FROM staffEval_studentList
                        WHERE sbsID = '$request->sbsID' AND studentID = '$studentID";
                $resultStdRemoved = $this->executeQueryForList($sql);
                }
                
            }
            return true;
        }
        catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return false;
    }
    /**
     * Method to check student exist in specific student evaluation
     * @param Int $sbsID, $studentID
     * @return Boolean
     * @throws ProfessionalException
     */
    public function checkStudentExistBySbsIdAndStudentId($sbsID, $studentID, $evalId){
        $sql = "SELECT 
                    studentID
                FROM
                    staffEval_studentList
                WHERE
                    studentID = '$studentID' AND sbsID = '$sbsID' AND evaluationID = '$evalId";
        try{
            if($result = $this->executeQueryForList($sql)){
                return true;
            }
        }
        catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return false;
    }
    /**
     * Method to students in specific student evaluation
     * @param Int $sbsID, $studentID
     * @return array Student List
     * @throws ProfessionalException
     */
    public function getAllStudentsInStaffEvaluationStudent($batchID, $evaluationID, $sbsID){
        $sql = "SELECT 
                    evaluationID,
                    sbsID,
                    subjectID,
                    studentID,
                    batchID
                FROM
                    staffEval_studentList
                WHERE
                batchID = '$batchID' AND evaluationID = '$evaluationID
                AND sbsID = '$sbsID";
        try{
            return $this->executeQueryForList($sql);
        }
        catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    /**
     * Method to remove students specific student evaluation
     * @param Object request
     * @return Boolean
     * @throws ProfessionalException
     */
    public function deleteStudentsInStaffEvaluationStudent($request){
        $sql = "DELETE 
                FROM
                    staffEval_studentList
                WHERE
                sbsID = '$request->sbsID' AND batchID = '$request->batchID'
                AND evaluationID = '$request->evalId";
        try{
            $this->executeQueryForList($sql);
            return true;
        }
        catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return false;
    }
    /**
     * Method to get sbs List of staff evaluation
     * @param Integer batchID, evalTypeID
     * @return Array $staffList
     * @throws ProfessionalException
     */
    public function getStaffEvalStaffSbsList($batchID, $evalTypeID){
        $sql = "SELECT sbsID, batchID semID, eval_typeID
                FROM
                    staffeval_stafflist 
                WHERE
                    batchID = '$batchID' AND eval_typeID = '$evalTypeID";
        try{
            return $this->executeQueryForList($sql);
        }
        catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return false;
    }
    /**
     * Get all sections
     * @param Integer $sectionId
     * @return Array $sections
     * @throws ProfessionalException
     */
    public function getAllSections($sectionId = null){
        $where = [];
        $sectionId ? $where [] = " id = '$sectionId'" : null;
        $sql = "SELECT id, code, name, description, properties
                FROM staffeval_question_sections
                " . ($where ? " WHERE " . implode(' AND ', $where) : "")."
                ORDER BY properties->'$.order';";
        try{
            $sections = $this->executeQueryForList($sql);
            foreach ($sections as $section)
            {
                $section->properties = json_decode($section->properties);
            }
            return $sections;
        }
        catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    /**
     * Method to Lock a evaluation by id
     * @param id
     * @return Boolean
     * @throws ProfessionalException
     */
    public function updateEvaluationQuestionsSection($sectionId,$questionId,$evaluationId){
        $sql = "UPDATE `staffeval_type_questions` SET `section_id`='$sectionId
        WHERE `eval_typeID`='$evaluationId' and `questionID` = '$questionId";
        try{
            return $this->executeQuery($sql);
        }catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    /**
     * Method to Lock a evaluation by id
     * @param id
     * @return Boolean
     * @throws ProfessionalException
     */
    public function getEvaluationQuestionSections($questionId,$evaluationId){
        $sql = "Select section_id as sectionId from staffeval_type_questions where questionID = '$questionId' and eval_typeID = '$evaluationId";
        try{
            return $this->executeQueryForObject($sql)->sectionId;
        }catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    /**
     * Method to Lock a evaluation by id
     * @param id
     * @return Boolean
     * @throws ProfessionalException
     */
    public function findQuestionSectionId($questionId){
        $sql = "select s.id as sectionId from staffeval_questions q 
        inner join staffeval_question_sections s on s.code = q.section_code 
        where q.questionID = '$questionId';";
        try{
            return $this->executeQueryForObject($sql)->sectionId;
        }catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    /**
     * Method to Lock a question by id
     * @param String questionId
     * @param Array answerId
     * @return Boolean
     * @throws ProfessionalException
     */
    public function getQuestion($questionId,$answerIds = []){
        $where = [];
        $answerIds && count($answerIds) ? $where [] = " a.answerID in (".implode(',',$answerIds).") " : null;
        $where [] = "q.questionID = '$questionId'";
        $sql = "SELECT q.questionID, q.question, q.isExtra_question, q.section_code, q.is_multiple_choice_question, a.answerID, a.answer, a.point 
            FROM staffeval_questions q
            INNER JOIN staffeval_answers a ON a.questionID = q.questionID
            " . ($where ? " WHERE " . implode(' AND ', $where) : "") . "
            ORDER BY a.point;";
        try{
            $question = $this->executeQueryForList($sql, $this->mapper[StaffEvaluationMapper::EVALUATION_QUESTIONS])[0];
            $answers = [];
            if($question->isMultiChoice){
                if(!count($answerIds) && empty($answerIds)){
                    $answers [] = $question->answers[0];
                    $question->answers = $answers;
                }
            }else{
                $answers [] = $question->answers[0];
                $question->answers = $answers;
            }
            return $question;
        }catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    
    /**
     * Method to Lock a question by id
     * @param String questionId
     * @param Array answerId
     * @return Boolean
     * @throws ProfessionalException
     */
    public function checkEvaluationHaveMultiChoiceQuestion($evaluationId){
        $sql = "SELECT count(q.questionID) as checker from staffeval_type_questions eq
        inner join staffeval_questions q on q.questionID = eq.questionID
        where q.is_multiple_choice_question = '1' and eq.eval_typeID = '$evaluationId'";
        try{
            $checker = $this->executeQueryForObject($sql)->checker;
            return $checker ? true : false ;
        }catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    /**
     * Get all sections
     * @param String $sectionCode
     * @return Array $sections
     * @throws ProfessionalException
     */
    public function getAllSectionsForReport($sectionCode = null){
        $where = [];
        $sectionCode ? $where [] = " code = '$sectionCode'" : null;
        $sql = "SELECT id, code, name, description, properties
                FROM staffeval_question_sections
                " . ($where ? " WHERE " . implode(' AND ', $where) : "")."
                ORDER BY properties->'$.order';";
        try{
            $allSections = $this->executeQueryForList($sql);
            foreach ($allSections as $sec){
                $section = new stdClass();
                $section->name = $sec->name;
                $section->code = $sec->code;
                $sec->properties = json_decode($sec->properties);
                $section->order = $sec->properties->order;
                $section->show_at_staff = $sec->properties->show_at_staff;
                $section->show_at_student = $sec->properties->show_at_student;
                $sections [] = $section;
            }
            return $sections;
        }
        catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    /**
     * Get all evaluation for a staff by request
     */
    public function getAllStaffsEvaluationDetailsByRequest($request)
    {
        $request->staffId && count($request->staffId) ? $where [] =" sst.staffID IN (".implode(' , ',$request->staffId).") ":"";
        $request->batchId && count($request->batchId) ? $where [] = " sbs.batchID IN (".implode(' , ',$request->batchId).") ":"";
        $request->semId && count($request->semId) ? $where [] = " sbs.semID IN (".implode(' , ',$request->semId).") ":"";
        $request->subjectId ? $where [] = " sbs.subjectID = $request->subjectId ":"";
        $request->sbsId && count($request->sbsId) ? $where [] = " sst.sbsID IN (".implode(' , ',$request->sbsId).") ":"";
        $request->staffId && count($request->staffId) ? $where [] = " sbs.staffID IN (".implode(' , ',$request->staffId).") ":"";
        $sql = "SELECT 
            sst.sbsID, sst.eval_typeID, st.eval_name, bat.batchName, bat.deptID, group_concat(distinct sbs.batchID) as batchId, sbs.staffID, sbs.subjectID, sbs.semID
            FROM staffeval_type st
            INNER JOIN staffeval_studentanswers sst ON sst.eval_typeID = st.eval_typeID
            INNER JOIN sbs_relation sbs ON sbs.sbsID = sst.sbsID
            INNER JOIN batches bat ON bat.batchID = sst.batchID
            ".($where?" WHERE ".implode(' AND ',$where):"")."
            GROUP BY st.eval_typeID";
        try{
            return $this->executeQueryForList($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    } 
    /**
     * Method to Lock a evaluation by id
     * @param id
     * @return Boolean
     * @throws ProfessionalException
     */
    public function getEvaluationQuestions($evaluationId){
        $sql = "SELECT eval_typeID AS typeId, questionID AS questionId, question_order AS questionOrder, section_id AS sectionId 
            FROM staffeval_type_questions WHERE eval_typeID = '$evaluationId";
        try{
            return $this->executeQueryForList($sql);
        }catch(\Exception $e){
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    public function getEvaluationData ( $evalId ) {
        $evaluationDetails = null;
        $evalId = $this->realEscapeString($evalId);
        $sql = "SELECT `name`,`instruction`,`question_per_page`,`expiryDate`,`isLocked`,`is_mandatory` from evaluation WHERE id = $evalId";
        
        try {
            $evaluationDetails = $this->executeQueryForObject( $sql );
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        return $evaluationDetails;
    }
    /**
     * Create evaluations for excel purpose
     */
    public function createStaffEvaluation ( $evaluation ) {
        $evaluation = $this->realEscapeObject($evaluation);
        $evaluation->success = true;
        $sql = "INSERT INTO staffeval_type(eval_name,instruction,student_suggestion,evalStartDate,evalEndDate,loginType,staffeval_type,default_result_view,is_mandatory,minimum_student_attendance_percentage,hide_suggestion,createdBy, createdDate, updatedBy, updatedDate, is_locked)
        VALUES('$evaluation->evaluation_name','$evaluation->instructions','$evaluation->student_suggestions_mandatory','$evaluation->start_date','$evaluation->end_date','$evaluation->login_method','$evaluation->evaluation_type','$evaluation->default_result_view','$evaluation->mandatory_evaluation','$evaluation->student_attendaned_percentage','$evaluation->students_suggestions',$evaluation->userId,utc_timestamp(),$evaluation->userId, utc_timestamp(),1);";
        try {
            $this->executeQuery("START TRANSACTION");
            $evaluation->id = $this->executeQueryForObject( $sql , true);
            // inserting batches relations
            foreach ($evaluation->batches as $key => $batch) {
                $this->executeQuery("INSERT IGNORE INTO staffeval_savestudent(staffeval_type_id, studentaccount_id, fullPerform, batches_id)
                SELECT $evaluation->id,s.studentID,0,s.batchID FROM studentaccount s WHERE batchID = $batch->batchID;");
            }
            // inserting staff relations
            foreach ($evaluation->subjectRelations as $key => $subjectRelations) {
                $this->executeQuery("INSERT IGNORE INTO staffeval_stafflist
                (sbsID, batchID, semID, eval_typeID, subbatchID)
                SELECT sr.sbsID,sr.batchID,sr.semID,$evaluation->id,0 FROM sbs_relation sr WHERE sr.sbsID = $subjectRelations->sbsID;");
            }
            // inserting question
            foreach ($evaluation->question as $key => $question) {
                $question->id = $this->executeQueryForObject("INSERT INTO staffeval_questions
                (question, isExtra_question, section_code, is_multiple_choice_question)
                VALUES('$question->questions', 0, 'section1', 0);", true);
                foreach ([1,2,3,4,5] as $key => $value) {
                    // inserting answer to question
                    $this->executeQuery("INSERT INTO staffeval_answers(questionID, answer, `point`)
                    VALUES($question->id, '".$question->{"option_".$value}."', '".$question->{"score_".$value}."');");
                }
                // inserting question to evaluations
                $question->id = $this->executeQuery("INSERT INTO staffeval_type_questions
                (eval_typeID, questionID, question_order, section_id)
                VALUES('$evaluation->id', $question->id$question->question_order, 1);");
            } 
            $this->executeQuery("COMMIT");
        } catch (\Exception $e) {
            $this->executeQuery("ROLLBACK");
            $evaluation->success = false;
        }
        return $evaluation;
    }
    /**
     * excecut query for excel purpose
     */
    public function executeQueriesByString ( $sql, $getKey = false ) {
        try {
            if($getKey){
                return $this->executeQueryForObject( $sql , true)->id;
            }else{
                $this->executeQuery($sql);
            }
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
    }
    public function deleteEvaluation($id)
    {
        try {
            $updations = [];
            $sql = "SELECT id from staffeval_savestudent WHERE staffeval_type_id = \"$id\"";
            $studentsAttended = $this->executeQueryForObject($sql);
            if($studentsAttended)
            {
                $msg = "Unable to delete  Reason :Some students are already attended";
            }else{
                $sql="DELETE FROM staffeval_type WHERE eval_typeID=\"$id\"";
                $updations[] = $this->executeQuery($sql);
            }
            $results = new stdClass();
            $results->updations = $updations;
            $results->msg = $msg;
            return $results;
        }catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
    }
    public function getAllEvaluations()
    {
        try{
            $sql = "select
                            t1.eval_typeID,
                            t1.eval_name,
                            (
                            select
                                count(distinct t2.batchID)
                            from
                                staffeval_studentanswers t2
                            where
                                t2.eval_typeID = t1.eval_typeID) as count
                        from
                            staffeval_type t1
                        ORDER BY
                            t1.eval_typeID DESC;";
            return $this->executeQueryForList($sql);                
        }catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
    }
    public function getSbsAndBatchDetailsByBatchAndEvalTypeID($evalTypeID, $batchID, $semID)
    {
        $evalTypeID = $this->realEscapeString($evalTypeID);
        $batchID = $this->realEscapeString($batchID);
        $semID = $this->realEscapeString($semID);
        try{
            $sql = "SELECT
                            sr.sbsID ,sr.staffID ,sr.semID ,sr.subjectID,sr.batchID ,sss.eval_typeID 
                        from
                            staffeval_studentanswer_sbsids sss
                        inner join sbs_relation sr on
                            sr.sbsID = sss.sbsID
                        WHERE
                            sss.eval_typeID = '$evalTypeID' and sr.batchID = '$batchID' and sr.semID  = '$semID' GROUP BY sr.sbsID ";
            return $this->executeQueryForList($sql);
        }catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
    }
    public function getEvaluationDetailsForBulkPrint($eval ,$batchID)
    {
        $eval = $this->realEscapeString($eval);
        $batchID = $this->realEscapeString($batchID);
        try{
            $sql="select t1.eval_name, t2.batchName from staffeval_type t1, batches t2 where t1.eval_typeID=\"$eval\" and t2.batchID=\"$batchID\"";
            return $this->executeQueryForObject($sql);
            
        }catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        
    }
    public function getSbsDetailsForBulkPrint($staffID , $sbs)
    {
        try{
            $staffID = $this->realEscapeString($staffID, $sbs);
            $sql ="SELECT t2.subjectID, t3.staffName, t3.staffCode, t4.subjectName, t4.subjectDesc, t4.syllabusName from sbs_relation t2, staffaccounts t3, subjects t4 WHERE t3.staffID=\"$staffID\" AND t4.subjectID = t2.subjectID AND t2.sbsID=\"$sbs\"";
            return $this->executeQueryForObject($sql);
        }catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
    }
    public function getQuestionsOfEvaluationForBulkPrint($eval_typeID)
    {
        try{
            $eval_typeID = $this->realEscapeString($eval_typeID);
            $sql="SELECT t1.questionID, t2.question from staffeval_type_questions t1, staffeval_questions t2 where t1.questionID=t2.questionID and t1.eval_typeID=\"$eval_typeID\" ORDER BY t1.question_order asc";
            return $this->executeQueryForList($sql);
        }catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
    }
    public function getStudentAnswerCount($batchID, $semID, $eval_typeID, $sbsID)
    {
        $batchID = $this->realEscapeString($batchID);
        $semID = $this->realEscapeString($semID);
        $eval_typeID = $this->realEscapeString($eval_typeID);
        $sbsID = $this->realEscapeString($sbsID);
        try{
            $sql ="SELECT sum(answer_count) as answerCount from staffeval_studentanswers where batchID=\"$batchID\" and semID=\"$semID\" and eval_typeID=\"$eval_typeID\" and sbsID=\"$sbsID\"";
            return $this->executeQueryForObject($sql);
        }catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
    }
    public function getAnswerForQuestion($eval_typeID, $sbsID, $questionID)
    {
        $eval_typeID = $this->realEscapeString($eval_typeID);
        $sbsID = $this->realEscapeString($sbsID);
        $questionID = $this->realEscapeString($questionID);
        try{
            $sql="select sa.answerID, sa.answer, sa.point, ss.answer_count from staffeval_answers sa left join staffeval_studentanswers ss ON ss.answerID=sa.answerID AND ss.eval_typeID=$eval_typeID AND ss.sbsID=$sbsID AND ss.questionID=sa.questionID WHERE sa.questionID=".$questionID;
            return $this->executeQueryForList($sql);
        }catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
    }
    public function getEvaluationsByDeptBatchSem($deptID = null, $batchID = null, $semID = null)
    {
        try{
            $conditions = [];
            if($deptID)
            {
                $deptID = $this->realEscapeString($deptID);
                $conditions[] = "b.deptID = '$deptID'";
            }
            if($batchID)
            {
                $batchID = $this->realEscapeString($batchID);
                $conditions[] = "ss.batchID = '$batchID'";
            }
            if($semID)
            {
                $semID = $this->realEscapeString($semID);
                $conditions[] = "ss.semID = '$semID'";
            }
            $sql = "SELECT
                        st.eval_typeID,
                        st.eval_name,
                        st.instruction,
                        st.question_per_page,
                        st.student_suggestion,
                        st.createdBy,
                        st.createdDate,
                        st.updatedBy,
                        st.updatedDate,
                        st.evalStartDate,
                        st.evalEndDate,
                        st.loginType,
                        st.staffeval_type,
                        st.default_result_view,
                        st.is_mandatory,
                        st.minimum_student_attendance_percentage
                    from
                        staffeval_type st
                        inner join staffeval_stafflist ss on ss.eval_typeID = st.eval_typeID  
                        inner join batches b on b.batchID = ss.batchID 
                        inner join department d on d.deptID = b.deptID
                        ".(count($conditions) > 0? "WHERE ".implode(" AND ",$conditions):"")."
                        GROUP BY st.eval_typeID 
                        ORDER BY
                        st.eval_typeID DESC";
             return $this->executeQueryForList($sql);
        }catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
    }
}