/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Tags::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'type' => $this->type]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use dosamigos\datetimepicker\DateTimePicker; use ut8ia\filemanager\widgets\TinyMCE; use kartik\select2\Select2; use ut8ia\multylang\models\Lang; use ut8ia\contentmodule\models\ContentRubrics; use ut8ia\contentmodule\models\ContentSections; use ut8ia\contentmodule\models\Tags; use conquer\codemirror\CodemirrorWidget; use conquer\codemirror\CodemirrorAsset; $model->SystemTags = $model->getLinkedTagsByType($model->id, 1, 0, null); $model->NavTags = $model->getLinkedTagsByType($model->id, 2, 0, null); $tags = new Tags(); ?> <div class="content-form"> <?php $form = ActiveForm::begin(['enableClientValidation' => false, 'options' => ['class' => 'form-horizontal', 'style' => 'padding-left:0px;'], 'fieldConfig' => ['template' => '<div class="col-lg-2 small">{label}</div><div class="col-lg-10">{input}{error}</div>', 'labelOptions' => ['style' => 'font-weight: lighter;'], 'inputOptions' => ['class' => 'form-control']]]); ?> <div class="form-group row"> <div class="col-lg-2 small"><?php echo Yii::t('main', 'Header'); ?> </div> <?php echo $form->field($model, 'name', ['template' => '<div class="col-lg-5">{input}</div>', 'options' => ['class' => 'inline']])->textInput(['maxlength' => true]); ?>
/* @var $form yii\widgets\ActiveForm */ // default navigation tag type $model->type = isset($model->type) ? $model->type : 2; ?> <div class="tags-form"> <?php $form = ActiveForm::begin(['enableClientValidation' => false, 'options' => ['class' => 'form-horizontal', 'style' => 'padding-left:0px;'], 'fieldConfig' => ['template' => '<div class="col-lg-2 small">{label}</div><div class="col-lg-10">{input}{error}</div>', 'labelOptions' => ['style' => 'font-weight: lighter;'], 'inputOptions' => ['class' => 'form-control']]]); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'type')->dropDownList(Tags::getSelector()); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
/** * Finds the Tags model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Tags the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tags::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return array */ public static function getSelector() { return Tags::getTypes(); }
use yii\grid\GridView; use ut8ia\contentmodule\models\Tags; /* @var $this yii\web\View */ /* @var $searchModel common\models\TagsSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('app', 'Tags'); // dd($tag_types); ?> <div class="tags-index"> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a(Yii::t('app', 'Create Tags'), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\ActionColumn', 'contentOptions' => ['class' => 'col-sm-1 small text-right', 'nowrap' => 'nowrap']], ['contentOptions' => ['class' => 'col-sm-1 small text-left'], 'attribute' => 'Id', 'format' => 'html', 'value' => function ($model) { return $model->id; }], ['contentOptions' => ['class' => 'col-sm-7 small text-left'], 'attribute' => 'Name', 'format' => 'html', 'value' => function ($model) { return $model->name; }], ['contentOptions' => ['class' => 'col-sm-4 small text-left'], 'attribute' => 'Type', 'format' => 'html', 'value' => function ($model) { return Tags::getTypes()[$model->type]; }]]]); ?> </div>
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use dosamigos\datetimepicker\DateTimePicker; use ut8ia\filemanager\widgets\TinyMCE; use kartik\select2\Select2; use ut8ia\multylang\models\Lang; use ut8ia\contentmodule\models\ContentRubrics; use ut8ia\contentmodule\models\ContentSections; use ut8ia\contentmodule\models\Tags; $model->SystemTags = $model->getLinkedTagsByType($model->id, 1, 0, null); $model->NavTags = $model->getLinkedTagsByType($model->id, 2, 0, null); $tags = new Tags(); ?> <div class="content-form"> <?php $form = ActiveForm::begin(['enableClientValidation' => false, 'options' => ['class' => 'form-horizontal', 'style' => 'padding-left:0px;'], 'fieldConfig' => ['template' => '<div class="col-lg-2 small">{label}</div><div class="col-lg-10">{input}{error}</div>', 'labelOptions' => ['style' => 'font-weight: lighter;'], 'inputOptions' => ['class' => 'form-control']]]); ?> <div class="form-group row"> <div class="col-lg-2 small"><?php echo Yii::t('main', 'Header'); ?> </div> <?php echo $form->field($model, 'name', ['template' => '<div class="col-lg-5">{input}</div>', 'options' => ['class' => 'inline']])->textInput(['maxlength' => true]); ?> <?php
/** * @param $article_id * @param $tag_type * @param $asArray * @param null $limit * @return $this|string */ public function getLinkedTagsByType($article_id, $tag_type, $asArray, $limit = null) { $out = ""; $ans = Tags::find()->from(['contentmanager_content'])->join('INNER JOIN', 'contentmanager_tags_link', '`contentmanager_tags_link`.`link_id` = `contentmanager_content`.`id`')->join('INNER JOIN', 'contentmanager_tags', '`contentmanager_tags`.`id` = `contentmanager_tags_link`.`tag_id`')->select(['`contentmanager_tags`.*'])->indexBy('id')->where(['=', '`contentmanager_content`.`id`', $article_id])->andWhere(['=', '`contentmanager_tags`.`type`', $tag_type]); if ((int) $limit) { $ans->limit($limit); } if ($asArray) { $ans->asArray(); } $ans = $ans->all(); if ($asArray) { foreach ($ans as $ind => $val) { $out[$ind] = $val['name']; } return $out; } return $ans; }