/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Explorer::find(); //->isExists(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]); $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, 'is_exsit' => $this->is_exsit, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'action', $this->action])->andFilterWhere(['like', 'session', $this->session])->andFilterWhere(['like', 'field', $this->field])->andFilterWhere(['like', 'path', $this->path])->andFilterWhere(['like', 'dir', $this->dir]); return $dataProvider; }
/** * @inheritdoc */ protected function getValue($event) { //查找资源表,获取有效资源信息 $del = Explorer::find()->where(['field' => $this->fileAttribute])->deleteDraft()->all(); $ins = Explorer::find()->where(['field' => $this->fileAttribute])->insertDraft()->all(); $owner = $this->owner; $value = $owner->getOldAttribute($this->fileAttribute); //注意:bug // print_r($value); // print_r($del); // print_r($ins); // exit; $fvalue = []; if ($value) { $fvalue = explode(',', $value); } $fdel = []; foreach ($del as $de) { $fdel[] = $de->path; //更新草稿状态 $de->status = Explorer::STATUS_COMPLETE; $de->update(false); } $fins = []; foreach ($ins as $in) { $fins[] = $in->path; //更新草稿状态 $in->status = Explorer::STATUS_COMPLETE; $in->update(false); } $fnew = []; if ($fins) { $fvalue = ArrayHelper::merge($fvalue, $fins); //所有不重复的文件 } if ($fdel) { $fvalue = array_diff($fvalue, $fdel); //取差集 } if (is_array($fvalue)) { sort($fvalue); } //排序 return empty($fvalue) ? '' : implode(',', $fvalue); }
/** * 资源管理器 * @param array $data * 数据: * ['action' => $data['action'], 'field' => $data['field'], 'path' => $data['path'], 'dir' => $data['dir'],] */ protected function addRecord($data) { //清除同名文件: if (!empty($data['path'])) { Explorer::deleteAll(['path' => $data['path'], 'status' => Explorer::STATUS_DRAFT, 'session' => Yii::$app->getSession()->id]); } if (!empty($data['field']) && !empty($data['path']) && !empty($data['dir']) && !empty($data['action'])) { $newData = ['is_exsit' => $data['action'] == Explorer::ACTION_DEL ? Explorer::EXIST_NO : Explorer::EXIST_YES, 'status' => Explorer::STATUS_DRAFT, 'session' => Yii::$app->getSession()->id, 'action' => $data['action'], 'field' => $data['field'], 'path' => $data['path'], 'dir' => $data['dir']]; $model = new Explorer(); if ($model->load($newData, '') && $model->save()) { fb($model->getErrors()); } } else { fb('上传资源参数有误。'); } }
/** * Finds the Explorer model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Explorer the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Explorer::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }