EVOLUTION-NINJA
Edit File: Batch_Model.php
<?php namespace App\Models\Admin; use CodeIgniter\Model; class Batch_Model extends Model { protected $table = 'batches'; protected $primaryKey = 'batch_id'; protected $returnType = 'array'; protected $allowedFields = [ 'batch_id', 'domain_id', 'sub_domain_id', 'faculty_id', 'batch_size', 'from_time', 'batch_name', 'course_type', 'batch_type', 'batch_from_date', 'batch_to_date', 'batch_approval_status', 'batch_status', 'batch_duration', 'created_by', // Add other fields here... ]; public function get_all_faculty_added_batches() { $builder = $this->db->table('batches A'); $builder->select('A.*, B.domain_name, C.sub_domain, D.fullname as faculty_name, E.username as created_by'); $builder->join('domains B', 'B.domain_id = A.domain_id'); $builder->join('sub_domains C', 'C.sub_domain_id = A.sub_domain_id'); $builder->join('faculty_registration D', 'D.login_id = A.faculty_id', 'left'); $builder->join('login E', 'E.login_id = A.created_by'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('A.created_by !=', '1'); $builder->where('A.institution_id', 0); $results = $builder->get()->getResultArray(); foreach ($results as &$result) { if ($result['batch_from_date'] && $result['batch_to_date']) { $result['batch_from_to_date'] = $result['batch_from_date'] . ' to ' . $result['batch_to_date']; } else { $result['batch_from_to_date'] = ''; } if ($result['batch_status'] == 'IN_PROGRESS') { $result['batch_status'] = 'IN PROGRESS'; } elseif ($result['batch_status'] == 'COMPLETED') { $result['batch_status'] = 'COMPLETED'; } else { $result['batch_status'] = 'NOT YET STARTED'; } } return $results; } public function updateData($where, $table, $data) { $builder = $this->db->table($table); $builder->where($where); return $builder->update($data); } public function checkBatch($batchId) { if (empty($batchId)) { return []; // Return an empty array or handle the error accordingly } $whereBatchIds = [ 'enroll_status' => 'ENROLLED', 'payment_status' => 'PAID', 'delete_status' => 'ACTIVE', ]; return $this->select('*') ->from('user_course_mapping') ->like('batch_ids', $batchId) ->where($whereBatchIds) ->get() ->getResult(); } // public function deleteBatch($batchId) // { // $this->where('batch_id', $batchId) // ->set(['delete_status' => 'INACTIVE']) // ->update(); // return $this->db->affectedRows() > 0; // } public function deleteBatch($batchId) { // Check if the record with the specified batch_id exists if ($this->find($batchId)) { $this->where('batch_id', $batchId) ->set(['delete_status' => 'INACTIVE']) ->update($data); return $this->db->affectedRows() > 0; } else { // Record with the specified batch_id does not exist return false; } } public function getWhereRow($table, $where) { $builder = $this->db->table($table); $builder->select('*'); $builder->where($where); $query = $builder->get(); return $query->getRow(); } public function insertData($table, $data) { $builder = $this->db->table($table); $builder->insert($data); return $this->db->insertID(); } public function getWhereResultOrderByAsc($table, $where, $orderBy) { $builder = $this->db->table($table); $builder->select('*'); $builder->where($where); $builder->orderBy($orderBy, 'ASC'); $query = $builder->get(); return $query->getResult(); } public function getWhereOrderByRow($table, $where, $orderBy) { $builder = $this->db->table($table); $builder->select('*'); $builder->where($where); $builder->orderBy($orderBy, 'DESC'); return $builder->get()->getRow(); } }