<?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  forum_theme_entity extends Entity
{
	public function __construct($data=null)
	{
		$this->_data['id']=&$this->_data['theme_id'];
		parent::__construct($data);
	}

	public function __set($k, $v)
	{
		parent::__set($k, $v);
		if ($k=='hidden_by') {
			$this->_data['hidden']=is_object($v)?$v->id:null;
		}

		if ($k=='forum') {
			$this->_data['forum_id']=$v->id;
		}

		if ($k=='last_user') {
			$this->_data['last_user_id']=is_object($v)?$v->id:null;
			$this->_data['last_user_name']=is_object($v)?$v->login:null;
		}

		if ($k=='total_posts') {
			$this->_data['total_pages']=ceil($v/config::get('forum_posts_at_page'));
		}

		if ($k=='author') {
			if (is_object($v)) {
				$this->_data['author_id']=$v->isGuest()?null:$v->id;
				$this->_data['author_name']=$v->isGuest()?$v->login:null;
			} else {
				$this->_data['author_id']=$this->_data['author_name']=null;
			}
		}
	}

	public function getSubsribeId()
	{
		return 'forum_theme_'.$this->id;
	}
}