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

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

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

    public function isCron($chapterId)
    {
        $cron = $this->Db()->select(array('year','month','day','hour'))->from(self::table())->where(array('cid'=>$chapterId))->find(true);
        if (empty($cron))
        {
            return false;
        }

        return $this->isValid($cron);
    }

    public function isValid($cron)
    {
        $datetime = $cron['year'] . '-' . $cron['month'] . '-' . $cron['day'] . ' ' . $cron['hour'] . ':00:00';
        $timestr = strtotime($datetime);
        if ($timestr > CTIME)
        {
            return $datetime;
        }

        return false;
    }
}
