diff --git a/backend/controllers/CheckPriceController.php b/backend/controllers/CheckPriceController.php index a0814fe..3525ab3 100644 --- a/backend/controllers/CheckPriceController.php +++ b/backend/controllers/CheckPriceController.php @@ -63,7 +63,6 @@ class CheckPriceController extends BaseController { //$query = (new Query())->select('*')->from('{{%importer_files}}')->where(['not', ['time_end' => null]])->orderBy(['upload_time' => SORT_DESC]); $query = Importers::find()->where(['active' => true])->orderBy(['price_date_update' => SORT_DESC]); - $provider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ @@ -82,6 +81,9 @@ class CheckPriceController extends BaseController $query = Details::find()->where(['IMPORT_ID' => $id, 'timestamp' => $date_update])->limit(20); + $importer = Importers::findOne($id)->name; + $date = Yii::$app->formatter->asDate( $date_update, 'yyyy-MM-dd' ); + $provider = new ActiveDataProvider([ 'query' => $query, 'pagination' => false, @@ -89,7 +91,10 @@ class CheckPriceController extends BaseController ]); return $this->renderAjax('view', - ['dataProvider' => $provider]); + ['dataProvider' => $provider, + 'importer' => $importer, + 'date' => $date, + ]); } } diff --git a/backend/controllers/ImportersPrefixController.php b/backend/controllers/ImportersPrefixController.php new file mode 100644 index 0000000..dec3025 --- /dev/null +++ b/backend/controllers/ImportersPrefixController.php @@ -0,0 +1,112 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['post'], + ], + ], + ]; + } + + /** + * Lists all ImportersPrefix models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new ImportersPrefixSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + + /** + * Creates a new ImportersPrefix model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new ImportersPrefix(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing ImportersPrefix model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param string $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing ImportersPrefix model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param string $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the ImportersPrefix model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param string $id + * @return ImportersPrefix the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = ImportersPrefix::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/models/ImportersPrefix.php b/backend/models/ImportersPrefix.php new file mode 100644 index 0000000..ae0ca79 --- /dev/null +++ b/backend/models/ImportersPrefix.php @@ -0,0 +1,54 @@ + 100], + [['prefix'], 'string', 'max' => 50], + [['importer_id', 'brand', 'prefix'], 'unique', 'targetAttribute' => ['importer_id', 'brand', 'prefix'], 'message' => 'The combination of Importer ID, Brand and Prefix has already been taken.'] + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('app', 'ID'), + 'importer_id' => Yii::t('app', 'Importer ID'), + 'brand' => Yii::t('app', 'Brand'), + 'prefix' => Yii::t('app', 'Prefix'), + 'timestamp' => Yii::t('app', 'Timestamp'), + ]; + } +} diff --git a/backend/models/ImportersPrefixSearch.php b/backend/models/ImportersPrefixSearch.php new file mode 100644 index 0000000..2cbe07b --- /dev/null +++ b/backend/models/ImportersPrefixSearch.php @@ -0,0 +1,69 @@ + $query, + ]); + + $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, + 'importer_id' => $this->importer_id, + 'timestamp' => $this->timestamp, + ]); + + $query->andFilterWhere(['like', 'brand', $this->brand]) + ->andFilterWhere(['like', 'prefix', $this->prefix]); + + return $dataProvider; + } +} diff --git a/backend/models/UploadFileParsingForm.php b/backend/models/UploadFileParsingForm.php index 3f8eb10..19d32c2 100644 --- a/backend/models/UploadFileParsingForm.php +++ b/backend/models/UploadFileParsingForm.php @@ -69,10 +69,10 @@ class UploadFileParsingForm extends Model ]; } - public function readFile(){ + public function readFile( $options = [] ){ - $data = Yii::$app->multiparser->parse( $this->file_path ); - if( !is_array($data) ){ + $data = Yii::$app->multiparser->parse( $this->file_path, $options ); + if( !is_array( $data ) ){ $data = ['No results']; } diff --git a/backend/views/check-price/index.php b/backend/views/check-price/index.php index dce29bb..8fe6322 100644 --- a/backend/views/check-price/index.php +++ b/backend/views/check-price/index.php @@ -16,7 +16,8 @@ $this->title = 'Проверка прайсов'; $this->params['breadcrumbs'][] = $this->title; // зарегистрируем скрипт для обработки загрузки модального окна ParserAsset::register($this); -Pjax::begin(); +// убрал Pjax потому что он при выполнении блокирует скрипт вызова модального окна +//Pjax::begin(); ?>
+ = Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> + = Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id', + 'importer_id', + 'brand', + 'prefix', + 'timestamp', + ], + ]) ?> + +