Commit 2cdc93f0d475e731c75ff4c4f191fbc10ccedd04

Authored by Mihail
1 parent ef571c30

add crud models for ImportersPrefix

backend/controllers/CheckPriceController.php
... ... @@ -63,7 +63,6 @@ class CheckPriceController extends BaseController
63 63 {
64 64 //$query = (new Query())->select('*')->from('{{%importer_files}}')->where(['not', ['time_end' => null]])->orderBy(['upload_time' => SORT_DESC]);
65 65 $query = Importers::find()->where(['active' => true])->orderBy(['price_date_update' => SORT_DESC]);
66   -
67 66 $provider = new ActiveDataProvider([
68 67 'query' => $query,
69 68 'pagination' => [
... ... @@ -82,6 +81,9 @@ class CheckPriceController extends BaseController
82 81  
83 82 $query = Details::find()->where(['IMPORT_ID' => $id, 'timestamp' => $date_update])->limit(20);
84 83  
  84 + $importer = Importers::findOne($id)->name;
  85 + $date = Yii::$app->formatter->asDate( $date_update, 'yyyy-MM-dd' );
  86 +
85 87 $provider = new ActiveDataProvider([
86 88 'query' => $query,
87 89 'pagination' => false,
... ... @@ -89,7 +91,10 @@ class CheckPriceController extends BaseController
89 91 ]);
90 92  
91 93 return $this->renderAjax('view',
92   - ['dataProvider' => $provider]);
  94 + ['dataProvider' => $provider,
  95 + 'importer' => $importer,
  96 + 'date' => $date,
  97 + ]);
93 98 }
94 99  
95 100 }
... ...
backend/controllers/ImportersPrefixController.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace backend\controllers;
  4 +
  5 +use Yii;
  6 +use backend\models\ImportersPrefix;
  7 +use backend\models\ImportersPrefixSearch;
  8 +use backend\components\base\BaseController;
  9 +use yii\web\NotFoundHttpException;
  10 +use yii\filters\VerbFilter;
  11 +
  12 +/**
  13 + * ImportersPrefixController implements the CRUD actions for ImportersPrefix model.
  14 + */
  15 +class ImportersPrefixController extends BaseController
  16 +{
  17 + public $layout = "/column";
  18 +
  19 + public function behaviors()
  20 + {
  21 + return [
  22 + 'verbs' => [
  23 + 'class' => VerbFilter::className(),
  24 + 'actions' => [
  25 + 'delete' => ['post'],
  26 + ],
  27 + ],
  28 + ];
  29 + }
  30 +
  31 + /**
  32 + * Lists all ImportersPrefix models.
  33 + * @return mixed
  34 + */
  35 + public function actionIndex()
  36 + {
  37 + $searchModel = new ImportersPrefixSearch();
  38 + $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  39 +
  40 + return $this->render('index', [
  41 + 'searchModel' => $searchModel,
  42 + 'dataProvider' => $dataProvider,
  43 + ]);
  44 + }
  45 +
  46 +
  47 + /**
  48 + * Creates a new ImportersPrefix model.
  49 + * If creation is successful, the browser will be redirected to the 'view' page.
  50 + * @return mixed
  51 + */
  52 + public function actionCreate()
  53 + {
  54 + $model = new ImportersPrefix();
  55 +
  56 + if ($model->load(Yii::$app->request->post()) && $model->save()) {
  57 + return $this->redirect(['view', 'id' => $model->id]);
  58 + } else {
  59 + return $this->render('create', [
  60 + 'model' => $model,
  61 + ]);
  62 + }
  63 + }
  64 +
  65 + /**
  66 + * Updates an existing ImportersPrefix model.
  67 + * If update is successful, the browser will be redirected to the 'view' page.
  68 + * @param string $id
  69 + * @return mixed
  70 + */
  71 + public function actionUpdate($id)
  72 + {
  73 + $model = $this->findModel($id);
  74 +
  75 + if ($model->load(Yii::$app->request->post()) && $model->save()) {
  76 + return $this->redirect(['view', 'id' => $model->id]);
  77 + } else {
  78 + return $this->render('update', [
  79 + 'model' => $model,
  80 + ]);
  81 + }
  82 + }
  83 +
  84 + /**
  85 + * Deletes an existing ImportersPrefix model.
  86 + * If deletion is successful, the browser will be redirected to the 'index' page.
  87 + * @param string $id
  88 + * @return mixed
  89 + */
  90 + public function actionDelete($id)
  91 + {
  92 + $this->findModel($id)->delete();
  93 +
  94 + return $this->redirect(['index']);
  95 + }
  96 +
  97 + /**
  98 + * Finds the ImportersPrefix model based on its primary key value.
  99 + * If the model is not found, a 404 HTTP exception will be thrown.
  100 + * @param string $id
  101 + * @return ImportersPrefix the loaded model
  102 + * @throws NotFoundHttpException if the model cannot be found
  103 + */
  104 + protected function findModel($id)
  105 + {
  106 + if (($model = ImportersPrefix::findOne($id)) !== null) {
  107 + return $model;
  108 + } else {
  109 + throw new NotFoundHttpException('The requested page does not exist.');
  110 + }
  111 + }
  112 +}
... ...
backend/models/ImportersPrefix.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace backend\models;
  4 +
  5 +use Yii;
  6 +
  7 +/**
  8 + * This is the model class for table "w_importers_prefix".
  9 + *
  10 + * @property string $id
  11 + * @property string $importer_id
  12 + * @property string $brand
  13 + * @property string $prefix
  14 + * @property string $timestamp
  15 + */
  16 +class ImportersPrefix extends \backend\components\base\BaseActiveRecord
  17 +{
  18 + /**
  19 + * @inheritdoc
  20 + */
  21 + public static function tableName()
  22 + {
  23 + return 'w_importers_prefix';
  24 + }
  25 +
  26 + /**
  27 + * @inheritdoc
  28 + */
  29 + public function rules()
  30 + {
  31 + return [
  32 + [['importer_id', 'brand', 'prefix'], 'required'],
  33 + [['importer_id'], 'integer'],
  34 + [['timestamp'], 'safe'],
  35 + [['brand'], 'string', 'max' => 100],
  36 + [['prefix'], 'string', 'max' => 50],
  37 + [['importer_id', 'brand', 'prefix'], 'unique', 'targetAttribute' => ['importer_id', 'brand', 'prefix'], 'message' => 'The combination of Importer ID, Brand and Prefix has already been taken.']
  38 + ];
  39 + }
  40 +
  41 + /**
  42 + * @inheritdoc
  43 + */
  44 + public function attributeLabels()
  45 + {
  46 + return [
  47 + 'id' => Yii::t('app', 'ID'),
  48 + 'importer_id' => Yii::t('app', 'Importer ID'),
  49 + 'brand' => Yii::t('app', 'Brand'),
  50 + 'prefix' => Yii::t('app', 'Prefix'),
  51 + 'timestamp' => Yii::t('app', 'Timestamp'),
  52 + ];
  53 + }
  54 +}
... ...
backend/models/ImportersPrefixSearch.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace backend\models;
  4 +
  5 +use Yii;
  6 +use yii\base\Model;
  7 +use yii\data\ActiveDataProvider;
  8 +use backend\models\ImportersPrefix;
  9 +
  10 +/**
  11 + * ImportersPrefixSearh represents the model behind the search form about `backend\models\ImportersPrefix`.
  12 + */
  13 +class ImportersPrefixSearch extends ImportersPrefix
  14 +{
  15 + /**
  16 + * @inheritdoc
  17 + */
  18 + public function rules()
  19 + {
  20 + return [
  21 + [['id', 'importer_id'], 'integer'],
  22 + [['brand', 'prefix', 'timestamp'], 'safe'],
  23 + ];
  24 + }
  25 +
  26 + /**
  27 + * @inheritdoc
  28 + */
  29 + public function scenarios()
  30 + {
  31 + // bypass scenarios() implementation in the parent class
  32 + return Model::scenarios();
  33 + }
  34 +
  35 + /**
  36 + * Creates data provider instance with search query applied
  37 + *
  38 + * @param array $params
  39 + *
  40 + * @return ActiveDataProvider
  41 + */
  42 + public function search($params)
  43 + {
  44 + $query = ImportersPrefix::find();
  45 +
  46 + $dataProvider = new ActiveDataProvider([
  47 + 'query' => $query,
  48 + ]);
  49 +
  50 + $this->load($params);
  51 +
  52 + if (!$this->validate()) {
  53 + // uncomment the following line if you do not want to return any records when validation fails
  54 + // $query->where('0=1');
  55 + return $dataProvider;
  56 + }
  57 +
  58 + $query->andFilterWhere([
  59 + 'id' => $this->id,
  60 + 'importer_id' => $this->importer_id,
  61 + 'timestamp' => $this->timestamp,
  62 + ]);
  63 +
  64 + $query->andFilterWhere(['like', 'brand', $this->brand])
  65 + ->andFilterWhere(['like', 'prefix', $this->prefix]);
  66 +
  67 + return $dataProvider;
  68 + }
  69 +}
... ...
backend/models/UploadFileParsingForm.php
... ... @@ -69,10 +69,10 @@ class UploadFileParsingForm extends Model
69 69 ];
70 70 }
71 71  
72   - public function readFile(){
  72 + public function readFile( $options = [] ){
73 73  
74   - $data = Yii::$app->multiparser->parse( $this->file_path );
75   - if( !is_array($data) ){
  74 + $data = Yii::$app->multiparser->parse( $this->file_path, $options );
  75 + if( !is_array( $data ) ){
76 76 $data = ['No results'];
77 77 }
78 78  
... ...
backend/views/check-price/index.php
... ... @@ -16,7 +16,8 @@ $this-&gt;title = &#39;Проверка прайсов&#39;;
16 16 $this->params['breadcrumbs'][] = $this->title;
17 17 // зарегистрируем скрипт для обработки загрузки модального окна
18 18 ParserAsset::register($this);
19   -Pjax::begin();
  19 +// убрал Pjax потому что он при выполнении блокирует скрипт вызова модального окна
  20 +//Pjax::begin();
20 21 ?>
21 22 <div class="catalog-index">
22 23  
... ... @@ -73,9 +74,8 @@ Pjax::begin();
73 74 ]);
74 75  
75 76 echo "<div id='modalContent'></div>";
76   -
77 77 Modal::end();
78   - Pjax::end();
  78 + // Pjax::end();
79 79 ?>
80 80  
81 81  
... ...
backend/views/check-price/view.php
... ... @@ -8,8 +8,7 @@ use yii\bootstrap\Modal;
8 8 /* @var $this yii\web\View */
9 9 /* @var $searchModel backend\models\CatalogSearch */
10 10 /* @var $dataProvider yii\data\ActiveDataProvider */
11   -
12   -$this->title = 'Проверка прайсов';
  11 +$this->title = 'Прайс ' . Html::encode( "{$importer} от {$date}" );
13 12 $this->params['breadcrumbs'][] = $this->title;
14 13  
15 14 ?>
... ...
backend/views/importers-prefix/_form.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\widgets\ActiveForm;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model backend\models\ImportersPrefix */
  8 +/* @var $form yii\widgets\ActiveForm */
  9 +?>
  10 +
  11 +<div class="importers-prefix-form">
  12 +
  13 + <?php $form = ActiveForm::begin(); ?>
  14 +
  15 + <?= $form->field($model, 'importer_id')->textInput(['maxlength' => true]) ?>
  16 +
  17 + <?= $form->field($model, 'brand')->textInput(['maxlength' => true]) ?>
  18 +
  19 + <?= $form->field($model, 'prefix')->textInput(['maxlength' => true]) ?>
  20 +
  21 + <?= $form->field($model, 'timestamp')->textInput() ?>
  22 +
  23 + <div class="form-group">
  24 + <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
  25 + </div>
  26 +
  27 + <?php ActiveForm::end(); ?>
  28 +
  29 +</div>
... ...
backend/views/importers-prefix/_search.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\widgets\ActiveForm;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model backend\models\ImportersPrefixSearсh */
  8 +/* @var $form yii\widgets\ActiveForm */
  9 +?>
  10 +
  11 +<div class="importers-prefix-search">
  12 +
  13 + <?php $form = ActiveForm::begin([
  14 + 'action' => ['index'],
  15 + 'method' => 'get',
  16 + ]); ?>
  17 +
  18 + <?= $form->field($model, 'id') ?>
  19 +
  20 + <?= $form->field($model, 'importer_id') ?>
  21 +
  22 + <?= $form->field($model, 'brand') ?>
  23 +
  24 + <?= $form->field($model, 'prefix') ?>
  25 +
  26 + <?= $form->field($model, 'timestamp') ?>
  27 +
  28 + <div class="form-group">
  29 + <?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?>
  30 + <?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?>
  31 + </div>
  32 +
  33 + <?php ActiveForm::end(); ?>
  34 +
  35 +</div>
... ...
backend/views/importers-prefix/create.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model backend\models\ImportersPrefix */
  8 +
  9 +$this->title = Yii::t('app', 'Create Importers Prefix');
  10 +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Importers Prefixes'), 'url' => ['index']];
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +<div class="importers-prefix-create">
  14 +
  15 + <h1><?= Html::encode($this->title) ?></h1>
  16 +
  17 + <?= $this->render('_form', [
  18 + 'model' => $model,
  19 + ]) ?>
  20 +
  21 +</div>
... ...
backend/views/importers-prefix/index.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\grid\GridView;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $searchModel backend\models\ImportersPrefixSearсh */
  8 +/* @var $dataProvider yii\data\ActiveDataProvider */
  9 +
  10 +$this->title = Yii::t('app', 'Список префиксов поставщиков');
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +
  14 +<div class="importers-prefix-index">
  15 +
  16 + <h1><?= Html::encode($this->title) ?></h1>
  17 + <?= Html::a(Yii::t('app', 'Create Importers Prefix'), ['create'], ['class' => 'btn btn-success']) ?>
  18 + <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
  19 +
  20 +
  21 +
  22 + <?= GridView::widget([
  23 + 'dataProvider' => $dataProvider,
  24 + 'filterModel' => $searchModel,
  25 + 'columns' => [
  26 + ['class' => 'yii\grid\SerialColumn'],
  27 +
  28 + 'importer_id',
  29 + 'brand',
  30 + 'prefix',
  31 + 'timestamp',
  32 +
  33 + ['class' => 'yii\grid\ActionColumn',
  34 + 'template' => '{update},{delete}'],
  35 + ],
  36 + ]); ?>
  37 +
  38 +</div>
... ...
backend/views/importers-prefix/update.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +
  5 +/* @var $this yii\web\View */
  6 +/* @var $model backend\models\ImportersPrefix */
  7 +
  8 +$this->title = Yii::t('app', 'Update {modelClass}: ', [
  9 + 'modelClass' => 'Importers Prefix',
  10 +]) . ' ' . $model->id;
  11 +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Importers Prefixes'), 'url' => ['index']];
  12 +$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
  13 +$this->params['breadcrumbs'][] = Yii::t('app', 'Update');
  14 +?>
  15 +<div class="importers-prefix-update">
  16 +
  17 + <h1><?= Html::encode($this->title) ?></h1>
  18 +
  19 + <?= $this->render('_form', [
  20 + 'model' => $model,
  21 + ]) ?>
  22 +
  23 +</div>
... ...
backend/views/importers-prefix/view.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\widgets\DetailView;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model backend\models\ImportersPrefix */
  8 +
  9 +$this->title = $model->id;
  10 +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Importers Prefixes'), 'url' => ['index']];
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +<div class="importers-prefix-view">
  14 +
  15 + <h1><?= Html::encode($this->title) ?></h1>
  16 +
  17 + <p>
  18 + <?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
  19 + <?= Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [
  20 + 'class' => 'btn btn-danger',
  21 + 'data' => [
  22 + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'),
  23 + 'method' => 'post',
  24 + ],
  25 + ]) ?>
  26 + </p>
  27 +
  28 + <?= DetailView::widget([
  29 + 'model' => $model,
  30 + 'attributes' => [
  31 + 'id',
  32 + 'importer_id',
  33 + 'brand',
  34 + 'prefix',
  35 + 'timestamp',
  36 + ],
  37 + ]) ?>
  38 +
  39 +</div>
