/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Files::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['date' => SORT_DESC]]]);
     $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, 'user_id' => $this->user_id, 'size' => $this->size, 'width' => $this->width, 'height' => $this->height, 'date' => $this->date, 'date_gmt' => $this->date_gmt, 'update' => $this->update, 'update_gmt' => $this->update_gmt]);
     $query->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'thumbnail_url', $this->thumbnail_url])->andFilterWhere(['like', 'file_name', $this->file_name])->andFilterWhere(['like', 'type', $this->type])->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
 /**
  * run function.
  *
  * @access public
  * @return void
  */
 public function run()
 {
     $randomId = uniqid();
     if (isset($this->clientOptions['fileTypes']) && !in_array('*', $this->clientOptions['fileTypes'])) {
         echo 'here';
         $where = ['type' => $this->clientOptions['fileTypes']];
     } else {
         $where = [];
     }
     $imageArray = ArrayHelper::map(Files::find()->select(['id', 'title'])->where($where)->orderBy('title')->all(), 'id', 'title');
     $selectOptions = ArrayHelper::merge(['' => 'Select a Thumbnail'], $imageArray);
     if ($this->hasModel()) {
         echo Html::activeDropDownList($this->model, $this->attribute, $selectOptions, $this->options);
     } else {
         echo Html::dropDownList($this->name, $this->value, $selectOptions, $this->options);
     }
 }
예제 #3
0
 /**
  * FileTerms function.
  *
  * @access public
  * @static
  * @param int $id (default: 0)
  * @return array
  */
 public static function FileTerms($id = 0)
 {
     $file = Files::findOne($id);
     $terms = [];
     if (!empty($file->fileTerms)) {
         foreach ($file->fileTerms as $v) {
             $terms[$v->type] = $v->value;
         }
     }
     return $terms;
 }
 /**
  * Finds the Files model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Files the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Files::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFile()
 {
     return $this->hasOne(Files::className(), ['id' => 'file_id']);
 }
예제 #6
0
 public function getFirstfile()
 {
     return $this->hasMany(Files::className(), ['id' => 'file_id'])->viaTable('{{%file_tag_relationships}}', ['tag_id' => 'id'], function ($query) {
         return $query->orderBy('sort');
     })->limit(1);
 }