<commit_before><?php

class gardener_model extends CI_Model {
	public function __construct()	{
	  $this->load->database();
	}


	public function get_flower(){

		$query = $this->db->query('SELECT * from flower');
		$data= $query->result_array();
		return $data;
	}

  public function getAllProvince()
  {
    return $this->db->query('SELECT * from province')->result_array();
  }

	public function province_near_by(){

		$query = $this->db->query('SELECT p.* from province as p,nearbyprovince as n WHERE p.province_id=n.Province_PROVINCE_ID');
		$data= $query->result_array();
		return $data;
	}
	public function gardener_list(){

		$query = $this->db->query('SELECT g.*,p.province_name from gardener as g, province as p WHERE g.province_id=p.province_id');
		$data= $query->result_array();
		return $data;
	}

	public function gardener_info($member_id){
		$query = $this->db->query('SELECT * from gardener as G, province as P WHERE GARDENER_ID='.$member_id);
		$data= $query->row_array();
		return $data;

	}
	public function garden_all(){
		$query = $this->db->query('SELECT * from garden WHERE STATUS="APPROVE" ');
		$data= $query->result_array();
		return $data;
		
	}
	public function garden_info($member_id,$type="MEMBER"){


		$query = $this->db->query('SELECT * from garden WHERE GARDEN_TYPE="'.$type.'" AND GARDENER_ID='.$member_id);
		$data= $query->row_array();
		return $data;

	}

	public function gardenflower_info($garden_id){
		$query = $this->db->query('SELECT * from gardenflower WHERE GARDEN_GARDEN_ID='.$garden_id);
		$data= $query->result_array();
		return $data;

	}

