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

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

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

    public function create($data)
    {
        unset($data['lastpost']);
        $insert = array();
        $sql = 'INSERT INTO '.self::table().' SET ';
        $insert[] = self::getEscapeString('week', date('W'));
        $insert[] = self::getEscapeString('createdate', CDATETIME);
        $insert[] = self::getEscapeString('stable', BookPost::table($data['bookid']));
        foreach ($data as $key => $value)
        {
            $insert[] = self::getEscapeString($key, $value);
        }
        $sql .= implode(',', $insert);
        $this->Db()->query($sql);
    }
}