/** * Создает DataProvider на основе переданных данных * @param $params - параметры * @return ActiveDataProvider */ public function search($params) { $query = Template::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $this::COUNT]]); $this->load($params); // Если валидация не пройдена, то ничего не выводить if (!$this->validate()) { $query->where('0=1'); return $dataProvider; } // Фильтрация $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'path', $this->path]); return $dataProvider; }
/** * Создание нового поля шаблона * @return string|\yii\web\Response */ public function actionCreate() { $model = new Field(); $model->template_id = Yii::$app->request->get('template_id'); $model->min = 0; $model->max = 1; $template = Template::findOne($model->template_id); if ($template == null) { throw new NotFoundHttpException(Yii::t('document', 'Запрашиваемая страница не найдена')); } if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->getSession()->setFlash('success', Yii::t('document', 'Новый поле создано.')); return $this->redirect(['template/update', 'id' => $model->template_id]); } else { return $this->render('@vendor/lowbase/yii2-document/views/field/create', ['model' => $model, 'template' => $template]); } }
<div class="col-lg-6"> <?php echo $form->field($model, 'status')->dropDownList(Document::getStatusArray()); ?> </div> </div> <div class="row"> <div class="col-lg-6"> <?php echo $form->field($model, 'parent_id')->widget(Select2::classname(), ['data' => Document::getAll(), 'options' => ['placeholder' => '', 'class' => 'parent_id'], 'pluginOptions' => ['allowClear' => true]]); ?> </div> <div class="col-lg-6"> <?php echo $form->field($model, 'template_id')->widget(Select2::classname(), ['data' => Template::getAll(), 'options' => ['placeholder' => '', 'class' => 'template_id'], 'pluginOptions' => ['allowClear' => true]]); ?> </div> </div> <div class="row"> <div class="col-lg-6"> <?php echo $form->field($model, 'meta_keywords')->textarea(['rows' => 2]); ?> </div> <div class="col-lg-6"> <?php echo $form->field($model, 'meta_description')->textarea(['rows' => 2]); ?> </div>
/** * Шаблон документа * @return \yii\db\ActiveQuery */ public function getTemplate() { return $this->hasOne(Template::className(), ['id' => 'template_id']); }
<?php echo $this->render('_search', ['model' => $searchModel]); ?> <?php echo $this->render('_tree', ['model' => $searchModel]); ?> <?php $gridColumns = [['class' => 'kartik\\grid\\SerialColumn', 'contentOptions' => ['class' => 'kartik-sheet-style'], 'width' => '30px', 'header' => '', 'headerOptions' => ['class' => 'kartik-sheet-style']], ['attribute' => 'id', 'width' => '70px', 'format' => 'raw', 'value' => function ($model) { $icon = $model->is_folder ? 'glyphicon glyphicon-folder-open' : 'glyphicon glyphicon-file'; return "<span class='" . $icon . "'></span> " . $model->id; }], 'name', ['attribute' => 'parent_id', 'vAlign' => 'middle', 'format' => 'raw', 'width' => '150px', 'value' => function ($model) { return $model->parent_id && $model->parent ? $model->parent->name : null; }, 'filter' => Document::getAll(), 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]], 'filterInputOptions' => ['placeholder' => ' ', 'class' => 'form-control']], ['attribute' => 'template_id', 'vAlign' => 'middle', 'format' => 'raw', 'width' => '150px', 'value' => function ($model) { return $model->template_id && $model->template ? $model->template->name : null; }, 'filter' => Template::getAll(), 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]], 'filterInputOptions' => ['placeholder' => ' ', 'class' => 'form-control']], ['attribute' => 'created_at', 'format' => ['date', 'dd.MM.Y HH:mm:ss'], 'width' => '200px', 'filter' => DatePicker::widget(['value' => isset($_GET['DocumentSearch']['created_at']) ? $_GET['DocumentSearch']['created_at'] : '', 'name' => 'DocumentSearch[created_at]', 'type' => DatePicker::TYPE_COMPONENT_APPEND, 'pluginOptions' => ['format' => 'dd.mm.yyyy', 'todayHighlight' => true]])], 'created_by', ['attribute' => 'status', 'vAlign' => 'middle', 'format' => 'raw', 'value' => function ($model) { switch ($model->status) { case Document::STATUS_BLOCKED: return '<span class="label label-danger"> <i class="glyphicon glyphicon-lock"></i> ' . Document::getStatusArray()[Document::STATUS_BLOCKED] . '</span>'; break; case Document::STATUS_WAIT: return '<span class="label label-warning"> <i class="glyphicon glyphicon-hourglass"></i> ' . Document::getStatusArray()[Document::STATUS_WAIT] . '</span>'; break; case Document::STATUS_ACTIVE: return '<span class="label label-success"> <i class="glyphicon glyphicon-ok"></i> ' . Document::getStatusArray()[Document::STATUS_ACTIVE] . '</span>'; break; } return false;
/** * Поиск модели шаблона по ID * @param integer $id * @return Template the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Template::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(Yii::t('document', 'Запрашиваемая страница не найдена.')); } }