EVOLUTION-NINJA
Edit File: Faculty_Model.php
<?php namespace App\Models; use CodeIgniter\Model; class Faculty_Model extends Model { protected $table = 'faculty_subject_mapping'; protected $useSoftDeletes = true; public function get_enrolled_students($loginId) { $builder = $this->db->table('faculty_subject_mapping A'); $builder->select('*'); $builder->where('A.login_id', $loginId); $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); $result = $query->getResult(); $finalSubArray = []; $resultArray = []; foreach ($result as $value) { $subjectSubDomainIds = json_decode($value->sub_domain_id); foreach ($subjectSubDomainIds as $sub) { array_push($finalSubArray, $sub); } } $subjectSubDomainIds = json_decode($value->sub_domain_id); $builder = $this->db->table('user_course_mapping A'); $builder->select('A.*, B.full_name, B.phone_number, C.course_title, A.course_price, C.sub_domain_id, D.email'); $builder->join('user_registrations B', 'A.user_id = B.login_id'); $builder->join('courses C', 'C.course_id = A.course_id'); $builder->join('login D', 'D.login_id = B.login_id'); $builder->where('A.enroll_status', 'ENROLLED'); $builder->where('A.payment_status', 'PAID'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('C.delete_status', 'ACTIVE'); $builder->where('D.delete_status', 'ACTIVE'); $builder->where('D.verified_status', 'VERIFIED'); $courseQuery = $builder->get(); $enrolledResult = $courseQuery->getResult(); if ($enrolledResult) { $subIdArray = []; $i = 0; foreach ($enrolledResult as $val) { $facId = ''; if ($val->faculty_ids != 'null') { $facultyIds = json_decode($val->faculty_ids); } else { $batchIds = json_decode($val->batch_ids); $builder = $this->db->table('batches A'); $builder->select('*'); $builder->whereIn('A.batch_id', $batchIds); $builder->where('A.delete_status', 'ACTIVE'); $result = $builder->get()->getResult(); $facultyIds = []; foreach ($result as $batches) { array_push($facultyIds, $batches->faculty_id); } } if ($facultyIds) { foreach ($facultyIds as $facultyId) { if ($facultyId == $loginId) { $facId = $facultyId; } } } if ($facId) { $subDomainIdArray = []; $enrolledSubIds = json_decode($val->sub_domain_id); foreach ($enrolledSubIds as $ids) { $i = $i + 1; array_push($subDomainIdArray, $ids); } if ($i > 0) { $subDomain = ''; foreach ($subDomainIdArray as $ids) { $builder = $this->db->table('sub_domains D'); $builder->select('*'); $builder->where('D.sub_domain_id', $ids); $builder->where('D.delete_status', 'ACTIVE'); $subQuery = $builder->get(); $subResult = $subQuery->getRow(); if ($subResult) { if ($subDomain == '') { $subDomain = $subResult->sub_domain; } else { $subDomain = $subDomain . ', ' . $subResult->sub_domain; } } } $data['subjects'] = $subDomain; $data['user_name'] = $val->full_name; $data['phone_number'] = $val->phone_number; $typeArray = []; foreach (json_decode($val->session_type) as $value) { array_push($typeArray, ucfirst($value)); } $data['session_type'] = implode(', ', $typeArray); $data['course_title'] = $val->course_title; if ($val->institution_id == '0') { $data['course_price'] = $val->course_price; } else { $data['course_price'] = ''; } $data['created_at'] = date("d-m-Y H:i:s", strtotime($val->created_at)); $data['email'] = $val->email; array_push($resultArray, $data); } $i = 0; } else { // Handle the case when $facId is not set } } } return $resultArray; } public function update_data($where, $table, $data) { $builder = $this->db->table($table); $builder->where($where); return $builder->update($data); } public function get_faculty_feedback_list($login_id) { $db = \Config\Database::connect(); $builder = $db->table('feedback A'); $builder->select('A.*, B.*, C.*, A.created_at as added_on'); $builder->join('courses B', 'B.course_id = A.course_id'); $builder->join('login C', 'C.login_id = A.created_by'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('A.faculty_id', $login_id); $builder->where('B.delete_status', 'ACTIVE'); $query = $builder->get(); $result = $query->getResult(); $array = array(); foreach ($result as $val) { $data['feedback_id'] = $val->feedback_id; $data['feedback'] = $val->feedback; $data['username'] = $val->username; $data['course_title'] = $val->course_title; $data['username'] = $val->username; $data['created_at'] = date("d-m-Y", strtotime($val->added_on)); array_push($array, $data); } return $array; } public function UpdateData1($where, $registrationTable, $registrationData) { $builder = $this->db->table($registrationTable); $builder->where($where); $result = $builder->update($registrationData); return $result; } public function UpdateData2($where, $loginTable, $loginData) { $builder = $this->db->table($loginTable); $builder->where($where); $result = $builder->update($loginData); return $result; } public function UpdateData3($where, $table, $data) { $builder = $this->db->table($table); $builder->where($where); $result = $builder->update($data); return $result; } public function UpdateData4($where, $registration_table, $registration_data) { $builder = $this->db->table($registration_table); $builder->where($where); $result = $builder->update($registration_data); return $result; } public function UpdateData5($where, $login_table, $login_data) { $builder = $this->db->table($login_table); $builder->where($where); $result = $builder->update($login_data); return $result; } public function UpdateData6($whereId, $loginTable, $updateData) { $builder = $this->db->table($loginTable); $builder->where($whereId); $result = $builder->update($updateData); return $result; } public function UpdateData7($whereReg, $regTable, $updateData) { $builder = $this->db->table($regTable); $builder->where($whereReg); $result = $builder->update($updateData); return $result; } public function get_where_row1($loginTable, $whereLogin) { return $this->db->table($loginTable) ->select('*') ->where($whereLogin) ->get() ->getRow(); } public function get_where_row($table, $where) { return $this->db->table($table) ->select('*') ->where($where) ->get() ->getRow(); } public function get_where_result($table, $where) { $builder = $this->db->table($table); $builder->select('*'); $builder->where($where); $query = $builder->get(); return $query->getResult(); } public function get_where_result1($domain_table, $where_domain) { $builder = $this->db->table($domain_table); $builder->select('*'); $builder->where($where_domain); $query = $builder->get(); return $query->getResult(); } public function getWhereRow($table, $where) { $builder = $this->db->table($table); $builder->select('*'); $builder->where($where); $query = $builder->get(); return $query->getRow(); } public function getWhereRow1($course_table, $where_course) { $builder = $this->db->table($course_table); $builder->select('*'); $builder->where($where_course); $query = $builder->get(); return $query->getRow(); } public function getWhereRow2($loginTable, $whereLogin) { $builder = $this->db->table($loginTable); $builder->select('*'); $builder->where($whereLogin); $query = $builder->get(); return $query->getRow(); } public function getWhereRow3($batchTable, $where) { $builder = $this->db->table($batchTable); $builder->select('*'); $builder->where($where); $query = $builder->get(); return $query->getRow(); } public function getWhereResultOrderByAsc($table, $where, $order_by) { $builder = $this->db->table($table); $builder->select('*'); $builder->where($where); $builder->orderBy($order_by, 'ASC'); $query = $builder->get(); return $query->getResult(); } public function getWhereResultOrderByAsc3($batchTable, $whereBatch, $orderByBatch) { $builder = $this->db->table($batchTable); $builder->select('*'); $builder->where($whereBatch); $builder->orderBy($orderByBatch, 'ASC'); $query = $builder->get(); return $query->getResult(); } public function getWhereResultOrderByAsc1($courseTable, $whereCourse, $orderBy) { $builder = $this->db->table($courseTable); $builder->select('*'); $builder->where($whereCourse); $builder->orderBy($orderBy, 'ASC'); $query = $builder->get(); return $query->getResult(); } public function getWhereResultOrderByAsc2($subDomainTable, $whereSubDomain, $orderBy) { $builder = $this->db->table($subDomainTable); $builder->select('*'); $builder->where($whereSubDomain); $builder->orderBy($orderBy, 'ASC'); $query = $builder->get(); return $query->getResult(); } public function getDomains($id) { $builder = $this->db->table('faculty_subject_mapping A'); $builder->select('*'); $builder->join('domains B', 'B.domain_id = A.domain_id'); $builder->whereIn('A.login_id', [$id]); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('A.approval_status', 'APPROVED'); $builder->where('A.return_status', 'NOT_RETURNED'); $builder->groupBy('A.domain_id'); $query = $builder->get(); return $query->getResult(); } public function getWhereOrderbyRow($table, $where, $order_by) { $builder = $this->db->table($table); $builder->select('*'); $builder->where($where); $builder->orderBy($order_by, 'DESC'); return $builder->get()->getRow(); } public function getWhereOrderbyRow1($batchTable, $whereBatch, $orderByBatch) { $builder = $this->db->table($batchTable); $builder->select('*'); $builder->where($whereBatch); $builder->orderBy($orderByBatch, 'DESC'); return $builder->get()->getRow(); } public function insertData($table, $data) { $builder = $this->db->table($table); $builder->insert($data); return $this->db->insertID(); } public function getFacultyTopicsList($login_id) { $builder = $this->db->table('topics A'); $builder->select('A.*, B.sub_domain, C.domain_name, D.chapter_name, D.chapter_id'); $builder->join('sub_domains B', 'B.sub_domain_id = A.sub_domain_id'); $builder->join('domains C', 'C.domain_id = A.domain_id'); $builder->join('syllabus_chapter D', 'D.chapter_id = A.chapter_id'); $builder->where('A.created_by', $login_id); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('C.delete_status', 'ACTIVE'); $builder->where('D.delete_status', 'ACTIVE'); $builder->groupBy('A.chapter_id'); $query = $builder->get(); $result = $query->getResult(); $array = []; if ($result) { foreach ($result as $value) { $data['chapter_id'] = $value->chapter_id; $data['sub_domain'] = $value->sub_domain; $data['domain_name'] = $value->domain_name; $data['chapter_name'] = $value->chapter_name; $data['topic_name'] = $value->topic_name; $data['topic_id'] = $value->topic_id; $data['created_at'] = date("d-m-Y h:i:s", strtotime($value->created_at)); $array[] = $data; } } return $array; } public function UpdateData($table, $data, $where) { $builder = $this->db->table($table); $builder->where($where); $result = $builder->update($data); return $result; } public function deleteRecord($table, $where) { $builder = $this->db->table($table); $builder->where($where); return $builder->delete(); } public function getTopicsChapters($sub_domain_id, $login_id) { $builder = $this->db->table('syllabus_chapter A'); $builder->select('*'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('A.sub_domain_id', $sub_domain_id); $query = $builder->get(); return $query->getResult(); } public function get_domain_subdomain($login_id, $domain_id) { $builder = $this->db->table('faculty_subject_mapping A'); $builder->select('*'); $builder->where('A.domain_id', $domain_id); $builder->where('A.login_id', $login_id); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('A.approval_status', 'APPROVED'); $builder->where('A.return_status', 'NOT_RETURNED'); $query = $builder->get(); $result = $query->getResult(); if ($result) { $id_array = []; foreach ($result as $value) { $ids = json_decode($value->sub_domain_id); foreach ($ids as $val_1) { array_push($id_array, $val_1); } } $sub_domains = implode(',', $id_array); $sql = "SELECT sub_domain, sub_domain_id FROM sub_domains WHERE sub_domain_id IN ($sub_domains) AND delete_status='ACTIVE'"; $domain_result = $this->db->query($sql); $domain_result = $domain_result->getResult(); return $domain_result; } } public function getChapterwiseTopics($chapter_id) { $login_id = session('faculty_login_id'); $builder = $this->db->table('topics A'); $builder->select('A.*, B.*, A.created_at as added_date'); $builder->join('login B', 'B.login_id = A.created_by'); $builder->where('A.chapter_id', $chapter_id); $builder->where('A.created_by', $login_id); $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); $query = $query->getResult(); $array = []; foreach ($query as $val) { $data['added_date'] = date("d-m-Y h:i:s", strtotime($val->added_date)); $data['approval_status'] = $val->approval_status; $data['chapter_id'] = $val->chapter_id; $data['created_at'] = $val->created_at; $data['domain_id'] = $val->domain_id; $data['topic_id'] = $val->topic_id; $data['topic_name'] = $val->topic_name; array_push($array, $data); } return $array; } public function checkFacultySessionType($faculty_id) { $builder = $this->db->table('faculty_subject_mapping A'); $builder->select('*'); $builder->join('faculty_available_timings B', 'B.subject_mapping_id = A.mapping_id'); $builder->where('B.faculty_id', $faculty_id); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('A.approval_status', 'APPROVED'); $builder->where('A.return_status', 'NOT_RETURNED'); $builder->where('B.approval_status', 'APPROVED'); $builder->where('B.return_status', 'NOT_RETURNED'); $query = $builder->get(); return $query->getResult(); } public function getSessionList($login_id) { $builder = $this->db->table('training_plans A'); $builder->select('A.*, C.sub_domain_id, C.sub_domain, D.domain_id, D.domain_name'); $builder->join('sub_domains C', 'A.sub_domain_id = C.sub_domain_id'); $builder->join('domains D', 'D.domain_id = C.domain_id'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('A.created_by', $login_id); $builder->where('C.delete_status', 'ACTIVE'); $builder->where('D.delete_status', 'ACTIVE'); $builder->groupBy('A.sub_domain_id'); $query = $builder->get(); $result = $query->getResult(); $resArray = []; foreach ($result as $res) { $subDomainQuery = $this->db->table('training_plans A'); $subDomainQuery->select('*'); $subDomainQuery->where('A.delete_status', 'ACTIVE'); $subDomainQuery->where('A.sub_domain_id', $res->sub_domain_id); $subDomainQuery->where('A.created_by', $res->created_by); $subDomainResult = $subDomainQuery->get()->getResult(); $totalDuration = '00:00'; foreach ($subDomainResult as $val) { $duration = explode(':', $totalDuration); $dur = explode(':', $val->session_time); $totalTimeHr = number_format($duration[0]) + number_format($dur[0]); $totalTimeMin = number_format($duration[1]) + number_format($dur[1]); if ($totalTimeMin >= 60) { $totalTimeHr += 1; $totalTimeMin -= 60; } $totalDuration = $totalTimeHr . ':' . $totalTimeMin; } $totalDur = explode(':', $totalDuration); if (strlen((string)$totalDur[1]) == 1) { $totalTimeMin = '0' . $totalTimeMin; $totalDuration = $totalTimeHr . ':' . $totalTimeMin; } $data = [ 'training_plan_id' => $res->training_plan_id, 'sub_domain_id' => $res->sub_domain_id, 'sub_domain' => $res->sub_domain, 'domain_name' => $res->domain_name, 'total_duration' => $totalDuration, ]; array_push($resArray, $data); } return $resArray; } public function get_training_plan_edit_chapters($sub_domain_id, $login_id, $id) { $builder = $this->db->table('training_plans A'); $builder->select('*'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('A.created_by', $login_id); $builder->where('A.training_plan_id !=', $id); $query = $builder->get(); $training_result = $query->getResult(); if ($training_result) { $chapter_array = []; foreach ($training_result as $value) { $chapter_ids = json_decode($value->chapter_ids); foreach ($chapter_ids as $val) { $chapter_array[] = $val; } } if (!empty($chapter_array)) { $chapter_array = implode(',', $chapter_array); $sql = "SELECT chapter_id, chapter_name FROM syllabus_chapter WHERE chapter_id NOT IN ($chapter_array) AND sub_domain_id = :sub_domain_id AND delete_status = 'ACTIVE'"; $result = $this->db->query($sql, ['sub_domain_id' => $sub_domain_id]); return $result->getResult(); } } // If there are no training results or $chapter_array is empty $sql = "SELECT chapter_id, chapter_name FROM syllabus_chapter WHERE sub_domain_id = :sub_domain_id AND delete_status = 'ACTIVE'"; $result = $this->db->query($sql, ['sub_domain_id' => $sub_domain_id]); return $result->getResult(); } public function chapter_wise_training_plans($sub_domain_id, $login_id) { $builder = $this->db->table('training_plans A'); $builder->select('A.*, C.sub_domain_id, C.sub_domain, D.domain_id, D.domain_name'); $builder->join('sub_domains C', 'A.sub_domain_id = C.sub_domain_id'); $builder->join('domains D', 'D.domain_id = C.domain_id'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('A.created_by', $login_id); $builder->where('C.delete_status', 'ACTIVE'); $builder->where('D.delete_status', 'ACTIVE'); $builder->where('A.sub_domain_id', $sub_domain_id); $query = $builder->get(); $result = $query->getResult(); $result_array = []; foreach ($result as $value) { $builder = $this->db->table('syllabus_chapter A'); $builder->select('*'); $builder->whereIn('A.chapter_id', json_decode($value->chapter_ids)); $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); $chapter_result = $query->getResult(); $chapter_array = []; foreach ($chapter_result as $val) { array_push($chapter_array, $val->chapter_name); } $data['chapters'] = implode(', ', $chapter_array); $data['sub_domain'] = $value->sub_domain; $data['domain_name'] = $value->domain_name; $data['session_time'] = $value->session_time; if ($value->updated_at != '0000-00-00 00:00:00') { $data['created_at'] = date("d-m-Y H:i:s", strtotime($value->updated_at)); } else { $data['created_at'] = date("d-m-Y H:i:s", strtotime($value->created_at)); } $data['training_plan_id'] = $value->training_plan_id; if ($value->return_status == 'RETURNED') { $retVal = 'RETURNED'; $data['approval_status'] = $retVal; } else { $retVal = $value->approval_status; $data['approval_status'] = $retVal; } array_push($result_array, $data); } return $result_array; } public function getMocktestSettingsWithoutChapterDetails($loginId) { $builder = $this->db->table('faculty_mocktest_setting A'); $builder->select('A.*, B.login_id, B.username, C.sub_domain_id, C.sub_domain, E.domain_id, E.domain_name'); $builder->join('login B', 'B.login_id = A.created_by'); $builder->join('sub_domains C', 'C.sub_domain_id = A.sub_domain_id'); $builder->join('domains E', 'E.domain_id = A.domain_id'); // $builder->join('syllabus_chapter D', 'D.chapter_id = A.chapter'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('C.delete_status', 'ACTIVE'); $builder->where('E.delete_status', 'ACTIVE'); $builder->where('A.created_by', $loginId); $query = $builder->get(); $result = $query->getResult(); $array = []; foreach ($result as $res) { $totalDuration = $res->total_time; $data['id'] = $res->id; $data['selected_type'] = $res->selected_type; $data['test_type'] = $res->test_type; $data['domain_name'] = $res->domain_name; $data['sub_domain'] = $res->sub_domain; $data['passing_criteria'] = $res->passing_criteria; $data['total_time'] = $totalDuration; $data['number_of_questions'] = $res->number_of_questions; switch ($res->question_order) { case 'asc': $data['question_order'] = 'Ascending'; break; case 'desc': $data['question_order'] = 'Descending'; break; case 'random': $data['question_order'] = 'Random'; break; default: $data['question_order'] = $res->question_order; break; } $data['created_at'] = date("d-m-Y", strtotime($res->created_at)); $array[] = $data; } return $array; } public function getWhereResultNew($table, $where) { $builder = $this->db->table($table); $builder->select('*'); $builder->where($where); return $builder->countAllResults(); } public function getMocktestSettingsDetails($loginId, $id) { $builder = $this->db->table('faculty_mocktest_setting A'); $builder->select('A.*, B.login_id, B.username, C.sub_domain_id, C.sub_domain, D.chapter_id, D.chapter_name, E.domain_id, E.domain_name'); $builder->join('login B', 'B.login_id = A.created_by'); $builder->join('sub_domains C', 'C.sub_domain_id = A.sub_domain_id'); $builder->join('domains E', 'E.domain_id = A.domain_id'); $builder->join('syllabus_chapter D', 'D.chapter_id = A.chapter'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('C.delete_status', 'ACTIVE'); $builder->where('E.delete_status', 'ACTIVE'); $builder->where('A.id', $id); $builder->where('A.created_by', $loginId); return $builder->get()->getResult(); } public function faculty_batch_list($login_id) { $db = \Config\Database::connect(); $builder = $db->table('batches A'); $builder->select('A.*,B.sub_domain,B.sub_domain_id,C.username'); $builder->join('sub_domains B', 'B.sub_domain_id = A.sub_domain_id'); $builder->join('login C', 'C.login_id = A.created_by'); $builder->where('A.faculty_id', $login_id); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $query = $builder->get(); $row = $query->getResultArray(); $array = array(); foreach ($row as $value) { $data['batch_id'] = $value['batch_id']; $data['sub_domain'] = $value['sub_domain']; $data['batch_name'] = $value['batch_name']; $data['course_type'] = $value['course_type']; $from_time = $value['from_time']; if ($from_time == '0') { $data['from_time'] = ''; } else if ($from_time == 'full_day') { $data['from_time'] = 'Full Day'; } else { $data['from_time'] = $from_time; } $data['created_at'] = date("d-m-Y h:i:s", strtotime($value['created_at'])); $data['username'] = $value['username']; $data['batch_size'] = $value['batch_size']; $data['batch_from_date'] = $value['batch_from_date']; $data['batch_to_date'] = $value['batch_to_date']; if ($data['batch_from_date'] != '' && $data['batch_to_date'] != '') { $data['batch_from_to_date'] = $value['batch_from_date'] . ' to ' . $value['batch_to_date']; } else { $data['batch_from_to_date'] = ''; } if ($value['batch_approval_status'] == 'APPROVED') { if ($value['batch_status'] == 'IN_PROGRESS') { $data['batch_status'] = 'IN PROGRESS'; } else if ($value['batch_status'] == 'COMPLETED') { $data['batch_status'] = 'COMPLETED'; } else { $data['batch_status'] = 'NOT YET STARTED'; } } else { $data['batch_status'] = ''; } $data['batch_duration'] = $value['batch_duration']; $created_by = $value['created_by']; if ($created_by == '1') { $data['created_by'] = 'Admin'; } else { $data['created_by'] = $value['username']; } $data['batch_approval_status'] = $value['batch_approval_status']; array_push($array, $data); } return $array; } public function getWhereFacultyList($domain_id, $sub_domain_id) { $db = \Config\Database::connect(); $query = $db->table('faculty_subject_mapping A') ->select('*') ->where('A.delete_status', 'ACTIVE') ->where('A.approval_status', 'APPROVED') ->where('A.domain_id', $domain_id) ->groupBy('A.faculty_reg_id') ->get(); $res = $query->getResult(); $faculty_array = array(); foreach ($res as $value) { $subdomain = json_decode($value->sub_domain_id); if (in_array($sub_domain_id, $subdomain)) { $query = $db->table('faculty_registration A') ->select('*') ->where('A.delete_status', 'ACTIVE') ->where('A.faculty_reg_id', $value->faculty_reg_id) ->get(); $res = $query->getRow(); $data['faculty_id'] = $res->login_id; $data['faculty_name'] = $res->fullname; array_push($faculty_array, $data); } } return $faculty_array; } public function getWhereFacultyList1($batchDomainId, $batchSubDomainId) { $db = \Config\Database::connect(); $query = $db->table('faculty_subject_mapping A') ->select('*') ->where('A.delete_status', 'ACTIVE') ->where('A.approval_status', 'APPROVED') ->where('A.domain_id', $batchDomainId) ->groupBy('A.faculty_reg_id') ->get(); $res = $query->getResult(); $faculty_array = array(); foreach ($res as $value) { $subdomain = json_decode($value->sub_domain_id); if (in_array($batchSubDomainId, $subdomain)) { $query = $db->table('faculty_registration A') ->select('*') ->where('A.delete_status', 'ACTIVE') ->where('A.faculty_reg_id', $value->faculty_reg_id) ->get(); $res = $query->getRow(); $data['faculty_id'] = $res->login_id; $data['faculty_name'] = $res->fullname; array_push($faculty_array, $data); } } return $faculty_array; } public function getNotEnrolledFacTimings($facId, $subDomainId, $domainId) { $subDomainIds = json_encode($subDomainId); $facultyId = json_encode($facId); $builder = $this->db->table('user_course_mapping'); $builder->select('*'); if (!is_null($facultyId)) { $builder->like('faculty_ids', $facultyId); } if (!is_null($subDomainIds)) { $builder->like('sub_domain_ids', $subDomainIds); } $builder->where('delete_status', 'ACTIVE'); $query = $builder->get(); $res = $query->getResult(); $array = []; if (!empty($res)) { foreach ($res as $result) { $userId = $result->user_id; $facultyIds = json_decode($result->faculty_ids); $facultyFromTime = trim($result->from_time, '["'); $facFromTime = trim($facultyFromTime, '"]'); $facultyToTime = trim($result->to_time, '["'); $facToTime = trim($facultyToTime, '"]'); $builder = $this->db->table('faculty_subject_mapping A'); $builder->select('*'); $builder->join('faculty_available_timings B', 'B.faculty_id = A.login_id AND B.subject_id = A.sub_domain_id'); $builder->where('A.domain_id', $domainId); $builder->like('B.course_type', 'live'); $builder->whereIn('B.faculty_id', $facultyIds); $builder->like('B.subject_id', $subDomainIds); $builder->where('B.from_time !=', $facFromTime); $builder->where('B.to_time !=', $facToTime); $builder->where('A.approval_status', 'APPROVED'); $builder->where('B.approval_status', 'APPROVED'); $builder->groupBy('B.from_time'); $builder->groupBy('B.to_time'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $query = $builder->get(); $res1 = $query->getResult(); foreach ($res1 as $result1) { $data['available_type'] = $result1->available_type; $data['from_time'] = $result1->from_time; $data['to_time'] = $result1->to_time; $data['from_to_time'] = $data['from_time'] . ' - ' . $data['to_time']; $array[] = $data; } } } else { $builder = $this->db->table('faculty_available_timings'); $builder->select('*'); $builder->where('faculty_id', $facId); if (!is_null($subDomainId)) { $builder->like('subject_id', $subDomainId); } $builder->where('approval_status', 'APPROVED'); $builder->where('delete_status', 'ACTIVE'); $query = $builder->get(); $res = $query->getResult(); foreach ($res as $result1) { $data['available_type'] = $result1->available_type; $data['from_time'] = $result1->from_time; $data['to_time'] = $result1->to_time; $data['from_to_time'] = $data['from_time'] . ' - ' . $data['to_time']; $array[] = $data; } } return $array; } public function getNotEnrolledFacTimings1($batchFacId, $batchSubDomainId, $batchDomainId) { $subDomainIds = json_encode($batchSubDomainId); $facultyId = json_encode($batchFacId); $builder = $this->db->table('user_course_mapping'); $builder->select('*'); if (!is_null($facultyId)) { $builder->like('faculty_ids', $facultyId); } if (!is_null($subDomainIds)) { $builder->like('sub_domain_ids', $subDomainIds); } $builder->where('delete_status', 'ACTIVE'); $query = $builder->get(); $res = $query->getResult(); $array = []; if (!empty($res)) { foreach ($res as $result) { $userId = $result->user_id; $facultyIds = json_decode($result->faculty_ids); $facultyFromTime = trim($result->from_time, '["'); $facFromTime = trim($facultyFromTime, '"]'); $facultyToTime = trim($result->to_time, '["'); $facToTime = trim($facultyToTime, '"]'); $builder = $this->db->table('faculty_subject_mapping A'); $builder->select('*'); $builder->join('faculty_available_timings B', 'B.faculty_id = A.login_id AND B.subject_id = A.sub_domain_id'); $builder->where('A.domain_id', $batchDomainId); $builder->like('B.course_type', 'live'); $builder->whereIn('B.faculty_id', $facultyIds); $builder->like('B.subject_id', $subDomainIds); $builder->where('B.from_time !=', $facFromTime); $builder->where('B.to_time !=', $facToTime); $builder->where('A.approval_status', 'APPROVED'); $builder->where('B.approval_status', 'APPROVED'); $builder->groupBy('B.from_time'); $builder->groupBy('B.to_time'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $query = $builder->get(); $res1 = $query->getResult(); foreach ($res1 as $result1) { $data['available_type'] = $result1->available_type; $data['from_time'] = $result1->from_time; $data['to_time'] = $result1->to_time; $data['from_to_time'] = $data['from_time'] . ' - ' . $data['to_time']; $array[] = $data; } } } else { $builder = $this->db->table('faculty_available_timings'); $builder->select('*'); $builder->where('faculty_id', $facId); if (!is_null($subDomainId)) { $builder->like('subject_id', $subDomainId); } $builder->where('approval_status', 'APPROVED'); $builder->where('delete_status', 'ACTIVE'); $query = $builder->get(); $res = $query->getResult(); foreach ($res as $result1) { $data['available_type'] = $result1->available_type; $data['from_time'] = $result1->from_time; $data['to_time'] = $result1->to_time; $data['from_to_time'] = $data['from_time'] . ' - ' . $data['to_time']; $array[] = $data; } } return $array; } // public function getWhereBatches($table, $batch_id) // { // $builder = $this->db->table('batches A'); // $builder->select('A.*,B.login_id,B.fullname,C.sub_domain_id,C.sub_domain,D.*,E.*,A.domain_id as batch_domain_id'); // $builder->join('faculty_registration B', 'B.login_id = A.faculty_id'); // $builder->join('sub_domains C', 'C.sub_domain_id = A.sub_domain_id'); // $builder->join('domains D', 'D.domain_id = A.domain_id'); // $builder->join('courses E', 'E.course_id = A.course_id', 'left'); // $builder->where('A.batch_id', $batch_id); // $builder->where('A.delete_status', 'ACTIVE'); // $builder->where('B.delete_status', 'ACTIVE'); // $builder->where('C.delete_status', 'ACTIVE'); // $builder->where('D.delete_status', 'ACTIVE'); // $query = $builder->get(); // return $query->getRow(); // } public function getWhereBatches($table, $batch_id) { $builder = $this->db->table('batches A'); $builder->select('A.*, B.login_id, B.fullname, C.sub_domain_id, C.sub_domain, D.*, E.*, A.domain_id as batch_domain_id'); $builder->join('faculty_registration B', 'B.login_id = A.faculty_id'); $builder->join('sub_domains C', 'C.sub_domain_id = A.sub_domain_id'); $builder->join('domains D', 'D.domain_id = A.domain_id'); $builder->join('courses E', 'E.course_id = A.course_id', 'left'); $builder->where('A.batch_id', $batch_id); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('C.delete_status', 'ACTIVE'); $builder->where('D.delete_status', 'ACTIVE'); $query = $builder->get(); return $query->getRow(); } public function getTrainingPlanDuration($facultyId, $subDomainId, $domainId) { $builder = $this->db->table($this->table); $builder->select('*'); $builder->where('delete_status', 'ACTIVE'); $builder->where('approval_status', 'APPROVED'); $builder->where('domain_id', $domainId); $builder->where('sub_domain_id', $subDomainId); $builder->where('created_by', $facultyId); $query = $builder->get(); $res1 = $query->getResult(); $array = []; foreach ($res1 as $value) { $sessionDuration = $value->session_time; array_push($array, $sessionDuration); } $minutes = 0; foreach ($array as $time) { list($hour, $minute) = explode(':', $time); $minutes += $hour * 60; $minutes += $minute; } $hours = floor($minutes / 60); $minutes -= $hours * 60; $totalDuration = sprintf('%02d:%02d', $hours, $minutes); return $totalDuration; } public function getFacultyFeedbackList($loginId) { $builder = $this->db->table('feedback A'); $builder->select('A.*, B.*, C.*, A.created_at as added_on'); $builder->join('courses B', 'B.course_id = A.course_id'); $builder->join('login C', 'C.login_id = A.created_by'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('A.faculty_id', $loginId); $builder->where('B.delete_status', 'ACTIVE'); // $builder->where('C.delete_status', 'ACTIVE'); $query = $builder->get(); $result = $query->getResult(); $array = []; foreach ($result as $val) { $data['feedback_id'] = $val->feedback_id; $data['feedback'] = $val->feedback; $data['username'] = $val->username; $data['course_title'] = $val->course_title; $data['username'] = $val->username; $data['created_at'] = date("d-m-Y", strtotime($val->added_on)); $array[] = $data; } return $array; } public function getWhereFeedback($feedbackId) { $builder = $this->db->table('feedback A'); $builder->select('*'); $builder->join('login B', 'B.login_id = A.faculty_id'); $builder->join('courses C', 'C.course_id = A.course_id'); $builder->where('A.feedback_id', $feedbackId); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('C.delete_status', 'ACTIVE'); $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); return $query->getRow(); } public function checkFeedbackCourseType($feedbackId) { $builder = $this->db->table('feedback A'); $builder->select('*'); $builder->join('user_course_mapping B', 'B.course_id = A.course_id AND B.user_id = A.created_by'); $builder->where('A.feedback_id', $feedbackId); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); return $query->getRow(); } public function getRequestFacultyList($userTypeId, $loginId) { $builder = $this->db->table('faculty_subject_mapping A'); $builder->select('A.*, B.domain_name, C.username'); $builder->join('domains B', 'A.domain_id = B.domain_id'); $builder->join('login C', 'C.login_id = A.login_id'); //$builder->groupBy('A.sub_domain_id'); //$builder->groupBy('A.approval_status'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('A.login_id', $loginId); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('C.delete_status', 'ACTIVE'); $builder->where('A.added_from', 'REQUEST'); if ($userTypeId == 2) { $builder->where('A.login_id', $loginId); } $query = $builder->get(); $result = $query->getResult(); $array = []; foreach ($result as $value) { $subDomainIds = json_decode($value->sub_domain_id); $subDomainArray = []; $subDomainBuilder = $this->db->table('sub_domains B'); $subDomainBuilder->select('B.sub_domain'); $subDomainBuilder->where('B.delete_status', 'ACTIVE'); $subDomainBuilder->whereIn('B.sub_domain_id', $subDomainIds); $subDomainQuery = $subDomainBuilder->get(); $subDomainResult = $subDomainQuery->getResult(); foreach ($subDomainResult as $val) { array_push($subDomainArray, $val->sub_domain); } $data['sub_domains'] = implode(', ', $subDomainArray); $data['domain_name'] = $value->domain_name; $data['domain_id'] = $value->domain_id; $data['mapping_id'] = $value->mapping_id; $data['login_id'] = $value->login_id; $data['user_name'] = $value->username; $data['created_at'] = $value->created_at; $data['comments'] = $value->comments; $data['approval_status'] = $value->approval_status; $data['return_status'] = $value->return_status; $timeBuilder = $this->db->table('faculty_available_timings D'); $timeBuilder->select('*'); $timeBuilder->where('D.delete_status', 'ACTIVE'); $timeBuilder->where('D.subject_mapping_id', $value->mapping_id); $timeBuilder->where('D.faculty_id', $loginId); //$timeBuilder->where('D.approval_status', $value->approval_status); $timeQuery = $timeBuilder->get(); $timeResult = $timeQuery->getResult(); $timeRes = $timeQuery->getRow(); if ($timeRes) { if ($timeRes->available_type == 'timings') { $timingsArray = []; foreach ($timeResult as $time) { if ($time->available_type == 'timings') { $timings = $time->from_time . ' To ' . $time->to_time; array_push($timingsArray, $timings); } } $data['available_type'] = 'Live'; $data['faculty_timings'] = implode(', ', $timingsArray); } else if ($timeRes->available_type == 'full_day') { $fullDayArray = []; $data['faculty_timings'] = 'Fullday'; foreach ($timeResult as $time) { if ($time->available_type == 'full_day') { $courseType = json_decode($time->course_type); foreach ($courseType as $type) { $fullDayTime = ucfirst($type); array_push($fullDayArray, $fullDayTime); } } } $data['available_type'] = implode(', ', $fullDayArray); } else { $data['available_type'] = 'Recorded'; $data['faculty_timings'] = ''; } } array_push($array, $data); } return $array; } public function getSubDomains($id) { $db = \Config\Database::connect(); // Connect to the database $builder = $db->table('faculty_subject_mapping A'); $builder->select('*'); $builder->join('faculty_available_timings B', 'B.subject_mapping_id = A.mapping_id'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('A.login_id', $id); $builder->where('B.faculty_id', $id); $builder->where('A.return_status', 'NOT_RETURNED'); $builder->where('B.return_status', 'NOT_RETURNED'); $builder->groupBy('B.subject_mapping_id'); $query = $builder->get(); $result = $query->getResult(); $resArray = []; foreach ($result as $val) { $subDomainId = json_decode($val->subject_id, true); // Add true to decode as an associative array if (is_array($subDomainId)) { foreach ($subDomainId as $subId) { $builder = $db->table('sub_domains A'); $builder->select('*'); $builder->join('domains B', 'B.domain_id = A.domain_id'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('A.sub_domain_id', $subId); $query = $builder->get(); if ($query->getResult()) { // Check if there are results before continuing $subDomain = $query->getRow(); $data = []; if (($val->added_from == 'REQUEST' && $val->approval_status == 'APPROVED') || ($val->added_from == 'REGISTRATION')) { if ($subDomain) { $data['sub_domain'] = $subDomain->sub_domain; $data['domain_name'] = $subDomain->domain_name; $data['batch_size'] = $val->batch_size; } else { $data['sub_domain'] = ''; $data['domain_name'] = ''; $data['batch_size'] = ''; } // ... (remaining code unchanged) if ($val->available_type == 'timings') { $facultyQuery = $db->table('login A'); $facultyQuery->select('*'); $facultyQuery->where('A.delete_status', 'ACTIVE'); $facultyQuery->where('A.login_id', $id); $faculty = $facultyQuery->get()->getRow(); $timingQuery = $db->table('faculty_available_timings A'); $timingQuery->select('*'); $timingQuery->where('A.delete_status', 'ACTIVE'); $timingQuery->where('A.faculty_id', $id); $timingQuery->where('A.return_status', 'NOT_RETURNED'); if ($faculty->approval_status == 'APPROVED') { $timingQuery->where('A.approval_status', 'APPROVED'); } $timingQuery->where('A.subject_mapping_id', $val->mapping_id); $timeResult = $timingQuery->get()->getResult(); $timingsArray = []; foreach ($timeResult as $time) { if ($time->available_type == 'timings') { $timings = $time->from_time . ' To ' . $time->to_time; array_push($timingsArray, $timings); } } $fullDayArray = []; $courseType = json_decode($val->course_type); foreach ($courseType as $course) { $fullDayTime = ucfirst($course); array_push($fullDayArray, $fullDayTime); } $data['available_type'] = implode(', ', $fullDayArray); $data['faculty_timings'] = implode(', ', $timingsArray); } elseif ($val->available_type == 'full_day') { $fullDayArray = []; $data['available_type'] = 'Fullday'; $timeResult = json_decode($val->course_type); foreach ($timeResult as $time) { $fullDayTime = ucfirst($time); array_push($fullDayArray, $fullDayTime); } $data['faculty_timings'] = implode(', ', $fullDayArray); } else { $fullDayArray = []; $data['available_type'] = 'Recorded'; $timeResult = json_decode($val->course_type); foreach ($timeResult as $time) { $fullDayTime = ucfirst($time); array_push($fullDayArray, $fullDayTime); } $data['faculty_timings'] = implode(', ', $fullDayArray); } array_push($resArray, $data); } } } } } return $resArray; } protected $table_1 = 'sub_domains A'; public function getWhereSubDomain($domainArray, $id) { $builder = $this->db->table($this->table_1); $builder->select('A.sub_domain'); $builder->where('A.domain_id', $id); // Extract the values of 'sub_domain_id' from the array $subDomainIds = array_column($domainArray, 'sub_domain_id'); if (!empty($subDomainIds)) { // Use whereIn with key-value pair $builder->whereIn('A.sub_domain_id', $subDomainIds); } else { // Handle the case when $domainArray is empty or not an array $builder->where('A.sub_domain_id', 'IS NULL', false); } $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); $result = $query->getResult(); $subDomainArray = []; foreach ($result as $row) { $subDomainArray[] = $row->sub_domain; } return implode(', ', $subDomainArray); } public function get_chapter_topics($chapter_id, $login_id) { $builder = $this->db->table('topics'); $builder->select('*'); $builder->where('chapter_id', $chapter_id); $builder->where('created_by', $login_id); $builder->where('delete_status', 'ACTIVE'); $query = $builder->get(); $result = $query->getResult(); $array = []; foreach ($result as $res) { $data['topic_id'] = $res->topic_id; $data['topic_name'] = htmlspecialchars($res->topic_name); array_push($array, $data); } return $array; } public function getWhereFacultyAddedQuestions($table, $where) { $builder = $this->db->table('questions'); $builder->select('*'); $builder->where($where); $query = $builder->get(); $res = $query->getResult(); $res_array = array(); foreach ($res as $result) { $data['qid'] = $result->qid; $data['questions'] = htmlspecialchars_decode($result->questions); $data['no_of_options'] = $result->no_of_options; $data['ans1'] = htmlspecialchars_decode($result->ans1); $data['ans2'] = htmlspecialchars_decode($result->ans2); $data['ans3'] = htmlspecialchars_decode($result->ans3); $data['ans4'] = htmlspecialchars_decode($result->ans4); $data['ans'] = $result->ans; $data['explanation'] = htmlspecialchars_decode($result->explanation); array_push($res_array, $data); } return $res_array; } public function getWhereLike($table, $where) { $builder = $this->db->table($table); $builder->select('*'); $builder->like($where); return $builder->get()->getRow(); } public function approvedSubjects($subDomainId) { $builder = $this->select('*') ->whereIn('sub_domain_id', $subDomainId) ->where('delete_status', 'ACTIVE') ->get(); return $builder->getResult(); } }