<commit_before><?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Queries extends CI_Model {

    /*
    | -------------------------------------------------------------------
    |  Essentials
    | -------------------------------------------------------------------
    */

    public function get_single_user_information($user_id) {
        $query = $this->db->get_where('booking_users', array('id' => $user_id));
        return $query->row_array();
    }

    public function get_specific_user_group($access_level) {
        $query = $this->db->get_where('booking_users', array('access_level' => $access_level));
        return $query->result_array();
    }

    /*
    | -------------------------------------------------------------------
    |  Dashboard
    | -------------------------------------------------------------------
    */

    public function get_users_count($type = FALSE) {
        if ($type === FALSE) {
            $query = $this->db->query("SELECT * FROM `booking_users`");
            return $query->num_rows();
        } else {
            $query = $this->db->get_where('booking_users', array('access_level' => $type));
            return $query->num_rows();
        }
        
    }

    public function all_bookings_count() {
        $query = $this->db->query("SELECT * FROM `booking_sessions`");
        return $query->num_rows();
    }

    /*
    | -------------------------------------------------------------------
    |  Bookings
    | -------------------------------------------------------------------
    */

    public function all_bookings($access_level, $user_id) {
        if ($access_level == 1 || $access_level == 3) {
            $query = $this->db->query("SELECT * FROM `booking_sessions`");
            return $query->result_array();
        }
        elseif ($access_level == 2) {
            $query = $this->db->get_where('booking_sessions', array('instructor_id' => $user_id));
            return $query->result_array();
        }
        elseif ($access_level == 4) {
            $query = $this->db->get_where('booking_sessions', array('booked_by' => $user_id));
            return $query->result_array();
        }
    }

    public function get_booking_types() {
        $query = $this->db->query("SELECT * FROM `booking_types`");
        return $query->result_array();
    }

    public function create_booking($booking_date, $booked_by, $instructor_id, $booking_type) {
        $sql = "INSERT INTO `booking_sessions` (id, session_date, booked_by, instructor_id, status, booking_type)
                VALUES ('', ?, ?, ?, 0, ?)";
        $this->db->query($sql, array($booking_date, $booked_by, $instructor_id, $booking_type));
    }

    public function check_for_active_session($user_id) {
        // where status is 0
        $query = $this->db->get_where('booking_sessions', array('booked_by' => $user_id, 'status' => 0));
        return $query->num_rows();
    }

    /*
    | -------------------------------------------------------------------
    |  Members
    | -------------------------------------------------------------------
    */

    public function all_users($user_id = false) {
        if ($user_id === false) {
            $query = $this->db->query('SELECT * FROM `booking_users`');
            return $query->result_array();
        } else {
            $query = $this->db->get_where('booking_users', array('id' => $user_id));
            return $query->row_array();
        }
    }

    /*
    | -------------------------------------------------------------------<commit_msg>Updated queries<commit_after><?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Queries extends CI_Model {

    /*
    | -------------------------------------------------------------------
    |  Essentials
    | -------------------------------------------------------------------
    */

    public function get_single_user_information($user_id) {
        $query = $this->db->get_where('booking_users', array('id' => $user_id));
        return $query->row_array();
    }

    public function get_specific_user_group($access_level) {
        $query = $this->db->get_where('booking_users', array('access_level' => $access_level));
        return $query->result_array();
    }

    /*
    | -------------------------------------------------------------------
    |  Dashboard
    | -------------------------------------------------------------------
    */

    public function get_users_count($type = FALSE) {
        if ($type === FALSE) {
            $query = $this->db->query("SELECT * FROM `booking_users`");
            return $query->num_rows();
        } else {
            $query = $this->db->get_where('booking_users', array('access_level' => $type));
            return $query->num_rows();
        }
        
    }

    public function all_bookings_count() {
        $query = $this->db->query("SELECT * FROM `booking_sessions`");
        return $query->num_rows();
    }

    /*
    | -------------------------------------------------------------------
    |  Bookings
    | -------------------------------------------------------------------
    */

    public function all_bookings($access_level, $user_id) {
        if ($access_level == 1 || $access_level == 3) {
            $query = $this->db->query("SELECT * FROM `booking_sessions`");
            return $query->result_array();
        }
        elseif ($access_level == 2) {
            $query = $this->db->get_where('booking_sessions', array('instructor_id' => $user_id));
            return $query->result_array();
        }
        elseif ($access_level == 4) {
            $query = $this->db->get_where('booking_sessions', array('booked_by' => $user_id));
            return $query->result_array();
        }
    }

    public function get_booking_types() {
        $query = $this->db->query("SELECT * FROM `booking_types`");
        return $query->result_array();
    }

    public function create_booking($booking_date, $booked_by, $instructor_id, $booking_type) {
        $sql = "INSERT INTO `booking_sessions` (id, session_date, booked_by, instructor_id, status, booking_type)
                VALUES ('', ?, ?, ?, 0, ?)";
        $this->db->query($sql, array($booking_date, $booked_by, $instructor_id, $booking_type));
    }

    public function check_for_active_session($user_id) {
        // where status is 0
        $query = $this->db->get_where('booking_sessions', array('booked_by' => $user_id, 'status' => 0));
        return $query->num_rows();
    }

    /*
    | -------------------------------------------------------------------
    |  Members
    | -------------------------------------------------------------------
    */

    public function all_users($user_id = false) {
        if ($user_id === false) {
            $query = $this->db->query('SELECT * FROM `booking_users`');
            return $query->result_array();
        } else {
            $query = $this->db->get_where('booking_users', array('id' => $user_id));
            return $query->row_array();
        }
    }

    public function remove_user($user_id = false) {
        if ($user_id === false) {
            return 0;
        } else {
            $this->db->where('id', $user_id);
            $this->db->delete('booking_users');
        }
    }

    public function make_instructor($user_id = false) {
        if ($user_id === false) {
            return 0;
        } else {
            $this->db->set('access_level', 2);
            $this->db->where('id', $user_id);
            $this->db->update('booking_users');
        }
    }

    public function make_slope($user_id = false) {
        if ($user_id === false) {
            return 0;
        } else {
            $this->db->set('access_level', 3);
            $this->db->where('id', $user_id);
            $this->db->update('booking_users');
        }
    }

    /*
    | -------------------------------------------------------------------
{'fraction_non_alphanumeric': 0.29147306291598646, 'fraction_numerical': 0.002386035413788773, 'mean_word_length': 1.414796846573681, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 111, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2204834', 'n_tokens_mistral': 2194, 'n_tokens_neox': 2143, 'n_words': 370}