/**
  * run function.
  *
  * @access public
  * @return void
  */
 public function run()
 {
     $randomId = uniqid();
     $tagsArray = ArrayHelper::map(FileTag::find()->select(['id', 'name'])->orderBy('name')->all(), 'id', 'name');
     $selectOptions = ArrayHelper::merge(['' => 'Select a File Tag'], $tagsArray);
     if ($this->hasModel()) {
         echo Html::activeDropDownList($this->model, $this->attribute, $selectOptions, $this->options);
     } else {
         echo Html::dropDownList($this->name, $this->value, $selectOptions, $this->options);
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = FileTag::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'slug', $this->slug]);
     return $dataProvider;
 }
示例#3
0
 public static function TagFirstFileOutput($id = 0, $options = [], $urlOnly = false)
 {
     $awsConfig = \Yii::$app->getModule('filemanager')->aws;
     $url = \Yii::$app->getModule('filemanager')->url;
     $path = \Yii::$app->getModule('filemanager')->path;
     $fileTag = FileTag::findOne($id);
     if (!$fileTag) {
         return null;
     }
     if (!isset($fileTag->firstfile[0])) {
         return null;
     }
     if ($urlOnly) {
         $return = $url . $fileTag->firstfile[0]->url;
     } else {
         $return = Html::img($url . $fileTag->firstfile[0]->url, $options);
     }
     return $return;
 }
 /**
  * [getFiles description]
  */
 public function getTags()
 {
     return $this->hasMany(FileTag::className(), ['id' => 'tag_id'])->viaTable('{{%file_tag_relationships}}', ['file_id' => 'id']);
 }
 /**
  * Updates an existing Files model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     FilemanagerAssets::register($this->view);
     $model = $this->findModel($id);
     $tags = FileTag::find()->orderBy('name')->all();
     $newTag = new FileTag();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         FileTagRelationships::deleteAll('file_id = ' . $model->id);
         $fielTags = new FileTagRelationships();
         $data = Yii::$app->request->post();
         if (isset($data['tags'])) {
             foreach ($data['tags'] as $value) {
                 $fielTags->isNewRecord = true;
                 $fielTags->id = null;
                 $fielTags->file_id = $model->id;
                 $fielTags->tag_id = $value;
                 $fielTags->save();
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'tags' => $tags, 'newTag' => $newTag]);
     }
 }
 /**
  * Finds the FileTag model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return FileTag the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = FileTag::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }