<?php defined('SYSPATH') OR die('No direct access allowed.');

class plato {

	/**
	 * 
	 *
	 * @param   string   image
	 * @return  string
	 */
	public static function get_user()
	{
        if(Arr::get($_GET,"ses_key"))
		    return Arr::get($_GET,"ses_key");
        else
            return Auth::instance()->get_user()->id;
	}
	
	public static function get_user_roles()
	{
		$user = plato::get_user();
		$plato_server = Kohana::config('site.plato_server');
		$address = $plato_server . "/get_user_roles/$user";
		$arr = json_decode(file_get_contents($address));
		return $arr;
	}
	
	public static function parse_object_to_array($obj)
	{
		if (is_object($obj))
		{
			$array = array();
			$array = get_object_vars($obj);
		}
		else
		{
			$array = $obj;
		}
		
		return $array;
	}
	
	public static function get_company_id()
	{
		$comp_info = plato::get_company_info();
		return $comp_info["comp_id"];
	}
	
	public static function get_company_info()
	{
		$user = plato::get_user(); //Arr::get($_GET, "ses_key");
		$plato_server = Kohana::config('site.plato_server');
		$address = $plato_server . "/get_company_info/$user";
		
					echo "<h5>" . $address . "</h5>";
		
		
		$response = file_get_contents($address);
		$obj = json_decode($response);
		$arr = plato::parse_object_to_array($obj);
		return $arr;
	}
	
	public static function get_username($user_id = null)
	{
		$plato_server = Kohana::config('site.plato_server');
		
		if($user_id)
		{
			$address = $plato_server . "/get_username/$user_id";
		}
		else
		{
			$user = plato::get_user(); //Arr::get($_GET, "ses_key");	
			$address = $plato_server . "/get_username/$user";
		}
		
		$arr = json_decode(file_get_contents($address));
		return $arr;
	}
	
	public static function get_company_users()
	{
		$user = plato::get_user(); //Arr::get($_GET, "ses_key");
		$plato_server = Kohana::config('site.plato_server');
		$address = $plato_server . "/get_company_users/$user";
		$arr = json_decode(file_get_contents($address));
		return $arr;
	}
}
