/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Post::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $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; } $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'author_id' => $this->author_id]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'anons', $this->anons])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'publish_status', $this->publish_status])->andFilterWhere(['>=', 'created_at', $this->date_from ? strtotime($this->date_from . ' 00:00:00') : null])->andFilterWhere(['<=', 'created_at', $this->date_to ? strtotime($this->date_to . ' 23:59:59') : null])->andFilterWhere(['>=', 'updated_at', $this->dateUpd_from ? strtotime($this->dateUpd_from . ' 00:00:00') : null])->andFilterWhere(['<=', 'updated_at', $this->dateUpd_to ? strtotime($this->dateUpd_to . ' 23:59:59') : null]); /*->andFilterWhere(['FROM_UNIXTIME(created_at, "%Y-%m-%d")' => $this->created_at]) ->andFilterWhere(['FROM_UNIXTIME(updated_at, "%Y-%m-%d")' => $this->updated_at]);*/ return $dataProvider; }
</p> <p class="pull-right"> <?php echo Html::a('<i class="glyphicon glyphicon-th-large"></i> ' . Module::t('module', 'BUTTON_CATEGORIES'), ['category/index'], ['class' => 'btn btn-primary']); ?> <?php echo Html::a('<i class="glyphicon glyphicon-tags"></i> ' . Module::t('module', 'BUTTON_TAGS'), ['tags/index'], ['class' => 'btn btn-primary']); ?> <?php echo Html::a('<i class="glyphicon glyphicon-comment"></i> ' . Module::t('module', 'BUTTON_COMMENTS') . ' <span class="badge">' . $countPending . '</span>', ['comment/index'], ['class' => 'btn btn-primary']); ?> </p> </div> </div> <?php $gridColumn = [['class' => 'yii\\grid\\SerialColumn'], ['class' => LinkColumn::className(), 'attribute' => 'title'], ['attribute' => 'author_id', 'label' => Module::t('module', 'LABEL_AUTHOR'), 'format' => 'text', 'content' => function ($data) { return $data->getAuthorName(); }, 'filter' => Post::getAuthorList()], ['filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'date_from', 'attribute2' => 'date_to', 'type' => DatePicker::TYPE_RANGE, 'separator' => '-', 'pluginOptions' => ['format' => 'yyyy-mm-dd', 'todayHighlight' => true]]), 'attribute' => 'created_at', 'format' => ['date', 'php:d M Y г., H:i:s']], ['filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'dateUpd_from', 'attribute2' => 'dateUpd_to', 'type' => DatePicker::TYPE_RANGE, 'separator' => '-', 'pluginOptions' => ['format' => 'yyyy-mm-dd', 'todayHighlight' => true]]), 'attribute' => 'updated_at', 'format' => ['date', 'php:d M Y г., H:i:s']], ['class' => SetColumn::className(), 'attribute' => 'publish_status', 'filter' => Post::getStatusesArray(), 'name' => function ($model) { return Post::getStatusTitle($model->publish_status); }, 'cssCLasses' => [Post::STATUS_PUBLISH => 'success', Post::STATUS_DRAFT => 'default', Post::STATUS_ARCHIVE => 'info']], ['attribute' => 'category_id', 'label' => Module::t('module', 'LABEL_CATEGORY'), 'format' => 'text', 'content' => function ($data) { return $data->getCategoryTitle(); }, 'filter' => Post::getCategoryList()], ['class' => ActionColumn::className()]]; ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => $gridColumn, 'responsive' => true, 'hover' => true, 'pjax' => false, 'resizableColumns' => true, 'toolbar' => [['content' => Html::a('<i class="glyphicon glyphicon-repeat"></i>', ['index'], ['class' => 'btn btn-default', 'title' => Module::t('module', 'RESET_GRID')])], '{toggleData}'], 'panel' => ['heading' => '<h3 class="panel-title"><i class="glyphicon glyphicon-th-list"></i> ' . Html::encode($this->title) . '</h3>', 'type' => 'primary', 'before' => Html::a('<i class="glyphicon glyphicon-plus"></i> ' . Module::t('module', 'BUTTON_CREATE'), ['create'], ['class' => 'btn btn-success', 'data-pjax' => 0])]]); ?> </div>
/** * 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.'); } }
/* @var $this yii\web\View */ /* @var $model app\modules\admin\modules\blog\models\Post */ /* @var $author app\modules\user\models\User */ $this->title = $model->title; $this->params['breadcrumbs'][] = ['label' => Module::t('module', 'ADMIN'), 'url' => ['/admin/default/index']]; $this->params['breadcrumbs'][] = ['label' => Module::t('module', 'ADMIN_BLOG'), 'url' => ['/admin/blog/default/index']]; $this->params['breadcrumbs'][] = ['label' => Module::t('module', 'ADMIN_POSTS'), 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="admin-blog-post-view"> <h1><?php echo Html::encode($this->title); ?> </h1> <p> <?php echo Html::a(Module::t('module', 'BUTTON_UPDATE'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a(Module::t('module', 'BUTTON_DELETE'), ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => Module::t('module', 'WANT_YOU_DELETE_ELEMENT'), 'method' => 'post']]); ?> </p> <?php echo DetailView::widget(['model' => $model, 'attributes' => ['id', 'title', ['attribute' => 'anons', 'format' => 'raw', 'value' => Markdown::convert($model->anons)], ['attribute' => 'content', 'format' => 'raw', 'value' => Markdown::convert($model->content)], ['attribute' => Module::t('module', 'LABEL_CATEGORY'), 'format' => 'raw', 'value' => $model->category->title], ['attribute' => Module::t('module', 'LABEL_AUTHOR'), 'format' => 'raw', 'value' => $model->author->username], ['attribute' => 'publish_status', 'format' => 'raw', 'value' => Post::getDetailStatusTitle($model->publish_status)], ['attribute' => 'created_at', 'format' => ['date', 'php:d M Y г., H:i:s']], ['attribute' => 'updated_at', 'format' => ['date', 'php:d M Y г., H:i:s']]]]); ?> </div>