GIF89a; CRX
KBHT HEHE
Server IP : 172.26.0.195  /  Your IP : 3.136.19.124
Web Server : Apache
System : Linux 43-205-77-33.cprapid.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User : jnclnmuac ( 1026)
PHP Version : 8.0.30
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/jnclnmuac/public_html/web/../css/../cas/application/models/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/jnclnmuac/public_html/web/../css/../cas/application/models/admin/TaskAndQuizManagement.php
<?php

/**
 * Model For Handling All DB Operations Related To Tasks, Assignments & Quizzes
 *
 * @author Softpro India Pvt. Ltd.
 */
defined('BASEPATH') OR exit('No direct script access allowed');

class TaskAndQuizManagement extends CI_Model {

    function createNewTopic(array $newTopicInfo) {
        $this->db->insert('subject_topics_mst', $newTopicInfo);
        return $this->db->insert_id();
    }

    function getAllSubjectTopics() {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_topics_mst STM');
        $this->db->join('subject_mst SM', 'STM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'STM.stm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'STM.stm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->order_by("STM.stm_updated_on", "desc");
        return $this->db->get();
    }

    function getTopicInfoBy($topic_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_topics_mst STM');
        $this->db->join('subject_mst SM', 'STM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'STM.stm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'STM.stm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("STM.stm_id", $topic_id);
        return $this->db->get();
    }

    function getTopicInfoByName($topic_name) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_topics_mst STM');
        $this->db->join('subject_mst SM', 'STM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'STM.stm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'STM.stm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("STM.stm_name", $topic_name);
        return $this->db->get();
    }

    function getAllNonDeletedActiveSubjectTopicsBy($sm_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_topics_mst STM');
        $this->db->join('subject_mst SM', 'STM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'STM.stm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'STM.stm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("STM.stm_active_status", "T");
        $this->db->where("STM.stm_delete_status", "F");
        $this->db->where("STM.sm_id", $sm_id);
        $this->db->order_by("STM.stm_updated_on", "desc");
        return $this->db->get();
    }

    function isTopicNameSafeUpdate($topic_id, $topic_name) {
        $this->db->select("*");
        $this->db->from('subject_topics_mst');
        $this->db->where('stm_name', $topic_name);
        $this->db->where('stm_id != ' . $topic_id);
        $result = $this->db->get()->result();
        if (sizeof($result)) {
            return FALSE;
        } else {
            return TRUE;
        }
    }

    function updateTopicInfo(array $topicUpdatedInfo) {
        $this->db->where('stm_id', $topicUpdatedInfo['stm_id']);
        return $this->db->update('subject_topics_mst', $topicUpdatedInfo);
    }

    /* Functions For Group Questions */

    function createNewQuestionGroup(array $newQuestionGroup) {
        $this->db->insert('question_group', $newQuestionGroup);
        return $this->db->insert_id();
    }

    function getGroupQuestionInfoBy($qg_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('question_group QG');
        $this->db->join('question_bank QB', 'QG.qg_id = QB.qg_id');
        $this->db->join('subject_topics_mst STM', 'QB.stm_id = STM.stm_id');
        $this->db->join('subject_mst SM', 'STM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'QG.qg_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'QG.qg_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("QG.qg_id", $qg_id);
        return $this->db->get();
    }

    function getAllGroupQuestionsOfUser($smember_id, $question_type, array $topic_ids = array(), $subject_id = '') {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('question_bank QB');
        $this->db->join('question_group QG', 'QB.qg_id = QG.qg_id');
        $this->db->join('subject_topics_mst STM', 'QB.stm_id = STM.stm_id');
        $this->db->join('subject_mst SM', 'STM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'QG.qg_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'QG.qg_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("QB.qb_ques_type_flag", $question_type);
        $this->db->where("QG.qg_delete_status", "F");
        $this->db->where("QG.qg_added_by", $smember_id);
        if (sizeof($topic_ids)) {
            $this->db->where_in("QB.stm_id", $topic_ids);
        }
        if ($subject_id != '') {
            $this->db->where("SM.sm_id", $subject_id);
        }
        $this->db->where("QB.qg_id IS NOT NULL");
        $this->db->order_by("QG.qg_added_on", "desc");
        return $this->db->get();
    }

    function getAllGroupQuestionInfoBy($qg_id, $question_type) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('question_bank QB');
        $this->db->join('question_group QG', 'QB.qg_id = QG.qg_id');
        $this->db->join('subject_topics_mst STM', 'QB.stm_id = STM.stm_id');
        $this->db->join('subject_mst SM', 'STM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'SQG.qg_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'SQG.qg_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("QB.qb_ques_type_flag", $question_type);
        $this->db->where("QG.qg_id", $qg_id);
        return $this->db->get();
    }

    function getModelExamPaperGroupQuestionsBy($mepm_id) {
        $this->db->select("*");
        $this->db->from('model_exam_paper_ques_map MEPQM');
        $this->db->join('question_bank QB', 'MEPQM.qb_id = QB.qb_id');
        $this->db->join('question_group QG', 'QB.qg_id = QG.qg_id');
        $this->db->join('subject_topics_mst STM', 'QB.stm_id = STM.stm_id');
        $this->db->join('subject_mst SM', 'STM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->where("MEPQM.mepm_id", $mepm_id);
        $this->db->where("QB.qg_id IS NOT NULL");
        $this->db->order_by("QB.qg_id");
        return $this->db->get();
    }

    function updateGroupQuestionInfo(array $groupQuestionUpdatedInfo) {
        $this->db->where('qg_id', $groupQuestionUpdatedInfo['qg_id']);
        return $this->db->update('question_group', $groupQuestionUpdatedInfo);
    }

    /* Functions For General Questions */

    function createNewGeneralQuestion(array $newQuestionInfo) {
        $this->db->insert('question_bank', $newQuestionInfo);
        return $this->db->insert_id();
    }

    function createNewGeneralQuestionsMulti(array $newQuestionInfo) {
        $this->db->insert_batch('question_bank', $newQuestionInfo);
        return $this->db->insert_id();
    }

    function getAllGeneralQuestionsOfUser($smember_id, $question_type, array $topic_ids = array(), $subject_id = '') {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('question_bank QB');
        $this->db->join('subject_topics_mst STM', 'QB.stm_id = STM.stm_id');
        $this->db->join('subject_mst SM', 'STM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'QB.qb_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'QB.qb_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("QB.qb_ques_type_flag", $question_type);
        $this->db->where("QB.qb_delete_status", "F");
        $this->db->where("QB.qb_added_by", $smember_id);
        if (sizeof($topic_ids)) {
            $this->db->where_in("QB.stm_id", $topic_ids);
        }
        if ($subject_id != '') {
            $this->db->where("SM.sm_id", $subject_id);
        }
        $this->db->where("(QB.qg_id IS NULL OR QB.qg_id = '')");
        $this->db->order_by("QB.qb_added_on", "desc");
        return $this->db->get();
    }

    function getGeneralQuestionInfoBy($qb_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('question_bank QB');
        $this->db->join('subject_topics_mst STM', 'QB.stm_id = STM.stm_id');
        $this->db->join('subject_mst SM', 'STM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'QB.qb_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'QB.qb_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("QB.qb_id", $qb_id);
        return $this->db->get();
    }

    function getModelExamPaperGeneralQuestionsBy($mepm_id) {
        $this->db->select("*");
        $this->db->from('model_exam_paper_ques_map MEPQM');
        $this->db->join('question_bank QB', 'MEPQM.qb_id = QB.qb_id');
        $this->db->join('subject_topics_mst STM', 'QB.stm_id = STM.stm_id');
        $this->db->join('subject_mst SM', 'STM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->where("MEPQM.mepm_id", $mepm_id);
        $this->db->where("(QB.qg_id IS NULL OR QB.qg_id = '')");
        return $this->db->get();
    }

    function deleteQuestionsBy($qg_id) {
        $this->db->where("qg_id", $qg_id);
        $this->db->delete("question_bank");
    }

    function updateGenralQuestionInfo(array $generalQuestionUpdatedInfo) {
        $this->db->where('qb_id', $generalQuestionUpdatedInfo['qb_id']);
        return $this->db->update('question_bank', $generalQuestionUpdatedInfo);
    }

    /* Functions For Model Papers & Related Stuffs */

    function createNewModelPaper(array $newModelPaperInfo) {
        $this->db->insert('model_exam_paper_mst', $newModelPaperInfo);
        return $this->db->insert_id();
    }

    function createNewModelPaperQuestionMappingMulti(array $newModelPaperQuestionMappingInfo) {
        $this->db->insert_batch('model_exam_paper_ques_map', $newModelPaperQuestionMappingInfo);
        return $this->db->insert_id();
    }

    function getModelExamPaperInfoBy($mepm_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('model_exam_paper_mst MEPM');
        $this->db->join('subject_mst SM', 'MEPM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'MEPM.mepm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'MEPM.mepm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("MEPM.mepm_id", $mepm_id);
        return $this->db->get();
    }

    function getAllModelExamPapersOfUser($smember_id, $model_paper_type) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('model_exam_paper_mst MEPM');
        $this->db->join('subject_mst SM', 'MEPM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'MEPM.mepm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'MEPM.mepm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("MEPM.mepm_type", $model_paper_type);
        $this->db->where("MEPM.mepm_delete_status", "F");
        $this->db->where("MEPM.mepm_added_by", $smember_id);
        $this->db->order_by("MEPM.mepm_added_on", "desc");
        return $this->db->get();
    }

    function getAllModelExamPapersOfUserBySubject($smember_id, $subject) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('model_exam_paper_mst MEPM');
        $this->db->join('subject_mst SM', 'MEPM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'MEPM.mepm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'MEPM.mepm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("SM.sm_id", $subject);
        $this->db->where("MEPM.mepm_delete_status", "F");
        $this->db->where("MEPM.mepm_added_by", $smember_id);
        $this->db->order_by("MEPM.mepm_added_on", "desc");
        return $this->db->get();
    }

    function updateModelExamPaperInfo(array $modelPaperUpdatedInfo) {
        $this->db->where('mepm_id', $modelPaperUpdatedInfo['mepm_id']);
        return $this->db->update('model_exam_paper_mst', $modelPaperUpdatedInfo);
    }

    /* Functions For Model Paper Scheduling & Related Stuffs */

    function createNewModelPaperSchedule(array $newModelPaperScheduleInfo) {
        $this->db->insert('model_exam_paper_schedule', $newModelPaperScheduleInfo);
        return $this->db->insert_id();
    }

    function getAllSchedulesOfModelPaperBy($mepm_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('model_exam_paper_schedule MEPSCH');
        $this->db->join('model_exam_paper_mst MEPM', 'MEPSCH.mepm_id = MEPM.mepm_id');
        $this->db->join('subject_mst SM', 'MEPM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'MEPSCH.mepsch_scheduled_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'MEPSCH.mepsch_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("MEPSCH.mepm_id", $mepm_id);
        $this->db->where("MEPSCH.mepsch_delete_status", "F");
        $this->db->order_by("MEPSCH.mepsch_schedule_on", "desc");
        return $this->db->get();
    }

    function getModelPaperScheduleInfoBy($mepsch_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('model_exam_paper_schedule MEPSCH');
        $this->db->join('model_exam_paper_mst MEPM', 'MEPSCH.mepm_id = MEPM.mepm_id');
        $this->db->join('subject_mst SM', 'MEPM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'MEPSCH.mepsch_scheduled_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'MEPSCH.mepsch_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("MEPSCH.mepsch_id", $mepsch_id);
        $this->db->where("MEPSCH.mepsch_delete_status", "F");
        $this->db->order_by("MEPSCH.mepsch_schedule_on", "desc");
        return $this->db->get();
    }

    function updateModelExamPaperScheduleInfo(array $modelPaperScheduleUpdatedInfo) {
        $this->db->where('mepsch_id', $modelPaperScheduleUpdatedInfo['mepsch_id']);
        return $this->db->update('model_exam_paper_schedule', $modelPaperScheduleUpdatedInfo);
    }

    /* Functions For Student Model Papers & Related Stuffs */

    function createNewModelPaperStudentAllotmentMulti(array $newModelPaperStudentAllotInfo) {
        $this->db->insert_batch('model_exam_paper_student_allot', $newModelPaperStudentAllotInfo);
        return $this->db->insert_id();
    }

    function getAllottedModelPapersByStudent($tspi_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('model_exam_paper_student_allot MEPSA');
        $this->db->join('model_exam_paper_schedule MEPSCH', 'MEPSA.mepsch_id = MEPSCH.mepsch_id');
        $this->db->join('model_exam_paper_mst MEPM', 'MEPSA.mepm_id = MEPM.mepm_id');
        $this->db->join('subject_mst SM', 'MEPM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'MEPSCH.mepsch_scheduled_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'MEPSCH.mepsch_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("MEPSCH.mepsch_active_status", "T");
        $this->db->where("MEPSCH.mepsch_delete_status", "F");
        $this->db->where("MEPSA.tspi_id", $tspi_id);
        $this->db->order_by("MEPSCH.mepsch_schedule_on", "desc");
        return $this->db->get();
    }

    function getAllottedModelPaperInfoBy($mepm_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('model_exam_paper_student_allot MEPSA');
        $this->db->join('model_exam_paper_schedule MEPSCH', 'MEPSA.mepsch_id = MEPSCH.mepsch_id');
        $this->db->join('model_exam_paper_mst MEPM', 'MEPSA.mepm_id = MEPM.mepm_id');
        $this->db->join('subject_mst SM', 'MEPM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'MEPM.mepm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'MEPM.mepm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("MEPM.mepm_active_status", "T");
        $this->db->where("MEPM.mepm_delete_status", "F");
        $this->db->where("MEPSA.mepm_id", $mepm_id);
        $this->db->order_by("MEPSCH.mepsch_schedule_on", "desc");
        return $this->db->get();
    }

    function getAllottedModelPapersBySchedule($mepsch_id, $mepm_id = '', $tspi_id = '') {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('model_exam_paper_student_allot MEPSA');
        $this->db->join('model_exam_paper_schedule MEPSCH', 'MEPSA.mepsch_id = MEPSCH.mepsch_id');
        $this->db->join('model_exam_paper_mst MEPM', 'MEPSA.mepm_id = MEPM.mepm_id');
        $this->db->join('subject_mst SM', 'MEPM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'MEPSCH.mepsch_scheduled_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'MEPSCH.mepsch_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("MEPSCH.mepsch_id", $mepsch_id);
        if (trim($mepm_id) != "") {
            $this->db->where("MEPSA.mepm_id", $mepm_id);
        }
        if (trim($tspi_id) != "") {
            $this->db->where("MEPSA.tspi_id", $tspi_id);
        }
        return $this->db->get();
    }

    function deleteModelExamPaperStudentAllotment($mepsch_id) {
        $this->db->where("mepsch_id", $mepsch_id);
        $this->db->delete("model_exam_paper_student_allot");
    }

    /* Functions For Student's Model Paper Attempts And Related Stuffs */

    function createNewStudentAttempt(array $newStudentModelPaperAttemptInfo) {
        $this->db->insert('model_exam_paper_student_attempt', $newStudentModelPaperAttemptInfo);
        return $this->db->insert_id();
    }

    function createNewStudentResponse(array $newStudentModelPaperResponseInfo) {
        $this->db->insert_batch('model_exam_paper_response_mst', $newStudentModelPaperResponseInfo);
        return $this->db->insert_id();
    }

    function getModelPaperAttemptByStudent($tspi_id, $mepm_id) {
        $this->db->select("*");
        $this->db->from('model_exam_paper_student_attempt MEPSAT');
        $this->db->join('model_exam_paper_mst MEPM', 'MEPSAT.mepm_id = MEPM.mepm_id');
        $this->db->where("MEPSAT.tspi_id", $tspi_id);
        $this->db->where("MEPSAT.mepm_id", $mepm_id);
        return $this->db->get();
    }

    function getModelPaperAttemptResponseByStudent($tspi_id, $mepm_id) {
        $this->db->select("*");
        $this->db->from('model_exam_paper_response_mst MEPRM');
        $this->db->join('model_exam_paper_ques_map MEPQM', 'MEPRM.mepqm_id = MEPQM.mepqm_id');
        $this->db->join('model_exam_paper_mst MEPM', 'MEPRM.mepm_id = MEPM.mepm_id');
        $this->db->join('question_bank QB', 'MEPRM.qb_id = QB.qb_id');
        $this->db->join('question_group QG', 'QB.qg_id = QG.qg_id', 'left');
        $this->db->join('subject_topics_mst STM', 'QB.stm_id = STM.stm_id');
        $this->db->join('subject_mst SM', 'STM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->where("MEPRM.tspi_id", $tspi_id);
        $this->db->where("MEPRM.mepm_id", $mepm_id);
        return $this->db->get();
    }

    function updateNewStudentResponse(array $studentModelPaperResponse) {
        $this->db->where(array('tspi_id' => $studentModelPaperResponse['tspi_id'], 'qb_id' => $studentModelPaperResponse['qb_id'], 'mepm_id' => $studentModelPaperResponse['mepm_id']));
        return $this->db->update('model_exam_paper_response_mst', $studentModelPaperResponse);
    }

    function deleteModelPaperStudentAttempt($mepsch_id, $mepm_id, $tspi_id, $del_latest_only) {
        if ($del_latest_only) {
            $this->db->where("mepsat_id  = (select mepsat_id from (select max(mepsat_id) mepsat_id from model_exam_paper_student_attempt where tspi_id = " . $tspi_id . " and mepm_id = " . $mepm_id . " and mepsch_id = " . $mepsch_id . ") tt)");
            $this->db->delete("model_exam_paper_student_attempt");
        } else {
            $this->db->where("tspi_id", $tspi_id);
            $this->db->where("mepm_id", $mepm_id);
            $this->db->where("mepsch_id", $mepsch_id);
            $this->db->delete("model_exam_paper_student_attempt");
        }
    }

    function deleteModelPaperStudentResponse($mepsch_id, $mepm_id, $tspi_id) {
        $this->db->where("tspi_id", $tspi_id);
        $this->db->where("mepm_id", $mepm_id);
        $this->db->where("mepsch_id", $mepsch_id);
        $this->db->delete("model_exam_paper_response_mst");
    }

    /* Functions For E-Content Management */

    function createNewEContent(array $newEContentInfo) {
        $this->db->insert('econtent_mst', $newEContentInfo);
        return $this->db->insert_id();
    }

    function getEContentInfoBy($ecm_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('econtent_mst ECM');
        $this->db->join('tbl_session_master TSM', 'ECM.session_id = TSM.session_id');
        $this->db->join('subject_mst SM', 'ECM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'ECM.ecm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'ECM.ecm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("ECM.ecm_id", $ecm_id);
        return $this->db->get();
    }

    function getAllEContentsBy($smember_id = '', $deleteStatus = '', $titleOrDesc = '', $session = '', $subject = '', $startDate = '', $endDate = '', $rangeAppliedWith = '') {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('econtent_mst ECM');
        $this->db->join('tbl_session_master TSM', 'ECM.session_id = TSM.session_id');
        $this->db->join('subject_mst SM', 'ECM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'ECM.ecm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'ECM.ecm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("(ECM.ecm_title LIKE '%" . $titleOrDesc . "%' OR ECM.ecm_description LIKE '%" . $titleOrDesc . "%')");
        /* Staff Member Wise Filter */
        if ($smember_id != '') {
            $this->db->where("ECM.ecm_added_by", $smember_id);
        }
        /* Staff Member Wise Filter */
        /* Delete Status Wise Filter */
        if ($deleteStatus != '') {
            $this->db->where("ECM.ecm_delete_status", $deleteStatus);
        }
        /* Delete Status Wise Filter */
        /* Session Wise Filter */
        if ($session != "") {
            $this->db->where("TSM.session_id", $session);
        }
        /* Session Wise Filter */
        /* Subject Wise Filter */
        if ($subject != "") {
            $this->db->where("SM.sm_id", $subject);
        }
        /* Subject Wise Filter */
        /* Dates Combination */
        if ($startDate != '' && $endDate != '' && $rangeAppliedWith != '') {
            if ($rangeAppliedWith == "CD") {
                $this->db->where("ECM.ecm_added_on >= '" . $startDate . "' && ECM.ecm_added_on <= '" . $endDate . "'");
            } else {
                $this->db->where("ECM.ecm_updated_on >= '" . $startDate . "' && ECM.ecm_updated_on <= '" . $endDate . "'");
            }
        } else if ($startDate == '' && $endDate != '' && $rangeAppliedWith != '') {
            if ($rangeAppliedWith == "CD") {
                $this->db->where("ECM.ecm_added_on <= '" . $endDate . "'");
            } else {
                $this->db->where("ECM.ecm_updated_on <= '" . $endDate . "'");
            }
        } else if ($startDate != '' && $endDate == '' && $rangeAppliedWith != '') {
            if ($rangeAppliedWith == "CD") {
                $this->db->where("ECM.ecm_added_on >= '" . $startDate . "'");
            } else {
                $this->db->where("ECM.ecm_updated_on >= '" . $startDate . "'");
            }
        }
        /* Dates Combination */
        return $this->db->get();
    }

    function updateEContentInfo(array $eContentUpdatedInfo) {
        $this->db->where('ecm_id', $eContentUpdatedInfo['ecm_id']);
        return $this->db->update('econtent_mst', $eContentUpdatedInfo);
    }

    /* Functions For E-Content Schedules & Assignments Related Stuffs */

    function createNewEContentSchedule(array $newEContentScheduleInfo) {
        $this->db->insert('econtent_schedule_mst', $newEContentScheduleInfo);
        return $this->db->insert_id();
    }

    function createNewEContentAssignmentMulti(array $newEContentAssignmentInfo) {
        $this->db->insert_batch('econtent_student_assign', $newEContentAssignmentInfo);
        return $this->db->insert_id();
    }

    function getEContentScheduleInfoBy($ecsm_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('econtent_schedule_mst ECSM');
        $this->db->join('econtent_mst ECM', 'ECSM.ecm_id = ECM.ecm_id ');
        $this->db->join('tbl_session_master TSM', 'ECM.session_id = TSM.session_id');
        $this->db->join('subject_mst SM', 'ECM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'ECM.ecm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'ECM.ecm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("ECSM.ecsm_id", $ecsm_id);
        return $this->db->get();
    }

    function getAssignedEContentsBySchedule($ecsm_id, $ecm_id = '', $tspi_id = '') {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('econtent_student_assign ECSA');
        $this->db->join('econtent_schedule_mst ECSM', 'ECSA.ecsm_id = ECSM.ecsm_id ');
        $this->db->join('econtent_mst ECM', 'ECSM.ecm_id = ECM.ecm_id ');
        $this->db->join('tbl_session_master TSM', 'ECM.session_id = TSM.session_id');
        $this->db->join('subject_mst SM', 'ECM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'ECM.ecm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'ECM.ecm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("ECSM.ecsm_id", $ecsm_id);
        if (trim($ecm_id) != "") {
            $this->db->where("ECSM.ecm_id", $ecm_id);
        }
        if (trim($tspi_id) != "") {
            $this->db->where("ECSA.tspi_id", $tspi_id);
        }
        return $this->db->get();
    }

    function getAssignedEContentsByStudent($tspi_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('econtent_student_assign ECSA');
        $this->db->join('econtent_schedule_mst ECSM', 'ECSA.ecsm_id = ECSM.ecsm_id ');
        $this->db->join('econtent_mst ECM', 'ECSM.ecm_id = ECM.ecm_id ');
        $this->db->join('tbl_session_master TSM', 'ECM.session_id = TSM.session_id');
        $this->db->join('subject_mst SM', 'ECM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'ECSM.ecsm_scheduled_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'ECSM.ecsm_scheduled_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("ECSM.ecsm_active_status", "T");
        $this->db->where("ECSM.ecsm_delete_status", "F");
        $this->db->where("ECM.ecm_active_status", "T");
        $this->db->where("ECM.ecm_delete_status", "F");
        $this->db->where("ECSA.tspi_id", $tspi_id);
        return $this->db->get();
    }

    function getAllEContentSchedulesBy($smember_id = '', $deleteStatus = '', $titleOrDesc = '', $session = '', $subject = '', $econtent = '', $startDate = '', $endDate = '') {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('econtent_schedule_mst ECSM');
        $this->db->join('econtent_mst ECM', 'ECSM.ecm_id = ECM.ecm_id ');
        $this->db->join('tbl_session_master TSM', 'ECM.session_id = TSM.session_id');
        $this->db->join('subject_mst SM', 'ECM.sm_id = SM.sm_id');
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', 'ECM.ecm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'ECM.ecm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("(ECM.ecm_title LIKE '%" . $titleOrDesc . "%' OR ECM.ecm_description LIKE '%" . $titleOrDesc . "%')");
        /* Staff Member Wise Filter */
        if ($smember_id != '') {
            $this->db->where("ECM.ecm_added_by", $smember_id);
        }
        /* Staff Member Wise Filter */
        /* Schedule Delete Status Wise Filter */
        if ($deleteStatus != '') {
            $this->db->where("ECSM.ecsm_delete_status", $deleteStatus);
            $this->db->where("ECM.ecm_delete_status", $deleteStatus);
        }
        /* Schedule Delete Status Wise Filter */
        /* Session Wise Filter */
        if ($session != "") {
            $this->db->where("ECM.session_id", $session);
        }
        /* Session Wise Filter */
        /* Subject Wise Filter */
        if ($subject != "") {
            $this->db->where("ECM.sm_id", $subject);
        }
        /* Subject Wise Filter */
        /* E-Content Wise Filter */
        if ($econtent != '') {
            $this->db->where("ECSM.ecm_id", $econtent);
        }
        /* E-Content Wise Filter */
        /* Dates Combination */
        if ($startDate != '' && $endDate != '') {
            $this->db->where("ECSM.ecsm_start_date >= '" . $startDate . "' && ECSM.ecsm_end_date <= '" . $endDate . "'");
        } else if ($startDate == '' && $endDate != '') {
            $this->db->where("ECSM.ecsm_end_date <= '" . $endDate . "'");
        } else if ($startDate != '' && $endDate == '') {
            $this->db->where("ECSM.ecsm_start_date >= '" . $startDate . "'");
        }
        /* Dates Combination */
        return $this->db->get();
    }

    function updateEContentScheduleInfo(array $eContentScheduleUpdatedInfo) {
        $this->db->where('ecsm_id', $eContentScheduleUpdatedInfo['ecsm_id']);
        return $this->db->update('econtent_schedule_mst', $eContentScheduleUpdatedInfo);
    }

    function deleteEContentStudentAssignment($ecsm_id) {
        $this->db->where("ecsm_id", $ecsm_id);
        $this->db->delete("econtent_student_assign");
    }

}

KBHT - 2023