/**
  * Show user count, post count, post-comment count on index (dashboard).
  *
  * @return string
  */
 public function actionIndex()
 {
     $userQuery = User::find()->andWhere(['blocked_at' => null, 'confirmed_at' => 'is not null']);
     $userCloneQuery = clone $userQuery;
     $userCount = $userCloneQuery->count();
     $users = $userQuery->limit(12)->orderBy(['id' => SORT_DESC])->all();
     $postQuery = Post::find()->andWhere(['post_status' => 'publish']);
     $postCloneQuery = clone $postQuery;
     $postCount = $postCloneQuery->count();
     $posts = $postQuery->limit(10)->orderBy(['id' => SORT_DESC])->all();
     $commentQuery = PostComment::find()->andWhere(['comment_approved' => 'approved']);
     $commentCloneQuery = clone $commentQuery;
     $commentCount = $commentCloneQuery->count();
     $comments = $commentQuery->limit(5)->orderBy(['id' => SORT_DESC])->all();
     return $this->render('index', ['users' => $users, 'posts' => $posts, 'comments' => $comments, 'userCount' => $userCount, 'postCount' => $postCount, 'commentCount' => $commentCount]);
 }
Beispiel #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @param integer $category
  * @param null|string $user
  * @return ActiveDataProvider
  * @internal param int $post_type
  */
 public function searchFront($params, $category = null)
 {
     $query = PostModel::find();
     if ($category) {
         $query->join('left join', 'term_relationship', "term_relationship.post_id = post.id");
         $query->andWhere(['term_relationship.term_id' => $category]);
     }
     $query->andWhere(['post.post_type' => 1]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['attributes' => ArrayHelper::merge($dataProvider->sort->attributes, ['username' => ['asc' => ['username' => SORT_ASC], 'desc' => ['username' => SORT_DESC], 'label' => 'Author', 'value' => 'username']]), 'defaultOrder' => ['post_date' => SORT_DESC]]);
     $dataProvider->setPagination(['pageSize' => 2]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     return $dataProvider;
 }
 /**
  * Render file browser for editor and file input
  *
  * @param int|null $post_id
  * @param bool     $editor
  *
  * @throws \yii\web\NotFoundHttpException
  * @return string
  */
 public function actionPopup($post_id = null, $editor = false)
 {
     $this->layout = "blank";
     $model = new Media(['scenario' => 'upload']);
     $showButtons = Yii::$app->request->post('show_buttons') == 'false' ? false : true;
     if ($post_id) {
         if ($post = Post::findOne($post_id)) {
             return $this->render('popup', ['post' => $post, 'model' => $model, 'editor' => $editor, 'showButtons' => $showButtons]);
         } else {
             throw new NotFoundHttpException(Yii::t('content', 'The requested page does not exist.'));
         }
     }
     return $this->render('popup', ['model' => $model, 'editor' => $editor, 'showButtons' => $showButtons]);
 }
Beispiel #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPosts()
 {
     return $this->hasMany(Post::className(), ['id' => 'post_id'])->viaTable('{{%term_relationship}}', ['term_id' => 'id']);
 }
 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, it will return false.
  *
  * @param integer $id
  *
  * @return Post|bool|null|static
  */
 protected function findPost($id)
 {
     if (($model = Post::findOne($id)) !== null) {
         return $model;
     } else {
         return false;
     }
 }
Beispiel #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCommentPost()
 {
     return $this->hasOne(Post::className(), ['id' => 'comment_post_id']);
 }
Beispiel #7
0
            <div class="col-sm-7 col-sm-push-2">
                <?php 
echo Html::radioList('Option[show_on_front][option_value]', $model->show_on_front->option_value, ['page' => Yii::t('content', 'Static page')], ['separator' => '<br />', 'class' => 'radio']);
?>
                <?php 
echo Html::label(Yii::t('content', 'Front page: '), 'option-front_page');
?>
                <?php 
echo Html::dropDownList('Option[front_page][option_value]', $model->front_page->option_value, Post::findOne($model->front_page->option_value) ? ArrayHelper::map(Post::find()->select(['id', 'post_title'])->where(['id' => $model->front_page->option_value])->all(), 'id', 'post_title') : [], ['class' => 'search-post', 'disabled']);
?>

                <?php 
echo Html::label(Yii::t('content', 'Posts page: '), 'option-posts_page');
?>
                <?php 
echo Html::dropDownList('Option[posts_page][option_value]', $model->posts_page->option_value, Post::findOne($model->posts_page->option_value) ? ArrayHelper::map(Post::find()->select(['id', 'post_title'])->where(['id' => $model->posts_page->option_value])->all(), 'id', 'post_title') : [], ['class' => 'search-post', 'disabled']);
?>
            </div>
        </div>

        <div class="form-group">
            <?php 
echo Html::label(Yii::t('content', 'Posts per page'), 'option-post_per_page', ['class' => 'col-sm-2 control-label']);
?>
            <div class="col-sm-7">
                <?php 
echo Html::input('number', 'Option[posts_per_page][option_value]', $model->posts_per_page->option_value, ['id' => 'option-post_per_page', 'min' => 1, 'step' => 1]);
?>
            </div>
        </div>
Beispiel #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPosts()
 {
     return $this->hasMany(Post::className(), ['post_type' => 'id']);
 }
 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  *
  * @return Post the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Post::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param string $post_slug
  *
  * @return Post the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModelBySlug($post_slug)
 {
     $model = Post::findOne(['post_slug' => $post_slug, 'post_status' => 'publish']);
     if ($model) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #11
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMediaPost()
 {
     return $this->hasOne(Post::className(), ['id' => 'media_post_id']);
 }
 /**
  * Search post by title and content
  *
  * @param $s
  *
  * @return string
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionSearch($s)
 {
     $query = Post::find()->orWhere(['LIKE', 'post_title', $s])->orWhere(['LIKE', 'post_content', $s])->andWhere(['post_status' => 'publish'])->orderBy(['id' => SORT_DESC]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => Option::get('posts_per_page')]);
     $query->offset($pages->offset)->limit($pages->limit);
     $posts = $query->all();
     if ($posts) {
         return $this->render('/site/search', ['posts' => $posts, 'pages' => $pages, 's' => $s]);
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }