Blog::userIn PHP Method

userIn() public method

public userIn ( $userId, integer $status = UserToBlog::STATUS_ACTIVE ) : boolean | integer
$userId
$status integer
return boolean | integer
    public function userIn($userId, $status = UserToBlog::STATUS_ACTIVE)
    {
        $blogs = Yii::app()->getCache()->get("Blog::Blog::members::{$userId}");
        if (false === $blogs) {
            $result = Yii::app()->getDb()->createCommand('SELECT blog_id, status FROM {{blog_user_to_blog}} WHERE user_id = :userId')->bindValue(':userId', (int) $userId)->queryAll();
            $blogs = [];
            foreach ($result as $data) {
                $blogs[$data['blog_id']] = $data['status'];
            }
            Yii::app()->getCache()->set("Blog::Blog::members::{$userId}", $blogs);
        }
        if (false !== $status) {
            if (isset($blogs[$this->id]) && (int) $blogs[$this->id] === (int) $status) {
                return true;
            }
            return false;
        }
        return isset($blogs[$this->id]) ? (int) $blogs[$this->id] : false;
    }