<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

class bug_tracker_file_entity extends Entity
{
	public function __construct($data)
	{
		$this->_data['id']=&$this->_data['file_id'];
		parent::__construct($data);
	}


	public function __set($k, $v)
	{
		parent::__set($k, $v);
		if (in_array($k, array('name', 'type', 'id', 'file_id'))) {
			$this->_setPath();
		}
	}

	
	protected function _setPath()
	{
		if ($this->name===null || $this->type===null || $this->id===null) return;
		$tn=config::get('tn');
		if ($this->isImage()) {
			foreach ($tn['images'] as $k=>$v) {
				$path[$k]=$tn['img_path'].$v['path'].'/'.$this->id.'.'.$this->type;
			}
		} else {
			$path=$tn['file_path'].'/'.$this->id.'.'.$this->type;
		}
		$this->path=$path;
	}
	
	public function isImage()
	{
		if (isset($this->image)) return $this->image;
		return $this->image=in_array($this->type, array('gif', 'jpg', 'jpeg', 'png'));
	}
}