... ...
backend/views/layouts/column.php
... ... @@ -287,6 +287,7 @@ $this-&gt;beginContent(&#39;@app/views/layouts/main.php&#39;);
287 287 ['label' => 'Загрузить файл на сервер', 'url' => ['parser/index', 'mode' => 1]],
288 288 ['label' => 'Ручная загрузка', 'url' => ['parser/index']],
289 289 ['label' => 'Проверка прайс файлов', 'url' => ['check-price/index']],
  290 + ['label' => 'Управление префиксами', 'url' => ['importers-prefix/index']],
290 291 ],
291 292 ],
292 293 ['label' => 'Управление ролями', 'url' => ['#'], 'items' => [
... ...
backend/web/js/parser.js
1 1 $(function(){
2 2  
  3 + // check-price\view.php
3 4 // для каждой строки обрабатываем клик по ссылке
4 5 $('.modalButton').click(function (){
5 6 // находим контейнер с модальным контентом и подгружаем в него по оджаксу результат
6 7 $('#modal').modal('show')
7 8 .find('#modalContent')
8 9 .load($(this).attr('value')); // в 'value' - у нас указан путь с гет параметрами к конроллеру
  10 +
9 11 });
10 12  
  13 +
  14 + // server-files.php
11 15 $('.deleteLink').click(function ()
12 16 {
13 17 if ( confirm('Вы уверены что хотите удалить этот файл?') ){
... ...
vendor/yiisoft/multiparser/CsvParser.php
... ... @@ -97,7 +97,7 @@ class CsvParser implements ParserInterface
97 97 {
98 98  
99 99 $finish = false;
100   - while (!$finish) {
  100 + while (!$finish ) {
101 101 $this->current_line ++;
102 102  
103 103 $j = 0;
... ... @@ -118,9 +118,10 @@ class CsvParser implements ParserInterface
118 118 }
119 119 }
120 120 }
121   - die();
122   - // $this->current_line --;
123   - $this->file->seek( $this->current_line );
  121 + // @todo - сделать опционально
  122 + // код для того что бы парсить первую строку, закомментировано как предполагается что первая значимая строка это заголовок
  123 + // $this->current_line --;
  124 +// $this->file->seek( $this->current_line );
124 125 }
125 126  
126 127 /**
... ...