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

class Item extends CI_Model{
	private $table = "items";
	private $tableShop;

	/** Item columns **/
	private $id = "item_id";
	private $rate = "item_rate";
	private $pic = "item_pic";
	private $status = "item_stats";
	private $qty = "item_qty";
	private $desc = "item_desc";
	private $cashBond = "item_cash_bond";
	private $rentalMode = "item_rental_mode";
	private $penalty = "item_penalty";
	private $shopId = "shop_id";
	private $subscriberId = "subscriber_id";

	private $limit = 5;
	private $offset = 0;

	// Alias
	private $itemAlias = 'i';
	private $shopAlias = 's';
	private $subscriberAlias = 'sub';
	private $categoryAlias = 'c';

	public function __construct() {
		parent::__construct();
	}

	public function create($data) {
		$this->db->insert($this->table, $data);
		$this->clearCache();
		return $this->db->insert_id();
	}

	public function update($data) {
		$this->db->update($this->table, $data, array(
				$this->id => $data[$this->id]
			)
		);
		$this->clearCache();
    return $this->db->affected_rows();
	}

	public function updateStatus($id, $status) {
		$this->db->where($this->id, $id);
		$this->db->update($this->table, array($this->status => $status));
		$this->clearCache();
		return $this->db->affected_rows();
	}

	public function delete($id) {
		$this->db->delete($this->table, array($this->id => $id));
		$this->clearCache();
		return $this->db->affected_rows();
	}

	public function all($select = "", $status = "", $like = "") {
		$where = array();

		if (!empty($status)) {
			$where[] = $this->itemAlias .".". $this->status ." = '$status'";
		}

		if (!empty($like)) {
			$where[] = $this->itemAlias.".".$this->desc ." LIKE '%$like%' " . " OR ".
			 						$this->shopAlias . "." . $this->RentalShop->getName() . " LIKE '%$like%'" . " OR ".
			 						$this->shopAlias . "." . $this->RentalShop->getBranch() . " LIKE '%$like%'";
		}

		if (!empty($where)) {
			$this->db->where(implode('AND ', $where));
		}

		if (empty($select)) {
			$select = $this->_joinSelect();
		}

		$joinShop = $this->_joinShop();
		$joinSubs = $this->_joinSubscriber();
		$data['count'] = $this->db
			->from($this->table ." as i")
			->join($joinShop['table'], $joinShop['on'], $joinShop['type'])
			->count_all_results();
		if (!empty($where)) {
			$this->db->where(implode('AND ', $where));
		}
		$data['data'] = $query = $this->db
			->select($select)
			->from($this->table ." as ". $this->itemAlias)
			->join($joinShop['table'], $joinShop['on'], $joinShop['type'])
			->join($joinSubs['table'], $joinSubs['on'], $joinSubs['type'])
			->limit($this->limit, $this->offset)
			->get()
			->result();
		return $data;
	}

	public function findBySubscriberId($lessorId, $key = "") {
		$this->load->model('RentalShop');
		$itemAlias = 'i';
		$shopAlias = 's';
		$select = "$itemAlias.*, $shopAlias.{$this->RentalShop->getName()}, $shopAlias.{$this->RentalShop->getBranch()}";
		$joinCondition = "$shopAlias." .  $this->RentalShop->getId() .  
										" = $itemAlias." . $this->shopId;
		$where = array($itemAlias.'.'.$this->subscriberId => $lessorId);
		$data['count'] = $this->db->from($this->table ." as i")->where($where)->like($itemAlias.'.'.$this->desc, $key)->count_all_results();
		$data['data'] = $this->db
			->select($select)
			->from($this->table ." as i")
			->join($this->RentalShop->getTable() . " as s", $joinCondition, 'left')
			->where($where)
			->like($itemAlias.'.'.$this->desc, $key)
			->or_like($shopAlias.'.'.$this->RentalShop->getName(), $key)
			->or_like($shopAlias.'.'.$this->RentalShop->getBranch(), $key)
			->limit($this->limit, $this->offset)
			->get()->result();
		return $data;
	}

