model() 공개 정적인 메소드

Returns the static model of the specified AR class.
public static model ( string $className = __CLASS__ ) : UserToBlog
$className string
리턴 UserToBlog the static model class
예제 #1
0
 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;
 }
예제 #3
0
파일: Blog.php 프로젝트: sherifflight/yupe
 public function getMembers()
 {
     return UserToBlog::model()->with('user')->findAll('blog_id = :blog_id', array(':blog_id' => $this->id));
 }
예제 #4
0
 /**
  * @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;
     }
 }
예제 #6
0
 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));
 }
예제 #7
0
파일: Blog.php 프로젝트: sepaker/yupe
 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));
 }