EVOLUTION-NINJA
Edit File: Amcad_Home.php
<?php namespace App\Models; use CodeIgniter\Model; use Config\Database; class Amcad_Home extends Model { public function search_all_1($search_value) { $sql = "(SELECT domain_id, domain_name, 'category' as type FROM domains WHERE domain_name LIKE '%" . $search_value . "%' and domains.delete_status='ACTIVE' and domains.user_type_id='1') UNION (SELECT sub_domain_id, sub_domain, 'sub_category' as type FROM sub_domains INNER JOIN domains ON domains.domain_id=sub_domains.domain_id WHERE sub_domain LIKE '%" . $search_value . "%' and sub_domains.delete_status='ACTIVE' and domains.delete_status='ACTIVE' and sub_domains.user_type_id='1') UNION (SELECT course_id, course_title, 'course' as type FROM courses INNER JOIN domains ON domains.domain_id=courses.domain_id WHERE course_title LIKE '%" . $search_value . "%' and courses.delete_status='ACTIVE' and domains.delete_status='ACTIVE' and courses.user_type_id='1')"; $query = $this->db->query($sql); $domain_result = $query->getResult(); $category_array = []; $sub_cat_array = []; $course_array = []; foreach ($domain_result as $val) { if ($val->type === 'category') { $course_query = $this->db->query("Select * from courses where domain_id LIKE '%" . $val->domain_id . "%' and delete_status='ACTIVE'"); $course_result = $course_query->getResult(); if ($course_result) { $data['domain_id'] = $val->domain_id; $data['domain_name'] = $val->domain_name; $data['type'] = 'category'; array_push($category_array, $data); } } elseif ($val->type === 'sub_category') { $course_query = $this->db->query("Select * from courses where sub_domain_id LIKE '%" . $val->domain_id . "%' and delete_status='ACTIVE'"); $course_result = $course_query->getResult(); if ($course_result) { $data['domain_id'] = $val->domain_id; $data['domain_name'] = $val->domain_name; $data['type'] = 'sub_category'; array_push($sub_cat_array, $data); } } elseif ($val->type === 'course') { $domain_query = $this->db->query("Select * from domains where domain_id LIKE '%" . $val->domain_id . "%' and delete_status='ACTIVE'"); $course_result = $domain_query->getResult(); if ($course_result) { $data['domain_id'] = $val->domain_id; $data['domain_name'] = $val->domain_name; $data['type'] = 'course'; array_push($course_array, $data); } } } $final_array = array_merge($category_array, $sub_cat_array, $course_array); return $final_array; } public function get_searched_value_subdomain_id($search_bar, $search_value) { if ($search_value == 'category') { $sql = "Select * from domains A where A.domain_name LIKE '%$search_bar%' and A.delete_status='ACTIVE'"; $query = $this->db->query($sql); return $query->getRow(); } elseif ($search_value == 'sub_category') { $sql = "Select * from sub_domains A where A.sub_domain LIKE '%$search_bar%' and A.delete_status='ACTIVE'"; $query = $this->db->query($sql); return $query->getRow(); } elseif ($search_value == 'course') { $sql = "Select * from courses A where A.course_title LIKE '%$search_bar%' and A.delete_status='ACTIVE'"; $query = $this->db->query($sql); return $query->getRow(); } } public function get_category_courses($domain_id) { $query = $this->db->table('domains A') ->select('*') ->join('courses B', 'A.domain_id = B.domain_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('A.domain_id', $domain_id) ->get(); $result = $query->getResult(); $new_array = []; foreach ($result as $value) { $new_data = [ 'course_id' => $value->course_id, 'course_title' => $value->course_title, 'course_image' => $value->course_image, 'course_price' => $value->course_price, 'domain_name' => $value->domain_name ]; $sub_domains = implode(',', json_decode($value->sub_domain_id)); $sql = "SELECT sub_domain FROM sub_domains WHERE sub_domain_id IN ($sub_domains) AND delete_status = 'ACTIVE'"; $domain_result = $this->db->query($sql)->getResult(); $domain_array = []; foreach ($domain_result as $value1) { $domain_array[] = $value1->sub_domain; } $new_data['sub_domains'] = implode(',', $domain_array); $query = $this->db->table('user_course_mapping C') ->select('*') ->where('C.delete_status', 'ACTIVE') ->where('C.course_id', $value->course_id) ->get(); $enrollment_result = $query->getResult(); $new_data['total_enrollment'] = count($enrollment_result); $new_array[] = $new_data; } return $new_array; } public function get_domain_courses() { $db = \Config\Database::connect(); $query = $db->table('courses A') ->select('*') ->join('domains B', 'B.domain_id = A.domain_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('A.user_type_id', '1') ->where('B.user_type_id', '1') ->groupBy('A.domain_id') ->get(); $result = $query->getResult(); $res_array = array(); foreach ($result as $values) { $query = $db->table('courses A') ->select('*') //->join('domains B', 'B.domain_id = A.domain_id') ->where('A.domain_id', $values->domain_id) ->where('A.delete_status', 'ACTIVE') ->where('A.user_type_id', '1') ->get(); $result = $query->getResult(); $sub_domain_array = array(); foreach ($result as $val) { $sub_domain_id = json_decode($val->sub_domain_id); foreach ($sub_domain_id as $id) { array_push($sub_domain_array, $id); } } $query = $db->table('sub_domains A') ->select('*') ->whereIn('A.sub_domain_id', $sub_domain_array) ->where('A.delete_status', 'ACTIVE') ->where('A.user_type_id', '1') ->distinct('A.sub_domain_id') ->get(); $data['sub_domains'] = $query->getResult(); $data['domains'] = $values; array_push($res_array, $data); } return $res_array; } public function get_all_courses() { $array = []; $categoriesQuery = $this->db->table('domains A') ->select('*') ->where('A.delete_status', 'ACTIVE') ->get(); $categories = $categoriesQuery->getResult(); foreach ($categories as $val) { $data['domain_name'] = $val->domain_name; $data['domain_id'] = $val->domain_id; $resultQuery = $this->db->table('courses B') ->select('*') ->where('B.delete_status', 'ACTIVE') ->where('B.domain_id', $val->domain_id) ->orderBy('B.created_at', 'DESC') ->where('B.user_type_id', '1') ->limit(4) ->get(); $result = $resultQuery->getResult(); $courseCountQuery = $this->db->table('courses B') ->select('*') ->where('B.delete_status', 'ACTIVE') ->where('B.domain_id', $val->domain_id) ->orderBy('B.created_at', 'DESC') ->where('B.user_type_id', '1') ->get(); $courseCount = $courseCountQuery->getResult(); $newArray = []; foreach ($result as $value) { $newData['course_id'] = $value->course_id; $newData['course_title'] = $value->course_title; $newData['course_image'] = $value->course_image; $newData['course_price'] = $value->course_price; $subDomains = json_decode($value->sub_domain_id); $subDomains = implode(',', $subDomains); $sql = "SELECT sub_domain FROM sub_domains WHERE sub_domain_id IN ($subDomains) AND delete_status='ACTIVE'"; $domainResult = $this->db->query($sql)->getResult(); $domainArray = []; foreach ($domainResult as $value1) { array_push($domainArray, $value1->sub_domain); } $newData['sub_domains'] = implode(',', $domainArray); $enrollmentCountQuery = $this->db->table('user_course_mapping C') ->select('*') ->where('C.delete_status', 'ACTIVE') ->where('C.course_id', $value->course_id) ->get(); $enrollmentCount = count($enrollmentCountQuery->getResult()); $newData['total_enrollment'] = $enrollmentCount; array_push($newArray, $newData); } $data['course_count'] = $courseCount; $data['course'] = $newArray; array_push($array, $data); } return $array; } protected $table = 'popular_course_clicks'; public function get_popular_course_on_clicks() { $builder = $this->db->table('popular_course_clicks A'); $builder->select('A.clicks, B.course_id, B.course_title, B.course_price, B.course_image'); $builder->join('courses B', 'B.course_id = A.course_id'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('B.user_type_id', '1'); $builder->orderBy('A.clicks', 'DESC'); $builder->limit(8); $query = $builder->get(); return $query->getResult(); } public function get_sub_domains($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('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(); $res_array = []; foreach ($result as $val) { $sub_domain_id = json_decode($val->subject_id); foreach ($sub_domain_id as $sub_id) { $builder = $this->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', $sub_id); $sub_domain_query = $builder->get(); $sub_domain = $sub_domain_query->getRow(); $data = []; if (($val->added_from == 'REQUEST' && $val->approval_status == 'APPROVED') || ($val->added_from == 'REGISTRATION')) { if ($sub_domain) { $data['sub_domain'] = $sub_domain->sub_domain; $data['domain_name'] = $sub_domain->domain_name; $data['batch_size'] = $val->batch_size; } else { $data['sub_domain'] = ''; $data['domain_name'] = ''; $data['batch_size'] = ''; } array_push($res_array, $data); } } } return $res_array; } public function fetch_data($table) { $builder = $this->db->table($table); $query = $builder->get(); return $query->getResult(); } public function get_where_orderby_row($table, $where, $order_by) { return $this->db->table($table) ->select('*') ->where($where) ->orderBy($order_by, 'DESC') ->get() ->getRow(); } public function get_where_orderby_row1($table_fac, $where_fac, $order_by) { return $this->db->table($table_fac) ->select('*') ->where($where_fac) ->orderBy($order_by, 'DESC') ->get() ->getRow(); } public function get_instructors_details($course_id) { $course = $this->db->table('courses') ->select('course_id, sub_domain_id, course_title, course_type') ->where('course_id', $course_id) ->get() ->getRow(); $sub_domain_id = json_decode($course->sub_domain_id); $course_type = json_decode($course->course_type); $type = implode(', ', $course_type); $mapping_result = $this->db->table('faculty_subject_mapping') ->select('*') ->where('delete_status', 'ACTIVE') ->get() ->getResult(); $login_ids_query = $this->db->table('faculty_subject_mapping') ->select('login_id') ->where('delete_status', 'ACTIVE') ->groupBy('login_id') ->get() ->getResult(); $mapping_result_array = []; foreach ($login_ids_query as $sub_ids) { $fin_sub_array = []; $sub_array = []; foreach ($mapping_result as $map) { if ($map->login_id == $sub_ids->login_id) { $sub_domain_ids = json_decode($map->sub_domain_id); foreach ($sub_domain_ids as $ids) { array_push($sub_array, $ids); } } } foreach ($sub_array as $sub) { array_push($fin_sub_array, $sub); } $mapping_data['login_id'] = $sub_ids->login_id; $mapping_data['sub_domain_ids'] = $fin_sub_array; array_push($mapping_result_array, $mapping_data); } $res_array = []; foreach ($mapping_result_array as $value) { $mapping_sub_domain_id = $value['sub_domain_ids']; $sub_domain_id_array = []; foreach ($mapping_sub_domain_id as $val) { foreach ($sub_domain_id as $id) { if ($val == $id) { $i++; array_push($sub_domain_id_array, $id); } } } if ($i > 0) { array_push($res_array, $data); } $i = 0; } return $res_array; } public function get_batch_list($course_id) { $course = $this->db->table('courses A') ->select('course_type, sub_domain_id') ->where('A.course_id', $course_id) ->where('A.delete_status', 'ACTIVE') ->get() ->getRow(); $sub_domain_ids = json_decode($course->sub_domain_id); $batchQuery = $this->db->table('batches A') ->select('*') ->join('faculty_registration B', 'A.faculty_id = B.login_id') ->join('sub_domains C', 'C.sub_domain_id = A.sub_domain_id') ->join('domains D', 'D.domain_id = C.domain_id') ->whereIn('A.sub_domain_id', $sub_domain_ids) ->where('A.batch_approval_status', 'APPROVED') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('C.delete_status', 'ACTIVE') ->where('D.delete_status', 'ACTIVE') ->where('A.institution_id', '0') ->get() ->getResult(); $batchArray = []; foreach ($batchQuery as $val) { $batch_size = $val->batch_size; $userCourseMappingQuery = $this->db->table('user_course_mapping A') ->select('*') ->where('A.delete_status', 'ACTIVE') ->get() ->getResult(); $i = 0; foreach ($userCourseMappingQuery as $value) { if ($value->batch_ids != 'null') { $batch_ids = json_decode($value->batch_ids); foreach ($batch_ids as $batch_id) { if ($batch_id == $val->batch_id) { $i++; } } } } if ($batch_size > $i) { $data['course_type'] = implode(', ', json_decode($course->course_type)); $data['batch_details'] = $val; } else { $data['course_type'] = ""; $data['batch_details'] = ""; } array_push($admin_batch_array, $data); } $finalArray = array_merge($admin_batch_array, $batchArray); return $finalArray; } public function get_feedbacks_list($course_id) { $query = $this->db->table('feedback A') ->select('A.feedback, C.username, D.fullname, A.created_at') ->join('courses B', 'B.course_id = A.course_id') ->join('login C', 'C.login_id = A.created_by') ->join('faculty_registration D', 'D.login_id = A.faculty_id') ->where('B.course_id', $course_id) ->where('A.display_status', 'DISPLAY') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('C.delete_status', 'ACTIVE') ->where('D.delete_status', 'ACTIVE') ->get() ->getResult(); return $query; } public function UpdateData($table, $data, $where) { $builder = $this->db->table($table); $builder->where($where); $result = $builder->update($data); return $result; } public function UpdateData123($where, $table, $data) { $builder = $this->db->table($table); $builder->where($where); $result = $builder->update($data); return $result; } public function UpdateData20($where_material, $table, $data) { $builder = $this->db->table($table); $builder->where($where_material); $result = $builder->update($data); return $result; } public function UpdateData99($login_table, $update_data, $where_id) { $builder = $this->db->table($login_table); $builder->where($where_id); $result = $builder->update($update_data); return $result; } public function get_user_signup_details($login_id) { $builder = $this->db->table('login A'); $builder->select('*'); $builder->join('user_registrations B', 'B.login_id = A.login_id'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('A.verified_status', 'VERIFIED'); $builder->where('A.login_id', $login_id); $query = $builder->get(); return $query->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_result3($timings_table, $where_timing) { $builder = $this->db->table($timings_table); $builder->select('*'); $builder->where($where_timing); $query = $builder->get(); return $query->getResult(); } public function get_where_result6($mapping_table, $where_domain) { $builder = $this->db->table($mapping_table); $builder->select('*'); $builder->where($where_domain); $query = $builder->get(); return $query->getResult(); } public function get_where_sub_domain($domain_array, $id) { $builder = $this->db->table('sub_domains A'); $builder->select('A.sub_domain'); $builder->where('A.domain_id', $id); $builder->whereIn('A.sub_domain_id', $domain_array); $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); $res = $query->getResult(); $sub_domain_array = array(); foreach ($res as $val) { array_push($sub_domain_array, $val->sub_domain); } $data = implode(', ', $sub_domain_array); return $data; } public function get_where_row9($domain_table, $where_domain) { return $this->db->table($domain_table) ->select('*') ->where($where_domain) ->get() ->getRow(); } public function insertData3($timing_table, $timing_data) { $builder = $this->db->table($timing_table); $builder->insert($timing_data); return $this->db->insertID(); } public function get_where_row8($reg_table, $where_reg) { return $this->db->table($reg_table) ->select('*') ->where($where_reg) ->get() ->getRow(); } public function get_where_row6($mapping_table, $where_mapping) { return $this->db->table($mapping_table) ->select('*') ->where($where_mapping) ->get() ->getRow(); } public function get_where_result2($answer_table, $where_answered_questions) { $builder = $this->db->table($answer_table); $builder->select('*'); $builder->where($where_answered_questions); $query = $builder->get(); return $query->getResult(); } public function get_where_result5($note_table, $where_note) { $builder = $this->db->table($note_table); $builder->select('*'); $builder->where($where_note); $query = $builder->get(); return $query->getResult(); } public function get_where_result1($tableOnlineTest, $whereUser) { $builder = $this->db->table($tableOnlineTest); $builder->select('*'); $builder->where($whereUser); $query = $builder->get(); return $query->getResult(); } public function insertData($table, $data) { $builder = $this->db->table($table); $builder->insert($data); return $this->db->insertID(); } public function insertDataf($feedback_table, $data) { $builder = $this->db->table('feedback'); $builder->insert($data); return $this->db->insertID(); } public function insertData2($user_table, $user_data) { $builder = $this->db->table($user_table); $builder->insert($user_data); return $this->db->insertID(); } public function insertData1($table, $data, $type = 'default') { if (!isset($data['question_number'])) { throw new \Exception('Question number is missing.'); } $builder = $this->db->table($table); $builder->insert($data); $insertID = $this->db->insertID(); if ($type === 'special') { } return $insertID; } public function insert_data($answer_table, $data) { $builder = $this->db->table($answer_table); $builder->insert($data); return $this->db->insertID(); } public function insert_data22($table, $data) { $builder = $this->db->table($table); $builder->insert($data); return $this->db->insertID(); } public function user_added_courses($login_id) { $builder = $this->db->table('courses A') ->join('user_course_mapping B', 'A.course_id = B.course_id') ->where('B.user_id', $login_id) ->where('A.delete_status', 'ACTIVE') ->where('B.payment_status', 'PAID') ->where('B.delete_status', 'ACTIVE') ->select('*'); $query = $builder->get(); // print_r($query);die(); $result = $query->getResult(); $result_array = []; foreach ($result as $value) { $sub_domain_id = json_decode($value->sub_domain_id); $subQuery = $this->db->table('sub_domains A') ->whereIn('A.sub_domain_id', $sub_domain_id) ->where('A.delete_status', 'ACTIVE') ->select('*'); $subQueryResult = $subQuery->get()->getResult(); $sub_array = []; foreach ($subQueryResult as $val) { $sub_array[] = $val->sub_domain; } $data = [ 'sub_domains' => implode(', ', $sub_array), 'mapping_id' => $value->mapping_id, 'course_price' => $value->course_price, 'course_title' => $value->course_title, 'course_image' => $value->course_image, 'institution_id' => $value->institution_id, ]; $result_array[] = $data; } return $result_array; } public function get_where_result4($table, $where, $order_by) { $builder = $this->db->table($table); $builder->where($where); if (!empty($order_by)) { $builder->orderBy($order_by); } return $builder->get()->getResult(); } public function get_where_result_orderby_asc($table, $where, $order_by) { $builder = $this->db->table($table); $builder->select('*')->where($where)->orderBy($order_by, 'ASC'); $query = $builder->get(); return $query->getResult(); } public function getWhereLeftChapterQuestions($mapping_id, $test_id, $login_id, $chapter_id, $sub_domain_id, $fac_id) { $array = []; $res = $this->db->table('question_mapping') ->join('faculty_mocktest_setting', 'faculty_mocktest_setting.sub_domain_id = question_mapping.subject_id') ->where('faculty_mocktest_setting.chapter', $chapter_id) ->where('faculty_mocktest_setting.delete_status', 'ACTIVE') ->where('question_mapping.test_id', $test_id) ->where('question_mapping.chapter_id', $chapter_id) ->where('question_mapping.subject_id', $sub_domain_id) ->whereIn('faculty_mocktest_setting.created_by', $fac_id) ->groupBy('question_mapping.test_id') ->get() ->getResult(); foreach ($res as $result) { $s_id = $result->subject_id; $c_id = $result->chapter_id; $questions = json_decode($result->question_id); $order_by = $result->question_order; $number_of_questions = $result->number_of_questions; $res2 = $this->db->table('user_course_mapping A') ->where('A.mapping_id', $mapping_id) ->where('A.delete_status', 'ACTIVE') ->groupBy('A.user_id') ->get() ->getResult(); foreach ($res2 as $result2) { $batch_id = json_decode($result2->batch_ids); $fac_id = json_decode($result2->faculty_ids); if ($batch_id != '') { if ($order_by == 'desc') { $res3 = $this->db->table('batches A') ->whereIn('A.batch_id', $batch_id) ->where('A.delete_status', 'ACTIVE') ->get() ->getRow(); $batch_fac_id = $res3->faculty_id; $res1 = $this->db->table('questions A') ->whereIn('A.faculty_id', $batch_fac_id) ->whereIn('A.chapter_id', $c_id) ->whereIn('A.sub_domain_id', $s_id) ->whereIn('A.qid', $questions) ->limit($number_of_questions) ->where('A.status', 'ACTIVE') ->orderBy('A.qid', 'desc') ->get() ->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } elseif ($order_by == 'asc') { $res3 = $this->db->table('batches A') ->whereIn('A.batch_id', $batch_id) ->where('A.delete_status', 'ACTIVE') ->get() ->getRow(); $batch_fac_id = $res3->faculty_id; $res1 = $this->db->table('questions A') ->whereIn('A.faculty_id', $batch_fac_id) ->whereIn('A.qid', $questions) ->where('A.status', 'ACTIVE') ->limit($number_of_questions) ->orderBy('A.qid', 'asc') ->get() ->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } else { $res3 = $this->db->table('batches A') ->whereIn('A.batch_id', $batch_id) ->where('A.delete_status', 'ACTIVE') ->get() ->getRow(); $batch_fac_id = $res3->faculty_id; $res1 = $this->db->table('questions A') ->whereIn('A.faculty_id', $batch_fac_id) ->whereIn('A.qid', $questions) ->where('A.status', 'ACTIVE') ->limit($number_of_questions) ->orderBy('A.qid', 'asc') ->get() ->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } } else { if ($order_by == 'desc') { $res1 = $this->db->table('questions A') ->whereIn('A.faculty_id', $fac_id) ->whereIn('A.qid', $questions) ->where('A.status', 'ACTIVE') ->limit($number_of_questions) ->orderBy('A.qid', 'desc') ->get() ->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } elseif ($order_by == 'asc') { $res1 = $this->db->table('questions A') ->whereIn('A.faculty_id', $fac_id) ->whereIn('A.qid', $questions) ->where('A.status', 'ACTIVE') ->limit($number_of_questions) ->orderBy('A.qid', 'asc') ->get() ->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } else { $res1 = $this->db->table('questions A') ->whereIn('A.faculty_id', $fac_id) ->whereIn('A.qid', $questions) ->where('A.status', 'ACTIVE') ->limit($number_of_questions) ->orderBy('A.qid', 'asc') ->get() ->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } } } } return $array; } public function getWhereRow10($table_sub_domain, $where_sub_domain) { $builder = $this->db->table($table_sub_domain); $builder->select('*'); $builder->where($where_sub_domain); $query = $builder->get(); return $query->getRow(); } public function getWhereRow12($sub_domain_table, $where_chapter) { $builder = $this->db->table($sub_domain_table); $builder->select('*'); $builder->where($where_chapter); $query = $builder->get(); return $query->getRow(); } public function get_subdomain_wise_courses($sub_domain_id) { $builder = $this->db->table('domains A'); $builder->select('*'); $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); $categories = $query->getResult(); $array = array(); $i = 0; foreach ($categories as $val) { $data['domain_name'] = $val->domain_name; $data['domain_id'] = $val->domain_id; $builder = $this->db->table('courses B'); $builder->select('*'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('B.domain_id', $val->domain_id); $builder->orderBy('B.created_at', 'DESC'); $query = $builder->get(); $result = $query->getResult(); $new_array = array(); foreach ($result as $value) { $sub_domains = json_decode($value->sub_domain_id); foreach ($sub_domains as $val) { if ($val == $sub_domain_id) { $data['course_count'] = $result; $i = $i + 1; $new_data['course_id'] = $value->course_id; $new_data['course_title'] = $value->course_title; $new_data['course_image'] = $value->course_image; $new_data['course_price'] = $value->course_price; $sub_domains = implode(',', $sub_domains); $sql = "SELECT sub_domain FROM sub_domains WHERE sub_domain_id IN ($sub_domains) AND delete_status='ACTIVE'"; $domain_result = $this->db->query($sql)->getResult(); $domain_array = array(); foreach ($domain_result as $value1) { array_push($domain_array, $value1->sub_domain); } $new_data['sub_domains'] = implode(',', $domain_array); $builder = $this->db->table('user_course_mapping C'); $builder->select('*'); $builder->where('C.delete_status', 'ACTIVE'); $builder->where('C.course_id', $value->course_id); $query = $builder->get(); $new_data['total_enrollment'] = count($query->getResult()); array_push($new_array, $new_data); } } } $data['course'] = $new_array; array_push($array, $data); } $result_data = array(); $result_data['i'] = $i; $result_data['result'] = $array; return $result_data; } public function get_where_row($table, $where) { return $this->db->table($table) ->select('*') ->where($where) ->get() ->getRow(); } public function get_where_row5($table, $where_course) { return $this->db->table($table) ->select('*') ->where($where_course) ->get() ->getRow(); } public function get_where_row1($table_sub, $where_sub) { return $this->db->table($table_sub) ->select('*') ->where($where_sub) ->get() ->getRow(); } public function get_cart_data_from_db($user_id) { $builder = $this->db->table('course_cart A'); $builder->select('A.*, B.*'); $builder->join('courses B', 'B.course_id = A.course_id'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('A.user_id', $user_id); $query = $builder->get(); return $query->getResult(); } public function get_where_row_11($table, $where) { $query = $this->db->table($table) ->select('*') ->where($where) ->getCompiledSelect(); log_message('debug', 'Generated SQL Query: ' . $query); return $this->db->table($table) ->select('*') ->where($where) ->get() ->getRow(); } public function get_user_course_details($login_id, $mapping_id) { $builder = $this->db->table('user_course_mapping A'); $builder->select('*'); $builder->join('courses B', 'B.course_id = A.course_id'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $where_status = ['A.enroll_status' => 'ENROLLED', 'A.payment_status' => 'PAID']; $builder->where('A.user_id', $login_id); $builder->where('A.mapping_id', $mapping_id); $builder->where($where_status); $query = $builder->get(); $result = $query->getResult(); $array = []; $id_array = []; foreach ($result as $val) { $ids = json_decode($val->sub_domain_id); foreach ($ids as $val_1) { array_push($id_array, $val_1); } $sub_domains = implode(',', $id_array); $sql1 = "SELECT sub_domain, sub_domain_id FROM sub_domains WHERE sub_domain_id IN ($sub_domains) AND delete_status='ACTIVE'"; $domain_result1 = $this->db->query($sql1); // print_r($domain_result1);die(); $domain_result1 = $domain_result1->getResult(); $data['subdomain'] = $domain_result1; array_push($array, $domain_result1); } return $array; } public function get_mapping_course_subjects($mapping_id) { $builder = $this->db->table('user_course_mapping A'); $builder->select('*'); $builder->join('courses B', 'B.course_id = A.course_id'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('A.mapping_id', $mapping_id); $query = $builder->get(); $result = $query->getRow(); // $sub_domain_id = json_decode($result->sub_domain_ids); $sub_domain_id = null; if ($result) { $sub_domain_id = json_decode($result->sub_domain_ids); } // $sub_domain_ids = implode(',', $sub_domain_id); $sub_domain_ids = ''; if ($sub_domain_id) { $sub_domain_ids = implode(',', $sub_domain_id); } $res_array = []; if ($result) { if ($result->batch_ids == 'null') { $faculty_ids = json_decode($result->faculty_ids); } else { $batch_ids = json_decode($result->batch_ids); $builder = $this->db->table('batches A'); $builder->select('*'); $builder->join('faculty_registration B', 'B.login_id = A.faculty_id'); $builder->whereIn('A.batch_id', $batch_ids); // $builder->where('A.delete_status', 'ACTIVE'); // $builder->where('B.delete_status', 'ACTIVE'); $builder->groupBy('A.faculty_id'); $query = $builder->get(); $batches = $query->getResult(); $faculty_ids = []; foreach ($batches as $batch) { array_push($faculty_ids, $batch->login_id); } } // Rest of the code... // $builder = $this->db->table('sub_domains A'); // $builder->select('*'); // $builder->join('domains B', 'B.domain_id = A.domain_id'); // $builder->join('syllabus_chapter C', 'A.sub_domain_id = C.sub_domain_id', 'left'); // $builder->whereIn('A.sub_domain_id', $sub_domain_ids); // $builder->where('A.delete_status', 'ACTIVE'); // $builder->where('B.delete_status', 'ACTIVE'); // $builder->where('C.delete_status', 'ACTIVE'); // $query = $builder->get(); // $syllabus_chapters = $query->getResult(); $builder = $this->db->table('sub_domains A'); $builder->select('*'); $builder->join('domains B', 'B.domain_id = A.domain_id'); $builder->join('syllabus_chapter C', 'A.sub_domain_id = C.sub_domain_id', 'left'); $builder->whereIn('A.sub_domain_id', [$sub_domain_ids]); // Convert $sub_domain_ids to an array $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('C.delete_status', 'ACTIVE'); $query = $builder->get(); $syllabus_chapters = $query->getResult(); $user_institution_id = session('user_institution_id'); foreach ($syllabus_chapters as $value) { $builder = $this->db->table('topics A'); $builder->select('*'); $builder->where('A.sub_domain_id', $value->sub_domain_id); $builder->where('A.chapter_id', $value->chapter_id); if ($user_institution_id == 0) { $builder->whereIn('A.created_by', $faculty_ids); } else { $builder->where('A.created_by', $user_institution_id); } $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); $topics = $query->getResult(); $data['sub_domain'] = $value->chapter_name; $data['subject_chapters'] = $topics; array_push($res_array, $data); } } return $res_array; } public function get_faculties($facultyIds) { $builder = $this->db->table('faculty_registration A'); $builder->select('*'); $builder->whereIn('A.login_id', $facultyIds); $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); return $query->getResult(); } public function get_batch_faculties($batch_ids) { $builder = $this->db->table('batches A'); $builder->select('*'); $builder->join('faculty_registration B', 'B.login_id = A.faculty_id'); $builder->whereIn('A.batch_id', $batch_ids); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->groupBy('A.faculty_id'); $query = $builder->get(); return $query->getResult(); } public function get_user_analysis_details($userId, $subDomainId) { $builder = $this->db->table('question_mapping A'); $builder->select('*'); $builder->join('sub_domains B', 'B.sub_domain_id = A.subject_id'); $builder->join('syllabus_chapter C', 'C.chapter_id = A.chapter_id'); $builder->whereIn('A.subject_id', $subDomainId); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('C.delete_status', 'ACTIVE'); $builder->where('A.user_id', $userId); $builder->groupBy('A.chapter_id'); $query = $builder->get(); $result = $query->getResult(); $array = []; foreach ($result as $val) { $data['sub_domain'] = $val->sub_domain; $data['chapter_name'] = $val->chapter_name; $chapterId = $val->chapter_id; $builder = $this->db->table('answered_questions A'); $builder->select('A.chapter_id, DATE(A.answered_on) as answered_date'); $builder->where('A.chapter_id', $chapterId); $builder->groupBy('answered_date'); $query = $builder->get(); $days = $query->getResult(); $daysArray = []; foreach ($days as $day) { if (!in_array($day->answered_date, $daysArray, true)) { $daysArray[] = $day->answered_date; } } $data['days'] = count($daysArray); $builder = $this->db->table('question_mapping A'); $builder->select('*'); $builder->where('A.chapter_id', $chapterId); $builder->where('A.user_id', $userId); $res = $builder->get(); $query = $res->getResult(); $res = $res->getNumRows(); $data['attempts'] = $res; $correctAnswers = 0; $totalQuestions = 0; foreach ($query as $value) { $testId = $value->test_id; $questionId = json_decode($value->question_id); $builder = $this->db->table('answered_questions A'); $builder->select('*'); $builder->join('questions', 'questions.ans = A.correct_answer AND questions.qid = A.question_id'); $builder->where('A.test_id', $testId); $builder->where('A.correct_answer !=', '0'); $query1 = $builder->get(); $res1 = $query1->getNumRows(); if ($res1 != '0') { $correctAnswers = $res1; } else { $correctAnswers = 0; } $builder = $this->db->table('answered_questions A'); $builder->select('*'); $builder->where('A.test_id', $testId); $builder->whereIn('A.question_id', $questionId); $builder->where('A.answered_by', $userId); $query1 = $builder->get(); $res2 = $query1->getNumRows(); if ($res2 != '0') { $totalQuestions = $res2; } else { $totalQuestions = 0; } } $data['correct_answers'] = $correctAnswers; $data['total_questions'] = $totalQuestions; array_push($array, $data); } return $array; } public function get_user_performance_details($userId, $courseId) { $builder = $this->db->table('question_mapping A'); $builder->select('*'); $builder->where('A.user_id', $userId); $builder->where('A.subject_id', $courseId); $builder->where('A.test_type', 'Mock Test'); $builder->where('A.chapter_id', 0); $query = $builder->get(); $result = $query->getResult(); $totalQuestions = 0; $correctAnswers = 0; if ($result) { foreach ($result as $value) { $questionIds = json_decode($value->question_id); foreach ($questionIds as $value_1) { $totalQuestions++; $builder = $this->db->table('answered_questions A'); $builder->select('*'); $builder->join('questions', 'questions.ans = A.correct_answer AND questions.qid = A.question_id'); $builder->where('questions.qid', $value_1); $builder->where('A.answered_by', $userId); $builder->where('A.test_id', $value->test_id); $builder->where('A.test_type', 'subject_wise'); $builder->where('A.correct_answer !=', '0'); $query = $builder->get(); $query = $query->getRow(); if ($query) { $correctAnswers++; } } } } $data['correct_answers'] = $correctAnswers; $data['total_questions'] = $totalQuestions; return $data; } public function get_user_progress_details($user_id, $course_id) { $builder = $this->db->table('question_mapping') ->where('user_id', $user_id) ->where('subject_id', $course_id) ->where('chapter_id !=', 0) ->select('*'); $query1 = $builder->get(); $result1 = $query1->getResult(); $total_questions = 0; $correct_answer = 0; if ($result1) { foreach ($result1 as $value) { $question_ids = json_decode($value->question_id); foreach ($question_ids as $value_1) { $total_questions++; $builder = $this->db->table('answered_questions') ->join('questions', 'questions.ans = answered_questions.correct_answer AND questions.qid = answered_questions.question_id') ->where('questions.qid', $value_1) ->where('answered_questions.answered_by', $user_id) ->where('answered_questions.test_id', $value->test_id) ->where('answered_questions.test_type', 'chapter_wise') ->where('answered_questions.correct_answer !=', '0') ->select('*'); $query = $builder->get(); $query = $query->getRow(); if ($query) { $correct_answer++; } } } } $data['correct_answers'] = $correct_answer; $data['total_questions'] = $total_questions; return $data; } public function get_where_result_new($table, $where) { $builder = $this->db->table($table); $builder->select('*'); $builder->where($where); $query = $builder->get(); return $query->getNumRows(); } public function single_course_details($mapping_id) { $builder = $this->db->table('user_course_mapping A'); $builder->select('B.course_id, B.course_title'); $builder->join('courses B', 'B.course_id = A.course_id'); $builder->where('A.mapping_id', $mapping_id); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $query = $builder->get(); $row = $query->getRow(); return $row; } public function correct_answer($chapter_id, $login_id, $test_id) { $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->join('questions', 'questions.ans = answered_questions.correct_answer AND questions.qid = answered_questions.question_id'); $builder->where('questions.chapter_id', $chapter_id); $builder->where('answered_questions.answered_by', $login_id); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.correct_answer !=', '0'); $query = $builder->get(); return $query->getNumRows(); } public function incorrect_answer($chapter_id, $login_id, $test_id) { $builder = $this->db->table('questions'); $builder->select('*'); $builder->where('questions.chapter_id', $chapter_id); $builder->where('questions.status', 'ACTIVE'); $query = $builder->get(); $questions = $query->getResult(); $arr = array(); foreach ($questions as $key => $value) { $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.answered_by', $login_id); $builder->where('answered_questions.question_id', $value->qid); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.correct_answer !=', $value->ans); $builder->where('answered_questions.correct_answer !=', '0'); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $incorrect_answer = $query->getRow(); if (!empty($incorrect_answer)) { array_push($arr, $incorrect_answer->answer_id); } } return count($arr); } public function getWhereResult21($question_table, $where_chapter) { return $this->db->table($question_table) ->select('*') ->where($where_chapter) ->get() ->getResult(); } public function getWhereLikeBatch2($table, $batchId) { $query = $this->db->table('batches') ->select('*'); if (!empty($batchId)) { $query->whereIn('batch_id', is_array($batchId) ? $batchId : []); } $query->where('delete_status', 'ACTIVE'); return $query->get()->getRow(); } public function not_attempted_answer($chapter_id, $login_id, $test_id) { $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.correct_answer', '0'); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $total = $query->getResult(); return count($total); } public function final_test_correct_answer($sub_domain_id, $login_id, $test_id) { $builder = $this->db->table('questions'); $builder->select('*'); $builder->whereIn('questions.sub_domain_id', $sub_domain_id); $builder->where('questions.status', 'ACTIVE'); $questionsQuery = $builder->get(); $questions = $questionsQuery->getResult(); $correctAnswers = array(); foreach ($questions as $question) { $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.answered_by', $login_id); $builder->where('answered_questions.question_id', $question->qid); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.correct_answer', $question->ans); $builder->where('answered_questions.correct_answer !=', '0'); $builder->where('answered_questions.delete_status', 'ACTIVE'); $answerQuery = $builder->get(); $correctAnswer = $answerQuery->getRow(); if (!empty($correctAnswer)) { $correctAnswers[] = $correctAnswer->answer_id; } } return count($correctAnswers); } public function get_batch_faculties_row($batch_ids) { $builder = $this->db->table('batches A'); $builder->select('*'); $builder->join('faculty_registration B', 'B.login_id = A.faculty_id'); $builder->whereIn('A.batch_id', $batch_ids); $builder->where('A.delete_status', 'ACTIVE'); $builder->groupBy('A.faculty_id'); $query = $builder->get(); return $query->getRow(); } public function get_mocktests($user_id, $sub_domain_id, $faculty) { $builder = $this->db->table('faculty_mocktest_setting A'); $builder->select('*'); $builder->where('A.test_type', 'Mock Test'); $builder->whereIn('A.created_by', $faculty); $builder->where('A.sub_domain_id', $sub_domain_id); $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); $res = $query->getResult(); $arr = array(); foreach ($res as $key => $value) { $mocktest_id = $data['mocktest_id'] = $value->mocktest_id; if (!is_array($sub_domain_id)) { $sub_domain_id = explode(',', $sub_domain_id); } $builder = $this->db->table('question_mapping'); $builder->select('*'); $builder->where('mocktest_id', $mocktest_id); $builder->where('user_id', $user_id); $builder->whereIn('subject_id', $sub_domain_id); $builder->orderBy('test_id', 'desc'); $query = $builder->get(); $result1 = $query->getRow(); if ($result1) { $test_id = $result1->test_id; $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->join('questions', 'questions.qid = answered_questions.question_id AND questions.ans = answered_questions.correct_answer'); $builder->where('test_id', $test_id); $builder->where('correct_answer !=', 0); $query = $builder->get(); $result2 = $query->getNumRows(); $data['mocktest_score'] = $result2; } else { $data['mocktest_score'] = 0; } array_push($arr, $data); } return $arr; } public function get_where_chapter_answered_details($user_id, $sub_domain_id, $faculty) { if (!is_array($sub_domain_id)) { $sub_domain_id = [$sub_domain_id]; } $builder = $this->db->table('syllabus_chapter'); $builder->select('*'); $builder->whereIn('sub_domain_id', $sub_domain_id); $builder->where('delete_status', 'ACTIVE'); $query = $builder->get(); $result = $query->getResultArray(); $n_array = array(); foreach ($result as $key => $value) { $chapter_id = $value['chapter_id']; $data['chapter_id'] = $value['chapter_id']; $data['chapter_name'] = $value['chapter_name']; $builder = $this->db->table('faculty_mocktest_setting'); $builder->select('*'); $builder->where('chapter', $chapter_id); $builder->whereIn('sub_domain_id', $sub_domain_id); $builder->whereIn('created_by', $faculty); $builder->where('delete_status', 'ACTIVE'); $query = $builder->get(); $result4 = $query->getNumRows(); if ($result4 != 0) { $data['test_setting'] = $result4; } else { $data['test_setting'] = 0; } $builder = $this->db->table('questions'); $builder->select('*'); $builder->where('chapter_id', $chapter_id); $builder->whereIn('sub_domain_id', $sub_domain_id); $builder->where('status', 'ACTIVE'); $query = $builder->get(); $result3 = $query->getNumRows(); if ($result3 != 0) { $data['tot_questions'] = $result3; } else { $data['tot_questions'] = 0; } $builder = $this->db->table('question_mapping'); $builder->select('*'); $builder->where('chapter_id', $chapter_id); $builder->where('user_id', $user_id); $builder->whereIn('subject_id', $sub_domain_id); $builder->orderBy('test_id', 'desc'); $query = $builder->get(); $result1 = $query->getRow(); if ($result1) { $test_id = $result1->test_id; $questions = json_decode($result1->question_id); $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('test_id', $test_id); $builder->where('correct_answer !=', 0); $query = $builder->get(); $result2 = $query->getNumRows(); $data['answers'] = $result2; $data['questions'] = count($questions); } else { $data['answers'] = 0; $data['questions'] = 0; } array_push($n_array, $data); } return $n_array; } public function get_course_name($mapping_id) { $db = \Config\Database::connect(); $builder = $db->table('user_course_mapping A'); $builder->select('*'); $builder->join('courses B', 'B.course_id = A.course_id'); $builder->where('A.mapping_id', $mapping_id); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $query = $builder->get(); $result = $query->getRow(); return $result; } // public function get_where_user_details($login_id) // { // $builder = $this->db->table($this->table); // $builder->select('*'); // $builder->where('delete_status', 'ACTIVE'); // $builder->where('created_by', $login_id); // $query = $builder->get(); // return $query->getRow(); // } public function get_where_user_details1($login_id) { //$sub_domain_ids = json_encode($sub_domain_id); $builder = $this->select('*') ->from('user_course_mapping A') //->like('A.sub_domain_ids', $sub_domain_ids) ->where('A.delete_status', 'ACTIVE') ->where('A.created_by', $login_id) ->get(); return $builder->getRow(); } public function get_where_result11($question_table, $where_sub_domain_id) { $builder = $this->db->table($question_table); $builder->select('*'); $builder->where($where_sub_domain_id); $query = $builder->get(); return $query->getResult(); } public function check_course_type($mapping_id) { $builder = $this->db->table('user_course_mapping A'); $builder->select('A.session_type'); $builder->join('courses B', 'B.course_id = A.course_id'); $builder->where('A.mapping_id', $mapping_id); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $query = $builder->get(); return $query->getRow(); } public function get_topic_name($topic_id) { $builder = $this->db->table('subject_materials A'); $builder->select('*'); $builder->join('syllabus_chapter B', 'B.chapter_id = A.chapter_id'); $builder->join('topics C', 'C.topic_id = A.topic_id'); $builder->where('A.topic_id', $topic_id); //$builder->where('A.approval_status', 'APPROVED'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('C.delete_status', 'ACTIVE'); $query = $builder->get(); $chapter = $query->getRow(); return $chapter; } public function chapter_wise_material_list($topic_id) { $builder = $this->db->table('subject_materials A'); $builder->select('A.*, B.sub_domain, 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.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('C.delete_status', 'ACTIVE'); $builder->where('A.approval_status', 'APPROVED'); $builder->where('A.topic_id', $topic_id); $query = $builder->get(); return $query->getResult(); } public function get_chapter_material($topic_id, $mapping_id) { $institutionId = session('user_institution_id'); $chapter = $this->db->table('subject_materials A') ->select('*') ->where('A.delete_status', 'ACTIVE') ->where('A.topic_id', $topic_id) ->where('A.approval_status', 'APPROVED') ->get() ->getResult(); $mappingRow = $this->db->table('user_course_mapping A') ->select('*') ->where('A.delete_status', 'ACTIVE') ->where('A.mapping_id', $mapping_id) ->get() ->getRow(); if (!empty($chapter) && is_object($mappingRow)) { $i = 0; if ($institutionId == 0) { if ($mappingRow->faculty_ids !== 'null') { $facultyIds = json_decode($mappingRow->faculty_ids); } else { $batch_ids = json_decode($mappingRow->batch_ids); $result = $this->db->table('batches A') ->select('*') ->whereIn('A.batch_id', $batch_ids) ->where('A.delete_status', 'ACTIVE') ->get() ->getResult(); $facultyIds = []; foreach ($result as $batches) { $facultyIds[] = $batches->faculty_id; } } } else { $facultyIds = [$institutionId]; } foreach ($facultyIds as $value) { foreach ($chapter as $chapters) { if ($value == $chapters->created_by) { $i++; } } } return ($i > 0) ? 1 : 0; } else { return 0; } } public function get_user_details($userId) { $builder = $this->db->table('user_registrations A'); $builder->select('*'); $builder->join('login B', 'B.login_id = A.login_id'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('A.login_id', $userId); $query = $builder->get(); return $query->getRow(); } public function update_data($where, $table, $data) { $builder = $this->db->table($table); $builder->where($where); return $builder->update($data); } public function update_data2($where_user, $mapping_table, $result_status) { $builder = $this->db->table($mapping_table); $builder->where($where_user); return $builder->update($result_status); } public function UpdateData12($where, $table, $data) { $builder = $this->db->table($table); $builder->where($where); $result = $builder->update($data); return $result; } public function UpdateData5($where_user, $table, $login_status) { $builder = $this->db->table($table); $builder->where($where_user); $result = $builder->update($login_status); return $result; } public function UpdateData6($where_user, $login_table, $login_status) { $builder = $this->db->table($login_table); $builder->where($where_user); $result = $builder->update($login_status); return $result; } public function UpdateData7($where_login, $login_table, $data) { $builder = $this->db->table($login_table); $builder->where($where_login); $result = $builder->update($data); return $result; } public function getWhereRow($table, $where) { $builder = $this->db->table($table); $builder->select('*'); $builder->where($where); $query = $builder->get(); return $query->getRow(); } public function getWhereRow15($domain_table, $where_domain) { $builder = $this->db->table($domain_table); $builder->select('*'); $builder->where($where_domain); $query = $builder->get(); return $query->getRow(); } public function getWhereRow11($courseTable, $whereCourse) { $builder = $this->db->table($courseTable); $builder->select('*'); $builder->where($whereCourse); $query = $builder->get(); return $query->getRow(); } public function getWhereRow22($table, $whereDomain) { $builder = $this->db->table($table); $builder->select('*'); $builder->where($whereDomain); $query = $builder->get(); return $query->getRow(); } public function getWhereInRow($user_id, $mapping_id) { return $this->db->table('user_course_mapping') ->select('*') ->where('mapping_id', $mapping_id) ->where('user_id', $user_id) ->where('delete_status', 'ACTIVE') ->get() ->getRow(); } public function getWhereRowOrderby($table, $where, $orderBy) { $builder = $this->db->table($table); $builder->select('*'); $builder->where($where); $builder->orderBy($orderBy, 'DESC'); $query = $builder->get(); return $query->getRow(); } public function getWhereRowOrderby2($table, $where_quests, $order_by) { $builder = $this->db->table($table); $builder->select('*'); $builder->where($where_quests); $builder->orderBy($order_by, 'DESC'); $query = $builder->get(); return $query->getRow(); } public function getWhereRowOrderby1($table_question_mapping, $where_sub_domain, $order_by) { $builder = $this->db->table($table_question_mapping); $builder->select('*'); $builder->where($where_sub_domain); $builder->orderBy($order_by, 'DESC'); $query = $builder->get(); return $query->getRow(); } public function getWhereResultNew($table, $where) { $builder = $this->db->table($table); $builder->select('*'); $builder->where($where); return $builder->countAllResults(); } public function getFaculties($facultyIds) { $builder = $this->db->table('faculty_registration A'); $builder->select('*'); $builder->whereIn('A.login_id', $facultyIds); $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); return $query->getResult(); } public function getBatchFaculties($batch_ids) { $builder = $this->db->table('batches A'); $builder->select('*'); $builder->join('faculty_registration B', 'B.login_id = A.faculty_id'); $builder->whereIn('A.batch_id', $batch_ids); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->groupBy('A.faculty_id'); $query = $builder->get(); return $query->getResult(); } public function get_where_like_batch($table, $batch_id) { $builder = $this->db->table($table); $builder->select('*'); $builder->whereIn('batch_id', $batch_id); $builder->where('delete_status', 'ACTIVE'); $query = $builder->get(); return $query->getRow(); } public function getWhereRow1($loginTable, $where) { $builder = $this->db->table($loginTable); $builder->select('*'); $builder->where($where); $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 getWhereRow16($login_table, $where_id) { $builder = $this->db->table($login_table); $builder->select('*'); $builder->where($where_id); $query = $builder->get(); return $query->getRow(); } public function getWhereRow3($table, $where_domain) { $builder = $this->db->table($table); $builder->select('*'); $builder->where($where_domain); $query = $builder->get(); return $query->getRow(); } public function getWhereRow8($table_mapping_sub_chapter, $where_id) { $builder = $this->db->table($table_mapping_sub_chapter); $builder->select('*'); $builder->where($where_id); $query = $builder->get(); return $query->getRow(); } public function getWhereRow5($courseTable, $whereCourse) { $builder = $this->db->table($courseTable); $builder->select('*'); $builder->where($whereCourse); $query = $builder->get(); return $query->getRow(); } public function getWhereRow4($course_table, $where_course) { $builder = $this->db->table($course_table); $builder->select('*'); $builder->where($where_course); $query = $builder->get(); return $query->getRow(); } public function UpdateData1($where, $loginTable, $loginData) { $builder = $this->db->table($loginTable); $builder->where($where); $result = $builder->update($loginData); return $result; } public function UpdateData2($where, $table, $data) { $builder = $this->db->table($table); $builder->where($where); $result = $builder->update($data); return $result; } public function getWhereQuestionsChapters($questionIds, $testIds, $chapterId) { $db = \Config\Database::connect(); $query = $db->table('answered_questions') ->select('question_id') ->where('answered_questions.test_id', $testIds) ->where('answered_questions.delete_status', 'ACTIVE') ->get(); $total = $query->getResult(); $array = []; foreach ($total as $value) { $answeredQid = $value->question_id; $array[] = $answeredQid; } $result = array_diff($questionIds, $array); return $result; } public function get_where_result24($answer_table, $where_answered_questions) { $builder = $this->db->table($answer_table); $builder->select('*'); $builder->where($where_answered_questions); $query = $builder->get(); return $query->getResult(); } public function UpdateData3($where, $loginTable, $data) { $builder = $this->db->table($loginTable); $builder->where($where); $result = $builder->update($data); return $result; } public function getWhereOrderbyRow2($login_table, $where_email, $order_by) { $builder = $this->db->table($login_table); $builder->select('*'); $builder->where($where_email); $builder->orderBy($order_by, 'DESC'); return $builder->get()->getRow(); } public function UpdateData4($where, $loginTable, $loginData) { $builder = $this->db->table($loginTable); $builder->where($where); $result = $builder->update($loginData); return $result; } public function getWhereResult($table_data1, $where_data1) { return $this->db->table($table_data1) ->select('*') ->where($where_data1) ->get() ->getResult(); } public function getWhereResult1($table, $where) { return $this->db->table($table) ->select('*') ->where($where) ->get() ->getResult(); } public function getWhereResult2($table_data2, $where_data2) { return $this->db->table($table_data2) ->select('*') ->where($where_data2) ->get() ->getResult(); } public function getUserCourseDetails($login_id, $mapping_id) { $builder = $this->db->table('user_course_mapping A'); $builder->join('courses B', 'B.course_id = A.course_id'); $builder->select('A.*, B.*'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where(['A.enroll_status' => 'ENROLLED', 'A.payment_status' => 'PAID']); $builder->where('A.user_id', $login_id); $builder->where('A.mapping_id', $mapping_id); $query = $builder->get(); $result = $query->getResult(); $data = []; $id_array = []; foreach ($result as $val) { $ids = json_decode($val->sub_domain_id); foreach ($ids as $val_1) { array_push($id_array, $val_1); } $sub_domains = implode(',', $id_array); $sql1 = "SELECT sub_domain, sub_domain_id FROM sub_domains WHERE sub_domain_id IN ($sub_domains) AND delete_status='ACTIVE'"; $domain_result1 = $this->db->query($sql1); $domain_result1 = $domain_result1->getResult(); $data['subdomain'] = $domain_result1; array_push($data, $domain_result1); } return $data; } public function getMappingCourseSubjects($mapping_id) { $builder = $this->db->table('user_course_mapping A'); $builder->join('courses B', 'B.course_id = A.course_id'); $builder->select('*'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('A.mapping_id', $mapping_id); $query = $builder->get(); $result = $query->getRow(); if (!$result) { return json_encode(['result' => 0, 'message' => 'Mapping not found']); } $sub_domain_id = json_decode($result->sub_domain_ids); $sub_domain_ids = implode(',', $sub_domain_id); $res_array = []; if ($result->batch_ids == 'null') { $faculty_ids = json_decode($result->faculty_ids); } else { $batch_ids = json_decode($result->batch_ids); $builder = $this->db->table('batches A'); $builder->join('faculty_registration B', 'B.login_id = A.faculty_id'); $builder->whereIn('A.batch_id', $batch_ids); $builder->groupBy('A.faculty_id'); $query = $builder->get(); $batches = $query->getResult(); $faculty_ids = []; foreach ($batches as $batch) { $faculty_ids[] = $batch->login_id; } } $builder = $this->db->table('sub_domains A'); $builder->join('domains B', 'B.domain_id = A.domain_id'); $builder->join('syllabus_chapter C', 'A.sub_domain_id = C.sub_domain_id', 'left'); $builder->whereIn('A.sub_domain_id', explode(',', $sub_domain_ids)); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('C.delete_status', 'ACTIVE'); $query = $builder->get(); $syllabus_chapters = $query->getResult(); $user_institution_id = session('user_institution_id'); foreach ($syllabus_chapters as $value) { $builder = $this->db->table('topics A'); $builder->where('A.sub_domain_id', $value->sub_domain_id); $builder->where('A.chapter_id', $value->chapter_id); if ($user_institution_id == 0) { $builder->whereIn('A.created_by', $faculty_ids); } else { $builder->where('A.created_by', $user_institution_id); } $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); $topics = $query->getResult(); $data['sub_domain'] = $value->chapter_name; $data['subject_chapters'] = $topics; $res_array[] = $data; } return json_encode(['result' => 1, 'data' => $res_array]); } 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 getWhereResultOrderByAsc1($subdomain_table, $where_subdomain, $order_by) { $builder = $this->db->table($subdomain_table); $builder->select('*'); $builder->where($where_subdomain); $builder->orderBy($order_by, 'ASC'); $query = $builder->get(); return $query->getResult(); } public function getWhereUserDetails($login_id) { $builder = $this->db->table('user_course_mapping A'); $builder->select('*'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('A.created_by', $login_id); $query = $builder->get(); $result = $query->getRow(); return $result; } public function getQuestionsForMocktestReview($sub_domain_id, $quest_id, $test_id, $faculty_id, $mocktest_id) { $builder = $this->db->table('faculty_mocktest_setting A'); $builder->select('*'); $builder->where('A.created_by', $faculty_id); $builder->where('A.sub_domain_id', $sub_domain_id); $builder->where('A.test_type', 'Mock Test'); $builder->where('A.mocktest_id', $mocktest_id); $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); $res = $query->getResult(); foreach ($res as $key => $value) { $question_order = $value->question_order; if ($question_order == 'random') { $question_id = json_decode($quest_id); $arr = []; sort($question_id); $clength = 1; for ($x = 0; $x < $clength; $x++) { $question_ids = $question_id[$x]; array_push($arr, $question_id); } $check_question = $arr; $builder = $this->db->table('questions A'); $builder->select('*'); $builder->join('answered_questions B', 'B.sub_domain_id = A.sub_domain_id AND B.question_id = A.qid'); $builder->where('A.status', 'ACTIVE'); $builder->where('B.test_id', $test_id); $builder->whereIn('A.qid', $question_id); $builder->groupBy('A.qid'); $query = $builder->get(); $res1 = $query->getResult(); } else if ($question_order == 'asc') { $question_id = json_decode($quest_id); $arr = []; asort($question_id); $clength = 1; for ($x = 0; $x < $clength; $x++) { $question_ids = $question_id[$x]; array_push($arr, $question_id); } $builder = $this->db->table('questions A'); $builder->select('*'); $builder->join('answered_questions B', 'B.sub_domain_id = A.sub_domain_id AND B.question_id = A.qid'); $builder->where('A.status', 'ACTIVE'); $builder->where('B.test_id', $test_id); $builder->whereIn('A.qid', $question_id); $builder->groupBy('A.qid'); $query = $builder->get(); $res1 = $query->getResult(); } else { $question_id = json_decode($quest_id); $arr = []; rsort($question_id); $clength = 1; for ($x = 0; $x < $clength; $x++) { $question_ids = $question_id[$x]; array_push($arr, $question_id); } $builder = $this->db->table('questions A'); $builder->select('*'); $builder->join('answered_questions B', 'B.sub_domain_id = A.sub_domain_id AND B.question_id = A.qid'); $builder->where('A.status', 'ACTIVE'); $builder->where('B.test_id', $test_id); $builder->whereIn('A.qid', $question_id); $builder->groupBy('A.qid'); $builder->orderBy('A.qid', 'desc'); $query = $builder->get(); $res1 = $query->getResult(); } } return $res1; } public function get_where_result20($question_table, $where_sub_domain_id) { $builder = $this->db->table($question_table); $builder->select('*'); $builder->where($where_sub_domain_id); $query = $builder->get(); return $query->getResult(); } public function getWhereResult3($question_table, $where_sub_domain_id) { return $this->db->table($question_table) ->select('*') ->where($where_sub_domain_id) ->get() ->getResult(); } // public function get_where_result1($tableOnlineTest, $whereUser) // { // $builder = $this->db->table($tableOnlineTest); // $builder->select('*'); // $builder->where($whereUser); // $query = $builder->get(); // return $query->getResult(); // } public function getWhereRow26($table_mapping_sub_chapter, $where_id) { $builder = $this->db->table($table_mapping_sub_chapter); $builder->select('*'); $builder->where($where_id); $query = $builder->get(); return $query->getRow(); } public function subjectWiseCorrectAnswer($sub_domain_id, $login_id, $test_id) { $correctAnswers = []; $questionsQuery = $this->db->table('questions') ->select('qid, ans') ->whereIn('sub_domain_id', (array) $sub_domain_id) ->where('status', 'ACTIVE') ->get(); if ($questionsQuery->resultID->num_rows > 0) { $questions = $questionsQuery->getResult(); foreach ($questions as $value) { $answeredQuery = $this->db->table('answered_questions') ->select('answer_id') ->where('answered_by', $login_id) ->where('question_id', $value->qid) ->where('test_id', $test_id) ->where('correct_answer', $value->ans) ->where('correct_answer !=', '0') ->get(); if ($answeredQuery->resultID->num_rows > 0) { $correct_answer = $answeredQuery->getRow(); $correctAnswers[] = $correct_answer->answer_id; } } } return count($correctAnswers); } public function subjectWiseIncorrectAnswer($sub_domain_id, $login_id, $test_id) { $builder = $this->db->table('questions'); $builder->select('*'); $builder->where('questions.sub_domain_id', $sub_domain_id); $builder->where('questions.status', 'ACTIVE'); $query = $builder->get(); $questions = $query->getResult(); $arr = []; foreach ($questions as $key => $value) { $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.answered_by', $login_id); $builder->where('answered_questions.question_id', $value->qid); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.correct_answer !=', $value->ans); $builder->where('answered_questions.correct_answer !=', '0'); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $incorrect_answer = $query->getRow(); if (!empty($incorrect_answer)) { array_push($arr, $incorrect_answer->answer_id); } } return count($arr); } public function subjectWiseNotAttemptedAnswer($sub_domain_id, $login_id, $test_id) { $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.correct_answer', '0'); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $total = $query->getResult(); return count($total); } public function get_where_result25($answer_table, $where_answered_questions) { $builder = $this->db->table($answer_table); $builder->select('*'); $builder->where($where_answered_questions); $query = $builder->get(); return $query->getResult(); } public function getWhereLikeBatch($table, $batch_id) { $builder = $this->db->table('batches'); $builder->select('*'); $builder->whereIn('batch_id', [$batch_id]); $builder->where('delete_status', 'ACTIVE'); $query = $builder->get(); return $query->getRow(); } public function getWhereLikeBatch1($table, $batchId) { $builder = $this->db->table('batches'); $builder->select('*'); $builder->whereIn('batch_id', $batchId); $builder->where('delete_status', 'ACTIVE'); $query = $builder->get(); return $query->getRow(); } public function getMockTestQuestions($chapterIds, $subDomainId, $facId) { $builder = $this->db->table('faculty_mocktest_setting A'); $builder->join('sub_domains B', 'B.sub_domain_id = A.sub_domain_id'); $builder->join('syllabus_chapter C', 'C.chapter_id = A.chapter'); $builder->select('*'); $builder->where('A.chapter', $chapterIds); $builder->where('A.sub_domain_id', $subDomainId); $builder->whereIn('A.created_by', $facId); $builder->where('A.delete_status', 'ACTIVE'); return $builder->get()->getResult(); } public function getMockTestQuestions1($chapterIds, $subDomainId, $facultyId) { $builder = $this->db->table('faculty_mocktest_setting A'); $builder->join('sub_domains B', 'B.sub_domain_id = A.sub_domain_id'); $builder->join('syllabus_chapter C', 'C.chapter_id = A.chapter'); $builder->select('*'); $builder->where('A.chapter', $chapterIds); $builder->where('A.sub_domain_id', $subDomainId); $builder->whereIn('A.created_by', $facultyId); $builder->where('A.delete_status', 'ACTIVE'); return $builder->get()->getResult(); } public function getMockTestQuestions3($chapterIds, $subjectId, $facultyId) { $builder = $this->db->table('faculty_mocktest_setting A'); $builder->join('sub_domains B', 'B.sub_domain_id = A.sub_domain_id'); $builder->join('syllabus_chapter C', 'C.chapter_id = A.chapter'); $builder->select('*'); $builder->where('A.chapter', $chapterIds); $builder->where('A.sub_domain_id', $subjectId); $builder->whereIn('A.created_by', $facultyId); $builder->where('A.delete_status', 'ACTIVE'); return $builder->get()->getResult(); } public function getMockTestQuestions2($chapterIds, $subjectId, $facultyId) { $builder = $this->db->table('faculty_mocktest_setting A'); $builder->join('sub_domains B', 'B.sub_domain_id = A.sub_domain_id'); $builder->join('syllabus_chapter C', 'C.chapter_id = A.chapter'); $builder->select('*'); $builder->where('A.chapter', $chapterIds); $builder->where('A.sub_domain_id', $subjectId); $builder->whereIn('A.created_by', $facultyId); $builder->where('A.delete_status', 'ACTIVE'); return $builder->get()->getResult(); } public function getWhereQuestionsCount($subDomainId, $facultyId) { $builder = $this->db->table('questions'); $builder->select('*'); $builder->whereIn('sub_domain_id', [$subDomainId]); $builder->whereIn('faculty_id', [$facultyId]); $builder->where('status', 'ACTIVE'); return $builder->get()->getResult(); } public function getWhereLikeChapterFaculty($chapter_id, $faculty_id, $course_id) { $builder = $this->db->table('faculty_mocktest_setting'); $builder->select('*'); $builder->whereIn('created_by', [$faculty_id]); $builder->where('chapter', $chapter_id); $builder->whereIn('sub_domain_id', [$course_id]); $builder->orderBy('id', 'desc'); $builder->where('delete_status', 'ACTIVE'); return $builder->get()->getFirstRow(); } public function getWhereLikeChapterFaculty1($chapterIds, $facultyId, $subDomainId) { $builder = $this->db->table('faculty_mocktest_setting'); $builder->select('*'); $builder->whereIn('created_by', $facultyId); $builder->where('chapter', $chapterIds); $builder->where('sub_domain_id', $subDomainId); $builder->orderBy('id', 'desc'); $builder->where('delete_status', 'ACTIVE'); return $builder->get()->getRow(); } public function getWhereInSubDomainId1($table, $where, $subDomainId) { $sub_domain_ids = json_decode($subDomainId); $builder = $this->db->table($table); $builder->select('*'); $builder->where($where); $builder->whereIn('subject_id', $sub_domain_ids); return $builder->get()->getRow(); } public function getWhereDomainsQuestions($mapping_id, $login_id, $chapter_id, $subject_id, $fac_id) { $array = []; $res = $this->db->table('faculty_mocktest_setting') ->where('chapter', $chapter_id) ->where('delete_status', 'ACTIVE') ->where('sub_domain_id', $subject_id) ->whereIn('created_by', $fac_id) ->get() ->getResult(); foreach ($res as $result) { $s_id = $result->sub_domain_id; $c_id = $result->chapter; $order_by = $result->question_order; $number_of_questions = $result->number_of_questions; $res2 = $this->db->table('user_course_mapping A') ->where('A.mapping_id', $mapping_id) ->where('A.delete_status', 'ACTIVE') ->groupBy('A.user_id') ->get() ->getResult(); foreach ($res2 as $result2) { $batch_id = json_decode($result2->batch_ids); $fac_id = json_decode($result2->faculty_ids); if ($batch_id != '') { $res3 = $this->db->table('batches A') ->whereIn('A.batch_id', $batch_id) ->where('A.delete_status', 'ACTIVE') ->get() ->getRow(); $batch_fac_id = $res3->faculty_id; $res1 = $this->db->table('questions A') ->whereIn('A.faculty_id', $batch_fac_id) ->where('A.sub_domain_id', $s_id) ->where('A.chapter_id', $c_id) ->orderBy('A.qid', $order_by) ->limit($number_of_questions) ->where('A.status', 'ACTIVE') ->get() ->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, 'faculty_id' => $result1->faculty_id, 'material_id' => $result1->material_id, ]; array_push($array, $data); } } else { $res1 = $this->db->table('questions A') ->whereIn('A.faculty_id', $fac_id) ->where('A.sub_domain_id', $s_id) ->where('A.chapter_id', $c_id) ->orderBy('A.qid', $order_by) ->limit($number_of_questions) ->where('A.status', 'ACTIVE') ->get() ->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, 'faculty_id' => $result1->faculty_id, 'material_id' => $result1->material_id, ]; array_push($array, $data); } } } } return $array; } public function getWhereInSubDomainId($table, $where, $subDomainId) { $sub_domain_ids = json_decode($subDomainId); $builder = $this->db->table($table); $builder->select('*'); $builder->where($where); $builder->whereIn('subject_id', $sub_domain_ids); return $builder->get()->getRow(); } public function insertData6($insert_table, $insert_data) { $builder = $this->db->table($insert_table); $builder->insert($insert_data); return $this->db->insertID(); } public function getMockTestSubjectQuestions($subject_id, $faculty_id, $mocktest_id) { $builder = $this->db->table('faculty_mocktest_setting A'); $builder->select('*'); $builder->join('sub_domains B', 'B.sub_domain_id = A.sub_domain_id'); $builder->where('A.test_type', 'Mock Test'); $builder->where('A.sub_domain_id', $subject_id); $builder->where('A.created_by', $faculty_id); $builder->where('A.chapter', 0); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('A.mocktest_id', $mocktest_id); $query = $builder->get(); return $query->getResult(); } public function checkApprovedMaterialsForMocktest($mapping_id, $loginId, $subjectId, $facId) { $query = $this->select('*') ->from('subject_materials A') ->whereIn('A.sub_domain_id', $subjectId) ->whereIn('A.created_by', $facId) ->where('A.approval_status', 'APPROVED') ->where('A.delete_status', 'ACTIVE') ->findAll(); foreach ($query as $result) { $mocktestQuery = $this->db->table('faculty_mocktest_setting') ->select('*') ->whereIn('created_by', $facId) ->whereIn('sub_domain_id', $subjectId) ->orderBy('id', 'desc') ->where('delete_status', 'ACTIVE') ->get() ->getResult(); return $mocktestQuery; } return $query; } public function check_approved_materials_for_mocktest($mapping_id, $loginId, $subjectId, $facId) { $db = \Config\Database::connect(); $subjectMaterialsQuery = $db->table('subject_materials A') ->select('*') ->whereIn('A.sub_domain_id', [$subjectId]) ->whereIn('A.created_by', $facId) ->where('A.approval_status', 'APPROVED') ->where('A.delete_status', 'ACTIVE') ->whereIn('created_by', $facId) ->get(); $subjectMaterialsResult = $subjectMaterialsQuery->getResult(); $facultyMockTestQuery = $db->table('faculty_mocktest_setting') ->select('*') ->whereIn('created_by', $facId) ->whereIn('sub_domain_id', [$subjectId]) ->orderBy('id', 'desc') ->where('delete_status', 'ACTIVE') ->get(); $facultyMockTestResult = $facultyMockTestQuery->getResult(); return [ 'subject_materials' => $subjectMaterialsResult, 'faculty_mocktest_setting' => $facultyMockTestResult, ]; } // public function checkApprovedMaterials($mapping_id, $login_id, $id, $subject_id, $fac_id) // { // $db = \Config\Database::connect(); // $query = $db->table('subject_materials A') // ->select('*') // ->whereIn('A.chapter_id', $id) // ->whereIn('A.sub_domain_id', $subject_id) // ->where('A.approval_status', 'APPROVED') // ->whereIn('A.created_by', $fac_id) // ->where('A.delete_status', 'ACTIVE') // ->get(); // $res = $query->getResult(); // foreach ($res as $result) { // $query = $db->table('faculty_mocktest_setting') // ->select('*') // ->where('chapter', $id) // ->whereIn('created_by', $fac_id) // ->whereIn('sub_domain_id', $subject_id) // ->orderBy('id', 'desc') // ->where('delete_status', 'ACTIVE') // ->get(); // $result = $query->getResult(); // } // return $res; // } public function checkApprovedMaterials($mapping_id, $login_id, $id, $subject_id, $fac_id) { $db = \Config\Database::connect(); $query = $db->table('subject_materials A') ->select('*') ->whereIn('A.chapter_id', (array)$id) ->whereIn('A.sub_domain_id', (array)$subject_id) ->where('A.approval_status', 'APPROVED') ->whereIn('A.created_by', (array)$fac_id) ->where('A.delete_status', 'ACTIVE') ->get(); $res = $query->getResult(); foreach ($res as $result) { $query = $db->table('faculty_mocktest_setting') ->select('*') ->where('chapter', (array)$id) ->whereIn('created_by', (array)$fac_id) ->whereIn('sub_domain_id', (array)$subject_id) ->orderBy('id', 'desc') ->where('delete_status', 'ACTIVE') ->get(); $result = $query->getResult(); } return $res; } public function get_mock_test_subject_questions($subject_id, $fac_id, $mocktest_id) { $builder = $this->db->table('faculty_mocktest_setting A'); $builder->select('*'); $builder->join('sub_domains B', 'B.sub_domain_id = A.sub_domain_id'); $builder->where('A.test_type', 'Mock Test'); $builder->where('A.sub_domain_id', $subject_id); $builder->whereIn('A.created_by', $fac_id); $builder->where('A.chapter', 0); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('A.mocktest_id', $mocktest_id); $query = $builder->get(); return $query->getResult(); } public function get_mock_test_subject_questions1($subject_id, $faculty_id, $mocktest_id) { $builder = $this->db->table('faculty_mocktest_setting A'); $builder->select('*'); $builder->join('sub_domains B', 'B.sub_domain_id = A.sub_domain_id'); $builder->where('A.test_type', 'Mock Test'); $builder->where('A.sub_domain_id', $subject_id); $builder->whereIn('A.created_by', $faculty_id); $builder->where('A.chapter', 0); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('A.mocktest_id', $mocktest_id); $query = $builder->get(); return $query->getResult(); } public function get_where_like_faculty($facultyId, $courseId) { $builder = $this->db->table('faculty_mocktest_setting'); $builder->select('*'); $builder->whereIn('created_by', $facultyId); $builder->whereIn('sub_domain_id', $courseId); $builder->whereIn('test_type', 'Mock Test'); $builder->whereIn('chapter', 0); $builder->orderBy('id', 'desc'); $builder->where('delete_status', 'ACTIVE'); $query = $builder->get(); return $query->getRow(); } public function getUserChapterAnswer($chapter_id, $user_id, $test_id, $qid, $subdomain_id) { $builder = $this->db->table('answered_questions A'); $builder->select('*'); $builder->join('questions B', 'B.qid = A.question_id'); $builder->where('A.question_id', $qid); $builder->where('A.chapter_id', $chapter_id); $builder->where('A.sub_domain_id', $subdomain_id); $builder->where('A.answered_by', $user_id); $builder->where('A.test_id', $test_id); $builder->limit(1); return $builder->get()->getRow(); } 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 getFinalTestQuestions($subject_id, $faculty_id) { $builder = $this->db->table('faculty_mocktest_setting A'); $builder->join('sub_domains B', 'B.sub_domain_id = A.sub_domain_id'); $builder->select('*'); $builder->where('A.sub_domain_id', $subject_id); $faculty_id = is_array($faculty_id) ? $faculty_id : [$faculty_id]; $builder->whereIn('A.created_by', $faculty_id); $builder->where('A.test_type', 'Final Test'); $builder->where('A.chapter', 0); $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); return $query->getResult(); } public function getWhereLikeFacultyForFinals($faculty_id, $course_id) { $builder = $this->db->table('faculty_mocktest_setting'); $builder->select('*'); $faculty_id = is_array($faculty_id) ? $faculty_id : [$faculty_id]; $builder->whereIn('created_by', $faculty_id); $course_id = is_array($course_id) ? $course_id : [$course_id]; $builder->whereIn('sub_domain_id', $course_id); $builder->where('chapter', 0); $builder->where('test_type', 'Final Test'); $builder->orderBy('id', 'desc'); $builder->where('delete_status', 'ACTIVE'); $query = $builder->get(); return $query->getRow(); } public function getWhereLikeFaculty($faculty_id, $course_id) { $builder = $this->db->table('faculty_mocktest_setting'); $builder->select('*'); $builder->whereIn('created_by', (array)$faculty_id); $builder->whereIn('sub_domain_id', (array)$course_id); $builder->whereIn('test_type', ['Mock Test']); $builder->whereIn('chapter', [0]); $builder->orderBy('id', 'desc'); $builder->where('delete_status', 'ACTIVE'); $query = $builder->get(); return $query->getRow(); } public function getWhereLike($table, $where) { $builder = $this->db->table($table); $builder->select('*'); $builder->like($where); return $builder->get()->getRow(); } public function getWhereFinalTestQuestions($mapping_id, $loginId, $subjectId, $facId) { $array = []; $query = $this->db->table('faculty_mocktest_setting') ->select('*') ->where('chapter', 0) ->where('delete_status', 'ACTIVE') ->where('test_type', 'Final Test') ->where('sub_domain_id', $subjectId) ->whereIn('created_by', (array)$facId) ->get(); $res = $query->getResult(); foreach ($res as $result) { $subjectId = $result->sub_domain_id; $orderBy = $result->question_order; $numberOfQuestions = $result->number_of_questions; $createdBy = $result->created_by; $query = $this->db->table('user_course_mapping A') ->select('*') ->where('A.mapping_id', $mapping_id) ->where('A.delete_status', 'ACTIVE') ->groupBy('A.user_id') ->get(); $res2 = $query->getResult(); foreach ($res2 as $result2) { $batchId = json_decode($result2->batch_ids); $facId = json_decode($result2->faculty_ids); if (!empty($batchId)) { $query = $this->db->table('batches A') ->select('*') ->whereIn('A.batch_id', (array)$batchId) ->where('A.delete_status', 'ACTIVE') ->get(); $res3 = $query->getRow(); $batchFacId = $res3->faculty_id; $query = $this->db->table('questions A') ->select('*') ->whereIn('A.faculty_id', (array)$batchFacId) ->where('A.sub_domain_id', $subjectId) ->orderBy('A.qid', $orderBy) ->limit($numberOfQuestions) ->where('A.status', 'ACTIVE') ->get(); $res1 = $query->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, 'material_id' => $result1->material_id, ]; array_push($array, $data); } } else { $query = $this->db->table('questions A') ->select('*') ->whereIn('A.faculty_id', (array)$facId) ->where('A.sub_domain_id', $subjectId) ->orderBy('A.qid', $orderBy) ->limit($numberOfQuestions) ->where('A.status', 'ACTIVE') ->get(); $res1 = $query->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, 'material_id' => $result1->material_id, ]; array_push($array, $data); } } } } return $array; } public function get_last_row() { $builder = $this->db->table('question_mapping'); $builder->select('*'); $builder->orderBy('test_id', 'DESC'); $builder->limit(1); $query = $builder->get(); return $query->getRow(); } public function getLeftSideFinalQuestions($mapping_id, $testId, $loginId, $subjectIds, $facId) { $builder = $this->db->table('question_mapping'); $builder->select('*'); $builder->join('faculty_mocktest_setting', 'faculty_mocktest_setting.sub_domain_id = question_mapping.subject_id'); $builder->where('faculty_mocktest_setting.chapter', 0); $builder->where('faculty_mocktest_setting.delete_status', 'ACTIVE'); $builder->where('faculty_mocktest_setting.test_type', 'Final Test'); $builder->where('question_mapping.test_id', $testId); $builder->where('question_mapping.chapter_id', 0); $builder->where('question_mapping.subject_id', $subjectIds); $builder->where('question_mapping.test_type', 'Final Test'); $builder->where('faculty_mocktest_setting.created_by', $facId); $query = $builder->get(); $res = $query->getResult(); $array = array(); foreach ($res as $result) { $sId = $result->subject_id; $questions = json_decode($result->question_id); $orderBy = $result->question_order; $numberOfQuestions = $result->number_of_questions; $builder = $this->db->table('user_course_mapping A'); $builder->select('*'); $builder->where('A.mapping_id', $mapping_id); $builder->where('A.delete_status', 'ACTIVE'); $builder->groupBy('A.user_id'); $query = $builder->get(); $res2 = $query->getResult(); foreach ($res2 as $result2) { $batchId = json_decode($result2->batch_ids); $facId = json_decode($result2->faculty_ids); if (!empty($batchId)) { $builder = $this->db->table('batches A'); $builder->select('*'); $builder->whereIn('A.batch_id', $batchId); $builder->where('A.delete_status', 'ACTIVE'); $query1 = $builder->get(); $res3 = $query1->getRow(); $batchFacId = $res3->faculty_id; $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $batchFacId); $builder->whereIn('A.qid', $questions); $builder->where('A.status', 'ACTIVE'); $builder->limit($numberOfQuestions); if ($orderBy == 'desc') { $builder->orderBy('A.qid', 'desc'); } else { $builder->orderBy('A.qid', 'asc'); } $query1 = $builder->get(); $res1 = $query1->getResult(); foreach ($res1 as $result1) { $data['question_id'] = $result1->qid; $data['ans1'] = $result1->ans1; $data['ans2'] = $result1->ans2; $data['ans3'] = $result1->ans3; $data['ans4'] = $result1->ans4; $data['ans'] = $result1->ans; $data['chapter_id'] = $result1->chapter_id; $data['sub_domain_id'] = $result1->sub_domain_id; $data['questions'] = $result1->questions; array_push($array, $data); } } else { $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $facId); $builder->whereIn('A.qid', $questions); $builder->where('A.status', 'ACTIVE'); $builder->limit($numberOfQuestions); if ($orderBy == 'desc') { $builder->orderBy('A.qid', 'desc'); } else { $builder->orderBy('A.qid', 'asc'); } $query1 = $builder->get(); $res1 = $query1->getResult(); foreach ($res1 as $result1) { $data['question_id'] = $result1->qid; $data['ans1'] = $result1->ans1; $data['ans2'] = $result1->ans2; $data['ans3'] = $result1->ans3; $data['ans4'] = $result1->ans4; $data['ans'] = $result1->ans; $data['chapter_id'] = $result1->chapter_id; $data['sub_domain_id'] = $result1->sub_domain_id; $data['questions'] = $result1->questions; array_push($array, $data); } } } } return $array; } public function limitationQuestions($mapping_id, $test_id, $login_id, $chapter_id, $sub_domain_id) { $array = []; $res = $this->db->table('question_mapping A') ->join('faculty_mocktest_setting B', 'B.sub_domain_id = A.subject_id') ->where('A.chapter_id', $chapter_id) ->where('A.subject_id', $sub_domain_id) ->where('A.test_id', $test_id) ->where('B.chapter', $chapter_id) ->where('B.delete_status', 'ACTIVE') ->groupBy('A.test_id') ->get() ->getResult(); foreach ($res as $result) { $c_id = $result->chapter; $s_id = $result->sub_domain_id; $order_by = $result->question_order; $number_of_questions = $result->number_of_questions; $questions = json_decode($result->question_id); $res2 = $this->db->table('user_course_mapping A') ->where('A.mapping_id', $mapping_id) ->where('A.delete_status', 'ACTIVE') ->groupBy('A.user_id') ->get() ->getResult(); foreach ($res2 as $result2) { $fac_id = json_decode($result2->faculty_ids); $batch_id = json_decode($result2->batch_ids); if ($batch_id != '') { $res3 = $this->db->table('batches A') ->whereIn('A.batch_id', $batch_id) ->where('A.delete_status', 'ACTIVE') ->get() ->getRow(); $batch_fac_id = $res3->faculty_id; if ($order_by == 'desc') { $res1 = $this->db->table('questions A') ->whereIn('A.faculty_id', $batch_fac_id) ->where('A.chapter_id', $chapter_id) ->where('A.sub_domain_id', $sub_domain_id) ->whereIn('A.qid', $questions) ->orderBy('A.qid', 'desc') ->limit(1) ->where('A.status', 'ACTIVE') ->get() ->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } elseif ($order_by == 'asc') { $res1 = $this->db->table('questions A') ->whereIn('A.faculty_id', $batch_fac_id) ->where('A.sub_domain_id', $sub_domain_id) ->whereIn('A.qid', $questions) ->orderBy('A.qid', 'asc') ->limit(1) ->where('A.status', 'ACTIVE') ->get() ->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } else { $res1 = $this->db->table('questions A') ->whereIn('A.faculty_id', $batch_fac_id) ->where('A.sub_domain_id', $sub_domain_id) ->whereIn('A.qid', $questions) ->orderBy('A.qid', 'asc') ->limit(1) ->where('A.status', 'ACTIVE') ->get() ->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } } else { if ($order_by == 'desc') { $res1 = $this->db->table('questions A') ->whereIn('A.faculty_id', $fac_id) ->where('A.sub_domain_id', $sub_domain_id) ->whereIn('A.qid', $questions) ->orderBy('A.qid', 'desc') ->limit(1) ->where('A.status', 'ACTIVE') ->get() ->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } elseif ($order_by == 'asc') { $res1 = $this->db->table('questions A') ->whereIn('A.faculty_id', $fac_id) ->where('A.chapter_id', $chapter_id) ->where('A.sub_domain_id', $sub_domain_id) ->whereIn('A.qid', $questions) ->orderBy('A.qid', 'asc') ->limit(1) ->where('A.status', 'ACTIVE') ->get() ->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } else { $res1 = $this->db->table('questions A') ->whereIn('A.faculty_id', $fac_id) ->where('A.chapter_id', $chapter_id) ->where('A.sub_domain_id', $sub_domain_id) ->whereIn('A.qid', $questions) ->orderBy('A.qid', 'asc') ->limit(1) ->where('A.status', 'ACTIVE') ->get() ->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } } } } return $array; } public function markForLaterChapterWise($chapter_id, $login_id, $test_id) { $arr = []; $markFor = $this->db->table('questions') ->select('*') ->where('chapter_id', $chapter_id) ->where('status', 'ACTIVE') ->get() ->getResult(); foreach ($markFor as $value) { $markForLater = $this->db->table('answered_questions') ->select('*') ->where('answered_questions.answered_by', $login_id) ->where('answered_questions.question_id', $value->qid) ->where('answered_questions.test_type', 'chapter_wise') ->where('answered_questions.test_id', $test_id) ->where('answered_questions.mark_for_later', 'NO') ->where('answered_questions.delete_status', 'ACTIVE') ->get() ->getRow(); if ($markForLater) { $data = [ 'question_id' => $markForLater->question_id, ]; array_push($arr, $data); } } return $arr; } public function finalTestLimitationQuestions($mapping_id, $testId, $loginId, $subjectIds) { $builder = $this->db->table('question_mapping A'); $builder->select('*'); $builder->join('faculty_mocktest_setting B', 'B.sub_domain_id = A.subject_id'); $builder->where('A.chapter_id', '0'); $builder->where('A.subject_id', $subjectIds); $builder->where('A.test_id', $testId); $builder->where('A.test_type', 'Final Test'); $builder->where('B.test_type', 'Final Test'); $builder->where('B.chapter', '0'); $builder->where('B.delete_status', 'ACTIVE'); $query1 = $builder->get(); $res = $query1->getResult(); $array = array(); foreach ($res as $result) { $questions = json_decode($result->question_id); $orderBy = $result->question_order; $builder = $this->db->table('user_course_mapping A'); $builder->select('*'); $builder->where('A.mapping_id', $mapping_id); $builder->where('A.delete_status', 'ACTIVE'); $builder->groupBy('A.user_id'); $query = $builder->get(); $res2 = $query->getResult(); foreach ($res2 as $result2) { $facId = json_decode($result2->faculty_ids); $batchId = json_decode($result2->batch_ids); if ($batchId != '') { $builder = $this->db->table('batches A'); $builder->select('*'); $builder->whereIn('A.batch_id', $batchId); $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); $res3 = $query->getRow(); $batchFacId = $res3->faculty_id; if ($orderBy == 'desc') { $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $batchFacId); $builder->where('A.sub_domain_id', $subjectIds); $builder->whereIn('A.qid', $questions); $builder->orderBy('A.qid', 'desc'); $builder->limit(1); $builder->where('A.status', 'ACTIVE'); $query1 = $builder->get(); $res1 = $query1->getResult(); foreach ($res1 as $result1) { $data['question_id'] = $result1->qid; $data['ans1'] = $result1->ans1; $data['ans2'] = $result1->ans2; $data['ans3'] = $result1->ans3; $data['ans4'] = $result1->ans4; $data['ans'] = $result1->ans; $data['chapter_id'] = $result1->chapter_id; $data['sub_domain_id'] = $result1->sub_domain_id; $data['questions'] = $result1->questions; array_push($array, $data); } } elseif ($orderBy == 'asc') { $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $batchFacId); $builder->where('A.sub_domain_id', $subjectIds); $builder->whereIn('A.qid', $questions); $builder->orderBy('A.qid', 'asc'); $builder->limit(1); $builder->where('A.status', 'ACTIVE'); $query1 = $builder->get(); $res1 = $query1->getResult(); foreach ($res1 as $result1) { $data['question_id'] = $result1->qid; $data['ans1'] = $result1->ans1; $data['ans2'] = $result1->ans2; $data['ans3'] = $result1->ans3; $data['ans4'] = $result1->ans4; $data['ans'] = $result1->ans; $data['chapter_id'] = $result1->chapter_id; $data['sub_domain_id'] = $result1->sub_domain_id; $data['questions'] = $result1->questions; array_push($array, $data); } } else { $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $batchFacId); $builder->where('A.sub_domain_id', $subjectIds); $builder->whereIn('A.qid', $questions); $builder->orderBy('A.qid', 'asc'); $builder->limit(1); $builder->where('A.status', 'ACTIVE'); $query1 = $builder->get(); $res1 = $query1->getResult(); foreach ($res1 as $result1) { $data['question_id'] = $result1->qid; $data['ans1'] = $result1->ans1; $data['ans2'] = $result1->ans2; $data['ans3'] = $result1->ans3; $data['ans4'] = $result1->ans4; $data['ans'] = $result1->ans; $data['chapter_id'] = $result1->chapter_id; $data['sub_domain_id'] = $result1->sub_domain_id; $data['questions'] = $result1->questions; array_push($array, $data); } } } else { if ($orderBy == 'desc') { $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $facId); $builder->where('A.sub_domain_id', $subjectIds); $builder->whereIn('A.qid', $questions); $builder->orderBy('A.qid', 'desc'); $builder->limit(1); $builder->where('A.status', 'ACTIVE'); $query1 = $builder->get(); $res1 = $query1->getResult(); foreach ($res1 as $result1) { $data['question_id'] = $result1->qid; $data['ans1'] = $result1->ans1; $data['ans2'] = $result1->ans2; $data['ans3'] = $result1->ans3; $data['ans4'] = $result1->ans4; $data['ans'] = $result1->ans; $data['chapter_id'] = $result1->chapter_id; $data['sub_domain_id'] = $result1->sub_domain_id; $data['questions'] = $result1->questions; array_push($array, $data); } } elseif ($orderBy == 'asc') { $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $facId); $builder->where('A.sub_domain_id', $subjectIds); $builder->whereIn('A.qid', $questions); $builder->orderBy('A.qid', 'asc'); $builder->limit(1); $builder->where('A.status', 'ACTIVE'); $query1 = $builder->get(); $res1 = $query1->getResult(); foreach ($res1 as $result1) { $data['question_id'] = $result1->qid; $data['ans1'] = $result1->ans1; $data['ans2'] = $result1->ans2; $data['ans3'] = $result1->ans3; $data['ans4'] = $result1->ans4; $data['ans'] = $result1->ans; $data['chapter_id'] = $result1->chapter_id; $data['sub_domain_id'] = $result1->sub_domain_id; $data['questions'] = $result1->questions; array_push($array, $data); } } else { $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $facId); $builder->where('A.sub_domain_id', $subjectIds); $builder->whereIn('A.qid', $questions); $builder->orderBy('A.qid', 'asc'); $builder->limit(1); $builder->where('A.status', 'ACTIVE'); $query1 = $builder->get(); $res1 = $query1->getResult(); foreach ($res1 as $result1) { $data['question_id'] = $result1->qid; $data['ans1'] = $result1->ans1; $data['ans2'] = $result1->ans2; $data['ans3'] = $result1->ans3; $data['ans4'] = $result1->ans4; $data['ans'] = $result1->ans; $data['chapter_id'] = $result1->chapter_id; $data['sub_domain_id'] = $result1->sub_domain_id; $data['questions'] = $result1->questions; array_push($array, $data); } } } } } return $array; } public function finalTestMarkLater($subDomainId, $loginId, $testId) { $builder = $this->db->table('questions'); $builder->select('*'); $builder->where('sub_domain_id', $subDomainId); $builder->where('questions.status', 'ACTIVE'); $query = $builder->get(); $markFor = $query->getResult(); $arr = array(); foreach ($markFor as $value) { $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.answered_by', $loginId); $builder->where('answered_questions.question_id', $value->qid); $builder->where('answered_questions.test_type', 'final_test'); $builder->where('answered_questions.test_id', $testId); $builder->where('answered_questions.mark_for_later', 'NO'); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $markForLater = $query->getRow(); if ($markForLater) { $d['question_id'] = $markForLater->question_id; array_push($arr, $markForLater); } } return $arr; } public function nextQuestionForFinals($mapping_id, $qid, $subDomainId, $testId, $loginId) { $builder = $this->db->table('question_mapping A'); $builder->join('faculty_mocktest_setting B', 'B.sub_domain_id = A.subject_id'); $builder->where('A.chapter_id', '0'); $builder->where('B.chapter', '0'); $builder->where('A.test_type', 'Final Test'); $builder->where('B.test_type', 'Final Test'); $builder->where('A.test_id', $testId); $builder->groupBy('A.test_id'); $builder->orderBy('A.test_id', 'desc'); $builder->where('B.delete_status', 'ACTIVE'); $query1 = $builder->get(); $res1 = $query1->getResult(); foreach ($res1 as $result1) { $initialQid[] = $qid; $orderBy = $result1->question_order; $sId = $result1->subject_id; $questionId = json_decode($result1->question_id); $numberOfQuestions = $result1->number_of_questions; $builder = $this->db->table('user_course_mapping A'); $builder->where('A.mapping_id', $mapping_id); $builder->where('A.delete_status', 'ACTIVE'); $builder->groupBy('A.user_id'); $query = $builder->get(); $res2 = $query->getResult(); foreach ($res2 as $result2) { $facId = json_decode($result2->faculty_ids); if ($orderBy == "desc") { $builder = $this->db->table('questions'); $builder->whereIn('questions.qid', $questionId); $builder->where('questions.qid <', $qid); $builder->whereNotIn('questions.qid', $initialQid); $builder->where('questions.status', 'ACTIVE'); $builder->whereIn('questions.faculty_id', $facId); $builder->orderBy('questions.qid', $orderBy); $query = $builder->get(); $nextQuestion = $query->getRow(); $arr = []; if ($nextQuestion) { $arr['qid'] = $nextQuestion->qid; $arr['sub_domain_id'] = $nextQuestion->sub_domain_id; $arr['questions'] = $nextQuestion->questions; $arr['ans1'] = $nextQuestion->ans1; $arr['ans2'] = $nextQuestion->ans2; $arr['ans3'] = $nextQuestion->ans3; $arr['ans4'] = $nextQuestion->ans4; $arr['ans'] = $nextQuestion->ans; $builder = $this->db->table('answered_questions'); $builder->where('answered_questions.answered_by', $loginId); $builder->where('answered_questions.question_id', $nextQuestion->qid); $builder->where('answered_questions.test_id', $testId); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $previousQuestion = $query->getRow(); if ($previousQuestion) { $arr['correct_answer'] = $previousQuestion->correct_answer; } else { $arr['correct_answer'] = 0; } } return $arr; } elseif ($orderBy == "asc") { $builder = $this->db->table('questions'); $builder->whereIn('questions.qid', $questionId); $builder->where('questions.qid >', $qid); $builder->whereNotIn('questions.qid', $initialQid); $builder->where('questions.status', 'ACTIVE'); $builder->whereIn('questions.faculty_id', $facId); $builder->orderBy('questions.qid', $orderBy); $query = $builder->get(); $nextQuestion = $query->getRow(); $arr = []; if ($nextQuestion) { $arr['qid'] = $nextQuestion->qid; $arr['sub_domain_id'] = $nextQuestion->sub_domain_id; $arr['questions'] = $nextQuestion->questions; $arr['ans1'] = $nextQuestion->ans1; $arr['ans2'] = $nextQuestion->ans2; $arr['ans3'] = $nextQuestion->ans3; $arr['ans4'] = $nextQuestion->ans4; $arr['ans'] = $nextQuestion->ans; $builder = $this->db->table('answered_questions'); $builder->where('answered_questions.answered_by', $loginId); $builder->where('answered_questions.question_id', $nextQuestion->qid); $builder->where('answered_questions.test_id', $testId); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $previousQuestion = $query->getRow(); if ($previousQuestion) { $arr['correct_answer'] = $previousQuestion->correct_answer; } else { $arr['correct_answer'] = 0; } } return $arr; } else { $builder = $this->db->table('questions'); $builder->whereIn('questions.qid', $questionId); $builder->where('questions.qid >', $qid); $builder->whereNotIn('questions.qid', $initialQid); $builder->where('questions.status', 'ACTIVE'); $builder->whereIn('questions.faculty_id', $facId); $query = $builder->get(); $nextQuestion = $query->getRow(); $arr = []; if ($nextQuestion) { $arr['qid'] = $nextQuestion->qid; $arr['sub_domain_id'] = $nextQuestion->sub_domain_id; $arr['questions'] = $nextQuestion->questions; $arr['ans1'] = $nextQuestion->ans1; $arr['ans2'] = $nextQuestion->ans2; $arr['ans3'] = $nextQuestion->ans3; $arr['ans4'] = $nextQuestion->ans4; $arr['ans'] = $nextQuestion->ans; $builder = $this->db->table('answered_questions'); $builder->where('answered_questions.answered_by', $loginId); $builder->where('answered_questions.question_id', $nextQuestion->qid); $builder->where('answered_questions.test_id', $testId); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $previousQuestion = $query->getRow(); if ($previousQuestion) { $arr['correct_answer'] = $previousQuestion->correct_answer; } else { $arr['correct_answer'] = 0; } } return $arr; } } } } public function previousQuestionForFinals($mapping_id, $test_id, $qid, $sub_domain_id, $login_id) { $builder = $this->db->table('question_mapping A'); $builder->join('faculty_mocktest_setting B', 'B.sub_domain_id = A.subject_id'); $builder->where('A.chapter_id', '0'); $builder->where('B.chapter', '0'); $builder->where('A.test_type', 'Final Test'); $builder->where('B.test_type', 'Final Test'); $builder->where('A.test_id', $test_id); $builder->where('B.delete_status', 'ACTIVE'); $builder->orderBy('A.test_id', 'desc'); $builder->groupBy('A.test_id'); $query1 = $builder->get(); $res1 = $query1->getResult(); foreach ($res1 as $result1) { $initialQid[] = $qid; $orderBy = $result1->question_order; $sId = $result1->subject_id; $questionId = json_decode($result1->question_id); $numberOfQuestions = $result1->number_of_questions; $builder = $this->db->table('user_course_mapping A'); $builder->where('A.mapping_id', $mapping_id); $builder->where('A.delete_status', 'ACTIVE'); $builder->groupBy('A.user_id'); $query = $builder->get(); $res2 = $query->getResult(); foreach ($res2 as $result2) { $facId = json_decode($result2->faculty_ids); $builder = $this->db->table('questions'); $builder->whereIn('questions.qid', $questionId); $builder->where('questions.sub_domain_id', $sub_domain_id); $builder->where('questions.status', 'ACTIVE'); $builder->whereIn('questions.faculty_id', $facId); if ($orderBy == 'desc') { $builder->where('questions.qid >', $qid); $builder->whereNotIn('questions.qid', $initialQid); $builder->orderBy('questions.qid', 'asc'); } elseif ($orderBy == 'asc') { $builder->where('questions.qid <', $qid); $builder->whereNotIn('questions.qid', $initialQid); $builder->orderBy('questions.qid', 'desc'); } else { $builder->where('questions.qid <', $qid); $builder->whereNotIn('questions.qid', $initialQid); $builder->orderBy('questions.qid', 'desc'); } $query = $builder->get(); $previousQuestion = $query->getRow(); $arr = []; if ($previousQuestion) { $a['qid'] = $previousQuestion->qid; $a['sub_domain_id'] = $previousQuestion->sub_domain_id; $a['chapter_id'] = $previousQuestion->chapter_id; $a['questions'] = $previousQuestion->questions; $a['ans1'] = $previousQuestion->ans1; $a['ans2'] = $previousQuestion->ans2; $a['ans3'] = $previousQuestion->ans3; $a['ans4'] = $previousQuestion->ans4; $a['ans'] = $previousQuestion->ans; $builder = $this->db->table('answered_questions'); $builder->where('answered_questions.answered_by', $login_id); $builder->where('answered_questions.question_id', $previousQuestion->qid); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $previousQuestions = $query->getRow(); if ($previousQuestions) { $a['correct_answer'] = $previousQuestions->correct_answer; } else { $a['correct_answer'] = 0; } } return $a; } } } public function markLaterQusFinals($testId, $loginId, $qid, $subDomainId) { $builder = $this->db->table('questions'); $builder->select('*'); $builder->where('questions.qid', $qid); $builder->where('questions.sub_domain_id', $subDomainId); $builder->where('questions.status', 'ACTIVE'); $query = $builder->get(); $markLaterSubject = $query->getRow(); $arr = []; if ($markLaterSubject) { $a['qid'] = $markLaterSubject->qid; $a['sub_domain_id'] = $markLaterSubject->sub_domain_id; $a['chapter_id'] = $markLaterSubject->chapter_id; $a['questions'] = $markLaterSubject->questions; $a['ans1'] = $markLaterSubject->ans1; $a['ans2'] = $markLaterSubject->ans2; $a['ans3'] = $markLaterSubject->ans3; $a['ans4'] = $markLaterSubject->ans4; $a['ans'] = $markLaterSubject->ans; $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.answered_by', $loginId); $builder->where('answered_questions.question_id', $qid); $builder->where('answered_questions.test_id', $testId); $builder->where('answered_questions.test_type', 'final_test'); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $previousQuestion = $query->getRow(); if ($previousQuestion) { $a['correct_answer'] = $previousQuestion->correct_answer; } else { $a['correct_answer'] = 0; } } return $a; } public function getWhereQuestionsSubjects($question_ids, $test_ids, $subject_id) { $builder = $this->db->table('answered_questions'); $builder->select('question_id'); $builder->where('answered_questions.test_id', $test_ids); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $total = $query->getResult(); $array = array(); foreach ($total as $value) { $answered_qid = $value->question_id; array_push($array, $answered_qid); } $result = array_diff($question_ids, $array); return $result; } public function getWhereQuestionsSubjects1($question_ids, $test_id, $subject_id) { $builder = $this->db->table('answered_questions'); $builder->select('question_id'); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $total = $query->getResult(); $array = array(); foreach ($total as $value) { $answered_qid = $value->question_id; array_push($array, $answered_qid); } $result = array_diff($question_ids, $array); return $result; } public function getMarkedFinalTestQuestions($loginId, $testId, $subjectId, $chapterId) { $builder = $this->db->table('answered_questions A'); $builder->select('A.*, B.questions, B.ans1, B.ans2, B.ans3, B.ans4'); $builder->join('questions B', 'B.qid = A.question_id'); $builder->where('A.answered_by', $loginId); $builder->where('A.mark_for_later', 'YES'); $builder->where('A.test_type', 'final_test'); $builder->where('A.test_id', $testId); $builder->where('A.sub_domain_id', $subjectId); $builder->where('A.chapter_id', '0'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.status', 'ACTIVE'); $query = $builder->get(); return $query->getResult(); } public function get_where_in($table, $where) { $builder = $this->db->table($table); $builder->select('*'); $builder->whereIn($where); $query = $builder->get(); return $query->getRow(); } public function get_where_domains_subject_wise_questions($mapping_id, $login_id, $id, $subject_id, $fac_id, $mocktest_id) { $builder = $this->db->table('faculty_mocktest_setting'); $builder->select('*'); $builder->where('mocktest_id', $mocktest_id); $builder->where('chapter', 0); $builder->where('delete_status', 'ACTIVE'); $builder->where('test_type', 'Mock Test'); $builder->where('sub_domain_id', $subject_id); $builder->whereIn('created_by', $fac_id); $res = $builder->get()->getResult(); $array = []; foreach ($res as $result) { $s_id = $result->sub_domain_id; $order_by = $result->question_order; $number_of_questions = $result->number_of_questions; $created_by = $result->created_by; $builder = $this->db->table('user_course_mapping A'); $builder->select('*'); $builder->where('A.mapping_id', $mapping_id); $builder->where('A.delete_status', 'ACTIVE'); $builder->groupBy('A.user_id'); $res2 = $builder->get()->getResult(); foreach ($res2 as $result2) { $batch_id = json_decode($result2->batch_ids); $fac_id = json_decode($result2->faculty_ids); if ($batch_id != '') { $builder = $this->db->table('batches A'); $builder->select('*'); $builder->whereIn('A.batch_id', $batch_id); $builder->where('A.delete_status', 'ACTIVE'); $res3 = $builder->get()->getRow(); $batch_fac_id = $res3->faculty_id; $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $fac_id); $builder->where('A.sub_domain_id', $subject_id); $builder->orderBy('A.qid', $order_by); $builder->limit($number_of_questions); $builder->where('A.status', 'ACTIVE'); $res1 = $builder->get()->getResult(); foreach ($res1 as $result1) { $data['question_id'] = $result1->qid; $data['ans1'] = $result1->ans1; $data['ans2'] = $result1->ans2; $data['ans3'] = $result1->ans3; $data['ans4'] = $result1->ans4; $data['ans'] = $result1->ans; $data['chapter_id'] = $result1->chapter_id; $data['sub_domain_id'] = $result1->sub_domain_id; $data['questions'] = $result1->questions; $data['material_id'] = $result1->material_id; $array[] = $data; } } else { $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $fac_id); $builder->where('A.sub_domain_id', $subject_id); $builder->orderBy('A.qid', $order_by); $builder->limit($number_of_questions); $builder->where('A.status', 'ACTIVE'); $res1 = $builder->get()->getResult(); foreach ($res1 as $result1) { $data['question_id'] = $result1->qid; $data['ans1'] = $result1->ans1; $data['ans2'] = $result1->ans2; $data['ans3'] = $result1->ans3; $data['ans4'] = $result1->ans4; $data['ans'] = $result1->ans; $data['chapter_id'] = $result1->chapter_id; $data['sub_domain_id'] = $result1->sub_domain_id; $data['questions'] = $result1->questions; $data['material_id'] = $result1->material_id; $array[] = $data; } } } } return $array; } public function get_where_left_subject_questions($mapping_id, $test_id, $login_id, $subject_id) { $array = []; $builder = $this->db->table('question_mapping'); $builder->select('*'); $builder->join('faculty_mocktest_setting', 'faculty_mocktest_setting.sub_domain_id = question_mapping.subject_id AND faculty_mocktest_setting.mocktest_id = question_mapping.mocktest_id'); $builder->where('faculty_mocktest_setting.chapter', 0); $builder->where('faculty_mocktest_setting.delete_status', 'ACTIVE'); $builder->where('faculty_mocktest_setting.test_type', 'Mock Test'); $builder->where('question_mapping.test_id', $test_id); $builder->where('question_mapping.chapter_id', 0); $builder->where('question_mapping.subject_id', $subject_id); $builder->where('question_mapping.test_type', 'Mock Test'); $builder->groupBy('question_mapping.test_id'); $res = $builder->get()->getResult(); foreach ($res as $result) { $s_id = $result->subject_id; $questions = json_decode($result->question_id); $order_by = $result->question_order; $number_of_questions = $result->number_of_questions; $builder = $this->db->table('user_course_mapping A'); $builder->select('*'); $builder->where('A.mapping_id', $mapping_id); $builder->where('A.delete_status', 'ACTIVE'); $builder->groupBy('A.user_id'); $res2 = $builder->get()->getResult(); foreach ($res2 as $result2) { $batch_id = json_decode($result2->batch_ids); $fac_id = json_decode($result2->faculty_ids); if (!empty($batch_id)) { if ($order_by == 'desc') { $builder = $this->db->table('batches A'); $builder->select('*'); $builder->whereIn('A.batch_id', $batch_id); $builder->where('A.delete_status', 'ACTIVE'); $res3 = $builder->get()->getRow(); $batch_fac_id = $res3->faculty_id; $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $batch_fac_id); $builder->whereIn('A.qid', $questions); $builder->where('A.status', 'ACTIVE'); $builder->limit($number_of_questions); $builder->orderBy('A.qid', 'desc'); $res1 = $builder->get()->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } elseif ($order_by == 'asc') { $builder = $this->db->table('batches A'); $builder->select('*'); $builder->whereIn('A.batch_id', $batch_id); $builder->where('A.delete_status', 'ACTIVE'); $res3 = $builder->get()->getRow(); $batch_fac_id = $res3->faculty_id; $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $batch_fac_id); $builder->whereIn('A.qid', $questions); $builder->where('A.status', 'ACTIVE'); $builder->limit($number_of_questions); $builder->orderBy('A.qid', 'asc'); $res1 = $builder->get()->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } else { $builder = $this->db->table('batches A'); $builder->select('*'); $builder->whereIn('A.batch_id', $batch_id); $builder->where('A.delete_status', 'ACTIVE'); $res3 = $builder->get()->getRow(); $batch_fac_id = $res3->faculty_id; $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $batch_fac_id); $builder->whereIn('A.qid', $questions); $builder->where('A.status', 'ACTIVE'); $builder->limit($number_of_questions); $builder->orderBy('A.qid', 'asc'); $res1 = $builder->get()->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } } else { if ($order_by == 'desc') { $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $fac_id); $builder->whereIn('A.qid', $questions); $builder->where('A.status', 'ACTIVE'); $builder->limit($number_of_questions); $builder->orderBy('A.qid', 'desc'); $res1 = $builder->get()->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } elseif ($order_by == 'asc') { $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $fac_id); $builder->whereIn('A.qid', $questions); $builder->where('A.status', 'ACTIVE'); $builder->orderBy('A.qid', 'asc'); $builder->limit($number_of_questions); $res1 = $builder->get()->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } else { $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $fac_id); $builder->whereIn('A.qid', $questions); $builder->where('A.status', 'ACTIVE'); $builder->limit($number_of_questions); $builder->orderBy('A.qid', 'asc'); $res1 = $builder->get()->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } } } } return $array; } public function getWhereRow13($table_sub, $where_sub) { $builder = $this->db->table($table_sub); $builder->select('*'); $builder->where($where_sub); $query = $builder->get(); return $query->getRow(); } public function getWhereRow25($table_mapping_sub_chapter, $where_id) { $builder = $this->db->table($table_mapping_sub_chapter); $builder->select('*'); $builder->where($where_id); $query = $builder->get(); return $query->getRow(); } public function UpdateData11($where, $table, $data) { $builder = $this->db->table($table); $builder->where($where); $result = $builder->update($data); return $result; } public function getWhereRowOrderby4($table_question_mapping, $where_chapter, $order_by) { $builder = $this->db->table($table_question_mapping); $builder->select('*'); $builder->where($where_chapter); $builder->orderBy($order_by, 'DESC'); $query = $builder->get(); return $query->getRow(); } public function get_where_result15($table_online_test, $where_user) { $builder = $this->db->table($table_online_test); $builder->select('*'); $builder->where($where_user); $query = $builder->get(); return $query->getResult(); } public function get_where_result16($table_question, $where_question) { $builder = $this->db->table($table_question); $builder->select('*'); $builder->where($where_question); $query = $builder->get(); return $query->getResult(); } public function get_where_result17($table_quest, $where_quest) { $builder = $this->db->table($table_quest); $builder->select('*'); $builder->where($where_quest); $query = $builder->get(); return $query->getResult(); } public function getWhereOrderbyRow11($fac_table, $where_fac, $order_by) { $builder = $this->db->table($fac_table); $builder->select('*'); $builder->where($where_fac); $builder->orderBy($order_by, 'DESC'); return $builder->get()->getRow(); } public function limitation_questions_subject_wise($mapping_id, $test_id, $login_id, $sub_domain_id) { $array = []; $builder = $this->db->table('question_mapping A'); $builder->select('*'); $builder->join('faculty_mocktest_setting B', 'B.sub_domain_id = A.subject_id AND B.mocktest_id = A.mocktest_id'); $builder->where('A.chapter_id', '0'); $builder->where('A.subject_id', $sub_domain_id); $builder->where('A.test_id', $test_id); $builder->where('B.chapter', '0'); $builder->where('B.delete_status', 'ACTIVE'); $res = $builder->get()->getResult(); foreach ($res as $result) { $questions = json_decode($result->question_id); $order_by = $result->question_order; $builder = $this->db->table('user_course_mapping A'); $builder->select('*'); $builder->where('A.mapping_id', $mapping_id); $builder->where('A.delete_status', 'ACTIVE'); $builder->groupBy('A.user_id'); $res2 = $builder->get()->getResult(); foreach ($res2 as $result2) { $fac_id = json_decode($result2->faculty_ids); $batch_id = json_decode($result2->batch_ids); if ($batch_id != '') { $builder = $this->db->table('batches A'); $builder->select('*'); $builder->whereIn('A.batch_id', $batch_id); $builder->where('A.delete_status', 'ACTIVE'); $res3 = $builder->get()->getRow(); $batch_fac_id = $res3->faculty_id; if ($order_by == 'desc') { $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $batch_fac_id); $builder->where('A.sub_domain_id', $sub_domain_id); $builder->whereIn('A.qid', $questions); $builder->orderBy('A.qid', 'desc'); $builder->limit(1); $builder->where('A.status', 'ACTIVE'); $res1 = $builder->get()->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } elseif ($order_by == 'asc') { $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $batch_fac_id); $builder->where('A.sub_domain_id', $sub_domain_id); $builder->whereIn('A.qid', $questions); $builder->orderBy('A.qid', 'asc'); $builder->limit(1); $builder->where('A.status', 'ACTIVE'); $res1 = $builder->get()->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } else { $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $batch_fac_id); $builder->where('A.sub_domain_id', $sub_domain_id); $builder->whereIn('A.qid', $questions); $builder->orderBy('A.qid', 'asc'); $builder->limit(1); $builder->where('A.status', 'ACTIVE'); $res1 = $builder->get()->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } } else { if ($order_by == 'desc') { $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $fac_id); $builder->where('A.sub_domain_id', $sub_domain_id); $builder->whereIn('A.qid', $questions); $builder->orderBy('A.qid', 'desc'); $builder->limit(1); $builder->where('A.status', 'ACTIVE'); $res1 = $builder->get()->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } elseif ($order_by == 'asc') { $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $fac_id); $builder->where('A.sub_domain_id', $sub_domain_id); $builder->whereIn('A.qid', $questions); $builder->orderBy('A.qid', 'asc'); $builder->limit(1); $builder->where('A.status', 'ACTIVE'); $res1 = $builder->get()->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } else { $builder = $this->db->table('questions A'); $builder->select('*'); $builder->whereIn('A.faculty_id', $fac_id); $builder->where('A.sub_domain_id', $sub_domain_id); $builder->whereIn('A.qid', $questions); $builder->orderBy('A.qid', 'asc'); $builder->limit(1); $builder->where('A.status', 'ACTIVE'); $res1 = $builder->get()->getResult(); foreach ($res1 as $result1) { $data = [ 'question_id' => $result1->qid, 'ans1' => $result1->ans1, 'ans2' => $result1->ans2, 'ans3' => $result1->ans3, 'ans4' => $result1->ans4, 'ans' => $result1->ans, 'chapter_id' => $result1->chapter_id, 'sub_domain_id' => $result1->sub_domain_id, 'questions' => $result1->questions, ]; array_push($array, $data); } } } } } return $array; } public function mark_for_later_subject_wise($sub_domain_id, $login_id, $test_id) { $arr = []; $builder = $this->db->table('questions'); $builder->select('*'); $builder->where('sub_domain_id', $sub_domain_id); $builder->where('questions.status', 'ACTIVE'); $mark_for = $builder->get()->getResult(); foreach ($mark_for as $value) { $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.answered_by', $login_id); $builder->where('answered_questions.question_id', $value->qid); $builder->where('answered_questions.test_type', 'subject_wise'); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.mark_for_later', 'NO'); $builder->where('answered_questions.delete_status', 'ACTIVE'); $mark_for_later = $builder->get()->getRow(); if ($mark_for_later) { $arr[] = $mark_for_later; } } return $arr; } // public function check_approved_materials($mapping_id, $login_id, $id, $subject_id, $fac_id) // { // $db = \Config\Database::connect(); // Connect to the database // // Query for subject materials // $builder = $db->table('subject_materials A'); // $builder->select('*'); // $builder->whereIn('A.chapter_id', (array)$id); // $builder->whereIn('A.sub_domain_id', (array)$subject_id); // $builder->where('A.approval_status', 'APPROVED'); // $builder->whereIn('A.created_by', (array)$fac_id); // $builder->where('A.delete_status', 'ACTIVE'); // $query = $builder->get(); // $res = $query->getResult(); // // Query for faculty mocktest setting // foreach ($res as $result) { // $builder = $db->table('faculty_mocktest_setting'); // $builder->select('*'); // $builder->where('chapter', (array)$id); // $builder->whereIn('created_by', (array)$fac_id); // $builder->whereIn('sub_domain_id', (array)$subject_id); // $builder->orderBy('id', 'desc'); // $builder->where('delete_status', 'ACTIVE'); // $query = $builder->get(); // $result = $query->getResult(); // } // return $res; // } // public function check_approved_materials($mapping_id, $login_id, $id, $subject_id, $fac_id) // { // try { // $db = \Config\Database::connect(); // Connect to the database // // Query for subject materials // $builder = $db->table('subject_materials A'); // $builder->select('*'); // $builder->whereIn('A.chapter_id', (array)$id); // $builder->whereIn('A.sub_domain_id', (array)$subject_id); // $builder->where('A.approval_status', 'APPROVED'); // $builder->whereIn('A.created_by', (array)$fac_id); // $builder->where('A.delete_status', 'ACTIVE'); // $query = $builder->get(); // $res = $query->getResult(); // // Query for faculty mocktest setting // foreach ($res as $result) { // $builder = $db->table('faculty_mocktest_setting'); // $builder->select('*'); // $builder->where('chapter', (array)$id); // $builder->whereIn('created_by', (array)$fac_id); // $builder->whereIn('sub_domain_id', (array)$subject_id); // $builder->orderBy('id', 'desc'); // $builder->where('delete_status', 'ACTIVE'); // $query = $builder->get(); // $result = $query->getResult(); // } // return $res; // } catch (\Exception $e) { // // Log the exception // log_message('error', 'Exception in check_approved_materials: ' . $e->getMessage()); // // Return a response indicating failure // return [ // 'error' => 'An internal error occurred. Please try again later.', // ]; // } // } public function check_approved_materials($mappingId, $loginId, $id, $subjectId, $facId) { $builder = $this->db->table('subject_materials A'); $builder->select('*'); if (is_array($id) && !empty($id)) { $builder->whereIn('A.chapter_id', $id); } if (is_array($subjectId) && !empty($subjectId)) { $builder->whereIn('A.sub_domain_id', $subjectId); } if (is_array($facId) && !empty($facId)) { $builder->whereIn('A.created_by', $facId); } $builder->where('A.approval_status', 'APPROVED'); $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); $res = $query->getResult(); return $res; } public function numberRows($table, $where) { $builder = $this->db->table($table); $builder->select('*'); $builder->where($where); $query = $builder->get(); return $query->getNumRows(); } public function get_where_mocktest_taken($mocktest_id, $user_id) { $builder = $this->db->table('question_mapping A'); $builder->select('*'); $builder->where('A.mocktest_id', $mocktest_id); $builder->where('A.user_id', $user_id); $query = $builder->get(); $result = $query->getResult(); $array = []; foreach ($result as $res) { $data['answered_on'] = $res->answered_on; $data['subject_id'] = $res->subject_id; $test_id = $res->test_id; $data['test_id'] = $test_id; $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->join('questions', 'questions.ans = answered_questions.correct_answer AND questions.qid = answered_questions.question_id'); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.correct_answer !=', '0'); $query1 = $builder->get(); $res1 = $query1->getNumRows(); if ($res1 != '0') { $data['correct_answers'] = $correct_answers = $res1; } else { $data['correct_answers'] = 0; } $array[] = $data; } return $array; } public function get_where_in_result($user_id, $sub_domain_ids) { $builder = $this->db->table('question_mapping'); $builder->select('*'); $builder->where('user_id', $user_id); $builder->where('test_type', 'Final Test'); $builder->whereIn('subject_id', json_decode($sub_domain_ids)); $query = $builder->get(); return $query->getResult(); } public function nextQuestion($mapping_id, $qid, $chapter_id, $sub_domain_id, $test_id, $login_id) { $initial_qid = []; $this->select('*'); $this->from('question_mapping A'); $this->join('faculty_mocktest_setting B', 'B.sub_domain_id = A.subject_id'); $this->where('A.chapter_id', $chapter_id); $this->where('A.subject_id', $sub_domain_id); $this->where('B.chapter', $chapter_id); $this->where('A.test_id', $test_id); $this->group_by('A.test_id'); $this->order_by('A.test_id', 'desc'); $this->where('B.delete_status', 'ACTIVE'); $query1 = $this->get(); $res1 = $query1->getResult(); foreach ($res1 as $result1) { $initial_qid[] = $qid; $order_by = $result1->question_order; $s_id = $result1->subject_id; $question_id = json_decode($result1->question_id); $number_of_questions = $result1->number_of_questions; $this->select('*'); $this->from('user_course_mapping A'); $this->where('A.mapping_id', $mapping_id); $this->where('A.delete_status', 'ACTIVE'); $this->group_by('A.user_id'); $query = $this->get(); $res2 = $query->getResult(); foreach ($res2 as $result2) { $fac_id = json_decode($result2->faculty_ids); if ($order_by == "desc") { $this->select('*'); $this->from('questions'); $this->whereIn('questions.qid', $question_id); $this->where('questions.qid <', $qid); $this->whereNotIn('questions.qid', $initial_qid); $this->where('questions.status', 'ACTIVE'); $this->whereIn('questions.faculty_id', $fac_id); $this->order_by('questions.qid', $order_by); $query = $this->get(); $next_question = $query->getRow(); $arr = []; if ($next_question) { $a['qid'] = $next_question->qid; $a['sub_domain_id'] = $next_question->sub_domain_id; $a['questions'] = $next_question->questions; $a['ans1'] = $next_question->ans1; $a['ans2'] = $next_question->ans2; $a['ans3'] = $next_question->ans3; $a['ans4'] = $next_question->ans4; $a['ans'] = $next_question->ans; $this->select('*'); $this->from('answered_questions'); $this->where('answered_questions.answered_by', $login_id); $this->where('answered_questions.question_id', $next_question->qid); $this->where('answered_questions.test_id', $test_id); $this->where('answered_questions.delete_status', 'ACTIVE'); $query = $this->get(); $previous_question = $query->getRow(); if ($previous_question) { $a['correct_answer'] = $previous_question->correct_answer; } else { $a['correct_answer'] = 0; } } return $a; } elseif ($order_by == "asc") { $this->select('*'); $this->from('questions'); $this->whereIn('questions.qid', $question_id); $this->where('questions.qid >', $qid); $this->whereNotIn('questions.qid', $initial_qid); $this->where('questions.status', 'ACTIVE'); $this->whereIn('questions.faculty_id', $fac_id); $this->order_by('questions.qid', $order_by); $query = $this->get(); $next_question = $query->getRow(); $arr = []; if ($next_question) { $a['qid'] = $next_question->qid; $a['sub_domain_id'] = $next_question->sub_domain_id; $a['questions'] = $next_question->questions; $a['ans1'] = $next_question->ans1; $a['ans2'] = $next_question->ans2; $a['ans3'] = $next_question->ans3; $a['ans4'] = $next_question->ans4; $a['ans'] = $next_question->ans; $this->select('*'); $this->from('answered_questions'); $this->where('answered_questions.answered_by', $login_id); $this->where('answered_questions.question_id', $next_question->qid); $this->where('answered_questions.test_id', $test_id); $this->where('answered_questions.delete_status', 'ACTIVE'); $query = $this->get(); $previous_question = $query->getRow(); if ($previous_question) { $a['correct_answer'] = $previous_question->correct_answer; } else { $a['correct_answer'] = 0; } } return $a; } else { $this->select('*'); $this->from('questions'); $this->whereIn('questions.qid', $question_id); $this->where('questions.qid >', $qid); $this->whereNotIn('questions.qid', $initial_qid); $this->where('questions.status', 'ACTIVE'); $this->whereIn('questions.faculty_id', $fac_id); //$this->order_by('questions.qid', 'rand()'); $query = $this->get(); $next_question = $query->getRow(); $arr = []; if ($next_question) { $a['qid'] = $next_question->qid; $a['sub_domain_id'] = $next_question->sub_domain_id; $a['questions'] = $next_question->questions; $a['ans1'] = $next_question->ans1; $a['ans2'] = $next_question->ans2; $a['ans3'] = $next_question->ans3; $a['ans4'] = $next_question->ans4; $a['ans'] = $next_question->ans; $this->select('*'); $this->from('answered_questions'); $this->where('answered_questions.answered_by', $login_id); $this->where('answered_questions.question_id', $next_question->qid); $this->where('answered_questions.test_id', $test_id); $this->where('answered_questions.delete_status', 'ACTIVE'); $query = $this->get(); $previous_question = $query->getRow(); if ($previous_question) { $a['correct_answer'] = $previous_question->correct_answer; } else { $a['correct_answer'] = 0; } } return $a; } } } } public function previous_question($mappingId, $testId, $qid, $cid, $loginId, $subDomainId) { $db = \Config\Database::connect(); $query1 = $db->table('question_mapping A') ->join('faculty_mocktest_setting B', 'B.sub_domain_id = A.subject_id') ->where('A.chapter_id', $cid) ->where('B.chapter', $cid) ->where('A.test_id', $testId) ->where('B.delete_status', 'ACTIVE') ->orderBy('A.test_id', 'desc') ->groupBy('A.test_id') ->get(); $res1 = $query1->getResult(); foreach ($res1 as $result1) { $initialQid[] = $qid; $orderBy = $result1->question_order; $cid = $result1->chapter_id; $questionId = json_decode($result1->question_id); $numberOfQuestions = $result1->number_of_questions; $query2 = $db->table('user_course_mapping A') ->where('A.mapping_id', $mappingId) ->where('A.delete_status', 'ACTIVE') ->groupBy('A.user_id') ->get(); $res2 = $query2->getResult(); foreach ($res2 as $result2) { $facId = json_decode($result2->faculty_ids); $query = $db->table('questions') ->whereIn('questions.qid', $questionId) ->whereNotIn('questions.qid', $initialQid) ->where('questions.chapter_id', $cid) ->where('questions.sub_domain_id', $subDomainId) ->whereIn('questions.faculty_id', $facId) ->where('questions.status', 'ACTIVE'); if ($orderBy == 'desc') { $query->where('questions.qid >', $qid); } elseif ($orderBy == 'asc') { $query->where('questions.qid <', $qid)->orderBy('questions.qid', 'desc'); } else { $query->where('questions.qid <', $qid)->orderBy('questions.qid', 'desc'); } $previousQuestion = $query->get()->getRow(); $arr = []; if ($previousQuestion) { $a['qid'] = $previousQuestion->qid; $a['sub_domain_id'] = $previousQuestion->sub_domain_id; $a['chapter_id'] = $previousQuestion->chapter_id; $a['questions'] = $previousQuestion->questions; $a['ans1'] = $previousQuestion->ans1; $a['ans2'] = $previousQuestion->ans2; $a['ans3'] = $previousQuestion->ans3; $a['ans4'] = $previousQuestion->ans4; $a['ans'] = $previousQuestion->ans; $query = $db->table('answered_questions') ->where('answered_questions.answered_by', $loginId) ->where('answered_questions.question_id', $previousQuestion->qid) ->where('answered_questions.test_id', $testId) ->where('answered_questions.delete_status', 'ACTIVE'); $previousQuestions = $query->get()->getRow(); if ($previousQuestions) { $a['correct_answer'] = $previousQuestions->correct_answer; } else { $a['correct_answer'] = 0; } } return $a; } } } public function next_question($mapping_id, $qid, $chapter_id, $sub_domain_id, $test_id, $login_id) { $db = \Config\Database::connect(); // Load the database connection $query1 = $db->table('question_mapping A') ->join('faculty_mocktest_setting B', 'B.sub_domain_id = A.subject_id') ->where('A.chapter_id', $chapter_id) ->where('A.subject_id', $sub_domain_id) ->where('B.chapter', $chapter_id) ->where('A.test_id', $test_id) ->where('B.delete_status', 'ACTIVE') ->groupBy('A.test_id') ->orderBy('A.test_id', 'desc') ->get(); $res1 = $query1->getResult(); foreach ($res1 as $result1) { $initial_qid[] = $qid; $order_by = $result1->question_order; $s_id = $result1->subject_id; $question_id = json_decode($result1->question_id); $number_of_questions = $result1->number_of_questions; $query2 = $db->table('user_course_mapping A') ->where('A.mapping_id', $mapping_id) ->where('A.delete_status', 'ACTIVE') ->groupBy('A.user_id') ->get(); $res2 = $query2->getResult(); foreach ($res2 as $result2) { $fac_id = json_decode($result2->faculty_ids); if ($order_by == "desc") { $query3 = $db->table('questions') ->whereIn('questions.qid', $question_id) ->where('questions.qid <', $qid) ->whereNotIn('questions.qid', $initial_qid) ->where('questions.status', 'ACTIVE') ->whereIn('questions.faculty_id', $fac_id) ->orderBy('questions.qid', $order_by) ->get(); $next_question = $query3->getRow(); } elseif ($order_by == "asc") { $query4 = $db->table('questions') ->whereIn('questions.qid', $question_id) ->where('questions.qid >', $qid) ->whereNotIn('questions.qid', $initial_qid) ->where('questions.status', 'ACTIVE') ->whereIn('questions.faculty_id', $fac_id) ->orderBy('questions.qid', $order_by) ->get(); $next_question = $query4->getRow(); } else { $query5 = $db->table('questions') ->whereIn('questions.qid', $question_id) ->where('questions.qid >', $qid) ->whereNotIn('questions.qid', $initial_qid) ->where('questions.status', 'ACTIVE') ->whereIn('questions.faculty_id', $fac_id) ->get(); $next_question = $query5->getRow(); } $arr = []; if ($next_question) { $a['qid'] = $next_question->qid; $a['sub_domain_id'] = $next_question->sub_domain_id; $a['questions'] = $next_question->questions; $a['ans1'] = $next_question->ans1; $a['ans2'] = $next_question->ans2; $a['ans3'] = $next_question->ans3; $a['ans4'] = $next_question->ans4; $a['ans'] = $next_question->ans; $query6 = $db->table('answered_questions') ->where('answered_questions.answered_by', $login_id) ->where('answered_questions.question_id', $next_question->qid) ->where('answered_questions.test_id', $test_id) ->where('answered_questions.delete_status', 'ACTIVE') ->get(); $previous_question = $query6->getRow(); if ($previous_question) { $a['correct_answer'] = $previous_question->correct_answer; } else { $a['correct_answer'] = 0; } } return $a; } } } public function getWhereResult15($answerTable, $whereAnsweredQuestions) { return $this->db->table($answerTable) ->select('*') ->where($whereAnsweredQuestions) ->get() ->getResult(); } public function insertData23($answerTable, $data) { try { $builder = $this->db->table($answerTable); $builder->insert($data); $insertId = $this->db->insertID(); if (!$insertId) { // Log or report error if insert ID is not obtained error_log('Failed to get insert ID after inserting data into ' . $answerTable); } return $insertId; } catch (\Exception $e) { // Log or report any exceptions that occur during insertion error_log('Error inserting data into ' . $answerTable . ': ' . $e->getMessage()); return false; } } public function get_marked_chapter_questions($login_id, $test_id, $subject_id, $chapter_id) { $builder = $this->db->table('answered_questions A'); $builder->select('A.*, B.questions, B.ans1, B.ans2, B.ans3, B.ans4'); $builder->join('questions B', 'B.qid = A.question_id'); $builder->where('A.answered_by', $login_id); $builder->where('A.mark_for_later', 'YES'); $builder->where('A.test_type', 'chapter_wise'); $builder->where('A.test_id', $test_id); $builder->where('A.sub_domain_id', $subject_id); $builder->where('A.chapter_id', $chapter_id); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.status', 'ACTIVE'); return $builder->get()->getResult(); } public function mark_later_qus_chapter($test_id, $qid, $cid, $login_id, $sub_domain_id) { $builder = $this->db->table('questions'); $builder->select('*'); $builder->where('questions.qid', $qid); $builder->where('questions.chapter_id', $cid); $builder->where('questions.sub_domain_id', $sub_domain_id); $builder->where('questions.status', 'ACTIVE'); $query = $builder->get(); $mark_later_chapter = $query->getRow(); $arr = []; if ($mark_later_chapter) { $a['qid'] = $mark_later_chapter->qid; $a['sub_domain_id'] = $mark_later_chapter->sub_domain_id; $a['chapter_id'] = $mark_later_chapter->chapter_id; $a['questions'] = $mark_later_chapter->questions; $a['ans1'] = $mark_later_chapter->ans1; $a['ans2'] = $mark_later_chapter->ans2; $a['ans3'] = $mark_later_chapter->ans3; $a['ans4'] = $mark_later_chapter->ans4; $a['ans'] = $mark_later_chapter->ans; $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.answered_by', $login_id); $builder->where('answered_questions.question_id', $qid); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.test_type', 'chapter_wise'); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $previous_question = $query->getRow(); if ($previous_question) { $a['correct_answer'] = $previous_question->correct_answer; } else { $a['correct_answer'] = 0; } } return $a; } public function get_where_questions_chapters($question_ids, $test_ids, $chapter_id) { $builder = $this->db->table('answered_questions'); $builder->select('question_id'); $builder->where('test_id', $test_ids); $builder->where('delete_status', 'ACTIVE'); $query = $builder->get(); $total = $query->getResult(); $array = []; foreach ($total as $value) { $answered_qid = $value->question_id; array_push($array, $answered_qid); } $result = array_diff($question_ids, $array); return $result; } public function get_questions_for_practice_review($sub_domain_id, $quest_id, $test_id, $faculty_id) { $builder = $this->db->table('faculty_mocktest_setting A'); $builder->select('*'); $builder->where('A.created_by', $faculty_id); $builder->where('A.sub_domain_id', $sub_domain_id); $builder->where('A.test_type', 'Practice Test'); $builder->where('A.delete_status', 'ACTIVE'); $res = $builder->get()->getResult(); $res1 = []; foreach ($res as $key => $value) { $question_order = $value->question_order; if ($question_order == 'random') { $question_id = json_decode($quest_id); $arr = []; sort($question_id); $clength = 1; for ($x = 0; $x < $clength; $x++) { $question_ids = $question_id[$x]; array_push($arr, $question_id); } $check_question = $arr; $builder = $this->db->table('questions A'); $builder->select('*'); $builder->join('answered_questions B', 'B.sub_domain_id = A.sub_domain_id AND B.question_id = A.qid'); $builder->where('A.status', 'ACTIVE'); $builder->where('B.test_id', $test_id); $builder->whereIn('A.qid', $question_id); $builder->groupBy('A.qid'); $res1 = $builder->get()->getResult(); } elseif ($question_order == 'asc') { $question_id = json_decode($quest_id); $arr = []; asort($question_id); $clength = 1; for ($x = 0; $x < $clength; $x++) { $question_ids = $question_id[$x]; array_push($arr, $question_id); } $builder = $this->db->table('questions A'); $builder->select('*'); $builder->join('answered_questions B', 'B.sub_domain_id = A.sub_domain_id AND B.question_id = A.qid'); $builder->where('A.status', 'ACTIVE'); $builder->where('B.test_id', $test_id); $builder->whereIn('A.qid', $question_id); $builder->groupBy('A.qid'); $res1 = $builder->get()->getResult(); } else { $question_id = json_decode($quest_id); $arr = []; rsort($question_id); $clength = 1; for ($x = 0; $x < $clength; $x++) { $question_ids = $question_id[$x]; array_push($arr, $question_id); } $builder = $this->db->table('questions A'); $builder->select('*'); $builder->join('answered_questions B', 'B.sub_domain_id = A.sub_domain_id AND B.question_id = A.qid'); $builder->where('A.status', 'ACTIVE'); $builder->where('B.test_id', $test_id); $builder->whereIn('A.qid', $question_id); $builder->groupBy('A.qid'); $builder->orderBy('A.qid', 'desc'); $res1 = $builder->get()->getResult(); } } return $res1; } public function get_where_row11($loginTable, $where) { return $this->db->table($loginTable) ->select('*') ->where($where) ->get() ->getRow(); } public function updateData22($whereId, $loginTable, $updateData) { $builder = $this->db->table($loginTable); $builder->where($whereId); return $builder->update($updateData); } public function updateData15($login_table, $update_id, $where_id) { $builder = $this->db->table($login_table); $builder->where($where_id); return $builder->update($update_id); } public function insert11($answer_table,$answer_data) { $db = db_connect(); $db->table($answer_table)->insert($answer_data); return $db->insertID(); } public function insert1($login_table, $login_data) { $db = db_connect(); $db->table($login_table)->insert($login_data); return $db->insertID(); } public function insert2($domain_table, $damain_data) { $db = db_connect(); $db->table($domain_table)->insert($damain_data); return $db->insertID(); } public function insert3($sub_domain_table, $sub_damain_data) { $db = db_connect(); $db->table($sub_domain_table)->insert($sub_damain_data); return $db->insertID(); } public function insert4($subDomainTable, $subDomainData) { $db = db_connect(); $db->table($subDomainTable)->insert($subDomainData); return $db->insertID(); } public function insert5($faculty_table, $faculty_data) { $db = db_connect(); $db->table($faculty_table)->insert($faculty_data); return $db->insertID(); } public function insert6($maping_table, $maping_data) { $db = db_connect(); $db->table($maping_table)->insert($maping_data); return $db->insertID(); } public function insert7($timing_table, $timing_data) { $db = db_connect(); $db->table($timing_table)->insert($timing_data); return $db->insertID(); } public function insert8($notification_table, $notification_data) { $db = db_connect(); $db->table($notification_table)->insert($notification_data); return $db->insertID(); } public function insert9($feedback_table, $data) { $db = db_connect(); $db->table($feedback_table)->insert($data); return $db->insertID(); } public function getWhereOrderByRow1($loginTable, $whereEmail, $orderBy) { return $this->db->table($loginTable) ->select('*') ->where($whereEmail) ->orderBy($orderBy, 'DESC') ->get() ->getRow(); } public function next_question_subject_wise($mapping_id, $qid, $sub_domain_id, $test_id, $login_id, $question_number) { $query1 = $this->db->table('question_mapping A') ->join('faculty_mocktest_setting B', 'B.sub_domain_id = A.subject_id AND B.mocktest_id = A.mocktest_id') ->where('A.chapter_id', '0') ->where('B.chapter', '0') ->where('A.test_type', 'Mock Test') ->where('B.test_type', 'Mock Test') ->where('A.test_id', $test_id) ->groupBy('A.test_id') ->orderBy('A.test_id', 'desc') ->where('B.delete_status', 'ACTIVE') ->get(); $res1 = $query1->getResult(); foreach ($res1 as $result1) { $initial_qid[] = $qid; $order_by = $result1->question_order; $s_id = $result1->subject_id; $question_id = json_decode($result1->question_id); $number_of_questions = $result1->number_of_questions; $query2 = $this->db->table('user_course_mapping A') ->where('A.mapping_id', $mapping_id) ->where('A.delete_status', 'ACTIVE') ->groupBy('A.user_id') ->get(); $res2 = $query2->getResult(); foreach ($res2 as $result2) { $fac_id = json_decode($result2->faculty_ids); if ($order_by == "desc") { $query3 = $this->db->table('questions') ->whereIn('questions.qid', $question_id) ->where('questions.qid <', $qid) ->whereNotIn('questions.qid', $initial_qid) ->where('questions.status', 'ACTIVE') ->whereIn('questions.faculty_id', $fac_id) ->orderBy('questions.qid', $order_by) ->get(); $next_question = $query3->getRow(); $arr = []; if ($next_question) { $a['qid'] = $next_question->qid; $a['sub_domain_id'] = $next_question->sub_domain_id; $a['questions'] = $next_question->questions; $a['ans1'] = $next_question->ans1; $a['ans2'] = $next_question->ans2; $a['ans3'] = $next_question->ans3; $a['ans4'] = $next_question->ans4; $a['ans'] = $next_question->ans; $query4 = $this->db->table('answered_questions') ->where('answered_questions.answered_by', $login_id) ->where('answered_questions.question_id', $next_question->qid) ->where('answered_questions.test_id', $test_id) ->where('answered_questions.delete_status', 'ACTIVE') ->get(); $previous_question = $query4->getRow(); if ($previous_question) { $a['correct_answer'] = $previous_question->correct_answer; } else { $a['correct_answer'] = 0; } } return $a; } else if ($order_by == "asc") { $query5 = $this->db->table('questions') ->whereIn('questions.qid', $question_id) ->where('questions.qid >', $qid) ->whereNotIn('questions.qid', $initial_qid) ->where('questions.status', 'ACTIVE') ->whereIn('questions.faculty_id', $fac_id) ->orderBy('questions.qid', $order_by) ->get(); $next_question = $query5->getRow(); $arr = []; if ($next_question) { $a['qid'] = $next_question->qid; $a['sub_domain_id'] = $next_question->sub_domain_id; $a['questions'] = $next_question->questions; $a['ans1'] = $next_question->ans1; $a['ans2'] = $next_question->ans2; $a['ans3'] = $next_question->ans3; $a['ans4'] = $next_question->ans4; $a['ans'] = $next_question->ans; $query6 = $this->db->table('answered_questions') ->where('answered_questions.answered_by', $login_id) ->where('answered_questions.question_id', $next_question->qid) ->where('answered_questions.test_id', $test_id) ->where('answered_questions.delete_status', 'ACTIVE') ->get(); $previous_question = $query6->getRow(); if ($previous_question) { $a['correct_answer'] = $previous_question->correct_answer; } else { $a['correct_answer'] = 0; } } return $a; } else { $query7 = $this->db->table('questions') ->whereIn('questions.qid', $question_id) ->where('questions.qid >', $qid) ->whereNotIn('questions.qid', $initial_qid) ->where('questions.status', 'ACTIVE') ->whereIn('questions.faculty_id', $fac_id) ->get(); $next_question = $query7->getRow(); $arr = []; if ($next_question) { $a['qid'] = $next_question->qid; $a['sub_domain_id'] = $next_question->sub_domain_id; $a['questions'] = $next_question->questions; $a['ans1'] = $next_question->ans1; $a['ans2'] = $next_question->ans2; $a['ans3'] = $next_question->ans3; $a['ans4'] = $next_question->ans4; $a['ans'] = $next_question->ans; $query8 = $this->db->table('answered_questions') ->where('answered_questions.answered_by', $login_id) ->where('answered_questions.question_id', $next_question->qid) ->where('answered_questions.test_id', $test_id) ->where('answered_questions.delete_status', 'ACTIVE') ->get(); $previous_question = $query8->getRow(); if ($previous_question) { $a['correct_answer'] = $previous_question->correct_answer; } else { $a['correct_answer'] = 0; } } return $a; } } } } public function previous_question_subject_wise($mapping_id, $test_id, $qid, $sub_domain_id, $login_id) { $builder = $this->db->table('question_mapping A'); $builder->select('*'); $builder->join('faculty_mocktest_setting B', 'B.sub_domain_id = A.subject_id AND B.mocktest_id = A.mocktest_id'); $builder->where('A.chapter_id', '0'); $builder->where('B.chapter', '0'); $builder->where('A.test_id', $test_id); $builder->where('A.test_type', 'Mock Test'); $builder->where('B.test_type', 'Mock Test'); $builder->where('B.delete_status', 'ACTIVE'); $builder->orderBy('A.test_id', 'desc'); $builder->groupBy('A.test_id'); $query1 = $builder->get(); $res1 = $query1->getResult(); foreach ($res1 as $result1) { $initial_qid[] = $qid; $order_by = $result1->question_order; $s_id = $result1->subject_id; $question_id = json_decode($result1->question_id); $number_of_questions = $result1->number_of_questions; $builder = $this->db->table('user_course_mapping A'); $builder->select('*'); $builder->where('A.mapping_id', $mapping_id); $builder->where('A.delete_status', 'ACTIVE'); $builder->groupBy('A.user_id'); $query = $builder->get(); $res2 = $query->getResult(); foreach ($res2 as $result2) { $fac_id = json_decode($result2->faculty_ids); if ($order_by == 'desc') { $builder = $this->db->table('questions'); $builder->select('*'); $builder->whereIn('questions.qid', $question_id); $builder->where('questions.qid >', $qid); $builder->whereNotIn('questions.qid', $initial_qid); $builder->where('questions.sub_domain_id', $sub_domain_id); $builder->where('questions.status', 'ACTIVE'); $builder->whereIn('questions.faculty_id', $fac_id); $builder->orderBy('questions.qid', 'asc'); $query = $builder->get(); $previous_question = $query->getRow(); $arr = []; if ($previous_question) { $a['qid'] = $previous_question->qid; $a['sub_domain_id'] = $previous_question->sub_domain_id; $a['chapter_id'] = $previous_question->chapter_id; $a['questions'] = $previous_question->questions; $a['ans1'] = $previous_question->ans1; $a['ans2'] = $previous_question->ans2; $a['ans3'] = $previous_question->ans3; $a['ans4'] = $previous_question->ans4; $a['ans'] = $previous_question->ans; $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.answered_by', $login_id); $builder->where('answered_questions.question_id', $previous_question->qid); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $previous_questions = $query->getRow(); if ($previous_questions) { $a['correct_answer'] = $previous_questions->correct_answer; } else { $a['correct_answer'] = 0; } } return $a; } elseif ($order_by == 'asc') { $builder = $this->db->table('questions'); $builder->select('*'); $builder->whereIn('questions.qid', $question_id); $builder->whereNotIn('questions.qid', $initial_qid); $builder->where('questions.qid <', $qid); $builder->where('questions.sub_domain_id', $sub_domain_id); $builder->where('questions.status', 'ACTIVE'); $builder->whereIn('questions.faculty_id', $fac_id); $builder->orderBy('questions.qid', 'desc'); $query = $builder->get(); $previous_question = $query->getRow(); $arr = []; if ($previous_question) { $a['qid'] = $previous_question->qid; $a['sub_domain_id'] = $previous_question->sub_domain_id; $a['chapter_id'] = $previous_question->chapter_id; $a['questions'] = $previous_question->questions; $a['ans1'] = $previous_question->ans1; $a['ans2'] = $previous_question->ans2; $a['ans3'] = $previous_question->ans3; $a['ans4'] = $previous_question->ans4; $a['ans'] = $previous_question->ans; $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.answered_by', $login_id); $builder->where('answered_questions.question_id', $previous_question->qid); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $previous_questions = $query->getRow(); if ($previous_questions) { $a['correct_answer'] = $previous_questions->correct_answer; } else { $a['correct_answer'] = 0; } } return $a; } else { $builder = $this->db->table('questions'); $builder->select('*'); $builder->whereIn('questions.qid', $question_id); $builder->where('questions.qid <', $qid); $builder->whereNotIn('questions.qid', $initial_qid); $builder->where('questions.sub_domain_id', $sub_domain_id); $builder->where('questions.status', 'ACTIVE'); $builder->whereIn('questions.faculty_id', $fac_id); $builder->orderBy('questions.qid', 'desc'); $query = $builder->get(); $previous_question = $query->getRow(); $arr = []; if ($previous_question) { $a['qid'] = $previous_question->qid; $a['sub_domain_id'] = $previous_question->sub_domain_id; $a['chapter_id'] = $previous_question->chapter_id; $a['questions'] = $previous_question->questions; $a['ans1'] = $previous_question->ans1; $a['ans2'] = $previous_question->ans2; $a['ans3'] = $previous_question->ans3; $a['ans4'] = $previous_question->ans4; $a['ans'] = $previous_question->ans; $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.answered_by', $login_id); $builder->where('answered_questions.question_id', $previous_question->qid); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $previous_questions = $query->getRow(); if ($previous_questions) { $a['correct_answer'] = $previous_questions->correct_answer; } else { $a['correct_answer'] = 0; } } return $a; } } } } public function mark_later_qus_subject($test_id, $login_id, $qid, $sub_domain_id) { $builder = $this->db->table('questions'); $builder->select('*'); $builder->where('questions.qid', $qid); $builder->where('questions.sub_domain_id', $sub_domain_id); $builder->where('questions.status', 'ACTIVE'); $mark_later_subject = $builder->get()->getRow(); $arr = []; if ($mark_later_subject) { $a['qid'] = $mark_later_subject->qid; $a['sub_domain_id'] = $mark_later_subject->sub_domain_id; $a['chapter_id'] = $mark_later_subject->chapter_id; $a['questions'] = $mark_later_subject->questions; $a['ans1'] = $mark_later_subject->ans1; $a['ans2'] = $mark_later_subject->ans2; $a['ans3'] = $mark_later_subject->ans3; $a['ans4'] = $mark_later_subject->ans4; $a['ans'] = $mark_later_subject->ans; $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.answered_by', $login_id); $builder->where('answered_questions.question_id', $qid); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.test_type', 'subject_wise'); $builder->where('answered_questions.delete_status', 'ACTIVE'); $previous_question = $builder->get()->getRow(); if ($previous_question) { $a['correct_answer'] = $previous_question->correct_answer; } else { $a['correct_answer'] = 0; } } return $a; } public function getQuestionsForPracticeReview($sub_domain_id, $quest_id, $test_id, $faculty_id) { $builder = $this->db->table('faculty_mocktest_setting A'); $builder->select('*'); $builder->where('A.created_by', $faculty_id); $builder->where('A.sub_domain_id', $sub_domain_id); $builder->where('A.test_type', 'Practice Test'); $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); $res = $query->getResult(); $resultArray = []; foreach ($res as $value) { $question_order = $value->question_order; if ($question_order == 'random') { $question_id = json_decode($quest_id); $arr = []; sort($question_id); $clength = 1; for ($x = 0; $x < $clength; $x++) { $question_ids = $question_id[$x]; array_push($arr, $question_id); } $check_question = $arr; $builder = $this->db->table('questions A'); $builder->select('*'); $builder->join('answered_questions B', 'B.sub_domain_id = A.sub_domain_id AND B.question_id = A.qid'); $builder->where('A.status', 'ACTIVE'); $builder->whereIn('A.qid', $question_id); $builder->where('B.test_id', $test_id); $builder->groupBy('A.qid'); $query = $builder->get(); $res1 = $query->getResult(); } elseif ($question_order == 'asc') { $question_id = json_decode($quest_id); $arr = []; asort($question_id); $clength = 1; for ($x = 0; $x < $clength; $x++) { $question_ids = $question_id[$x]; array_push($arr, $question_id); } $builder = $this->db->table('questions A'); $builder->select('*'); $builder->join('answered_questions B', 'B.sub_domain_id = A.sub_domain_id AND B.question_id = A.qid'); $builder->where('A.status', 'ACTIVE'); $builder->whereIn('A.qid', $question_id); $builder->where('B.test_id', $test_id); $builder->groupBy('A.qid'); $query = $builder->get(); $res1 = $query->getResult(); } else { $question_id = json_decode($quest_id); $arr = []; rsort($question_id); $clength = 1; for ($x = 0; $x < $clength; $x++) { $question_ids = $question_id[$x]; array_push($arr, $question_id); } $builder = $this->db->table('questions A'); $builder->select('*'); $builder->join('answered_questions B', 'B.sub_domain_id = A.sub_domain_id AND B.question_id = A.qid'); $builder->where('A.status', 'ACTIVE'); $builder->whereIn('A.qid', $question_id); $builder->where('B.test_id', $test_id); $builder->groupBy('A.qid'); $builder->orderBy('A.qid', 'desc'); $query = $builder->get(); $res1 = $query->getResult(); } $resultArray = array_merge($resultArray, $res1); } return $resultArray; } public function get_where_in1($sub_domain_table, $where) { $builder = $this->db->table($sub_domain_table); $builder->select('*'); foreach ($where as $column => $values) { // Make sure $values is an array before using whereIn if (is_array($values)) { $builder->whereIn($column, $values); } else { // Handle the case where $values is not an array (optional) // You might want to throw an exception or handle it differently // based on your application logic. } } $query = $builder->get(); return $query->getRow(); } public function get_where_result26($question_table, $where_chapter) { $builder = $this->db->table($question_table); $builder->select('*'); $builder->where($where_chapter); $query = $builder->get(); return $query->getResult(); } public function getMarkedQuestions($loginId, $testId, $subjectId) { $builder = $this->db->table('answered_questions A'); $builder->select('A.*, B.questions, B.ans1, B.ans2, B.ans3, B.ans4'); $builder->join('questions B', 'B.qid = A.question_id'); $builder->where('A.answered_by', $loginId); $builder->where('A.mark_for_later', 'YES'); $builder->where('A.test_type', 'subject_wise'); $builder->where('A.test_id', $testId); $builder->where('A.sub_domain_id', $subjectId); $builder->where('A.chapter_id', '0'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.status', 'ACTIVE'); return $builder->get()->getResult(); } public function get_questions_for_finals_review($sub_domain_id, $quest_id, $test_id, $faculty_id) { $builder = $this->db->table('faculty_mocktest_setting A'); $builder->select('*'); $builder->where('A.created_by', $faculty_id); $builder->where('A.sub_domain_id', $sub_domain_id); $builder->where('A.test_type', 'Final Test'); $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); $res = $query->getResult(); foreach ($res as $key => $value) { $question_order = $value->question_order; if ($question_order == 'random') { $question_id = json_decode($quest_id); $arr = array(); sort($question_id); $clength = 1; for ($x = 0; $x < $clength; $x++) { $question_ids = $question_id[$x]; array_push($arr, $question_id); } $check_question = $arr; $builder = $this->db->table('questions A'); $builder->select('*'); $builder->join('answered_questions B', 'B.sub_domain_id = A.sub_domain_id AND B.question_id = A.qid'); $builder->where('A.status', 'ACTIVE'); $builder->where('B.test_id', $test_id); $builder->whereIn('A.qid', $question_id); $builder->groupBy('A.qid'); $query = $builder->get(); $res1 = $query->getResult(); } elseif ($question_order == 'asc') { $question_id = json_decode($quest_id); $arr = array(); asort($question_id); $clength = 1; for ($x = 0; $x < $clength; $x++) { $question_ids = $question_id[$x]; array_push($arr, $question_id); } $builder = $this->db->table('questions A'); $builder->select('*'); $builder->join('answered_questions B', 'B.sub_domain_id = A.sub_domain_id AND B.question_id = A.qid'); $builder->where('A.status', 'ACTIVE'); $builder->where('B.test_id', $test_id); $builder->whereIn('A.qid', $question_id); $builder->groupBy('A.qid'); $query = $builder->get(); $res1 = $query->getResult(); } else { $question_id = json_decode($quest_id); $arr = array(); rsort($question_id); $clength = 1; for ($x = 0; $x < $clength; $x++) { $question_ids = $question_id[$x]; array_push($arr, $question_id); } $builder = $this->db->table('questions A'); $builder->select('*'); $builder->join('answered_questions B', 'B.sub_domain_id = A.sub_domain_id AND B.question_id = A.qid'); $builder->where('A.status', 'ACTIVE'); $builder->where('B.test_id', $test_id); $builder->whereIn('A.qid', $question_id); $builder->groupBy('A.qid'); $builder->orderBy('A.qid', 'desc'); $query = $builder->get(); $res1 = $query->getResult(); } } return $res1; } public function get_questions_for_finals_review1($sub_domain_id, $quest_id, $test_id, $faculty_id) { $res1 = []; // Initialize $res1 outside the loop $builder = $this->db->table('faculty_mocktest_setting A'); $builder->select('*'); $builder->where('A.created_by', $faculty_id); $builder->where('A.sub_domain_id', $sub_domain_id); $builder->where('A.test_type', 'Final Test'); $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); $res = $query->getResult(); foreach ($res as $key => $value) { $question_order = $value->question_order; if ($question_order == 'random') { $question_id = json_decode($quest_id); $arr = array(); sort($question_id); $clength = 1; for ($x = 0; $x < $clength; $x++) { $question_ids = $question_id[$x]; array_push($arr, $question_id); } $check_question = $arr; $builder = $this->db->table('questions A'); $builder->select('*'); $builder->join('answered_questions B', 'B.sub_domain_id = A.sub_domain_id AND B.question_id = A.qid'); $builder->where('A.status', 'ACTIVE'); $builder->where('B.test_id', $test_id); $builder->whereIn('A.qid', $question_id); $builder->groupBy('A.qid'); $query = $builder->get(); $res1 = $query->getResult(); } elseif ($question_order == 'asc') { $question_id = json_decode($quest_id); $arr = array(); asort($question_id); $clength = 1; for ($x = 0; $x < $clength; $x++) { $question_ids = $question_id[$x]; array_push($arr, $question_id); } $builder = $this->db->table('questions A'); $builder->select('*'); $builder->join('answered_questions B', 'B.sub_domain_id = A.sub_domain_id AND B.question_id = A.qid'); $builder->where('A.status', 'ACTIVE'); $builder->where('B.test_id', $test_id); $builder->whereIn('A.qid', $question_id); $builder->groupBy('A.qid'); $query = $builder->get(); $res1 = $query->getResult(); } else { $question_id = json_decode($quest_id); $arr = array(); rsort($question_id); $clength = 1; for ($x = 0; $x < $clength; $x++) { $question_ids = $question_id[$x]; array_push($arr, $question_id); } $builder = $this->db->table('questions A'); $builder->select('*'); $builder->join('answered_questions B', 'B.sub_domain_id = A.sub_domain_id AND B.question_id = A.qid'); $builder->where('A.status', 'ACTIVE'); $builder->where('B.test_id', $test_id); $builder->whereIn('A.qid', $question_id); $builder->groupBy('A.qid'); $builder->orderBy('A.qid', 'desc'); $query = $builder->get(); $res1 = $query->getResult(); } } return $res1; } public function subject_wise_correct_answer($sub_domain_id, $login_id, $test_id) { // Ensure $sub_domain_id is an array if (!is_array($sub_domain_id)) { $sub_domain_id = [$sub_domain_id]; } $builder = $this->db->table('questions'); $builder->select('*'); $builder->whereIn('questions.sub_domain_id', $sub_domain_id); $builder->where('questions.status', 'ACTIVE'); $query = $builder->get(); $questions = $query->getResult(); $arr = []; foreach ($questions as $key => $value) { $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.answered_by', $login_id); $builder->where('answered_questions.question_id', $value->qid); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.correct_answer', $value->ans); $builder->where('answered_questions.correct_answer !=', '0'); // $builder->where('answered_questions.mark_for_later', 'NO'); // $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $correct_answer = $query->getRow(); if (!empty($correct_answer)) { array_push($arr, $correct_answer->answer_id); } } return count($arr); } public function subject_wise_incorrect_answer($sub_domain_id, $login_id, $test_id) { $builder = $this->db->table('questions'); $builder->select('*'); $builder->where('questions.sub_domain_id', $sub_domain_id); $builder->where('questions.status', 'ACTIVE'); $query = $builder->get(); $questions = $query->getResult(); $arr = []; foreach ($questions as $key => $value) { $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.answered_by', $login_id); $builder->where('answered_questions.question_id', $value->qid); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.correct_answer !=', $value->ans); $builder->where('answered_questions.correct_answer !=', '0'); // $builder->where('answered_questions.mark_for_later', 'NO'); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $incorrect_answer = $query->getRow(); if (!empty($incorrect_answer)) { array_push($arr, $incorrect_answer->answer_id); } } return count($arr); } public function subject_wise_not_attempted_answer($sub_domain_id, $login_id, $test_id) { $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.correct_answer', '0'); // $builder->where('answered_questions.answered_by', $login_id); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.delete_status', 'ACTIVE'); // $builder->where('answered_questions.mark_for_later', 'NO'); $query = $builder->get(); $total = $query->getResult(); return count($total); } public function get_where_final_result_score($test_id, $login_id, $sub_domain_id) { if (!is_array($sub_domain_id)) { $sub_domain_id = [$sub_domain_id]; } $builder = $this->db->table('questions'); $builder->select('*'); $builder->whereIn('questions.sub_domain_id', $sub_domain_id); $builder->where('questions.status', 'ACTIVE'); $query = $builder->get(); $questions = $query->getResult(); $arr = []; foreach ($questions as $key => $value) { $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.answered_by', $login_id); $builder->where('answered_questions.question_id', $value->qid); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.correct_answer', $value->ans); $builder->where('answered_questions.correct_answer !=', '0'); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $correct_answer = $query->getRow(); if (!empty($correct_answer)) { array_push($arr, $correct_answer->answer_id); } } $finals_score = count($arr); return $finals_score; } public function getUserSubjectAnswer($user_id, $test_id, $qid, $sub_domain_id) { $builder = $this->db->table('answered_questions A'); $builder->select('*'); $builder->join('questions B', 'B.qid = A.question_id'); $builder->where('A.question_id', $qid); $builder->where('A.sub_domain_id', $sub_domain_id); $builder->where('A.answered_by', $user_id); $builder->where('A.test_id', $test_id); $builder->limit(1); $query = $builder->get(); return $query->getRow(); } public function finalTestIncorrectAnswer($sub_domain_id, $login_id, $test_id) { $builder = $this->db->table('questions'); $builder->select('*'); $builder->where('questions.sub_domain_id', $sub_domain_id); $builder->where('questions.status', 'ACTIVE'); $questionsQuery = $builder->get(); $questions = $questionsQuery->getResult(); $arr = []; foreach ($questions as $value) { $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.answered_by', $login_id); $builder->where('answered_questions.question_id', $value->qid); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.correct_answer !=', $value->ans); $builder->where('answered_questions.correct_answer !=', '0'); $builder->where('answered_questions.delete_status', 'ACTIVE'); $incorrectAnswerQuery = $builder->get(); $incorrectAnswer = $incorrectAnswerQuery->getRow(); if (!empty($incorrectAnswer)) { $arr[] = $incorrectAnswer->answer_id; } } return count($arr); } public function finalTestNotAttemptedAnswer($sub_domain_id, $login_id, $test_id) { $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('answered_questions.correct_answer', '0'); //$builder->where('answered_questions.answered_by', $login_id); $builder->where('answered_questions.test_id', $test_id); $builder->where('answered_questions.delete_status', 'ACTIVE'); $query = $builder->get(); $total = $query->getResult(); return count($total); } public function getQuestionsForFinalTestReview($sub_domain_id, $quest_id, $test_id, $faculty_id, $mocktest_id) { $login_id = session('user_login_id'); $builder = $this->db->table('faculty_mocktest_setting A'); $builder->select('*'); $builder->where('A.created_by', $faculty_id); $builder->where('A.sub_domain_id', $sub_domain_id); $builder->where('A.test_type', 'Final Test'); // $builder->where('A.mocktest_id', $mocktest_id); $builder->where('A.delete_status', 'ACTIVE'); $query = $builder->get(); $res = $query->getResult(); $res1 = []; foreach ($res as $key => $value) { $question_order = $value->question_order; if ($question_order == 'random') { $question_id = json_decode($quest_id); $arr = []; sort($question_id); $clength = 1; for ($x = 0; $x < $clength; $x++) { $question_ids = $question_id[$x]; array_push($arr, $question_id); } $check_question = $arr; $builder = $this->db->table('questions A'); $builder->select('*'); $builder->join('answered_questions B', 'B.sub_domain_id = A.sub_domain_id AND B.question_id = A.qid'); $builder->where('A.status', 'ACTIVE'); $builder->where('B.test_id', $test_id); $builder->whereIn('A.qid', $question_id); $builder->groupBy('A.qid'); $query = $builder->get(); $res1 = $query->getResult(); } elseif ($question_order == 'asc') { $question_id = json_decode($quest_id); $arr = []; asort($question_id); $clength = 1; for ($x = 0; $x < $clength; $x++) { $question_ids = $question_id[$x]; array_push($arr, $question_id); } $builder = $this->db->table('questions A'); $builder->select('*'); $builder->join('answered_questions B', 'B.sub_domain_id = A.sub_domain_id AND B.question_id = A.qid'); $builder->where('A.status', 'ACTIVE'); $builder->where('B.test_id', $test_id); $builder->whereIn('A.qid', $question_id); $builder->groupBy('A.qid'); $query = $builder->get(); $res1 = $query->getResult(); } else { $question_id = json_decode($quest_id); $arr = []; rsort($question_id); $clength = 1; for ($x = 0; $x < $clength; $x++) { $question_ids = $question_id[$x]; array_push($arr, $question_id); } $builder = $this->db->table('questions A'); $builder->select('*'); $builder->join('answered_questions B', 'B.sub_domain_id = A.sub_domain_id AND B.question_id = A.qid'); $builder->where('A.status', 'ACTIVE'); $builder->where('B.test_id', $test_id); $builder->whereIn('A.qid', $question_id); $builder->groupBy('A.qid'); $builder->orderBy('A.qid', 'desc'); $query = $builder->get(); $res1 = $query->getResult(); } } return $res1; } public function get_where_faculty($email, $password) { $builder = $this->db->table('login A'); $builder->select('A.*, B.*, C.*, A.user_type_id as faculty_user_type_id, A.institution_id as faculty_institution_id'); $builder->join('user_type B', 'B.user_type_id = A.user_type_id'); $builder->join('faculty_registration C', 'C.login_id = A.login_id'); $builder->where('A.email', $email); $builder->where('A.password', $password); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('A.user_type_id', '2'); $query = $builder->get(); return $query->getRow(); } public function correctAnswer($chapterId, $loginId, $testId) { $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->join('questions', 'questions.ans = answered_questions.correct_answer AND questions.qid = answered_questions.question_id'); $builder->where('questions.chapter_id', $chapterId); $builder->where('answered_questions.answered_by', $loginId); $builder->where('answered_questions.test_id', $testId); $builder->where('answered_questions.correct_answer !=', '0'); $query = $builder->get(); return $query->getNumRows(); } public function incorrectAnswer($chapterId, $loginId, $testId) { $questionsQuery = $this->db->table('questions') ->select('*') ->where('chapter_id', $chapterId) ->where('status', 'ACTIVE') ->get(); $questions = $questionsQuery->getResult(); $incorrectAnswers = []; foreach ($questions as $question) { $answeredQuery = $this->db->table('answered_questions') ->select('*') ->where('answered_by', $loginId) ->where('question_id', $question->qid) ->where('test_id', $testId) ->where('correct_answer !=', $question->ans) ->where('correct_answer !=', '0') ->where('delete_status', 'ACTIVE') ->get(); $incorrectAnswer = $answeredQuery->getRow(); if (!empty($incorrectAnswer)) { $incorrectAnswers[] = $incorrectAnswer->answer_id; } } return count($incorrectAnswers); } public function notAttemptedAnswer($chapterId, $loginId, $testId) { $builder = $this->db->table('answered_questions'); $builder->select('*'); $builder->where('correct_answer', '0'); // $builder->where('answered_by', $loginId); // Commented out as per your original code $builder->where('test_id', $testId); $builder->where('delete_status', 'ACTIVE'); // $builder->where('mark_for_later', 'NO'); // Commented out as per your original code $query = $builder->get(); $total = $query->getResult(); return count($total); } }