<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class ThreadsRating extends Model
{
	public static function single($className = __CLASS__)
	{
		if (is_null(self::$_self[$className]))
		{
			self::$_self[$className] = new $className;
		}
		
		return self::$_self[$className];
	}
	
    public static function table()
    {
        return 'ig_threadsrating';
    }
    
    public function create($tid, $pid, $fid, $uid, $point, $remark, $name = '酷币')
    {
        $this->Db()->insert(self::table())->value(array('tid'=>$tid,'pid'=>$pid,'uid'=>$uid,'point'=>$point,'remark'=>$remark,'name'=>$name,'createdate'=>CTIME))->q();
        if ($pid)
        {
            $this->Db()->update(Posts::table())->incrField(array('rating'=>1))->where('id='.$pid)->q();
        }
        else
        {
            $this->Db()->update(Threads::table())->incrField(array('rating'=>1, 'ratings'=>$point))->where('id='.$tid)->q();
        }
    }
}