	public function findById($id) {
		$query = $this->db->get_where($this->table, array($this->id => $id));
		return $query->row_array();
	}<commit_msg>Add method allForMonitor in Item model<commit_after><?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Item extends CI_Model{
	private $table = "items";
	private $tableShop;

	/** Item columns **/
	private $id = "item_id";
	private $rate = "item_rate";
	private $pic = "item_pic";
	private $status = "item_stats";
	private $qty = "item_qty";
	private $desc = "item_desc";
	private $cashBond = "item_cash_bond";
	private $rentalMode = "item_rental_mode";
	private $penalty = "item_penalty";
	private $shopId = "shop_id";
	private $subscriberId = "subscriber_id";

	private $limit = 5;
	private $offset = 0;

	// Alias
	private $itemAlias = 'i';
	private $shopAlias = 's';
	private $subscriberAlias = 'sub';
	private $categoryAlias = 'c';
	private $rdAlias = 'rd';

	public function __construct() {
		parent::__construct();
	}

	public function create($data) {
		$this->db->insert($this->table, $data);
		$this->clearCache();
		return $this->db->insert_id();
	}

	public function update($data) {
		$this->db->update($this->table, $data, array(
				$this->id => $data[$this->id]
			)
		);
		$this->clearCache();
    return $this->db->affected_rows();
	}

	public function updateStatus($id, $status) {
		$this->db->where($this->id, $id);
		$this->db->update($this->table, array($this->status => $status));
		$this->clearCache();
		return $this->db->affected_rows();
	}

	public function delete($id) {
		$this->db->delete($this->table, array($this->id => $id));
		$this->clearCache();
		return $this->db->affected_rows();
	}

	public function all($select = "", $status = "", $like = "") {
		$where = array();

		if (!empty($status)) {
			$where[] = $this->itemAlias .".". $this->status ." = '$status'";
		}

		if (!empty($like)) {
			$where[] = $this->itemAlias.".".$this->desc ." LIKE '%$like%' " . " OR ".
			 						$this->shopAlias . "." . $this->RentalShop->getName() . " LIKE '%$like%'" . " OR ".
			 						$this->shopAlias . "." . $this->RentalShop->getBranch() . " LIKE '%$like%'";
		}

		if (!empty($where)) {
			$this->db->where(implode('AND ', $where));
		}

		if (empty($select)) {
			$select = $this->_joinSelect();
		}

		$joinShop = $this->_joinShop();
		$joinSubs = $this->_joinSubscriber();
		$data['count'] = $this->db
			->from($this->table ." as i")
			->join($joinShop['table'], $joinShop['on'], $joinShop['type'])
			->count_all_results();
		if (!empty($where)) {
			$this->db->where(implode('AND ', $where));
		}
		$data['data'] = $query = $this->db
			->select($select)
			->from($this->table ." as ". $this->itemAlias)
			->join($joinShop['table'], $joinShop['on'], $joinShop['type'])
			->join($joinSubs['table'], $joinSubs['on'], $joinSubs['type'])
			->limit($this->limit, $this->offset)
			->get()
			->result();
		return $data;
	}

	public function allForMonitor() {
		$select = $this->_selectItem();
		$countRented = $this->_subCountRented();
		$query = $this->db
			->select($select . ", $countRented")
			->from($this->table . ' as ' . $this->itemAlias)
			->get();
		return $query->result();
	}

	private function _selectItem() {
		$select = array(
			$this->id, $this->rate,
			$this->pic, $this->status,
			$this->qty, $this->desc
		);
		return $this->itemAlias . '.' . implode(', ' . $this->itemAlias . '.', $select);
	}

	private function _subCountRented() {
		$this->load->model('ReservationDetail');
		$table = $this->ReservationDetail->getTable() . ' as ' . $this->rdAlias;
		$where = $this->itemAlias . '.' . $this->id . ' = ';
		$where .= $this->rdAlias . '.' . $this->ReservationDetail->getItemId();
		$select = "(SELECT count(1) FROM $table WHERE $where) as total_rented";
		return $select;
	}

	public function findBySubscriberId($lessorId, $key = "") {
		$this->load->model('RentalShop');
		$itemAlias = 'i';
		$shopAlias = 's';
		$select = "$itemAlias.*, $shopAlias.{$this->RentalShop->getName()}, $shopAlias.{$this->RentalShop->getBranch()}";
		$joinCondition = "$shopAlias." .  $this->RentalShop->getId() .  
										" = $itemAlias." . $this->shopId;
		$where = array($itemAlias.'.'.$this->subscriberId => $lessorId);
		$data['count'] = $this->db->from($this->table ." as i")->where($where)->like($itemAlias.'.'.$this->desc, $key)->count_all_results();
		$data['data'] = $this->db
			->select($select)
			->from($this->table ." as i")
			->join($this->RentalShop->getTable() . " as s", $joinCondition, 'left')
			->where($where)
			->like($itemAlias.'.'.$this->desc, $key)
			->or_like($shopAlias.'.'.$this->RentalShop->getName(), $key)
			->or_like($shopAlias.'.'.$this->RentalShop->getBranch(), $key)
			->limit($this->limit, $this->offset)
			->get()->result();
		return $data;
	}

	public function findById($id) {
		$query = $this->db->get_where($this->table, array($this->id => $id));
		return $query->row_array();
	}
{'fraction_non_alphanumeric': 0.2425222312045271, 'fraction_numerical': 0.0005774338838203026, 'mean_word_length': 3.937286202964652, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 256, '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': '91982', 'n_tokens_mistral': 3403, 'n_tokens_neox': 3080, 'n_words': 558}