Example #1
0
 public function getAllAttachments()
 {
     if ($this->owner->isNewRecord) {
         return [];
     }
     return Attachment::find()->where(['table' => $this->owner->tableName(), 'object_id' => $this->owner->id])->orderBy(['id' => SORT_ASC])->all();
 }
 public function actionSortable()
 {
     /** @var  $modelList Attachment[]*/
     $data = \Yii::$app->request->get('data');
     $modelList = Attachment::find()->where(['id' => $data])->orderBy([new Expression('FIND_IN_SET(id,"' . implode(',', $data) . '")')])->all();
     foreach ($modelList as $k => $model) {
         $model->position = $k + 1;
         $model->save(false, ['position']);
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $document_id)
 {
     $query = Attachment::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['order' => SORT_ASC]]]);
     $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, 'size' => $this->size, 'document_id' => $document_id, 'order' => $this->order]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'original_name', $this->original_name]);
     return $dataProvider;
 }
 public function actions()
 {
     return ['sorting' => ['class' => \kotchuprik\sortable\actions\Sorting::className(), 'query' => Attachment::find()]];
 }