Commit 165348a4b71ac507fc29b789b3b16f8e28d3edcf

Authored by Mihail
1 parent e8db28d9

draft commit

backend/controllers/ParserController.php
@@ -71,7 +71,8 @@ class ParserController extends BaseController @@ -71,7 +71,8 @@ class ParserController extends BaseController
71 if ($model->load(Yii::$app->request->post())) { 71 if ($model->load(Yii::$app->request->post())) {
72 $model->file = UploadedFile::getInstance($model, 'file'); 72 $model->file = UploadedFile::getInstance($model, 'file');
73 73
74 - if ($model->file && $model->validate()) { 74 + if ($model->validate()) {
  75 + //CustomVarDamp::dumpAndDie(Yii::$app->request->post());
75 $filePath = Yii::getAlias('@webroot') . '/uploads/' . $model->file->baseName . '.' . $model->file->extension; 76 $filePath = Yii::getAlias('@webroot') . '/uploads/' . $model->file->baseName . '.' . $model->file->extension;
76 77
77 $model->file->saveAs( $filePath ); 78 $model->file->saveAs( $filePath );
backend/models/Importer.php
@@ -89,4 +89,7 @@ class Importer extends BaseActiveRecord @@ -89,4 +89,7 @@ class Importer extends BaseActiveRecord
89 'price_date_update' => Yii::t('app', 'Price Date Update'), 89 'price_date_update' => Yii::t('app', 'Price Date Update'),
90 ]; 90 ];
91 } 91 }
  92 +
  93 +
  94 +
92 } 95 }
backend/models/UploadFileParsingForm.php
@@ -5,6 +5,7 @@ use yii\base\Model; @@ -5,6 +5,7 @@ use yii\base\Model;
5 use yii\web\UploadedFile; 5 use yii\web\UploadedFile;
6 use backend\components\ParserHandler; 6 use backend\components\ParserHandler;
7 use Yii; 7 use Yii;
  8 +use common\components\debug\CustomVarDamp;
8 9
9 /** 10 /**
10 * UploadForm is the model behind the upload form. 11 * UploadForm is the model behind the upload form.
@@ -17,9 +18,9 @@ class UploadFileParsingForm extends Model @@ -17,9 +18,9 @@ class UploadFileParsingForm extends Model
17 public $file; 18 public $file;
18 public $importer; 19 public $importer;
19 public $action; 20 public $action;
20 -// public $delimiter;  
21 -// public $delimiter_flag;  
22 -// public $delete_prefix; 21 + public $delimiter;
  22 + public $delete_price;
  23 + public $delete_prefix;
23 24
24 /** 25 /**
25 * @return array the validation rules. 26 * @return array the validation rules.
@@ -27,11 +28,15 @@ class UploadFileParsingForm extends Model @@ -27,11 +28,15 @@ class UploadFileParsingForm extends Model
27 public function rules() 28 public function rules()
28 { 29 {
29 return [ 30 return [
30 - [['file'], 'file', 'extensions' => ['csv', 'xml'] ],  
31 - ['importer', 'safe'],  
32 - ['action', 'boolean']  
33 -// ['delimiter', 'string', 'max' => 1],  
34 -// ['delimiter', 'default', 'value' => ';'], 31 + ['importer', 'required', 'message' => 'Не указан поставщик!' ],
  32 + ['file', 'required', 'message' => 'Не выбран файл!' ],
  33 + //@todo - not working this file validator!!! - fixed
  34 + [['file'], 'file', 'extensions' => ['csv', 'xml'] ], //'extensions' => ['csv'],
  35 + // 'wrongMimeType' => 'Указан неподдерживаемый тип файла. Можно выбирать csv, xml файлы.' ],
  36 + ['importer', 'integer','max' => 999999, 'min' => 0 ],
  37 + [['action','delete_prefix', 'delete_price'], 'boolean'],
  38 + ['delimiter', 'string', 'max' => 1],
  39 + ['delimiter', 'default', 'value' => ';']
35 40
36 ]; 41 ];
37 } 42 }
@@ -40,12 +45,13 @@ class UploadFileParsingForm extends Model @@ -40,12 +45,13 @@ class UploadFileParsingForm extends Model
40 { 45 {
41 return [ 46 return [
42 'file' => Yii::t('app', 'Источник'), 47 'file' => Yii::t('app', 'Источник'),
43 - 'first_line' => Yii::t('app', 'Первая значимая строка'),  
44 - 'first_column' => Yii::t('app', 'Первый значимый столбец'), 48 + 'importer' => Yii::t('app', 'Поставщик'),
  49 + 'delimiter' => Yii::t('app', 'Разделитель'),
45 ]; 50 ];
46 } 51 }
47 52
48 public function readFile($filePath){ 53 public function readFile($filePath){
  54 + CustomVarDamp::dumpAndDie( new ParserHandler( $filePath, $this ));
49 $parser = new ParserHandler( $filePath, $this ); 55 $parser = new ParserHandler( $filePath, $this );
50 $data = $parser->run(); 56 $data = $parser->run();
51 57
backend/views/parser/index.php
1 <?php 1 <?php
2 use yii\widgets\ActiveForm; 2 use yii\widgets\ActiveForm;
3 use yii\helpers\Html; 3 use yii\helpers\Html;
  4 +use backend\models\Importer;
  5 +use yii\helpers\ArrayHelper;
4 6
5 ?> 7 ?>
6 <div class="row"> 8 <div class="row">
@@ -9,11 +11,14 @@ use yii\helpers\Html; @@ -9,11 +11,14 @@ use yii\helpers\Html;
9 <h3>Загрузка прайсов поставщиков</h3> 11 <h3>Загрузка прайсов поставщиков</h3>
10 12
11 13
12 - <?= $form->field($model, 'importer')->dropDownList(['1'=>'test1', '2'=>'test2', '3'=>'test3' ]); ?>  
13 - <?= $form->field($model, 'file')->fileInput() ?>  
14 - <?= Html::radio('action', true, ['label' => 'Radio1']); ?>  
15 - <?= Html::radio('action', true, ['label' => 'Radio2']); ?>  
16 - <?= Html::checkbox('agree', true, ['label' => 'Checkbox']); ?> 14 + <?= $form->field($model, 'importer')->dropDownList(ArrayHelper::map( Importer::find()->all(), 'id','name' )); ?>
  15 + <?= $form->field($model, 'delete_price')->checkbox(['label' => 'Загрузить с удалением старого прайса']) ?>
  16 + <?= $form->field($model, 'file')->fileInput()->label(false) ?>
  17 + <?= $form->field($model, 'action')->radioList([1 => 'Стандартная обработка', 0 => 'С разделителем'])->label(false) ?>
  18 + <?= $form->field($model, 'delimiter', ['inputOptions' => ['value' => ';']]) ?>
  19 +
  20 + <?= $form->field($model, 'delete_prefix')->checkbox(['label' => 'Удалять префикс']) ?>
  21 +
17 22
18 <div class="form-group"> 23 <div class="form-group">
19 <?= Html::submitButton(Yii::t('app', 'Прочитать'), ['class' => 'btn btn-primary']) ?> 24 <?= Html::submitButton(Yii::t('app', 'Прочитать'), ['class' => 'btn btn-primary']) ?>