<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Sickbay_Model extends MY_Model
{


    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    // view operation

         public function delete_sickbay_record($id) {
            // Assuming 'canteen_records' is your database table name
            // echo "$id";
            $this->db->where('id', $id);
            $this->db->delete('sickbay');
        }

    public function get_sickbay_list($school_id = null)
    {
        

        
        $this->db->select('Sb.*, S.school_name, C.name AS class_name,Sc.name As section,A.name As attendant');
        $this->db->from('sickbay AS Sb');
        $this->db->join('schools AS S', 'S.id = Sb.school_id', 'left');
        $this->db->join('classes AS C', 'C.id = Sb.class', 'left');
        $this->db->join('sections AS Sc', 'Sc.id = Sb.section', 'left');
        $this->db->join('employees AS A', 'Sb.attendant = A.id', 'left');

        if ($this->session->userdata('role_id') == SUPER_ADMIN && $school_id) {
            $this->db->where('Sb.school_id', $school_id);
        }
        if ($this->session->userdata('role_id') != SUPER_ADMIN) {
            $this->db->where('Sb.school_id', $this->session->userdata('school_id'));
        }

        $this->db->where('S.status', 1);
        $this->db->order_by('Sb.id', 'DESC');
        return $this->db->get()->result();
    }
}
