<?php
/**
 * @link      http://www.u-bo.com
 * @copyright 南京友博网络科技有限公司 
 * @license   http://www.u-bo.com/license/
 */

namespace wap\models;

use Yii;
use yii\db\ActiveRecord;
use yii\db\Query;
use yii\helpers\Url;
use common\components\Tree;
use common\components\Tool;
use common\models\User;
use common\models\PermissionScope;
use common\models\Common;

/**
 * 日志表 ({{qc_blog}})
 *
 * @author legendjw http://blog.u-bo.com
 * @since 0.1
 */
class Blog extends \home\modules\blog\models\Blog
{
    /**
     * 获取某个关联的指定的一天的日志
     *
     * @param string $day 要获取哪天的日志
     *
     * @return bool|object 不存在则返回false,否则返回日志对象
     */
    public static function getLinkDayBlog($day, $linkType, $linkId)
    {
        $userId = Yii::$app->user->id;
        $startTime = strtotime($day . ' 00:00:00');
        $endTime = strtotime($day . ' 23:59:59');

        $blog = static::find()
            ->where(['link_id' => $linkId, 'link_type' => $linkType, 'user_id' => $userId])
            ->andWhere(['between', 'work_time', $startTime, $endTime])
            ->one();

        return ($blog === null) ? false : $blog;
    }

}
