/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $_1cid) { if (Yii::$app->user->can('admin')) { $query = Acts::find(); } else { $query = Acts::find()->where(['users_user_1c_id' => $_1cid]); } $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->joinWith('usersUser'); $query->andFilterWhere(['id' => $this->id, 'begdate' => $this->begdate, 'enddate' => $this->enddate, 'customers_customer_1c_id' => $this->customers_customer_1c_id]); $query->andFilterWhere(['like', 'num', $this->num])->andFilterWhere(['like', 'begenddate', $this->begenddate])->andFilterWhere(['like', 'user.fullname', $this->users_user_1c_id])->andFilterWhere(['like', 'typedoc', $this->typedoc]); return $dataProvider; }
/** * читаем файл реестра и заполняем таблицу Acts */ public function readreestr() { $filename = 'Acts/ActsStore/reestr.txt'; $readfile = fopen($filename, 'r'); $unfind = ''; //массив для ненайденых документов while ($str = fgets($readfile)) { $items = explode(';', $str); $numdoc = substr($items[0], -18); $extension = pathinfo($numdoc, PATHINFO_EXTENSION); if (!file_exists('Acts/ActsStore/' . $numdoc)) { $unfind[] = $numdoc; //учет ненайденых документов unset($items); continue; } $begenddate = date('dmY', strtotime($items[5])) . '-' . date('dmY', strtotime($items[6])); $act = Acts::find()->andFilterWhere(['begenddate' => $begenddate])->andFilterWhere(['customers_customer_1c_id' => $items[3]])->andFilterWhere(['typedoc' => $items[7]])->one(); if (isset($act)) { $modelact = $this->findModel($act->id); $modelact->num = $numdoc; $link = Yii::$app->security->generateRandomString(16); //определяем имя файла copy('Acts/ActsStore/' . $numdoc, 'Acts/ActsDoc/' . $link . '.' . $extension); unlink('Acts/ActsStore/' . $numdoc); $modelact->link = $link . '.' . $extension; $modelact->save(); } else { $modelact = new Acts(); $modelact->num = $numdoc; $link = Yii::$app->security->generateRandomString(16); //определяем имя файла copy('Acts/ActsStore/' . $numdoc, 'Acts/ActsDoc/' . $link . '.' . $extension); unlink('Acts/ActsStore/' . $numdoc); $modelact->link = $link . '.' . $extension; $modelact->begdate = date('Y-m-d', strtotime($items[5])); $modelact->enddate = date('Y-m-d', strtotime($items[6])); $modelact->users_user_1c_id = $items[1]; $modelact->customers_customer_1c_id = $items[3]; $modelact->begenddate = $begenddate; $modelact->typedoc = $items[7]; $modelact->save(); } unset($items); } fclose($readfile); unlink($filename); if (isset($unfind)) { return $unfind; } else { return 0; } }