EVOLUTION-NINJA
Edit File: Courses_Model.php
<?php namespace App\Models\Admin; use CodeIgniter\Model; class Course_Model extends Model { protected $table = 'domains'; protected $primaryKey = 'id'; protected $allowedFields = ['domain_name', 'delete_status', 'created_by', 'user_type_id']; public function get_course_row($course_id) { return $this->select('A.*, B.*, A.course_type as c_type') ->from('courses A') ->join('course_available_timings B', 'A.course_id = B.course_id', 'left') ->where('A.course_id', $course_id) ->where('A.delete_status', 'ACTIVE') ->get() ->getRow(); } public function getActiveDomains($login_id, $user_type_id) { return $this->where('delete_status', 'ACTIVE') ->where('created_by', $login_id) ->where('user_type_id', $user_type_id) ->orderBy('domain_name', 'ASC') ->get(); // Use 'get' instead of 'findAll' } public function getCourseRow($course_id) { return $this->select('A.*, B.*, A.course_type as c_type') ->from('courses A') ->join('course_available_timings B', 'A.course_id = B.course_id', 'left') ->where('A.course_id', $course_id) ->where('A.delete_status', 'ACTIVE') ->get() ->getRow(); } public function getWhereCoursesTimings($course_id) { return $this->select('*') ->where('course_id', $course_id) ->where('delete_status', 'ACTIVE') ->get() ->getResult(); } public function get_where_courses_timings($course_id) { return $this->select('*') ->from('course_available_timings A') ->where('A.course_id', $course_id) ->where('A.delete_status', 'ACTIVE') ->get() ->getResult(); } public function updateData($where, $table, $data) { $builder = $this->db->table($table); $builder->where($where); return $builder->update($data); } public function customInsert($data) { return $this->insert($data); // Call the parent insert method } public function getWhereOrderBy($where, $order_by, $direction) { return $this->where($where)->orderBy($order_by, $direction)->findAll(); } public function getDomainData() { // Replace 'domain_id' and 'domain_name' with your actual column names $query = $this->select('domain_id, domain_name')->get(); return $query->getResult(); } public function get_all_course_list() { $builder = $this->db->table('courses A') ->select('A.*, B.domain_name') ->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'); $query = $builder->get(); $results = $query->getResultArray(); $array = array(); foreach ($results as $val) { $data['course_id'] = $val['course_id']; $data['course_title'] = $val['course_title']; $data['domain_name'] = $val['domain_name']; $sub_domains = json_decode($val['sub_domain_id']); $sub_domains = implode(',', $sub_domains); $sql = "SELECT sub_domain FROM sub_domains WHERE sub_domain_id IN ($sub_domains) AND delete_status='ACTIVE'"; $domain_query = $this->db->query($sql); $domain_results = $domain_query->getResultArray(); $domain_array = array(); foreach ($domain_results as $value) { array_push($domain_array, $value['sub_domain']); } $data['sub_domains'] = implode(',', $domain_array); $type_array = array(); foreach (json_decode($val['course_type']) as $type) { array_push($type_array, ucfirst($type)); } $data['course_type'] = implode(',', $type_array); $data['course_price'] = $val['course_price']; array_push($array, $data); } return $array; } public function getWhereRow($table, $where) { $builder = $this->db->table($table); $builder->select('*'); $builder->where($where); $query = $builder->get(); return $query->getRow(); } public function getWhereResult($table, $where) { $builder = $this->db->table($table); $builder->select('*'); $builder->where($where); $query = $builder->get(); return $query->getResult(); } public function update_Data($where, $table, $data) { $builder = $this->db->table($table); $builder->update($data, $where); return $builder->resultID->numRows ?? 0; } public function insert($data = null, bool $returnID = true) { // Check if $data is provided, and if not, use $this->data if ($data === null) { $data = $this->data; } // Insert data into the 'domains' table $builder = $this->db->table('courses'); $builder->insert($data); // Check if $returnID is true and return the last inserted ID if so if ($returnID) { return $this->db->insertID(); } return true; // Return true if insert was successful without returning ID } public function getWhereResultOrderByAsc($table, $where, $order_by) { $query = $this->db->table($table) ->select('*') ->where($where) ->orderBy($order_by, 'ASC') ->get(); return $query->getResult(); } // public function getCourseImage($course_id) // { // // Replace 'courses' with your actual table name and 'course_image' with the actual column name where you store the course image. // return $this->table('courses')->where('course_id', $course_id)->select('course_image')->get()->getRow()->course_image; // } // public function getCourseImage($course_id) // { // // Replace 'courses' with your actual table name and 'course_image' with the actual column name where you store the course image. // return $this->table('courses')->select('course_image')->find($course_id); // } public function getCourseImage($course_id) { try { $result = $this->table('courses')->select('course_image')->find($course_id); if ($result) { return $result->course_image; } else { // Handle the case where the course with the given ID is not found. return null; } } catch (\Exception $e) { // Handle any database query errors here. log_message('error', 'Database error: ' . $e->getMessage()); return null; } } public function getCourseDemoVideo($course_id) { // Simulated data for demonstration purposes $courseDemoVideos = [ 1 => 'video1.mp4', 2 => 'video2.mp4', ]; // Check if the course ID exists in the simulated data if (isset($courseDemoVideos[$course_id])) { // Return the video file name or path return $courseDemoVideos[$course_id]; } else { // Return null or an appropriate value if the video is not found return null; } } public function getCourseDetails($course_id) { // Retrieve course details from the database based on $course_id // Example code: return $this->find($course_id); } }