protected function findModel($id) { if (($model = \plathir\smartblog\backend\models\Categorytree::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Category::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'name' => $this->name, 'description' => $this->description]); // $query->andFilterWhere(['like', 'description', $this->description]) // ->andFilterWhere(['like', 'intro_text', $this->intro_text]) // ->andFilterWhere(['like', 'full_text', $this->full_text]) // ->andFilterWhere(['like', 'intro_image', $this->intro_image]) // ->andFilterWhere(['like', "date_format(date(from_unixtime(created_at)) ,'%d-%m-%Y' )", $date_cr]) // ->andFilterWhere(['like', "date_format(date(from_unixtime(updated_at)) ,'%d-%m-%Y' )", $date_up]); // return $dataProvider; }
echo Html::a('Create Posts', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php $userModel = new $searchModel->module->userModel(); $user_items = \yii\helpers\ArrayHelper::map($userModel::find()->where('status = 10')->all(), 'id', 'username'); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'id', 'contentOptions' => ['style' => 'width: 7%;']], ['attribute' => 'description', 'contentOptions' => ['style' => 'width: 15%;']], ['attribute' => 'category', 'value' => function ($model) { if ($model->category) { $category = Category::findOne(['id' => $model->category]); if ($category) { return $category->name; } } }, 'contentOptions' => ['style' => 'width: 15%;'], 'filter' => TreeViewInput::widget(['model' => $searchModel, 'attribute' => 'category', 'showInactive' => true, 'query' => Category::find()->addOrderBy('root, lft'), 'headingOptions' => ['label' => 'Categories'], 'asDropdown' => true, 'multiple' => true, 'fontAwesome' => true, 'dropdownConfig' => ['dropdown' => ['style' => 'width:250px']], 'rootOptions' => ['label' => '<i class="fa fa-tree"></i>', 'class' => 'text-success']])], ['attribute' => 'user_created', 'value' => function ($model, $key, $index, $widget) { $userModel = new $model->module->userModel(); return $userModel::findOne(['id' => $model->user_created])->{$model->module->userNameField}; }, 'format' => 'html', 'contentOptions' => ['style' => 'width: 10%;'], 'filter' => \yii\bootstrap\Html::activeDropDownList($searchModel, 'user_created', $user_items, ['class' => 'form-control', 'prompt' => 'Select...'])], ['attribute' => 'created_at', 'format' => ['date', 'php:d-m-Y'], 'filter' => DateControl::widget(['model' => $searchModel, 'attribute' => 'created_at', 'name' => 'kartik-date-1', 'value' => 'created_at', 'type' => DateControl::FORMAT_DATE, 'options' => ['layout' => '{picker}{input}']]), 'contentOptions' => ['style' => 'width: 12%;']], ['attribute' => 'user_last_change', 'value' => function ($model, $key, $index, $widget) { $userModel = new $model->module->userModel(); return $userModel::findOne(['id' => $model->user_last_change])->{$model->module->userNameField}; }, 'format' => 'html', 'filter' => \yii\bootstrap\Html::activeDropDownList($searchModel, 'user_last_change', $user_items, ['class' => 'form-control', 'prompt' => 'Select...']), 'contentOptions' => ['style' => 'width: 10%;']], ['attribute' => 'updated_at', 'format' => ['date', 'php:d-m-Y'], 'filter' => DateControl::widget(['model' => $searchModel, 'attribute' => 'updated_at', 'name' => 'kartik-date-2', 'value' => 'updated_at', 'type' => DateControl::FORMAT_DATE, 'options' => ['layout' => '{picker}{input}']]), 'contentOptions' => ['style' => 'width: 10%;']], ['attribute' => 'publish', 'value' => function ($model, $key, $index, $widget) { return $model->publish == true ? '<span class="label label-success">Published</span>' : '<span class="label label-danger">Unpublished</span>'; }, 'format' => 'html', 'filter' => \yii\bootstrap\Html::activeDropDownList($searchModel, 'publish', ['0' => 'Unpublished', '1' => 'Published'], ['class' => 'form-control', 'prompt' => 'Select...']), 'contentOptions' => ['style' => 'width: 10%;']], ['class' => 'yii\\grid\\ActionColumn', 'contentOptions' => ['style' => 'min-width: 70px;']]]]); ?> </div> </div> </div>
<?php use yii\helpers\Html; use yii\helpers\Url; use yii\grid\GridView; use kartik\tree\TreeView; use yii\bootstrap\Tabs; ?> <div class="panel panel-primary"> <div class="panel-heading">Categories</div> <div class="panel-body"> <div class="posts-index"> <?php echo Tabs::widget(['items' => [['label' => 'Category Tree Admin', 'content' => '<br>' . TreeView::widget(['query' => \plathir\smartblog\backend\models\Categorytree::find()->addOrderBy('root, lft'), 'headingOptions' => ['label' => 'Categories'], 'isAdmin' => true, 'displayValue' => 1, 'softDelete' => true, 'showInactive' => true, 'cacheSettings' => ['enableCache' => false]])], ['label' => 'Extra fields', 'content' => '<br>' . GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['header' => 'Name', 'format' => 'html', 'value' => function ($model, $key, $index, $grid) { $lvlVal = ''; for ($x = 0; $x < $model->lvl; $x++) { if ($x == 0) { $lvlVal .= str_repeat(' ', 5); } $lvlVal .= '<span class="glyphicon glyphicon-minus" aria-hidden="true"></span>'; } if ($lvlVal == '') { $lvlVal .= '<span class="glyphicon glyphicon-tree-conifer" aria-hidden="true"></span>'; $lvlVal .= $model->name; } else { $lvlVal .= '<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>' . $model->name; } return $lvlVal; }], 'id', ['attribute' => 'active', 'value' => function ($model, $key, $index, $widget) { return $model->active == true ? '<span class="label label-success">Active</span>' : '<span class="label label-danger">Inactive</span>';
// 'minHeight' => 200, // // 'pastePlainText' => true, // // 'pasteImages' => true, // 'plugins' => [ // 'clips', // 'fullscreen' // ], //// 'imageGetJson' => Url::to(['/blog/posts/get']), //// 'imageUpload' => Url::to(['/blog/posts/image-upload']), //// 'fileUpload' => Url::to(['/blog/posts/file-upload']), //// 'clipboardUploadUrl' => Url::to(['/blog/posts/clipupl']) // ] // ]); ?> <?php echo $form->field($model, 'category')->widget(TreeViewInput::className(), ['model' => $model, 'attribute' => 'category', 'query' => Category::find()->addOrderBy('root, lft'), 'headingOptions' => ['label' => 'Categories'], 'asDropdown' => true, 'multiple' => false, 'showInactive' => true, 'fontAwesome' => true, 'rootOptions' => ['label' => '<i class="fa fa-tree"></i>', 'class' => 'text-success']]); ?> <?php echo $form->field($model, 'tags')->widget(SelectizeTextInput::className(), ['loadUrl' => ['/blog/posts/tagslist'], 'options' => ['class' => 'form-control'], 'clientOptions' => ['plugins' => ['remove_button'], 'valueField' => 'tags', 'labelField' => 'tags', 'searchField' => ['tags'], 'create' => true]]); ?> <div class="row-fluid"> <?php echo $form->field($model, 'attachments')->widget(UplWidget::className(), ['uploadUrl' => Url::toRoute(['/blog/posts/uploadfile']), 'previewUrl' => $model->module->ImagePathPreview, 'tempPreviewUrl' => $model->module->ImageTempPathPreview, 'KeyFolder' => $model->id]); ?> </div> <div class="row-fluid"> <?php echo $form->field($model, 'gallery')->widget(UplWidget::className(), ['uploadUrl' => Url::toRoute(['/blog/posts/uploadfile']), 'previewUrl' => $model->module->ImagePathPreview, 'tempPreviewUrl' => $model->module->ImageTempPathPreview, 'KeyFolder' => $model->id, 'galleryType' => true]); ?> </div>