<?php

class user_group {
	private $ug_id;
	private $ug_name;
	private $ug_description;
    private $ug_is_automatic;
	private $ug_deleted;
	

    /**
     * @return mixed
     */
    public function get_ug_id()
    {
        return $this->ug_id;
    }

    /**
     * @param mixed $ug_id
     *
     * @return self
     */
    public function set_ug_id($ug_id)
    {
        $this->ug_id = $ug_id;

        return $this;
    }

    /**
     * @return mixed
     */
    public function get_ug_name()
    {
        return $this->ug_name;
    }

    /**
     * @param mixed $ug_name
     *
     * @return self
     */
    public function set_ug_name($ug_name)
    {
        $this->ug_name = $ug_name;

        return $this;
    }

    /**
     * @return mixed
     */
    public function get_ug_description()
    {
        return $this->ug_description;
    }

    /**
     * @param mixed $ug_description
     *
     * @return self
     */
    public function set_ug_description($ug_description)
    {
        $this->ug_description = $ug_description;

        return $this;
    }

    /**
     * @return mixed
     */
    public function get_ug_is_automatic()
    {
        return $this->ug_is_automatic;
    }

    /**
     * @param mixed $ug_is_automatic
     *
     * @return self
     */
    public function set_ug_is_automatic($ug_is_automatic)
    {
        $this->ug_is_automatic = $ug_is_automatic;

        return $this;
    }

    /**
     * @return mixed
     */
    public function get_ug_deleted()
    {
        return $this->ug_deleted;
    }

    /**
     * @param mixed $ug_deleted
     *
     * @return self
     */
    public function set_ug_deleted($ug_deleted)
    {
        $this->ug_deleted = $ug_deleted;

        return $this;
    }

    /**
     * @return mixed
     */
    public function get_ug_filter()
    {
        return $this->ug_filter;
    }

    /**
     * @param mixed $ug_filter
     *
     * @return self
     */
    public function set_ug_filter($ug_filter)
    {
        $this->ug_filter = $ug_filter;

        return $this;
    }



    public function set_ug_data_by_id($_id) {
		global $sql;
		$set_data_assoc_array = $sql->assoc_array("select * from user_group where ug_id = " . $_id);
		$set_data_array = $set_data_assoc_array[0];
		foreach ($set_data_array as $field => $value) {
			$function_name = "set_" . $field;
			$this->$function_name($value); //alapadatok beállítása
		}
	}

    public static function create_user_group($_name, $_description, $_is_automatic = 0) {
        global $sql;

        return $sql->insert_into('user_group', array(
            'ug_name' => $_name,
            'ug_description' => $_description,
            'ug_is_automatic' => $_is_automatic,
            )
        );
    }

    public static function update_user_group($_name, $_description, $_id, $_is_automatic = 0) {
        global $sql;

        $sql->update_table('user_group', array(
            'ug_name' => $_name,
            'ug_description' => $_description,
            'ug_is_automatic' => $_is_automatic,
            ),
            array(
                'ug_id' => $_id,
            )
        );
    }

    public static function empty_group($_group_id) {
        //kitörli a usereket a groupból; categoryra szűrhető
        global $sql;
        $sql->execute_query("DELETE FROM user_group_kid WHERE ugk_user_group_ug_id = " . $_group_id);
        $sql->execute_query("DELETE FROM user_group_category WHERE ugc_user_group_ug_id = " . $_group_id);

    }

    public function get_user_group_filter_values() {
        global $sql;

        $ugfv_array = array();

        $ugfv_assoc_array = $sql->assoc_array("SELECT * FROM user_group_filter_value WHERE ugfv_group_id = " . $this->get_ug_id());

        foreach ($ugfv_assoc_array as $u) {
            $ugfv = new user_group_filter_value();
            $ugfv->set_ugfv_data_by_id($u['ugfv_id']);
            $ugfv_array[] = $ugfv;
        }

        return $ugfv_array;
    }
}


?>