<?php
/**
 * Klasa prostych artykulow
 *
 */
class SimpleArticle_MfArticle extends DataObject {

	static $TYPEART = 1;
	static $TYPENEWS = 2;
	static $TYPESTAGE = 3;
	static $TYPEGAL = 4;
	static $TYPEMAIN = 5;

	/**
	 * nazwa tabeli
	 */
	static $tableName = 'mf_article';

	/**
	 * nazwa klucza tabeli
	 */
	static $classTablePK = 'id_mf_article';

	/**
	 * nazwa klasy
	 */
	static $className = __CLASS__;

	static $types = array(
	1 =>'Artykuł',
	2 =>'Aktualość' ,
	3 =>'Scena' ,
	4 =>'Galeria' ,
	5 =>'Strona Główna'
	);

	static $categoryName = array(
	1 =>'Narzędzia i oprzyrządowanie do smaru',
	2 =>'Narzędzia i oprzyrządowanie do oleju' ,
	3 =>'Narzędzia i oprzyrządowanie do płynów' 
	);

	/**
	 * tabela mapująca pola z bazy SQL na pola klasy.
	 */
	static $fields = array(
	'id_mf_article' =>'id',
	'date' =>'date' ,
	'publication' =>'publication' ,
	'weight' =>'weight' ,
	'url' =>'url',
	'special' =>'special',
	'id_mf_picture' => 'idPicture',
	'id_mf_picture_mini' => 'idPictureMini',
	'id_structure' => 'idStructure',
	'type' =>'type',
	'id_category' =>'idCategory',
	'date_shown'=>'dateShown',
	'date_publication'=> 'datePublication',
	'zz_date_add' => 'addDate',
	'zz_date_edit' => 'editDate',
	'id_mf_image_group' => 'idImageGroup'
	);

	protected $id;
	private $date;
	private $publication;
	private $weight;
	private $url;
	private $lang;
	private $articleDescriptionObj;
	private $idPicture = 0;
	private $idPictureMini = 0;
	private $idStructure = 0;
	private $picture;
	private $pictureMini;
	private $special = 0;
	private $type;
	private $idCategory;
	private $dateShown;
	private $datePublication;
	private $addDate;
	private $editDate;
	private $idImageGroup;
	public $tag;
	public $customer;
	public $structure;
	public $arrayImage;


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

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

	public function GetDate() {
		return $this->date;
	}

	public function SetDate($date) {
		$this->date = $date;
	}
	public function GetSpecial() {
		return $this->special;
	}

	public function SetSpecial($special) {
		$this->special = $special;
	}

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

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

	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() {
		if($this->lang=='') {

			$this->SetLang(Router::$curLang);

		}


		return $this->lang;
	}

	public function SetIdPicture($idPicture) {
		$this->idPicture = $idPicture;
	}

	public function GetIdPicture() {
		return $this->idPicture;
	}
	public function SetIdPictureMini($idPictureMini) {
		$this->idPictureMini = $idPictureMini;
	}

	public function GetIdPictureMini() {
		return $this->idPictureMini;
	}
	public function SetIdStructure($idStructure) {
		$this->idStructure = $idStructure;
	}

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

	public function GetDescriptionObj() {
		if(!is_object($this->articleDescriptionObj)) {
			$articleDescriptionObj = SimpleArticle_MfArticleDescriptionDAL::GetResult(array('publication' => 1, 'lang'=>$this->GetLang(), 'id_mf_article'=>$this->GetId()), array('title', 'browser_title', 'description', 'shortnote',  'publication'));
			if(isset($articleDescriptionObj[0]) && is_object($articleDescriptionObj[0])) {
				$this->SetArticleDescriptionObj($articleDescriptionObj[0]);
			} else {
				throw new UserException('Brak wersji jezykowej dla tego rekordu! ('.$this->GetId().' '.$this->GetLang().')');
			}
		}
		return $this->articleDescriptionObj;
	}

	public function SetArticleDescriptionObj($articleDescriptionObj) {
		$this->articleDescriptionObj = $articleDescriptionObj;
	}
	public function SetSimpleArticle_MfArticleDescription($articleDescriptionObj) {
		$this->articleDescriptionObj = $articleDescriptionObj;
	}

	/*
	* Eksperymentalne przeciazenie metod kierowane do podobiektu slownikowego
	*/
	public function __call($name, $param) {

		$obj = $this->GetDescriptionObj();

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

	public function GetMfLinkDescription() {
		return $this->mfLinkDescription;
	}

	public function SetMfLinkDescription($mfLinkDescription) {
		$this->mfLinkDescription = $mfLinkDescription;
	}

	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;
	}

	public function SetPicture($picture) {
		$this->picture = $picture;
	}

	public function GetPicture() {
		if (!$this->picture && (int)$this->idPicture > 0) {
			$this->picture = PictureDAL::GetById($this->GetIdPicture());
		}

		return $this->picture;
	}

	public function GetPictureUrl() {
		if ($this->GetPicture()) {
			return Config::Get('URL_STATIC_CONTENT') . '/upload/Article/' . $this->GetPicture()->GetLink();
		} else {
			return null;
		}
	}

