<?php

class camp_apply {
	private $capp_id;
	private $capp_camp_kid_ck_id;
	private $capp_accomodation_type = null;
	private $capp_shuttle_type = null;
	private $capp_date = null;
	private $capp_status = null;
	private $capp_accept_date = null;
	private $capp_camp_id = null;




    /**
     * get_s the value of capp_id.
     *
     * @return mixed
     */
    public function get_capp_id()
    {
        return $this->capp_id;
    }

    /**
     * Sets the value of capp_id.
     *
     * @param mixed $capp_id the capp id
     *
     * @return self
     */
    private function set_capp_id($capp_id)
    {
        $this->capp_id = $capp_id;

        return $this;
    }

    /**
     * get_s the value of capp_camp_kid_ck_id.
     *
     * @return mixed
     */
    public function get_capp_camp_kid_ck_id()
    {
        return $this->capp_camp_kid_ck_id;
    }

    /**
     * Sets the value of capp_camp_kid_ck_id.
     *
     * @param mixed $capp_camp_kid_ck_id the capp camp user ck id
     *
     * @return self
     */
    private function set_capp_camp_kid_ck_id($capp_camp_kid_ck_id)
    {
        $this->capp_camp_kid_ck_id = $capp_camp_kid_ck_id;

        return $this;
    }

    /**
     * get_s the value of capp_accomodation_type.
     *
     * @return mixed
     */
    public function get_capp_accomodation_type()
    {
        return $this->capp_accomodation_type;
    }

    /**
     * Sets the value of capp_accomodation_type.
     *
     * @param mixed $capp_accomodation_type the capp accomodation type
     *
     * @return self
     */
    private function set_capp_accomodation_type($capp_accomodation_type)
    {
        $this->capp_accomodation_type = $capp_accomodation_type;

        return $this;
    }

    /**
     * get_s the value of capp_shuttle_type.
     *
     * @return mixed
     */
    public function get_capp_shuttle_type()
    {
        return $this->capp_shuttle_type;
    }

    /**
     * Sets the value of capp_shuttle_type.
     *
     * @param mixed $capp_shuttle_type the capp shuttle type
     *
     * @return self
     */
    private function set_capp_shuttle_type($capp_shuttle_type)
    {
        $this->capp_shuttle_type = $capp_shuttle_type;

        return $this;
    }

    /**
     * get_s the value of capp_date.
     *
     * @return mixed
     */
    public function get_capp_date()
    {
        return $this->capp_date;
    }

    /**
     * Sets the value of capp_date.
     *
     * @param mixed $capp_date the capp date
     *
     * @return self
     */
    private function set_capp_date($capp_date)
    {
        $this->capp_date = $capp_date;

        return $this;
    }

    /**
     * get_s the value of capp_status.
     *
     * @return mixed
     */
    public function get_capp_status()
    {
        return $this->capp_status;
    }

    /**
     * Sets the value of capp_status.
     *
     * @param mixed $capp_status the capp status
     *
     * @return self
     */
    public function set_capp_status($capp_status)
    {
        $this->capp_status = $capp_status;

        return $this;
    }

    /**
     * get_s the value of capp_accept_date.
     *
     * @return mixed
     */
    public function get_capp_accept_date()
    {
        return $this->capp_accept_date;
    }

    /**
     * Sets the value of capp_accept_date.
     *
     * @param mixed $capp_accept_date the capp accept date
     *
     * @return self
     */
    private function set_capp_accept_date($capp_accept_date)
    {
        $this->capp_accept_date = $capp_accept_date;

        return $this;
    }

    /**
     * get_s the value of capp_camp_id.
     *
     * @return mixed
     */
    public function get_capp_camp_id()
    {
        return $this->capp_camp_id;
    }

    /**
     * Sets the value of capp_camp_id.
     *
     * @param mixed $capp_camp_id the capp camp id
     *
     * @return self
     */
    private function set_capp_camp_id($capp_camp_id)
    {
        $this->capp_camp_id = $capp_camp_id;

        return $this;
    }

    //STATIC!
    public static function has_responsible_contact($_capp_id) {
    	global $sql;
    	return $sql->num_of_rows('SELECT * FROM camp_apply_contact WHERE cac_camp_apply_capp_id = ' . $_capp_id . ' AND cac_is_responsible = 1;');
    }

