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

	public function __set($k, $v)
	{
		parent::__set($k, $v);
		if ($k=='user') {
			$this->_data['user_id']=is_object($v)?$v->id:null;
			$this->_data['user_name']=is_object($v)?null:$v->id;
		} elseif ($k=='theme') {
			$this->_data['theme_id']=$v->id;
		} elseif ($k=='msg') {
			parent::__set('msg_html', getbb($v));
			//Hook::call(' forum_msg', $post->msg_html);
		} elseif ($k=='hidden_by') {
			$this->_data['hidden']=is_object($v)?$v->id:null;
		} elseif ($k=='edited_by') {
			$this->_data['edited']=is_object($v)?$v->id:null;
		} elseif ($k=='email') {
			if (empty($this->_data['user'])) $this->_data['user']=User::getUser();
			$this->user->email=$v;
		} elseif ($k=='user_name') {
			if (empty($this->_data['user'])) $this->_data['user']=User::getUser();
			$this->user->login=$v;
		}
	}

	public function isAuthor()
	{
		return $this->user->id==User::i()->id;
	}
}