public function checkSelf() { $messages = []; // count moderated users $membersCnt = UserToBlog::model()->count('status = :status', [':status' => UserToBlog::STATUS_CONFIRMATION]); if ($membersCnt) { $messages[WebModule::CHECK_NOTICE][] = ['type' => WebModule::CHECK_NOTICE, 'message' => Yii::t('BlogModule.blog', '{count} new members of blog wait for confirmation!', ['{count}' => CHtml::link($membersCnt, ['/blog/userToBlogBackend/index', 'UserToBlog[status]' => UserToBlog::STATUS_CONFIRMATION, 'order' => 'id.desc'])])]; } $postsCount = Post::model()->count('status = :status', [':status' => Post::STATUS_MODERATED]); if ($postsCount) { $messages[WebModule::CHECK_NOTICE][] = ['type' => WebModule::CHECK_NOTICE, 'message' => Yii::t('BlogModule.blog', '{count} new posts wait for moderation!', ['{count}' => CHtml::link($postsCount, ['/blog/postBackend/index', 'Post[status]' => Post::STATUS_MODERATED, 'order' => 'id.desc'])])]; } return isset($messages[WebModule::CHECK_ERROR]) || isset($messages[WebModule::CHECK_NOTICE]) ? $messages : true; }
/** * Возвращает модель по указанному идентификатору * Если модель не будет найдена - возникнет HTTP-исключение. * @param integer идентификатор нужной модели * @return UserToBlog $model */ public function loadModel($id) { $model = UserToBlog::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('BlogModule.blog', 'Requested page was not found!')); } return $model; }
public function getMembers() { return UserToBlog::model()->with('user')->findAll('blog_id = :blog_id', array(':blog_id' => $this->id)); }
/** * @param $userId * @return bool|int */ public function leave($userId) { if ($this->isPrivate()) { return false; } Yii::app()->getCache()->delete("Blog::Blog::members::{$userId}"); Yii::app()->eventManager->fire(BlogEvents::BLOG_LEAVE, new BlogJoinLeaveEvent($this, $userId)); return UserToBlog::model()->updateAll(['status' => UserToBlog::STATUS_DELETED, 'update_time' => new CDbExpression('NOW()')], 'user_id = :userId AND blog_id = :blogId', [':userId' => (int) $userId, ':blogId' => $this->id]); }
public function actionMembers() { $data = Yii::app()->ls->createCommand('SELECT * FROM prefix_blog_user')->queryAll(); $transaction = Yii::app()->db->beginTransaction(); try { UserToBlog::model()->deleteAll(); foreach ($data as $member) { $model = new UserToBlog(); $model->user_id = $member['user_id']; $model->blog_id = $member['blog_id']; $model->save(); } $transaction->commit(); } catch (Exception $e) { $transaction->rollback(); CVarDumper::dump($e); die; } }
public function run() { $models = UserToBlog::model()->with('blog')->findAll('user_id = :user_id', array(':user_id' => $this->userId)); $this->render($this->view, array('models' => $models)); }
public function leave($userId) { Yii::app()->cache->delete("Blog::Blog::members::{$userId}"); Yii::app()->eventManager->fire(BlogEvents::BLOG_LEAVE, new BlogJoinLeaveEvent($this, $userId)); return UserToBlog::model()->updateAll(array('status' => UserToBlog::STATUS_DELETED, 'update_date' => new CDbExpression('NOW()')), 'user_id = :userId AND blog_id = :blogId', array(':userId' => (int) $userId, ':blogId' => $this->id)); }