EVOLUTION-NINJA
Edit File: Chapter_material.php
<?php namespace App\Models; use CodeIgniter\Model; class Chapter_material extends Model { protected $table = 'subject_materials'; protected $primaryKey = 'material_id'; protected $allowedFields = ['*']; // public function get_chapter_material($topic_id, $mapping_id) // { // $session = session(); // $institution_id = $session->get('user_institution_id'); // $chapter = $this->select('*') // ->from('subject_materials A') // ->where('A.delete_status', 'ACTIVE') // ->where('A.topic_id', $topic_id) // ->where('A.approval_status', 'APPROVED') // ->get() // ->getResult(); // $mapping = $this->select('*') // ->from('user_course_mapping A') // ->where('A.delete_status', 'ACTIVE') // ->where('A.mapping_id', $mapping_id) // ->get() // ->getRow(); // if ($mapping && is_object($mapping)) { // $i = 0; // if ($institution_id == 0) { // if (!empty($mapping->faculty_ids)) { // $faculty_ids = json_decode($mapping->faculty_ids); // } else { // $batch_ids = json_decode($mapping->batch_ids); // $batches = $this->select('faculty_id') // ->from('batches A') // ->whereIn('A.batch_id', $batch_ids) // ->where('A.delete_status', 'ACTIVE') // ->get() // ->getResult(); // $faculty_ids = array_column($batches, 'faculty_id'); // } // } else { // $faculty_ids = [$institution_id]; // } // foreach ($faculty_ids as $value) { // foreach ($chapter as $chapters) { // if ($value == $chapters->created_by) { // $i++; // } // } // } // return ($i > 0) ? 1 : 0; // } else { // return 0; // } // } public function get_chapter_material($topic_id, $mapping_id) { $institution_id = session()->get('user_institution_id'); $db = \Config\Database::connect(); // Get the database connection instance $query = $db->table('subject_materials A') ->select('*') ->where('A.delete_status', 'ACTIVE') ->where('A.topic_id', $topic_id) ->where('A.approval_status', 'APPROVED') ->get(); $chapter = $query->getResult(); $query = $db->table('user_course_mapping A') ->select('*') ->where('A.delete_status', 'ACTIVE') ->where('A.mapping_id', $mapping_id) ->get(); $mapping_id_row = $query->getRow(); if (!empty($chapter)) { $i = 0; if ($institution_id == 0) { if (!empty($mapping_id_row->faculty_ids)) { $faculty_ids = json_decode($mapping_id_row->faculty_ids); } else { $batch_ids = json_decode($mapping_id_row->batch_ids); $query = $db->table('batches A') ->select('*') ->whereIn('A.batch_id', $batch_ids) ->where('A.delete_status', 'ACTIVE') ->get(); $result = $query->getResult(); $faculty_ids = []; foreach ($result as $batches) { array_push($faculty_ids, $batches->faculty_id); } } } else { $faculty_ids = [$institution_id]; } foreach ($faculty_ids as $value) { foreach ($chapter as $chapters) { if ($value == $chapters->created_by) { $i++; } } } return ($i > 0) ? 1 : 0; } else { return 0; } } }