Commit 02e174a34bc16346857d244ed2777c24709b86a1

Authored by Mihail
1 parent 002559aa

work with customer parser designer

backend/components/parsers/CustomCsvParser.php
... ... @@ -11,6 +11,11 @@ namespace backend\components\parsers;
11 11  
12 12 class CustomCsvParser extends \yii\multiparser\CsvParser {
13 13  
  14 + public $last_line = 10;
  15 + public $hasHeaderRow = true;
  16 + public $keys = ['first','second', 'third', 'forth', 'fifth'];
  17 +
  18 +
14 19 protected function readRow()
15 20 {
16 21  
... ...
backend/components/widgets/InputHeaderDataColumn.php 0 → 100644
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: Cibermag
  5 + * Date: 07.09.2015
  6 + * Time: 18:04
  7 + */
  8 +use yii\grid\DataColumn ;
  9 +class InputHeaderDataColumn extends DataColumn {
  10 +
  11 + protected function renderHeaderCellContent(){
  12 +
  13 + }
  14 +}
0 15 \ No newline at end of file
... ...
backend/controllers/ParserController.php
... ... @@ -9,7 +9,7 @@ use backend\models\UploadFileParsingForm;
9 9 use yii\web\UploadedFile;
10 10 use yii\data\ArrayDataProvider;
11 11  
12   -use common\components\debug\CustomVarDamp;
  12 +use common\components\CustomVarDamp;
13 13  
14 14 /**
15 15 * Parser controller
... ... @@ -28,18 +28,18 @@ class ParserController extends BaseController
28 28 'class' => AccessControl::className(),
29 29 'rules' => [
30 30 [
31   - 'actions' => ['index','results'],
  31 + 'actions' => ['index','results','write'],
32 32 'allow' => true,
33 33 'roles' => ['@'],
34 34 ],
35 35 ],
36 36 ],
37   - 'verbs' => [
38   - 'class' => VerbFilter::className(),
39   - 'actions' => [
40   - 'logout' => ['post'],
41   - ],
42   - ],
  37 +// 'verbs' => [
  38 +// 'class' => VerbFilter::className(),
  39 +// 'actions' => [
  40 +// 'logout' => ['post'],
  41 +// ],
  42 +// ],
43 43 ];
44 44 }
45 45  
... ... @@ -92,6 +92,7 @@ class ParserController extends BaseController
92 92  
93 93 return $this->render('results',
94 94 ['model' => $data,
  95 + 'imp' => $model,
95 96 'dataProvider' => $provider]);
96 97 }
97 98  
... ... @@ -111,12 +112,16 @@ class ParserController extends BaseController
111 112  
112 113 return $this->render('results',
113 114 ['model' => $data,
  115 + 'imp' => $model,
114 116 'dataProvider' => $provider]);
115 117 }
116 118  
117 119 return $this->render('index', ['model' => $model]);
118 120 }
  121 +public function actionWrite()
  122 +{
  123 + CustomVarDamp::dumpAndDie(Yii::$app->request->post());
119 124  
120   -
  125 +}
121 126  
122 127 }
... ...
backend/models/UploadFileParsingForm.php
... ... @@ -21,6 +21,7 @@ class UploadFileParsingForm extends Model
21 21 public $delimiter;
22 22 public $delete_price;
23 23 public $delete_prefix;
  24 + public $first;
24 25  
25 26 /**
26 27 * @return array the validation rules.
... ... @@ -36,7 +37,8 @@ class UploadFileParsingForm extends Model
36 37 ['importer', 'integer','max' => 999999, 'min' => 0 ],
37 38 [['action','delete_prefix', 'delete_price'], 'boolean'],
38 39 ['delimiter', 'string', 'max' => 1],
39   - ['delimiter', 'default', 'value' => ';']
  40 + ['delimiter', 'default', 'value' => ';'],
  41 + ['first', 'safe']
40 42  
41 43 ];
42 44 }
... ... @@ -53,7 +55,7 @@ class UploadFileParsingForm extends Model
53 55 public function readFile($filePath){
54 56  
55 57 $data = Yii::$app->multiparser->parse($filePath);
56   -
  58 + // \common\components\CustomVarDamp::dumpAndDie($data);
57 59 if( !is_array($data) ){
58 60 $data = ['No results'];
59 61 }
... ...
backend/views/parser/results.php
... ... @@ -3,6 +3,7 @@
3 3 use yii\helpers\Html;
4 4 use yii\grid\GridView;
5 5 use yii\grid\SerialColumn;
  6 +use yii\widgets\ActiveForm;
6 7  
7 8 /* @var $this yii\web\View */
8 9 /* @var $searchModel backend\models\CatalogSearch */
... ... @@ -14,22 +15,27 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
14 15 <div class="catalog-index">
15 16  
16 17 <h1><?= Html::encode($this->title) ?></h1>
17   - <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
18   -
  18 + <?php // echo $this->render('_search', ['model' => $searchModel]);
19 19  
20 20  
  21 + $form = ActiveForm::begin(['action' => 'write']);
  22 + ?>
21 23 <?= GridView::widget([
22 24 'dataProvider' => $dataProvider,
23 25 'columns' => [['class' => SerialColumn::className()],
24   - '1',
25   - '2',
  26 + ['header' => $form->field($imp, 'first')->dropDownList(['1'=>'001', '2'=>'002']),
  27 + 'attribute' => 'first' ],
  28 + 'second',
26 29 '3',
27 30 '4',
28 31 '5',]
29 32 ]); ?>
30 33  
  34 + <div class="form-group">
  35 + <?= Html::submitButton(Yii::t('app', 'Записать в БД'), ['class' => 'btn btn-primary']) ?>
  36 + </div>
31 37  
32   -
  38 + <?php ActiveForm::end() ?>
33 39 <?= Html::a('Вернуться', ['parser/index'], ['class' => 'btn btn-primary', 'name' => 'Return',]) ?>
34 40  
35 41 </div>
36 42 \ No newline at end of file
... ...