<?PHP
class clients_SQL extends SqlRequest{

	var $table = 'clients';

	function clients($add_sql = '', $execute = false, $cache = false){

		$this->LINE = __FILE__.' '.__LINE__;
		return $this->Select(
			"SELECT * FROM clients  ".
		$add_sql,
		$execute,
		$cache
		);
	}

	function clients_join_details($add_sql = '', $execute = false, $cache = false){

		$this->LINE = __FILE__.' '.__LINE__;
		return $this->Select(
			"SELECT p1.*, ".$this->columns('client_details', 'p2', array('id'), true)." FROM clients as p1  ".
			"JOIN client_details as p2 on p2.client_id=p1.id ".
		$add_sql,
		$execute,
		$cache
		);
	}

	function clients_join_users($add_sql = '', $execute = false, $cache = false){

		$this->LINE = __FILE__.' '.__LINE__;
		return $this->Select(
			"SELECT p1.*, ".$this->columns('users', 'p2', array('id'), true)." FROM clients AS p1 ".
			"JOIN users as p2 on p2.id=p1.user_id ".
		$add_sql,
		$execute,
		$cache
		);
	}

	function clients_join_details_users_roles($add_sql = '', $execute = false){

		$this->LINE = __FILE__.' '.__LINE__;
		return $this->Select(
			"SELECT p1.*, ".$this->columns('client_details', 'p2', array('id' => 'client_details_id'), true).", p3.name as user_name, p3.is_enabled FROM clients as p1  ".
			"JOIN client_details as p2 on p2.client_id=p1.id ".
			"JOIN users as p3 on p3.id=p1.user_id ".
			"JOIN roles as p4 on p4.id=p3.role_id ".
		$add_sql,
		$execute
		);
	}
}
?>