<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class Ufavorites extends Model
{
    public static function table()
    {
        return 'ig_favorites';
    }

	public static function single($className = __CLASS__)
	{
		if (!isset(self::$_self[$className]))
		{
			self::$_self[$className] = new $className;
		}

		return self::$_self[$className];
	}

    public function updateThreadFavorites($tid)
    {
        $count = $this->Db()->getValue('SELECT COUNT(*) FROM '.self::table().' WHERE id='.S::sqlEscape($tid).' AND type='.S::sqlEscape('thread'));
        $this->Db()->update(Threads::table())->value(array('favors'=>$count))->where(array('id'=>$tid))->q();
    }
}
