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

    public static function table()
    {
        return 'ig_bookpostcomplaints';
    }

    public function create($bookId, $data = array())
    {
        $table = $this->escape(self::table());
        $sql = "INSERT INTO $table SET ";
        $data['createdate'] = time();
        if (empty($data['content']))
        {
            iexit('请填写投诉理由');
        }

        if (mb_strlen($data['content'],'utf8') > 200)
        {
            iexit('投诉理由不能超过200个字');
        }

        $insert[] = self::getEscapeString('bookid', $bookId);

        foreach ($data as $key => $value)
		{
			$insert[] = self::getEscapeString($key, $value);
		}
		$sql .= implode(',', $insert);
		$this->_db->query($sql);

		return $this->_db->getInsertId();
    }
}