<?php
/**
 * Klasa kategorii artukułow 
 *
 */
class SimpleArticle_MfArticleCategory extends DataObject {
	
	/**
	 * nazwa tabeli
	 */
	static $tableName = 'mf_article_category';

	/**
	 * nazwa klucza tabeli
	 */
	static $classTablePK = 'id_mf_article_category';
		
	/**
	 * nazwa klasy
	 */
	static $className = __CLASS__;
	
	static $exts = array(
	    'jpg',
	    'gif',
	    'jpeg',
	    'bmp',
	    'png'
	);

	/**
	 * tabela mapująca pola z bazy SQL na pola klasy.
	 */
	static $fields = array(
		'id_mf_article_category' =>'id',
		'weight' =>'weight',
		'id_parent' =>'idParent',
		'publication' =>'publication'
		
	);

	protected $id;
	private $weight;
	private $publication;
	private $idParent;
	private $articleCategoryDescriptionObj;
	private $articleDescriptionObj;
	private $lang;

	public function GetId() {
		return $this->id;
	}

	public function SetId($id) {
		$this->id = $id;
	}

	public function GetPublication() {
		return $this->publication;
	}

	public function SetPublication($publication) {
		$this->publication = $publication;
	}

	public function SetIdParent($parent) {
		$this->idParent = $parent;
	}

	public function GetIdParent() {
		return $this->idParent;
	}

	public function GetWeight() {
		return $this->weight;
	}

	public function SetWeight($weight) {
		$this->weight = $weight;
	}

	public function GetUrl() {
		return $this->url;
	}

	public function SetUrl($url) {
		$this->url = $url;
	}

	public function GetLang() {
		return $this->lang;
	}

	public function SetLang($lang) {
		$this->lang = $lang;
	}

	public function GetDescriptionObj() {
		if(!is_object($this->articleDescriptionObj)) {
			$articleCategoryDescriptionObj = SimpleArticle_MfArticleCategoryDescriptionDAL::GetResult(array('lang'=>$this->GetLang(), 'id_mf_article_category'=>$this->GetId()), array('name', 'lang', 'publication', 'id_mf_article_category'));
			if(isset($articleCategoryDescriptionObj[0]) && is_object($articleCategoryDescriptionObj[0])) {
				$this->SetArticleCategoryDescriptionObj($articleCategoryDescriptionObj[0]);
			} else {
				throw new UserException('Brak wersji jezykowej dla tego rekordu! ('.$this->GetId().' '.$this->GetLang().')');
			}
		}
		return $this->articleCategoryDescriptionObj;
	}

	public function SetArticleCategoryDescriptionObj($articleCategoryDescriptionObj) {
		$this->articleCategoryDescriptionObj = $articleCategoryDescriptionObj;
	}
	
	/*
	 * Eksperymentalne przeciazenie metod kierowane do podobiektu slownikowego
	 */
	public function __call($name, $param) {

		$obj = $this->GetDescriptionObj();

		return $obj->$name($param);
	}

	public function GetMfLinkCategoryDescription() {
		return $this->mfLinkCategoryDescription;
	}

	public function SetMfLinkCategoryDescription($mfLinkCategoryDescription) {
		$this->mfLinkCategoryDescription = $mfLinkCategoryDescription;
	}

	public function GetMfLinkWeight() {
		return $this->mfLinkWeight;
	}

	public function SetMfLinkWeight($mfLinkWeight) {
		$this->mfLinkWeight = $mfLinkWeight;
	}

	public function GetMfLinkType() {
		return $this->mfLinkType;
	}

	public function SetMfLinkType($mfLinkType) {
		$this->mfLinkType = $mfLinkType;
	}

	/**
	 * Konstruktor klasy
	 *
	 * @param integer $id
	 */

	public function __construct($id = -1) {
		$this->SetId($id);
	}
	
	  /**
	 * Pobiera nazwę tabeli reprezentującej obiekt w SQL
	 * @return string
	 */
	
	public  function GetTableName(){
		return self::$tableName;
      }
	/**
       * Pobiera taablice mapującą pola klasy na pola tabeli
       * @return array
       */
	public  function GetFields(){
		return self::$fields;
      }
	/**
       * Pobiera nazwę klasy
       * @return string
       */
	public  function GetClassName(){
		return self::$className;
      }	


    public function GetClassTablePK() {
        return self::$classTablePK;
    }
    
    public function GetIconUrl() {
	    $return = null;
	    foreach(self::$exts as $ext) {
		$path = PATH_STATIC_CONTENT."/image/Admin/Categories/Icons/".$this->id.".".$ext;
		$url = URL_STATIC_CONTENT."/image/Admin/Categories/Icons/".$this->id.".".$ext;
		if(file_exists($path)) {
		    $return = $url;
		}
	    }
	    return $return;
	}


}
?>