/**
  * Creates data provider instance with search query applied
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = self::find()->orderBy('created_at DESC');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     if ($this->tagIds) {
         $query->joinWith('tags')->andFilterWhere(['in', Tag::tableName() . '.id', $this->tagIds]);
     }
     return $dataProvider;
 }
Example #2
0
<?php

use ut8ia\filemanager\Module;
use ut8ia\filemanager\models\Tag;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
/* @var $this yii\web\View */
$form = ActiveForm::begin(['action' => '?', 'method' => 'get']);
?>
	<?php 
echo $form->field($model, 'tagIds')->widget(\kartik\select2\Select2::className(), ['maintainOrder' => true, 'data' => ArrayHelper::map(Tag::find()->all(), 'id', 'name'), 'options' => ['multiple' => true], 'addon' => ['append' => ['content' => Html::submitButton(Module::t('main', 'Search'), ['class' => 'btn btn-primary']), 'asButton' => true]]])->label(false);
ActiveForm::end();
Example #3
0
echo Html::a(Module::t('main', 'Delete'), ['file/delete/', 'id' => $model->id], ['class' => 'text-danger', 'data-message' => Yii::t('yii', 'Are you sure you want to delete this item?'), 'data-id' => $model->id, 'role' => 'delete']);
?>
</li>
</ul>

<div class="filename"><?php 
echo $model->filename;
?>
</div>

<?php 
$form = ActiveForm::begin(['action' => ['file/update', 'id' => $model->id], 'enableClientValidation' => false, 'options' => ['id' => 'control-form']]);
?>

    <?php 
echo $form->field($model, 'tagIds')->widget(\kartik\select2\Select2::className(), ['id' => 'update-image-tag', 'maintainOrder' => true, 'data' => ArrayHelper::map(Tag::find()->all(), 'id', 'name'), 'options' => ['multiple' => true], 'pluginOptions' => ['tags' => true, 'maximumInputLength' => 10, 'createTag' => new \yii\web\JsExpression("function (params) {\n                if (/^\\d+\$/.test(params.term)) {\n                    return null;\n                }\n                return {id: params.term, text: params.term};\n            }")]]);
?>

    <?php 
if ($model->isImage()) {
    ?>
        <?php 
    echo $form->field($model, 'alt')->textInput(['class' => 'form-control input-sm']);
    ?>
    <?php 
}
?>

    <?php 
echo $form->field($model, 'description')->textarea(['class' => 'form-control input-sm']);
?>
Example #4
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     Tag::removeUnusedTags();
 }