    public static function apply_response($_apply_id, $_status_id) {
        global $sql;
        $sql->update_table('camp_apply', array('capp_status' => $_status_id, 'capp_accept_date' => date("Y-m-d H:i:s")), array('capp_id' => $_apply_id));
    }

    public static function has_contact($_capp_id) {
        global $sql;
        return $sql->num_of_rows('SELECT * FROM camp_apply_contact WHERE cac_camp_apply_capp_id = ' . $_capp_id . ';');
    }

    public function set_capp_data_by_id($_id) {
		global $sql;
		$capp_data_assoc_array = $sql->assoc_array("select * from camp_apply where capp_id = " . $_id);
		$capp_array = $capp_data_assoc_array[0];
		foreach ($capp_array as $field => $value) {
			$function_name = "set_" . $field;
			$this->$function_name($value);
			if ($field == 'capp_camp_kid_ck_id') {
				$new_kid = new camp_kid();
				$new_kid->set_ck_data_by_id($value);
				$this->$function_name($new_kid);
			}
			if ($field == 'capp_accomodation_type') {
				$new_cat = new camp_accomodation_type();
				$new_cat->set_cat_data_by_id($value);
				$this->$function_name($new_cat);
			}
			if ($field == 'capp_shuttle_type') {
				$new_cst = new camp_shuttle_type();
				$new_cst->set_cst_data_by_id($value);
				$this->$function_name($new_cst);
			}
			if ($field == 'capp_camp_id') {
				$new_camp = new camp();
				$new_camp->set_camp_data_by_id($value);
				$this->$function_name($new_camp);				
			}
		}
    }

    public function get_responsible_contact() {
        global $sql;
        $cc_id = $sql->single_variable("SELECT cac_camp_contact_cc_id FROM camp_apply_contact WHERE cac_camp_apply_capp_id = " . $this->get_capp_id() . " AND cac_is_responsible = 1;");
        $cc = new camp_contact();
        $cc->set_cc_data_by_id($cc_id);
        return $cc;
    }

    //egy létező jelentkezésnél felelős kapcsolattartóra állít valakit
    public static function make_contact_responsible($_apply_id, $_cc_id, $_is_responsible = false) {
    	global $sql;
    	//TODO: itt majd cac objektumot adjunk át, és akkor nem így kell updatelni hanem primary key alapján
    	$sql->update_table('camp_apply_contact',
    		array(
    			'cac_is_responsible' => $_is_responsible
    		),
    		array(
    			'cac_camp_apply_capp_id' => $_apply_id,
    			'cac_camp_contact_cc_id' => $_cc_id
    		)
		);
    }

    public static function create_camp_apply($_camp_kid, $_status = 1, $_camp_accom = 'null', $_camp_shuttle = 'null', $_camp_date = 'null', $_camp_accept_date = 'null', $_camp = 'null') {
    	global $sql;
    	return $sql->insert_into('camp_apply', array(
    		'capp_camp_kid_ck_id' => $_camp_kid,
    		'capp_accomodation_type' => $_camp_accom,
    		'capp_shuttle_type' => $_camp_shuttle,
    		'capp_date' => $_camp_date,
    		'capp_accept_date' => $_camp_accept_date,
    		'capp_status' => $_status,
    		'capp_camp_id' => $_camp,
    		)
		);
    }

    //ezzel nem lehet kid-et updatelni, arra külön function kell
    public static function update_camp_apply($_apply_id, $_status = 1, $_camp_accom = 'null', $_camp_shuttle = 'null', $_camp_date = 'null', $_camp_accept_date = 'null', $_camp = 'null') {
    	global $sql;
    	$sql->update_table('camp_apply', array(
    		'capp_accomodation_type' => $_camp_accom,
    		'capp_shuttle_type' => $_camp_shuttle,
    		'capp_date' => $_camp_date,
    		'capp_accept_date' => $_camp_accept_date,
    		'capp_status' => $_status,
    		'capp_camp_id' => $_camp,
		), array('capp_id' => $_apply_id));
    }
}



?>