Example #1
0
 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex($slug = 'index')
 {
     // display home page
     if (empty($slug) || $slug == 'index') {
         $query = Post::find()->where(['status' => Post::STATUS_PUBLISHED]);
         $countQuery = clone $query;
         $pagination = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => 5]);
         $posts = $query->offset($pagination->offset)->limit($pagination->limit)->all();
         return $this->render('index', ['posts' => $posts, 'pagination' => $pagination]);
     }
     //try to display action from controller
     try {
         return $this->runAction($slug);
     } catch (\yii\base\InvalidRouteException $ex) {
     }
     //try to display static page from datebase
     $page = Page::getDb()->cache(function ($db) use($slug) {
         return Page::findOne(['slug' => $slug, 'status' => Page::STATUS_PUBLISHED]);
     }, 3600);
     if ($page) {
         $pageAction = new PageAction($slug, $this, ['slug' => $slug, 'page' => $page]);
         return $pageAction->run();
     }
     //try to display post from datebase
     $post = Post::getDb()->cache(function ($db) use($slug) {
         return Post::findOne(['slug' => $slug, 'status' => Post::STATUS_PUBLISHED]);
     }, 3600);
     if ($post) {
         $postAction = new PostAction($slug, $this, ['slug' => $slug, 'post' => $post]);
         return $postAction->run();
     }
     //if nothing suitable was found then throw 404 error
     throw new \yii\web\NotFoundHttpException('Page not found.');
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->isNewRecord && $this->className() == Post::className()) {
         $this->published_at = time();
     }
     $this->on(self::EVENT_BEFORE_UPDATE, [$this, 'updateRevision']);
     $this->on(self::EVENT_AFTER_UPDATE, [$this, 'saveTags']);
     $this->on(self::EVENT_AFTER_INSERT, [$this, 'saveTags']);
 }
Example #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Post::find()->joinWith('translations');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->request->cookies->getValue('_grid_page_size', 20)], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'status' => $this->status, 'comment_status' => $this->comment_status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'revision' => $this->revision]);
     $query->andFilterWhere([$this->published_at_operand ? $this->published_at_operand : '=', 'published_at', $this->published_at ? strtotime($this->published_at) : null]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
Example #4
0
 public function run()
 {
     if (!$this->options) {
         $this->options = $this->getDefaultOptions();
     }
     if (User::hasPermission('viewPosts')) {
         $searchModel = new PostSearch();
         $formName = $searchModel->formName();
         $recentPosts = Post::find()->orderBy(['id' => SORT_DESC])->limit($this->recentLimit)->all();
         foreach ($this->options as &$option) {
             $count = Post::find()->filterWhere($option['filterWhere'])->count();
             $option['count'] = $count;
             $option['url'] = [$this->indexAction, $formName => $option['filterWhere']];
         }
         return $this->render('posts', ['height' => $this->height, 'width' => $this->width, 'position' => $this->position, 'posts' => $this->options, 'recentPosts' => $recentPosts]);
     }
 }
Example #5
0
 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex($slug = 'index')
 {
     if (empty($slug) || $slug == 'index') {
         throw new NotFoundHttpException('Page not found.');
     } else {
         $tag = Tag::find()->where(['slug' => $slug]);
         $tagCount = clone $tag;
         if (!$tagCount->count()) {
             throw new NotFoundHttpException('Page not found.');
         }
     }
     $query = Post::find()->joinWith('tags')->where(['status' => Post::STATUS_PUBLISHED, Tag::tableName() . '.slug' => $slug])->orderBy('published_at DESC');
     $countQuery = clone $query;
     $pagination = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => Yii::$app->settings->get('reading.page_size', 10)]);
     $posts = $query->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('index', ['posts' => $posts, 'tag' => $tag->one(), 'pagination' => $pagination]);
 }
Example #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPosts()
 {
     return $this->hasMany(Post::className(), ['category_id' => 'id']);
 }
Example #7
0
                <div class="col-sm-6 text-right">
                    <?php 
echo GridPageSize::widget(['pjaxId' => 'post-grid-pjax']);
?>
                </div>
            </div>

            <?php 
Pjax::begin(['id' => 'post-grid-pjax']);
?>

            <?php 
echo GridView::widget(['id' => 'post-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'bulkActionOptions' => ['gridId' => 'post-grid', 'actions' => [Url::to(['bulk-activate']) => Yii::t('yee', 'Publish'), Url::to(['bulk-deactivate']) => Yii::t('yee', 'Unpublish'), Url::to(['bulk-delete']) => Yii::t('yii', 'Delete')]], 'columns' => [['class' => 'yeesoft\\grid\\CheckboxColumn', 'options' => ['style' => 'width:10px']], ['class' => 'yeesoft\\grid\\columns\\TitleActionColumn', 'controller' => '/post/default', 'title' => function (Post $model) {
    return Html::a($model->title, ['/post/default/view', 'id' => $model->id], ['data-pjax' => 0]);
}], ['attribute' => 'created_by', 'filter' => yeesoft\models\User::getUsersList(), 'value' => function (Post $model) {
    return Html::a($model->author->username, ['/user/default/update', 'id' => $model->created_by], ['data-pjax' => 0]);
}, 'format' => 'raw', 'visible' => User::hasPermission('viewUsers'), 'options' => ['style' => 'width:180px']], ['class' => 'yeesoft\\grid\\columns\\StatusColumn', 'attribute' => 'status', 'optionsArray' => Post::getStatusOptionsList(), 'options' => ['style' => 'width:60px']], ['class' => 'yeesoft\\grid\\columns\\DateFilterColumn', 'attribute' => 'published_at', 'value' => function (Post $model) {
    return '<span style="font-size:85%;" class="label label-' . (time() >= $model->published_at ? 'primary' : 'default') . '">' . $model->publishedDate . '</span>';
}, 'format' => 'raw', 'options' => ['style' => 'width:150px']]]]);
?>

            <?php 
Pjax::end();
?>
        </div>
    </div>
</div>


Example #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPosts()
 {
     return $this->hasMany(Post::className(), ['id' => 'post_id'])->viaTable('{{%post_tag_post}}', ['tag_id' => 'id']);
 }
Example #9
0
<?php

/* @var $this yii\web\View */
use yeesoft\comments\widgets\Comments;
use yeesoft\post\models\Post;
/* @var $post yeesoft\post\models\Post */
$this->title = $post->title;
$this->params['breadcrumbs'][] = $post->title;
?>

<?php 
echo $this->render('/items/post.php', ['post' => $post]);
?>

<?php 
if ($post->comment_status == Post::COMMENT_STATUS_OPEN) {
    ?>
    <?php 
    echo Comments::widget(['model' => Post::className(), 'model_id' => $post->id]);
}
Example #10
0
                            <?php 
echo $form->field($model, 'status')->dropDownList(Post::getStatusList());
?>

                            <?php 
if (!$model->isNewRecord) {
    ?>
                                <?php 
    echo $form->field($model, 'created_by')->dropDownList(User::getUsersList());
    ?>
                            <?php 
}
?>

                            <?php 
echo $form->field($model, 'comment_status')->dropDownList(Post::getCommentStatusList());
?>

                            <?php 
echo $form->field($model, 'view')->dropDownList($this->context->module->viewList);
?>

                            <?php 
echo $form->field($model, 'layout')->dropDownList($this->context->module->layoutList);
?>

                        </div>
                    </div>
                </div>

                <div class="panel panel-default">