	public function garden_bloomingmonth($month,$garden_id){
	$query = $this->db->query('SELECT *FROM flower F ,gardenflower GF WHERE
	(
		(BLOOM_START_MONTH <= BLOOM_END_MONTH AND BLOOM_START_MONTH <='.$month.' AND BLOOM_END_MONTH >='.$month.')
		OR
		(BLOOM_START_MONTH >BLOOM_END_MONTH AND ('.$month.'<= BLOOM_END_MONTH   OR '.$month.'>= BLOOM_START_MONTH) )
	)
		AND GF.FLOWER_FLOWER_ID = F.FLOWER_ID
		AND GF.GARDEN_GARDEN_ID='.$garden_id);


		$data= $query->result_array();
		return $data;
	}

	public function gardenflower_insert($data){
		$check = $this->db->insert('gardenflower', $data);
		return $check;

	}
	public function insert_blooming($data){
		$check = $this->db->insert('blooming', $data);
		return $check;
	}
	public function blooming_info($garden_id){
		$query = $this->db->query('SELECT * from blooming AS B,flower AS F WHERE  F.FLOWER_ID = B.FLOWER_FLOWER_ID AND B.Garden_GARDEN_ID='.$garden_id);
		$data= $query->result_array();
		return $data;
	}
	public function garderflower_delete($id){

		$this->db->where('Garden_GARDEN_ID', $id);
		$check_delete = $this->db->delete('gardenflower');
		return $check_delete;
	}


  public function insert($data)
  {
    $has_email = isset($data['email']);
    $has_password = isset($data['password']);
    $has_password2 = isset($data['password2']);
    if (!$has_email || !$has_password || !$has_password2) {
      throw new Exception("Required email, password, and confirm password", 1);
    }

    $password_match = $data['password'] == $data['<PASSWORD>'];
    if (!$password_match) {
      throw new Exception("Password not match", 1);
    }

    $this->FIRSTNAME = isset($data['firstname']) ? $data['firstname'] : "";
    $this->LASTNAME = isset($data['lastname']) ? $data['lastname'] : "";
    $this->ADDRESS = isset($data['address']) ? $data['address'] : "";
    $this->PROVINCE_ID = isset($data['province']) ? $data['province'] : "";
    $this->MOBILE_NO = isset($data['phone']) ? $data['phone'] : "";
    $this->EMAIL = isset($data['email']) ? $data['email'] : "";
    $this->PASSWORD = isset($data['password']) ? md5($data['password']) : "";
    $this->STATUS = "approve";
    $this->REGISTER_DATE = date("Y-m-d H:i:s");

    $this->db->insert('gardener', $this);
    return $this;
  }

  public function insert_garden($data, $gardener_id)
  {
    $this->db->trans_begin();

    try {
      $has_gardener = !empty($gardener_id);
      if (!$has_gardener) {
        throw new Exception("Permission denied", 1);
      }

      $has_gardenflower = isset($data['selected']) ? !empty($data['selected']) : false;
      if (!$has_gardenflower) {
        throw new Exception("Required garden flower", 1);
      }

      $garden['GARDENER_ID'] = $gardener_id;
      $garden['NAME'] = isset($data['garden_name']) ? $data['garden_name'] : "";
      $garden['ADDRESS'] = isset($data['address']) ? $data['address'] : "";
      $garden['PROVINCE_ID'] = isset($data['province']) ? $data['province'] : "";
      $garden['GARDEN_TYPE'] = isset($data['garden_type']) ? $data['garden_type'] : "";
      $this->db->insert('garden', $garden);
      $garden_id = $this->db->insert_id();

      $selected_flowers = isset($data['selected']) ? $data['selected'] : array();
      $flowers = isset($data['flowers']) ? $data['flowers'] : array();
      foreach ($flowers as $flower_id => $flower) {
        if (!in_array($flower_id, $selected_flowers)) {
          continue;
        }

        $this->db->insert('gardenflower', array(
          'Garden_GARDEN_ID' => $garden_id,
          'Flower_FLOWER_ID' => $flower_id,
          'AMOUNT_HIVE' => isset($flower['hive']) ? $flower['hive'] : NULL,
          'RISK_MIX_HONEY' => isset($flower['risk']) ? $flower['risk']=='mix' : 0,
          'FLOWER_NEARBY_ID' => isset($flower['mix']) ? $flower['mix'] : NULL,
          'AREA' => isset($flower['area']) ? $flower['area'] : NULL,
        ));
      }

      $this->db->trans_commit();<commit_msg>FIX garden type<commit_after><?php

class gardener_model extends CI_Model {
	public function __construct()	{
	  $this->load->database();
	}


	public function get_flower(){

		$query = $this->db->query('SELECT * from flower');
		$data= $query->result_array();
		return $data;
	}

  public function getAllProvince()
  {
    return $this->db->query('SELECT * from province')->result_array();
  }

	public function province_near_by(){

		$query = $this->db->query('SELECT p.* from province as p,nearbyprovince as n WHERE p.province_id=n.Province_PROVINCE_ID');
		$data= $query->result_array();
		return $data;
	}
	public function gardener_list(){

		$query = $this->db->query('SELECT g.*,p.province_name from gardener as g, province as p WHERE g.province_id=p.province_id');
		$data= $query->result_array();
		return $data;
	}

	public function gardener_info($member_id){
		$query = $this->db->query('SELECT * from gardener as G, province as P WHERE GARDENER_ID='.$member_id);
		$data= $query->row_array();
		return $data;

	}
	public function garden_all(){
		$query = $this->db->query('SELECT * from garden WHERE STATUS="APPROVE" ');
		$data= $query->result_array();
		return $data;
		
	}
	public function garden_info($member_id,$type="MEMBER"){


		$query = $this->db->query('SELECT * from garden WHERE GARDEN_TYPE="'.$type.'" AND GARDENER_ID='.$member_id);
		$data= $query->row_array();
		return $data;

	}

	public function gardenflower_info($garden_id){
		$query = $this->db->query('SELECT * from gardenflower WHERE GARDEN_GARDEN_ID='.$garden_id);
		$data= $query->result_array();
		return $data;

	}

	public function garden_bloomingmonth($month,$garden_id){
	$query = $this->db->query('SELECT *FROM flower F ,gardenflower GF WHERE
	(
		(BLOOM_START_MONTH <= BLOOM_END_MONTH AND BLOOM_START_MONTH <='.$month.' AND BLOOM_END_MONTH >='.$month.')
		OR
		(BLOOM_START_MONTH >BLOOM_END_MONTH AND ('.$month.'<= BLOOM_END_MONTH   OR '.$month.'>= BLOOM_START_MONTH) )
	)
		AND GF.FLOWER_FLOWER_ID = F.FLOWER_ID
		AND GF.GARDEN_GARDEN_ID='.$garden_id);


		$data= $query->result_array();
		return $data;
	}

	public function gardenflower_insert($data){
		$check = $this->db->insert('gardenflower', $data);
		return $check;

	}
	public function insert_blooming($data){
		$check = $this->db->insert('blooming', $data);
		return $check;
	}
	public function blooming_info($garden_id){
		$query = $this->db->query('SELECT * from blooming AS B,flower AS F WHERE  F.FLOWER_ID = B.FLOWER_FLOWER_ID AND B.Garden_GARDEN_ID='.$garden_id);
		$data= $query->result_array();
		return $data;
	}
	public function garderflower_delete($id){

		$this->db->where('Garden_GARDEN_ID', $id);
		$check_delete = $this->db->delete('gardenflower');
		return $check_delete;
	}


  public function insert($data)
  {
    $has_email = isset($data['email']);
    $has_password = isset($data['password']);
    $has_password2 = isset($data['<PASSWORD>']);
    if (!$has_email || !$has_password || !$has_password2) {
      throw new Exception("Required email, password, and confirm password", 1);
    }

    $password_match = $data['password'] == $data['<PASSWORD>'];
    if (!$password_match) {
      throw new Exception("Password not match", 1);
    }

    $this->FIRSTNAME = isset($data['firstname']) ? $data['firstname'] : "";
    $this->LASTNAME = isset($data['lastname']) ? $data['lastname'] : "";
    $this->ADDRESS = isset($data['address']) ? $data['address'] : "";
    $this->PROVINCE_ID = isset($data['province']) ? $data['province'] : "";
    $this->MOBILE_NO = isset($data['phone']) ? $data['phone'] : "";
    $this->EMAIL = isset($data['email']) ? $data['email'] : "";
    $this->PASSWORD = isset($data['password']) ? md5($data['password']) : "";
    $this->STATUS = "approve";
    $this->REGISTER_DATE = date("Y-m-d H:i:s");

    $this->db->insert('gardener', $this);
    return $this;
  }

  public function insert_garden($data, $gardener_id)
  {
    $this->db->trans_begin();

    try {
      $has_gardener = !empty($gardener_id);
      if (!$has_gardener) {
        throw new Exception("Permission denied", 1);
      }

      $has_gardenflower = isset($data['selected']) ? !empty($data['selected']) : false;
      if (!$has_gardenflower) {
        throw new Exception("Required garden flower", 1);
      }

      $garden['GARDENER_ID'] = $gardener_id;
      $garden['NAME'] = isset($data['garden_name']) ? $data['garden_name'] : "";
      $garden['ADDRESS'] = isset($data['address']) ? $data['address'] : "";
      $garden['PROVINCE_ID'] = isset($data['province']) ? $data['province'] : "";
      $garden['GARDEN_TYPE'] = "MEMBER";
      $this->db->insert('garden', $garden);
      $garden_id = $this->db->insert_id();

      $selected_flowers = isset($data['selected']) ? $data['selected'] : array();
      $flowers = isset($data['flowers']) ? $data['flowers'] : array();
      foreach ($flowers as $flower_id => $flower) {
        if (!in_array($flower_id, $selected_flowers)) {
          continue;
        }

        $this->db->insert('gardenflower', array(
          'Garden_GARDEN_ID' => $garden_id,
          'Flower_FLOWER_ID' => $flower_id,
          'AMOUNT_HIVE' => isset($flower['hive']) ? $flower['hive'] : NULL,
          'RISK_MIX_HONEY' => isset($flower['risk']) ? $flower['risk']=='mix' : 0,
          'FLOWER_NEARBY_ID' => isset($flower['mix']) ? $flower['mix'] : NULL,
          'AREA' => isset($flower['area']) ? $flower['area'] : NULL,
        ));
      }

      $this->db->trans_commit();
{'fraction_non_alphanumeric': 0.1952061013255856, 'fraction_numerical': 0.0015434901035046304, 'mean_word_length': 4.139990667288847, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 148, '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': '4136021', 'n_tokens_mistral': 4071, 'n_tokens_neox': 3875, 'n_words': 706}