/** * 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; }
/** * 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]); } }