	public function GetPicturePath() {
		if ($this->GetPicture()) {
			return Config::Get('PATH_STATIC_CONTENT') . 'upload/Article/' . $this->GetPicture()->GetLink();
		} else {
			return null;
		}
	}


	public function SetPictureMini($pictureMini) {
		$this->pictureMini = $pictureMini;
	}

	public function GetPictureMini() {
		if (!$this->pictureMini && (int)$this->idPictureMini > 0) {
			$this->pictureMini = PictureDAL::GetById($this->GetIdPictureMini());
		}

		return $this->pictureMini;
	}

	public function GetPictureMiniUrl() {
		if ($this->GetPictureMini()) {
			return Config::Get('URL_STATIC_CONTENT') . '/upload/Article/' . $this->GetPictureMini()->GetLink();
		} else {
			return null;
		}
	}


	public function GetDateShown() {
		return $this->dateShown;
	}

	public function SetDateShown($date) {
		$this->dateShown = $date;
	}

	public function GetDatePublication() {
		return $this->datePublication;
	}

	public function GetDatePublicationWithoutTime() {
		return substr($this->datePublication, 0, -9);
	}

	public function GetDatePublicationTime() {
		if (!$this->datePublication) {
			return '00';
		} else {
			return substr($this->datePublication, 11, -6);
		}
		
	}

	public function SetDatePublication($datePublication) {
		$this->datePublication = $datePublication;
	}

	public function GetDateUpdate() {
		return $this->dateUpdate;
	}

	public function GetDateUpdateWithoutTime() {
		return substr($this->dateUpdate, 0, -9);
	}

	public function GetDateUpdateTime() {
		return substr($this->dateUpdate, 11, -6);
	}

	public function SetDateUpdate($dateUpdate) {
		$this->dateUpdate = $dateUpdate;
	}
	public function GetType() {
		return $this->type;
	}

	public function SetType($type) {
		$this->type = $type;
	}
	public function GetIdCategory() {
		return $this->idCategory;
	}

	public function SetIdCategory($idCategory) {
		$this->idCategory = $idCategory;
	}
	
	public function GetAddDate() {
		return $this->addDate;
	}

	public function SetAddDate($add) {
		$this->addDate = $add;
	}

	public function GetEditDate() {
		return $this->editDate;
	}

	public function SetEditDate($edit) {
		$this->editDate = $edit;
	}
	
//	public function getTags() {
//		if($this->tag=='') {
//			$this->setTags(TagDAL::GetResultByLink('mf_article', $this->GetId(), array()));
//		}
//		return $this->tag;
//	}
//
//	public function setTags($tag) {
//		$this->tag = $tag;
//	}
//	
//	public function getTagsArrayId() {
//		$arrayObj = $this->getTags();
//		$arraySel = array();
//		foreach ($arrayObj as $obj) {
//			$arraySel[] = $obj->GetId();
//		}
//		return $arraySel;
//	}
//
//	public function getCustomer() {
//		if($this->customer=='') {
//			$this->setCustomer(TagDAL::GetResultCustomerByLink('mf_article', $this->GetId(), array()));
//		}
//		return $this->customer;
//	}
//	
//	public function getCustomerArrayId() {
//		$arrayObj = $this->getCustomer();
//		$arraySel = array();
//		foreach ($arrayObj as $obj) {
//			$arraySel[] = $obj->GetId();
//		}
//		return $arraySel;
//	}
//
//	public function setCustomer($c) {
//		$this->customer = $c;
//	}
//
//	public function getStringTag($delimiter = ", ")
//	{
//		$stringTag = "";
//		if (is_array($this->getTags())) {
//
//
//			foreach($this->tag as $key => $value)
//			{
//				$stringTag .= $value->GetTag() . $delimiter;
//			}
//		}
//
//		return substr($stringTag,0,strlen($stringTag)-strlen($delimiter));
//	}

	public function setStructure($s) {
		$this->structure = $s;
	}

	public function getStructure()
	{
		return $this->structure;
	}
	
	public function setArrayImage($arrayImage) {
		$this->arrayImage = $arrayImage;
	}

	public function getArrayImage() {
		if (!$this->arrayImage && $this->idImageGroup > 0) {
			//$this->setArrayImage(ImageDAL::GetResultByLink('mf_article', $this->id));
			$this->setArrayImage(ImageDAL::GetResult(array('id_image_group' => $this->idImageGroup, 'size' => 2),null,'weight'));
		}
		return $this->arrayImage;
	}

	public function setIdImageGroup($idImageGroup) {
		$this->idImageGroup = $idImageGroup;
	}

	public function getIdImageGroup() {
		return $this->idImageGroup;
	}



	/**
	 * 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 GetTypes(){
		return self::$types;
	}

	public  function GetTypeName($type){
		return self::$fields[$type];
	}
	public  function GetCategoryNameTest($type){
		return self::$categoryName[$type];
	}
	public static function GetCategory(){
		return self::$categoryName;
	}


}
?>