Commit 02e174a34bc16346857d244ed2777c24709b86a1
1 parent
002559aa
work with customer parser designer
Showing
5 changed files
with
48 additions
and
16 deletions
Show diff stats
backend/components/parsers/CustomCsvParser.php
@@ -11,6 +11,11 @@ namespace backend\components\parsers; | @@ -11,6 +11,11 @@ namespace backend\components\parsers; | ||
11 | 11 | ||
12 | class CustomCsvParser extends \yii\multiparser\CsvParser { | 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 | protected function readRow() | 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 | \ No newline at end of file | 15 | \ No newline at end of file |
backend/controllers/ParserController.php
@@ -9,7 +9,7 @@ use backend\models\UploadFileParsingForm; | @@ -9,7 +9,7 @@ use backend\models\UploadFileParsingForm; | ||
9 | use yii\web\UploadedFile; | 9 | use yii\web\UploadedFile; |
10 | use yii\data\ArrayDataProvider; | 10 | use yii\data\ArrayDataProvider; |
11 | 11 | ||
12 | -use common\components\debug\CustomVarDamp; | 12 | +use common\components\CustomVarDamp; |
13 | 13 | ||
14 | /** | 14 | /** |
15 | * Parser controller | 15 | * Parser controller |
@@ -28,18 +28,18 @@ class ParserController extends BaseController | @@ -28,18 +28,18 @@ class ParserController extends BaseController | ||
28 | 'class' => AccessControl::className(), | 28 | 'class' => AccessControl::className(), |
29 | 'rules' => [ | 29 | 'rules' => [ |
30 | [ | 30 | [ |
31 | - 'actions' => ['index','results'], | 31 | + 'actions' => ['index','results','write'], |
32 | 'allow' => true, | 32 | 'allow' => true, |
33 | 'roles' => ['@'], | 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,6 +92,7 @@ class ParserController extends BaseController | ||
92 | 92 | ||
93 | return $this->render('results', | 93 | return $this->render('results', |
94 | ['model' => $data, | 94 | ['model' => $data, |
95 | + 'imp' => $model, | ||
95 | 'dataProvider' => $provider]); | 96 | 'dataProvider' => $provider]); |
96 | } | 97 | } |
97 | 98 | ||
@@ -111,12 +112,16 @@ class ParserController extends BaseController | @@ -111,12 +112,16 @@ class ParserController extends BaseController | ||
111 | 112 | ||
112 | return $this->render('results', | 113 | return $this->render('results', |
113 | ['model' => $data, | 114 | ['model' => $data, |
115 | + 'imp' => $model, | ||
114 | 'dataProvider' => $provider]); | 116 | 'dataProvider' => $provider]); |
115 | } | 117 | } |
116 | 118 | ||
117 | return $this->render('index', ['model' => $model]); | 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,6 +21,7 @@ class UploadFileParsingForm extends Model | ||
21 | public $delimiter; | 21 | public $delimiter; |
22 | public $delete_price; | 22 | public $delete_price; |
23 | public $delete_prefix; | 23 | public $delete_prefix; |
24 | + public $first; | ||
24 | 25 | ||
25 | /** | 26 | /** |
26 | * @return array the validation rules. | 27 | * @return array the validation rules. |
@@ -36,7 +37,8 @@ class UploadFileParsingForm extends Model | @@ -36,7 +37,8 @@ class UploadFileParsingForm extends Model | ||
36 | ['importer', 'integer','max' => 999999, 'min' => 0 ], | 37 | ['importer', 'integer','max' => 999999, 'min' => 0 ], |
37 | [['action','delete_prefix', 'delete_price'], 'boolean'], | 38 | [['action','delete_prefix', 'delete_price'], 'boolean'], |
38 | ['delimiter', 'string', 'max' => 1], | 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,7 +55,7 @@ class UploadFileParsingForm extends Model | ||
53 | public function readFile($filePath){ | 55 | public function readFile($filePath){ |
54 | 56 | ||
55 | $data = Yii::$app->multiparser->parse($filePath); | 57 | $data = Yii::$app->multiparser->parse($filePath); |
56 | - | 58 | + // \common\components\CustomVarDamp::dumpAndDie($data); |
57 | if( !is_array($data) ){ | 59 | if( !is_array($data) ){ |
58 | $data = ['No results']; | 60 | $data = ['No results']; |
59 | } | 61 | } |
backend/views/parser/results.php
@@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
3 | use yii\helpers\Html; | 3 | use yii\helpers\Html; |
4 | use yii\grid\GridView; | 4 | use yii\grid\GridView; |
5 | use yii\grid\SerialColumn; | 5 | use yii\grid\SerialColumn; |
6 | +use yii\widgets\ActiveForm; | ||
6 | 7 | ||
7 | /* @var $this yii\web\View */ | 8 | /* @var $this yii\web\View */ |
8 | /* @var $searchModel backend\models\CatalogSearch */ | 9 | /* @var $searchModel backend\models\CatalogSearch */ |
@@ -14,22 +15,27 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -14,22 +15,27 @@ $this->params['breadcrumbs'][] = $this->title; | ||
14 | <div class="catalog-index"> | 15 | <div class="catalog-index"> |
15 | 16 | ||
16 | <h1><?= Html::encode($this->title) ?></h1> | 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 | <?= GridView::widget([ | 23 | <?= GridView::widget([ |
22 | 'dataProvider' => $dataProvider, | 24 | 'dataProvider' => $dataProvider, |
23 | 'columns' => [['class' => SerialColumn::className()], | 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 | '3', | 29 | '3', |
27 | '4', | 30 | '4', |
28 | '5',] | 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 | <?= Html::a('Вернуться', ['parser/index'], ['class' => 'btn btn-primary', 'name' => 'Return',]) ?> | 39 | <?= Html::a('Вернуться', ['parser/index'], ['class' => 'btn btn-primary', 'name' => 'Return',]) ?> |
34 | 40 | ||
35 | </div> | 41 | </div> |
36 | \ No newline at end of file | 42 | \ No newline at end of file |