Commit 9e1b54038147b90c83edce3ba50b166353cd4820
Merge remote-tracking branch 'origin/master'
# Conflicts: # frontend/web/css/main.css
Showing
200 changed files
with
2602 additions
and
1540 deletions
Show diff stats
Too many changes.
To preserve performance only 100 of 200 files are displayed.
backend/components/base/BaseController.php
@@ -216,36 +216,5 @@ class BaseController extends Controller { | @@ -216,36 +216,5 @@ class BaseController extends Controller { | ||
216 | } | 216 | } |
217 | } | 217 | } |
218 | 218 | ||
219 | - /** | ||
220 | - * @param $mode - int: 0 - fetch from cache, - 1 - put in cache, <2 - delete from cache | ||
221 | - * @param $data - array | ||
222 | - * @param $configuration - array | ||
223 | - * @throws \ErrorException | ||
224 | - */ | ||
225 | - protected function parserCacheHandler( $mode, &$data = [], &$configuration = [] ){ | ||
226 | - switch ( $mode ) { | ||
227 | - case 0: | ||
228 | - if (Yii::$app->getCache()->get('parser_data') && Yii::$app->getCache()->get('parser_configuration')) { | ||
229 | - $data = json_decode(Yii::$app->getCache()->get('parser_data'), true); | ||
230 | - $configuration = unserialize(Yii::$app->getCache()->get('parser_configuration')); | ||
231 | - } else { | ||
232 | - throw new \ErrorException('Ошибка кеша'); | ||
233 | - } | ||
234 | - break; | ||
235 | - | ||
236 | - case 1: | ||
237 | - Yii::$app->getCache()->set('parser_data', json_encode($data), 1800); | ||
238 | - // сохраняем в кеш модель - в ней настройки для дальнейшей обработки данных | ||
239 | - Yii::$app->getCache()->set('parser_configuration', serialize($configuration), 1800); | ||
240 | - break; | ||
241 | - | ||
242 | - default: | ||
243 | - if( Yii::$app->getCache()->exists('parser_data') ) | ||
244 | - Yii::$app->getCache()->delete('parser_data'); | ||
245 | - | ||
246 | - if( Yii::$app->getCache()->exists('parser_configuration') ) | ||
247 | - Yii::$app->getCache()->delete('parser_configuration'); | ||
248 | - } | ||
249 | 219 | ||
250 | - } | ||
251 | } | 220 | } |
252 | \ No newline at end of file | 221 | \ No newline at end of file |
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Tsurkanov | ||
5 | + * Date: 01.12.2015 | ||
6 | + * Time: 9:42 | ||
7 | + */ | ||
8 | +namespace backend\components\traits; | ||
9 | + | ||
10 | +use common\components\parsers\DynamicFormHelper; | ||
11 | +use Yii; | ||
12 | +use yii\base\ErrorException; | ||
13 | +use yii\data\ArrayDataProvider; | ||
14 | + | ||
15 | +trait ParserTrait | ||
16 | +{ | ||
17 | + | ||
18 | + /** | ||
19 | + * @param $mode - int: 0 - fetch from cache, - 1 - put in cache, <2 - delete from cache | ||
20 | + * @param $data - array | ||
21 | + * @param $configuration - array | ||
22 | + * @throws \ErrorException | ||
23 | + */ | ||
24 | + public function parserCacheHandler($mode, &$data = [], &$configuration = []) | ||
25 | + { | ||
26 | + switch ($mode) { | ||
27 | + case 0: | ||
28 | + if (Yii::$app->getCache()->get('parser_data') && Yii::$app->getCache()->get('parser_configuration')) { | ||
29 | + $data = json_decode(Yii::$app->getCache()->get('parser_data'), true); | ||
30 | + $configuration = unserialize(Yii::$app->getCache()->get('parser_configuration')); | ||
31 | + } else { | ||
32 | + throw new \ErrorException('Ошибка кеша'); | ||
33 | + } | ||
34 | + break; | ||
35 | + | ||
36 | + case 1: | ||
37 | + Yii::$app->getCache()->set('parser_data', json_encode($data), 1800); | ||
38 | + // сохраняем в кеш модель - в ней настройки для дальнейшей обработки данных | ||
39 | + Yii::$app->getCache()->set('parser_configuration', serialize($configuration), 1800); | ||
40 | + break; | ||
41 | + | ||
42 | + default: | ||
43 | + if (Yii::$app->getCache()->exists('parser_data')) | ||
44 | + Yii::$app->getCache()->delete('parser_data'); | ||
45 | + | ||
46 | + if (Yii::$app->getCache()->exists('parser_configuration')) | ||
47 | + Yii::$app->getCache()->delete('parser_configuration'); | ||
48 | + } | ||
49 | + | ||
50 | + } | ||
51 | + | ||
52 | + public function renderResultView($data) | ||
53 | + { | ||
54 | + $provider = new ArrayDataProvider([ | ||
55 | + 'allModels' => $data, | ||
56 | + 'pagination' => [ | ||
57 | + 'pageSize' => 10, | ||
58 | + ], | ||
59 | + ]); | ||
60 | + | ||
61 | + // создадим модель на столько реквизитов сколько колонок в отпарсенном файле | ||
62 | + $last_index = end(array_flip($data[0])); | ||
63 | + $header_counts = $last_index + 1; | ||
64 | + $header_model = DynamicFormHelper::CreateDynamicModel($header_counts); | ||
65 | + | ||
66 | + // соберем массив данных из которых будет пользователь выбирать значения в конструкторе (выпадающий список) | ||
67 | + $basicColumns = $this->getBasicColumns(); | ||
68 | + | ||
69 | + return $this->render('results', | ||
70 | + ['model' => $data, | ||
71 | + 'header_model' => $header_model, | ||
72 | + // список колонок для выбора | ||
73 | + 'basic_column' => $basicColumns, | ||
74 | + 'dataProvider' => $provider]); | ||
75 | + | ||
76 | + } | ||
77 | + | ||
78 | + public function throwStringErrorException( $model , $exception, $errors_str = '' ) | ||
79 | + { | ||
80 | + foreach ( $model->getErrors() as $error ) | ||
81 | + { | ||
82 | + $errors_str .= ' ' . implode( array_values( $error ) ); | ||
83 | + } | ||
84 | + | ||
85 | + throw new $exception( $errors_str ); | ||
86 | + } | ||
87 | + | ||
88 | + } | ||
0 | \ No newline at end of file | 89 | \ No newline at end of file |
backend/config/main.php
@@ -16,6 +16,9 @@ return [ | @@ -16,6 +16,9 @@ return [ | ||
16 | 'user' => [ | 16 | 'user' => [ |
17 | 'identityClass' => 'common\models\User', | 17 | 'identityClass' => 'common\models\User', |
18 | 'enableAutoLogin' => true, | 18 | 'enableAutoLogin' => true, |
19 | + 'identityCookie' => [ | ||
20 | + 'name' => '_backendUser', // unique for backend | ||
21 | + ] | ||
19 | ], | 22 | ], |
20 | 'log' => [ | 23 | 'log' => [ |
21 | 'traceLevel' => YII_DEBUG ? 3 : 0, | 24 | 'traceLevel' => YII_DEBUG ? 3 : 0, |
@@ -30,6 +33,8 @@ return [ | @@ -30,6 +33,8 @@ return [ | ||
30 | 'errorAction' => 'parser/error', | 33 | 'errorAction' => 'parser/error', |
31 | ], | 34 | ], |
32 | 'request'=>[ | 35 | 'request'=>[ |
36 | + 'cookieValidationKey' => 'j4iuot9u5894e7tu8reyh78g9y54sy7i', | ||
37 | + 'csrfParam' => '_backendCSRF', | ||
33 | 38 | ||
34 | 'class' => 'common\components\Request', | 39 | 'class' => 'common\components\Request', |
35 | 40 | ||
@@ -38,6 +43,10 @@ return [ | @@ -38,6 +43,10 @@ return [ | ||
38 | 'adminUrl' => '/admin' | 43 | 'adminUrl' => '/admin' |
39 | 44 | ||
40 | ], | 45 | ], |
46 | + 'session' => [ | ||
47 | + 'name' => 'PHPBACKSESSID', | ||
48 | + 'savePath' => __DIR__ . '/../tmp', | ||
49 | + ], | ||
41 | 50 | ||
42 | ], | 51 | ], |
43 | 'params' => $params, | 52 | 'params' => $params, |
backend/controllers/CrossingUploadController.php
@@ -10,21 +10,24 @@ namespace backend\controllers; | @@ -10,21 +10,24 @@ namespace backend\controllers; | ||
10 | 10 | ||
11 | use backend\components\base\BaseController; | 11 | use backend\components\base\BaseController; |
12 | use common\components\CustomArrayHelper; | 12 | use common\components\CustomArrayHelper; |
13 | +use common\components\exceptions\CrossParsingException; | ||
14 | +use yii\base\Exception; | ||
13 | use yii\data\ArrayDataProvider; | 15 | use yii\data\ArrayDataProvider; |
14 | use yii\filters\VerbFilter; | 16 | use yii\filters\VerbFilter; |
15 | use yii\filters\AccessControl; | 17 | use yii\filters\AccessControl; |
16 | use backend\models\UploadFileCrossingForm; | 18 | use backend\models\UploadFileCrossingForm; |
17 | use backend\models\DetailsCrosses; | 19 | use backend\models\DetailsCrosses; |
18 | -use yii\multiparser\DynamicFormHelper; | 20 | +use common\components\parsers\DynamicFormHelper; |
19 | use yii\web\UploadedFile; | 21 | use yii\web\UploadedFile; |
20 | use common\components\ModelArrayValidator; | 22 | use common\components\ModelArrayValidator; |
21 | use \Yii; | 23 | use \Yii; |
24 | +use backend\components\traits\ParserTrait; | ||
22 | 25 | ||
23 | class CrossingUploadController extends BaseController | 26 | class CrossingUploadController extends BaseController |
24 | { | 27 | { |
28 | + use ParserTrait; | ||
25 | public $layout = "/column"; | 29 | public $layout = "/column"; |
26 | 30 | ||
27 | - | ||
28 | /** | 31 | /** |
29 | * @inheritdoc | 32 | * @inheritdoc |
30 | */ | 33 | */ |
@@ -35,7 +38,7 @@ class CrossingUploadController extends BaseController | @@ -35,7 +38,7 @@ class CrossingUploadController extends BaseController | ||
35 | 'class' => AccessControl::className(), | 38 | 'class' => AccessControl::className(), |
36 | 'rules' => [ | 39 | 'rules' => [ |
37 | [ | 40 | [ |
38 | - 'actions' => ['result', 'index', 'write'], | 41 | + 'actions' => ['result', 'index', 'write', 'error'], |
39 | 'allow' => true, | 42 | 'allow' => true, |
40 | 'roles' => ['@'], | 43 | 'roles' => ['@'], |
41 | ], | 44 | ], |
@@ -50,18 +53,6 @@ class CrossingUploadController extends BaseController | @@ -50,18 +53,6 @@ class CrossingUploadController extends BaseController | ||
50 | ]; | 53 | ]; |
51 | } | 54 | } |
52 | 55 | ||
53 | - /** | ||
54 | - * @inheritdoc | ||
55 | - */ | ||
56 | - public function actions() | ||
57 | - { | ||
58 | - return [ | ||
59 | - 'error' => [ | ||
60 | - 'class' => 'yii\web\ErrorAction', | ||
61 | - ], | ||
62 | - ]; | ||
63 | - } | ||
64 | - | ||
65 | 56 | ||
66 | public function actionIndex() | 57 | public function actionIndex() |
67 | { | 58 | { |
@@ -69,60 +60,56 @@ class CrossingUploadController extends BaseController | @@ -69,60 +60,56 @@ class CrossingUploadController extends BaseController | ||
69 | return $this->render('index', ['model' => $model]); | 60 | return $this->render('index', ['model' => $model]); |
70 | } | 61 | } |
71 | 62 | ||
63 | + | ||
72 | public function actionResult() | 64 | public function actionResult() |
73 | { | 65 | { |
74 | $model = new UploadFileCrossingForm(); | 66 | $model = new UploadFileCrossingForm(); |
75 | $data = []; | 67 | $data = []; |
76 | - if ($model->load(Yii::$app->request->post())) { | 68 | + if ( $model->load(Yii::$app->request->post()) ) { |
77 | $model->file = UploadedFile::getInstance($model, 'file'); | 69 | $model->file = UploadedFile::getInstance($model, 'file'); |
78 | - if ($model->validate()) { | 70 | + |
71 | + if ( $model->validate() ) { | ||
79 | $file_name = $model->file->name; | 72 | $file_name = $model->file->name; |
80 | $model->file_path = Yii::getAlias('@temp_upload') . '/' . $file_name; | 73 | $model->file_path = Yii::getAlias('@temp_upload') . '/' . $file_name; |
81 | $model->file->saveAs($model->file_path); | 74 | $model->file->saveAs($model->file_path); |
82 | //запускаем парсинг | 75 | //запускаем парсинг |
83 | $data = $model->readFile(); | 76 | $data = $model->readFile(); |
84 | // сохраняем в кеш отпарсенные даные | 77 | // сохраняем в кеш отпарсенные даные |
85 | - $this->parserCacheHandler( 1, $data, $model ); | ||
86 | - } else if (Yii::$app->getCache()->get('parser_data')) { | ||
87 | - $data = json_decode(Yii::$app->getCache()->get('parser_data'), true); | 78 | + $this->parserCacheHandler( 1, $data, $model ); |
79 | + } else { | ||
80 | + // не прошла валидация формы загрузки файлов | ||
81 | + $errors_str = "Ошибка загрузки файла. "; | ||
82 | + $this->throwStringErrorException( $model , new CrossParsingException( $errors_str ) ); | ||
88 | } | 83 | } |
89 | - $provider = new ArrayDataProvider([ | ||
90 | - 'allModels' => $data, | ||
91 | - 'pagination' => [ | ||
92 | - 'pageSize' => 10, | ||
93 | - ], | ||
94 | - ]); | ||
95 | - | ||
96 | - // создадим модель на столько реквизитов сколько колонок в отпарсенном файле | ||
97 | - $last_index = end(array_flip($data[0])); | ||
98 | - $header_counts = $last_index + 1; | ||
99 | - $header_model = DynamicFormHelper::CreateDynamicModel($header_counts); | ||
100 | - | ||
101 | - // соберем массив данных из которых будет пользователь выбирать значения в конструкторе (выпадающий список) | ||
102 | - $basicColumns = $this->getBasicColumns(); | ||
103 | - | ||
104 | - return $this->render('results', | ||
105 | - ['model' => $data, | ||
106 | - 'header_model' => $header_model, | ||
107 | - // список колонок для выбора | ||
108 | - 'basic_column' => $basicColumns, | ||
109 | - 'dataProvider' => $provider]); | 84 | + |
85 | + } else if ( Yii::$app->getCache()->get('parser_data') ) { | ||
86 | + | ||
87 | + $data = json_decode( Yii::$app->getCache()->get('parser_data'), true ); | ||
88 | + | ||
110 | } | 89 | } |
90 | + // сборка динамической модели и её рендеринг | ||
91 | + return $this->renderResultView( $data ); | ||
111 | } | 92 | } |
112 | 93 | ||
113 | public function actionWrite() | 94 | public function actionWrite() |
114 | { | 95 | { |
96 | + set_time_limit(600); | ||
115 | //получим колонки которые выбрал пользователь | 97 | //получим колонки которые выбрал пользователь |
116 | $arr_attributes = Yii::$app->request->post()['DynamicModel']; | 98 | $arr_attributes = Yii::$app->request->post()['DynamicModel']; |
117 | //соберем модель по полученным данным | 99 | //соберем модель по полученным данным |
118 | $model = DynamicFormHelper::CreateDynamicModel($arr_attributes); | 100 | $model = DynamicFormHelper::CreateDynamicModel($arr_attributes); |
101 | + $crosses_model = new DetailsCrosses(); | ||
102 | + $arr_keys = array_keys($this->getBasicColumns()); | ||
103 | + | ||
119 | //добавим правила валидации (колонки должны быть те что в модели) | 104 | //добавим правила валидации (колонки должны быть те что в модели) |
120 | foreach ($arr_attributes as $key => $value) { | 105 | foreach ($arr_attributes as $key => $value) { |
121 | - $model->addRule($key, 'in', [ 'range' => array_keys( $this->getBasicColumns() ) ]); | 106 | + $model->addRule($key, 'in', ['range' => $arr_keys]); |
122 | } | 107 | } |
123 | - | 108 | + // установим режим проверки обязательных полей |
109 | + $crosses_model->setScenario('form_upload_validation'); | ||
110 | + $model_validator = new ModelArrayValidator($crosses_model); | ||
124 | // провалидируем выбранные колонки | 111 | // провалидируем выбранные колонки |
125 | - if ( $model->validate() ) { | 112 | + if ( $model->validate() && $model_validator->validateRow( array_flip( $arr_attributes ) ) ) { |
126 | 113 | ||
127 | // валидация успешна у нас есть соответсвие колонок, преобразуем в массив данное соответсвие для дальнейшей работы | 114 | // валидация успешна у нас есть соответсвие колонок, преобразуем в массив данное соответсвие для дальнейшей работы |
128 | $arr = $model->toArray(); | 115 | $arr = $model->toArray(); |
@@ -132,41 +119,42 @@ class CrossingUploadController extends BaseController | @@ -132,41 +119,42 @@ class CrossingUploadController extends BaseController | ||
132 | 119 | ||
133 | // соотнесем отпарсенные данные с соответствием полученным от пользователя | 120 | // соотнесем отпарсенные данные с соответствием полученным от пользователя |
134 | // для этого преобразуем массив отпарсенных данных - назначим ключи согласно соответствию | 121 | // для этого преобразуем массив отпарсенных данных - назначим ключи согласно соответствию |
135 | - $data = CustomArrayHelper::createAssocArray($data, $arr, 'attr_'); | 122 | + $data = CustomArrayHelper::createAssocArray( $data, $arr, 'attr_' ); |
136 | 123 | ||
137 | // запустим конвертер над над данными | 124 | // запустим конвертер над над данными |
138 | $data = $this->convertDataByConfiguration( $data, $configuration ); | 125 | $data = $this->convertDataByConfiguration( $data, $configuration ); |
139 | 126 | ||
140 | // валидируем отпарсенные данные моделью в которую будем записывать | 127 | // валидируем отпарсенные данные моделью в которую будем записывать |
141 | - $crosses_model = new DetailsCrosses(); | ||
142 | - $model_validator = new ModelArrayValidator( $crosses_model ); | 128 | + $crosses_model->setScenario('default'); |
143 | $data = $model_validator->validate( $data ); | 129 | $data = $model_validator->validate( $data ); |
144 | $msg = $model_validator->getMassage(); | 130 | $msg = $model_validator->getMassage(); |
145 | - $type_msg = $model_validator->hasError() ? 'warning' : 'success'; | 131 | + $type_msg = $model_validator->hasError() ? 'warning' : 'success'; |
146 | $model_validator->close(); | 132 | $model_validator->close(); |
147 | 133 | ||
148 | - $data = $this->reverseCrosses( $data ); | 134 | + $data = $this->reverseCrosses($data); |
135 | + | ||
136 | + try { | ||
137 | + if ($crosses_model->ManualInsertWithIgnore( $data )) { | ||
149 | 138 | ||
150 | - if ( $crosses_model->ManualInsertWithIgnore( $data ) ) { | 139 | + // очистим кеш |
140 | + $this->parserCacheHandler(2); | ||
151 | 141 | ||
152 | - // очистим кеш | ||
153 | - $this->parserCacheHandler( 2 ); | 142 | + if (file_exists($configuration['file_path'])) |
143 | + unlink($configuration['file_path']); | ||
154 | 144 | ||
155 | - if ( file_exists($configuration['file_path']) ) | ||
156 | - unlink( $configuration['file_path'] ); | 145 | + Yii::$app->session->setFlash($type_msg, $msg); |
146 | + return $this->render('index', ['model' => $configuration]); | ||
157 | 147 | ||
158 | - Yii::$app->session->setFlash( $type_msg, $msg ); | ||
159 | - return $this->render('index', ['model' => $configuration]); | 148 | + } |
149 | + } catch (Exception $e) { | ||
160 | 150 | ||
151 | + new CrossParsingException( $e->getMessage() ); | ||
161 | } | 152 | } |
162 | 153 | ||
163 | } else { | 154 | } else { |
164 | // не прошла валидация формы загрузки файлов | 155 | // не прошла валидация формы загрузки файлов |
165 | - $errors_str = ''; | ||
166 | - foreach ($model->getErrors() as $error) { | ||
167 | - $errors_str .= implode(array_values($error)); | ||
168 | - } | ||
169 | - throw new \ErrorException($errors_str); | 156 | + $errors_str = "Ошибка валидации формы загрузки файлов. "; |
157 | + $this->throwStringErrorException( $crosses_model , 'common\components\exceptions\CrossParsingException', $errors_str ); | ||
170 | } | 158 | } |
171 | } | 159 | } |
172 | 160 | ||
@@ -181,7 +169,8 @@ class CrossingUploadController extends BaseController | @@ -181,7 +169,8 @@ class CrossingUploadController extends BaseController | ||
181 | 169 | ||
182 | } | 170 | } |
183 | 171 | ||
184 | - protected function convertDataByConfiguration( $data, $configuration ){ | 172 | + protected function convertDataByConfiguration($data, $configuration) |
173 | + { | ||
185 | 174 | ||
186 | // доп. опции для парсера - удаление префикса в артикулах | 175 | // доп. опции для парсера - удаление префикса в артикулах |
187 | $options['mode'] = 'crosses'; | 176 | $options['mode'] = 'crosses'; |
@@ -193,38 +182,38 @@ class CrossingUploadController extends BaseController | @@ -193,38 +182,38 @@ class CrossingUploadController extends BaseController | ||
193 | $fields[] = 'CROSS_ARTICLE'; | 182 | $fields[] = 'CROSS_ARTICLE'; |
194 | } | 183 | } |
195 | if ($fields) { | 184 | if ($fields) { |
196 | - $options ['converter_conf']['configuration'] = ["article" => $fields, | 185 | + $options ['converter_conf']['configuration'] = ["article" => $fields, |
197 | "string" => ['ARTICLE', 'CROSS_ARTICLE'],]; | 186 | "string" => ['ARTICLE', 'CROSS_ARTICLE'],]; |
198 | } else { | 187 | } else { |
199 | - $options ['converter_conf']['configuration'] = ["string" => ['ARTICLE', 'CROSS_ARTICLE'],]; | 188 | + $options ['converter_conf']['configuration'] = ["string" => ['ARTICLE', 'CROSS_ARTICLE'],]; |
200 | } | 189 | } |
201 | 190 | ||
202 | // получим базовую конфигурацию и объеденим её с той что образовалась после выбора пользователем настроек | 191 | // получим базовую конфигурацию и объеденим её с той что образовалась после выбора пользователем настроек |
203 | - $basic_options = Yii::$app->multiparser->getConfiguration( 'csv', 'crosses' ); | ||
204 | - $options = array_merge_recursive( $options, $basic_options ); | 192 | + $basic_options = Yii::$app->multiparser->getConfiguration('csv', 'crosses'); |
193 | + $options = array_merge_recursive($options, $basic_options); | ||
205 | 194 | ||
206 | - foreach ( $data as &$row ) { | ||
207 | - $row = Yii::$app->converter->convertByConfiguration( $row, $options['converter_conf'] ); | 195 | + foreach ($data as &$row) { |
196 | + $row = Yii::$app->converter->convertByConfiguration($row, $options['converter_conf']); | ||
208 | } | 197 | } |
209 | 198 | ||
210 | return $data; | 199 | return $data; |
211 | 200 | ||
212 | } | 201 | } |
213 | 202 | ||
214 | - protected function reverseCrosses ( $data ) | 203 | + protected function reverseCrosses($data) |
215 | { | 204 | { |
216 | // для доп массива обратных строк | 205 | // для доп массива обратных строк |
217 | - $i = count( $data ) - 1; | 206 | + $i = count($data) - 1; |
218 | $reverse_data = []; | 207 | $reverse_data = []; |
219 | - foreach ( $data as &$row ) { | 208 | + foreach ($data as &$row) { |
220 | // нужно добавить обратную строку по кроссам | 209 | // нужно добавить обратную строку по кроссам |
221 | - $reverse_data[ $i ]['ARTICLE'] = $row['CROSS_ARTICLE']; | ||
222 | - $reverse_data[ $i ]['CROSS_ARTICLE'] = $row['ARTICLE']; | ||
223 | - $reverse_data[ $i ]['BRAND'] = $row['CROSS_BRAND']; | ||
224 | - $reverse_data[ $i ]['CROSS_BRAND'] = $row['BRAND']; | 210 | + $reverse_data[$i]['ARTICLE'] = $row['CROSS_ARTICLE']; |
211 | + $reverse_data[$i]['CROSS_ARTICLE'] = $row['ARTICLE']; | ||
212 | + $reverse_data[$i]['BRAND'] = $row['CROSS_BRAND']; | ||
213 | + $reverse_data[$i]['CROSS_BRAND'] = $row['BRAND']; | ||
225 | $i++; | 214 | $i++; |
226 | } | 215 | } |
227 | - $data = array_merge( $data, $reverse_data ); | 216 | + $data = array_merge($data, $reverse_data); |
228 | 217 | ||
229 | return $data; | 218 | return $data; |
230 | } | 219 | } |
backend/controllers/NewsController.php
@@ -95,7 +95,7 @@ class NewsController extends BaseController | @@ -95,7 +95,7 @@ class NewsController extends BaseController | ||
95 | 95 | ||
96 | 96 | ||
97 | 97 | ||
98 | - if ($model->load(Yii::$app->request->post()) /*&& $model->save()*/ ) { | 98 | + if ($model->load(Yii::$app->request->post()) && $model->save() ) { |
99 | 99 | ||
100 | if ($model['mail_send'] == '1') { | 100 | if ($model['mail_send'] == '1') { |
101 | $sEmails = array(); | 101 | $sEmails = array(); |
backend/controllers/ParserController.php
1 | <?php | 1 | <?php |
2 | namespace backend\controllers; | 2 | namespace backend\controllers; |
3 | 3 | ||
4 | -use common\components\archives\ArchiveCreator; | ||
5 | -use common\components\mail\ImapMailReader; | ||
6 | -use common\components\mail\MailAttachmentsSaver; | 4 | +use backend\models\Details; |
5 | +use common\components\exceptions\CrossParsingException; | ||
6 | +use common\components\exceptions\PriceParsingException; | ||
7 | +use common\components\exceptions\RgParsingException; | ||
8 | +use common\components\ModelArrayValidator; | ||
7 | use common\components\parsers\MailParser; | 9 | use common\components\parsers\MailParser; |
8 | use Yii; | 10 | use Yii; |
9 | use yii\data\ActiveDataProvider; | 11 | use yii\data\ActiveDataProvider; |
@@ -13,19 +15,20 @@ use yii\filters\VerbFilter; | @@ -13,19 +15,20 @@ use yii\filters\VerbFilter; | ||
13 | use backend\models\UploadFileParsingForm; | 15 | use backend\models\UploadFileParsingForm; |
14 | use yii\web\UploadedFile; | 16 | use yii\web\UploadedFile; |
15 | use yii\data\ArrayDataProvider; | 17 | use yii\data\ArrayDataProvider; |
16 | -use yii\multiparser\DynamicFormHelper; | 18 | +use common\components\parsers\DynamicFormHelper; |
17 | use backend\models\ImportersFiles; | 19 | use backend\models\ImportersFiles; |
18 | use backend\models\Importers; | 20 | use backend\models\Importers; |
19 | use yii\base\ErrorException; | 21 | use yii\base\ErrorException; |
20 | use common\components\PriceWriter; | 22 | use common\components\PriceWriter; |
21 | -use common\components\CustomVarDamp; | ||
22 | use common\components\CustomArrayHelper; | 23 | use common\components\CustomArrayHelper; |
24 | +use backend\components\traits\ParserTrait; | ||
23 | 25 | ||
24 | /** | 26 | /** |
25 | * Parser controller | 27 | * Parser controller |
26 | */ | 28 | */ |
27 | class ParserController extends BaseController | 29 | class ParserController extends BaseController |
28 | { | 30 | { |
31 | + use ParserTrait; | ||
29 | public $layout = "/column"; | 32 | public $layout = "/column"; |
30 | 33 | ||
31 | /** | 34 | /** |
@@ -53,7 +56,6 @@ class ParserController extends BaseController | @@ -53,7 +56,6 @@ class ParserController extends BaseController | ||
53 | } | 56 | } |
54 | 57 | ||
55 | 58 | ||
56 | - | ||
57 | public function actionIndex($mode = 0) | 59 | public function actionIndex($mode = 0) |
58 | { | 60 | { |
59 | $model = new UploadFileParsingForm(); | 61 | $model = new UploadFileParsingForm(); |
@@ -65,21 +67,31 @@ class ParserController extends BaseController | @@ -65,21 +67,31 @@ class ParserController extends BaseController | ||
65 | public function actionError() | 67 | public function actionError() |
66 | { | 68 | { |
67 | $exception = Yii::$app->errorHandler->exception; | 69 | $exception = Yii::$app->errorHandler->exception; |
68 | - if ($exception !== null) { | ||
69 | - return $this->render('error', ['message' => $exception->getMessage()]); | 70 | + $action_name = ''; |
71 | + | ||
72 | + if ( $exception instanceof CrossParsingException ) { | ||
73 | + $action_name = ['crossing-upload/result']; | ||
74 | + }elseif ( $exception instanceof PriceParsingException ) { | ||
75 | + $action_name = ['results']; | ||
76 | + }elseif ( $exception instanceof RgParsingException ) { | ||
77 | + $action_name = ['rg-grup/results']; | ||
78 | + } | ||
79 | + | ||
80 | + if ( $exception !== null ) { | ||
81 | + $msg = $exception->getMessage(); | ||
82 | + return $this->render( 'error', [ 'message' => $msg, 'action_name' => $action_name ] ); | ||
70 | } | 83 | } |
71 | } | 84 | } |
72 | 85 | ||
73 | public function actionResults($mode = 0) | 86 | public function actionResults($mode = 0) |
74 | { | 87 | { |
88 | + set_time_limit(600); | ||
75 | $model = new UploadFileParsingForm( ['mode' => $mode] ); | 89 | $model = new UploadFileParsingForm( ['mode' => $mode] ); |
76 | $data = []; | 90 | $data = []; |
77 | if ( $model->load(Yii::$app->request->post()) ) { | 91 | if ( $model->load(Yii::$app->request->post()) ) { |
78 | - $model->file = UploadedFile::getInstance($model, 'file'); | ||
79 | - // первый проход - валидируем, | ||
80 | - // сохраняем файл, | 92 | + $model->file = UploadedFile::getInstance( $model, 'file' ); |
93 | + // первый проход - валидируем, сохраняем файл, | ||
81 | // ложим в кеш (для ручной загрузки) отпарсенные данные и параметры модели | 94 | // ложим в кеш (для ручной загрузки) отпарсенные данные и параметры модели |
82 | - // (потом при записи в базу данных они пригодятся) | ||
83 | if ( $model->validate() ) { | 95 | if ( $model->validate() ) { |
84 | // сохраним файл и создадим модель - ImportersFiles | 96 | // сохраним файл и создадим модель - ImportersFiles |
85 | $files_model = $this->saveParserFile($model); | 97 | $files_model = $this->saveParserFile($model); |
@@ -88,45 +100,19 @@ class ParserController extends BaseController | @@ -88,45 +100,19 @@ class ParserController extends BaseController | ||
88 | $model->success = true; | 100 | $model->success = true; |
89 | return $this->render('index', ['model' => $model]); | 101 | return $this->render('index', ['model' => $model]); |
90 | } | 102 | } |
91 | - | ||
92 | // === ручная загрузка =========== | 103 | // === ручная загрузка =========== |
93 | //запускаем парсинг | 104 | //запускаем парсинг |
94 | $data = $this->parseDataFromFile( $files_model, $model ); | 105 | $data = $this->parseDataFromFile( $files_model, $model ); |
95 | 106 | ||
96 | } else { | 107 | } else { |
97 | // не прошла валидация форма загрузки файлов | 108 | // не прошла валидация форма загрузки файлов |
98 | -// $errors_str = ''; | ||
99 | -// foreach ($model->getErrors() as $error) { | ||
100 | -// $errors_str .= implode( array_values($error) ); | ||
101 | -// } | ||
102 | -// throw new ErrorException( $errors_str ); | ||
103 | - $model->throwStringErrorException(); | 109 | + $this->throwStringErrorException( $model , 'common\components\exceptions\PriceParsingException' ); |
104 | } | 110 | } |
105 | // листаем пагинатором, или повторно вызываем - считываем из кеша отпрасенные данные | 111 | // листаем пагинатором, или повторно вызываем - считываем из кеша отпрасенные данные |
106 | } else if ( Yii::$app->getCache()->get('parser_data') ) { | 112 | } else if ( Yii::$app->getCache()->get('parser_data') ) { |
107 | - | ||
108 | $data = json_decode(Yii::$app->getCache()->get('parser_data'), true); | 113 | $data = json_decode(Yii::$app->getCache()->get('parser_data'), true); |
109 | - | ||
110 | } | 114 | } |
111 | - | ||
112 | - $provider = new ArrayDataProvider([ | ||
113 | - 'allModels' => $data, | ||
114 | - 'pagination' => [ | ||
115 | - 'pageSize' => 10, | ||
116 | - ], | ||
117 | - ]); | ||
118 | - | ||
119 | - $last_index = end( array_flip( $data[0] ) ); | ||
120 | - $header_counts = $last_index + 1; | ||
121 | - //формируем заголовок для пользователя, где он сможет выбрать соответсвие полей (выпадающий список) | ||
122 | - $header_model = DynamicFormHelper::CreateDynamicModel( $header_counts ); | ||
123 | - | ||
124 | - return $this->render('results', | ||
125 | - ['model' => $data, | ||
126 | - 'header_model' => $header_model, | ||
127 | - // список колонок для выбора | ||
128 | - 'basic_column' => Yii::$app->multiparser->getConfiguration('csv', 'basic_column'), | ||
129 | - 'dataProvider' => $provider]); | 115 | + return $this->renderResultView( $data ); |
130 | } | 116 | } |
131 | 117 | ||
132 | public function actionWrite() | 118 | public function actionWrite() |
@@ -135,13 +121,17 @@ class ParserController extends BaseController | @@ -135,13 +121,17 @@ class ParserController extends BaseController | ||
135 | $arr_attributes = Yii::$app->request->post()['DynamicModel']; | 121 | $arr_attributes = Yii::$app->request->post()['DynamicModel']; |
136 | //соберем модель по полученным данным | 122 | //соберем модель по полученным данным |
137 | $model = DynamicFormHelper::CreateDynamicModel($arr_attributes); | 123 | $model = DynamicFormHelper::CreateDynamicModel($arr_attributes); |
124 | + $details_model = new Details(); | ||
138 | //добавим правила валидации (колонки должны быть те что указаны в конфиге) | 125 | //добавим правила валидации (колонки должны быть те что указаны в конфиге) |
139 | foreach ($arr_attributes as $key => $value) { | 126 | foreach ($arr_attributes as $key => $value) { |
140 | $model->addRule($key, 'in', ['range' => array_keys(Yii::$app->multiparser->getConfiguration('csv', 'basic_column'))]); | 127 | $model->addRule($key, 'in', ['range' => array_keys(Yii::$app->multiparser->getConfiguration('csv', 'basic_column'))]); |
141 | } | 128 | } |
142 | 129 | ||
130 | + // установим режим проверки обязательных полей | ||
131 | + $details_model->setScenario('form_upload_validation'); | ||
132 | + $model_validator = new ModelArrayValidator( $details_model ); | ||
143 | // провалидируем выбранные колонки | 133 | // провалидируем выбранные колонки |
144 | - if ($model->validate()) { | 134 | + if ( $model->validate() && $model_validator->validateRow( array_flip( $arr_attributes ) ) ) { |
145 | 135 | ||
146 | // валидация успешна у нас есть соответсвие колонок, преобразуем в массив данное соответсвие для дальнейшей работы | 136 | // валидация успешна у нас есть соответсвие колонок, преобразуем в массив данное соответсвие для дальнейшей работы |
147 | $arr = $model->toArray(); | 137 | $arr = $model->toArray(); |
@@ -164,12 +154,16 @@ class ParserController extends BaseController | @@ -164,12 +154,16 @@ class ParserController extends BaseController | ||
164 | 154 | ||
165 | if( file_exists($configuration['file_path']) ) | 155 | if( file_exists($configuration['file_path']) ) |
166 | unlink($configuration['file_path']); | 156 | unlink($configuration['file_path']); |
167 | - | ||
168 | - Yii::$app->session->setFlash( $writer->getValidatedTypeMsg(), $writer->getValidatedMsg() ); | ||
169 | - return $this->render('index', ['model' => $configuration]); | 157 | + $validated_type_msg = $writer->hasValidationError() ? 'warning' : 'success'; |
158 | + Yii::$app->session->setFlash( $validated_type_msg, $writer->getValidatedMsg() ); | ||
159 | + return $this->render('index', ['model' => $configuration]); | ||
170 | 160 | ||
171 | }; | 161 | }; |
172 | 162 | ||
163 | + } else { | ||
164 | + // не прошла валидация формы загрузки файлов | ||
165 | + $errors_str = "Ошибка валидации формы загрузки файлов. "; | ||
166 | + $this->throwStringErrorException( $details_model , 'common\components\exceptions\PriceParsingException', $errors_str ); | ||
173 | } | 167 | } |
174 | 168 | ||
175 | } | 169 | } |
@@ -199,7 +193,7 @@ class ParserController extends BaseController | @@ -199,7 +193,7 @@ class ParserController extends BaseController | ||
199 | $arr_id_files[] = (int) $file_id; | 193 | $arr_id_files[] = (int) $file_id; |
200 | } | 194 | } |
201 | 195 | ||
202 | - $query = ImportersFiles::find()->where(['in', 'id', $arr_id_files])->orderBy(['upload_time' => SORT_DESC]); | 196 | + $query = ImportersFiles::find()->where(['in', 'id', $arr_id_files])->orderBy( ['upload_time' => SORT_DESC] ); |
203 | 197 | ||
204 | $provider = new ActiveDataProvider([ | 198 | $provider = new ActiveDataProvider([ |
205 | 'query' => $query, | 199 | 'query' => $query, |
@@ -300,4 +294,9 @@ class ParserController extends BaseController | @@ -300,4 +294,9 @@ class ParserController extends BaseController | ||
300 | return $data; | 294 | return $data; |
301 | } | 295 | } |
302 | 296 | ||
297 | + protected function getBasicColumns() | ||
298 | + { | ||
299 | + return Yii::$app->multiparser->getConfiguration('csv', 'basic_column'); | ||
300 | + | ||
301 | + } | ||
303 | } | 302 | } |
backend/controllers/RgGrupController.php
@@ -10,7 +10,8 @@ namespace backend\controllers; | @@ -10,7 +10,8 @@ namespace backend\controllers; | ||
10 | 10 | ||
11 | use backend\components\base\BaseController; | 11 | use backend\components\base\BaseController; |
12 | use backend\models\UploadFileRgForm; | 12 | use backend\models\UploadFileRgForm; |
13 | -use common\components\CustomVarDamp; | 13 | +use common\components\exceptions\RgParsingException; |
14 | +use common\components\ModelArrayValidator; | ||
14 | use common\components\parsers\MailAttachmentsSaver; | 15 | use common\components\parsers\MailAttachmentsSaver; |
15 | use common\models\Margins; | 16 | use common\models\Margins; |
16 | use common\models\MarginsGroups; | 17 | use common\models\MarginsGroups; |
@@ -18,11 +19,13 @@ use yii\filters\AccessControl; | @@ -18,11 +19,13 @@ use yii\filters\AccessControl; | ||
18 | use Yii; | 19 | use Yii; |
19 | use yii\web\UploadedFile; | 20 | use yii\web\UploadedFile; |
20 | use yii\data\ArrayDataProvider; | 21 | use yii\data\ArrayDataProvider; |
21 | -use yii\multiparser\DynamicFormHelper; | 22 | +use common\components\parsers\DynamicFormHelper; |
22 | use common\components\CustomArrayHelper; | 23 | use common\components\CustomArrayHelper; |
24 | +use backend\components\traits\ParserTrait; | ||
23 | 25 | ||
24 | class RgGrupController extends BaseController | 26 | class RgGrupController extends BaseController |
25 | { | 27 | { |
28 | + use ParserTrait; | ||
26 | public $layout = "/column"; | 29 | public $layout = "/column"; |
27 | 30 | ||
28 | /** | 31 | /** |
@@ -65,25 +68,15 @@ class RgGrupController extends BaseController | @@ -65,25 +68,15 @@ class RgGrupController extends BaseController | ||
65 | $model->file = UploadedFile::getInstance($model, 'file'); | 68 | $model->file = UploadedFile::getInstance($model, 'file'); |
66 | // первый проход - валидируем, сохраняем файл, ложим в кеш отпарсенные данные и параметры модели (потом при записи в базу данных они пригодятся) | 69 | // первый проход - валидируем, сохраняем файл, ложим в кеш отпарсенные данные и параметры модели (потом при записи в базу данных они пригодятся) |
67 | if ($model->validate()) { | 70 | if ($model->validate()) { |
68 | - | ||
69 | $model->file_path = Yii::getAlias('@manual_upload') . '/' . $model->file->name; | 71 | $model->file_path = Yii::getAlias('@manual_upload') . '/' . $model->file->name; |
70 | $model->file->saveAs($model->file_path); | 72 | $model->file->saveAs($model->file_path); |
71 | - | ||
72 | //запускаем парсинг | 73 | //запускаем парсинг |
73 | $data = $model->readFile(); | 74 | $data = $model->readFile(); |
74 | // сохраняем в кеш отпарсенные даные | 75 | // сохраняем в кеш отпарсенные даные |
75 | - Yii::$app->getCache()->set('parser_data', json_encode($data), 1800); | ||
76 | - // сохраняем в кеш модель - в ней настройки для дальнейшей обработки данных | ||
77 | - Yii::$app->getCache()->set('parser_configuration', serialize($model), 1800); | ||
78 | - | ||
79 | - | 76 | + $this->parserCacheHandler(1, $data, $model); |
80 | } else { | 77 | } else { |
81 | // не прошла валидация форма загрузки файлов | 78 | // не прошла валидация форма загрузки файлов |
82 | - $errors_str = ''; | ||
83 | - foreach ($model->getErrors() as $error) { | ||
84 | - $errors_str .= implode(array_values($error)); | ||
85 | - } | ||
86 | - throw new \ErrorException($errors_str); | 79 | + $this->throwStringErrorException($model, 'common\components\exceptions\RgParsingException'); |
87 | } | 80 | } |
88 | // листаем пагинатором, или повторно вызываем - считываем из кеша отпрасенные данные | 81 | // листаем пагинатором, или повторно вызываем - считываем из кеша отпрасенные данные |
89 | } else if (Yii::$app->getCache()->get('parser_data')) { | 82 | } else if (Yii::$app->getCache()->get('parser_data')) { |
@@ -91,52 +84,32 @@ class RgGrupController extends BaseController | @@ -91,52 +84,32 @@ class RgGrupController extends BaseController | ||
91 | $data = json_decode(Yii::$app->getCache()->get('parser_data'), true); | 84 | $data = json_decode(Yii::$app->getCache()->get('parser_data'), true); |
92 | 85 | ||
93 | } | 86 | } |
94 | - $provider = new ArrayDataProvider([ | ||
95 | - 'allModels' => $data, | ||
96 | - 'pagination' => [ | ||
97 | - 'pageSize' => 10, | ||
98 | - ], | ||
99 | - ]); | ||
100 | - // создадим модель на столько реквизитов сколько колонок в отпарсенном файле | ||
101 | - $last_index = end(array_flip($data[0])); | ||
102 | - $header_counts = $last_index + 1; | ||
103 | - $header_model = DynamicFormHelper::CreateDynamicModel($header_counts); | ||
104 | - | ||
105 | - // соберем массив данных из которых будет пользователь выбирать значения в конструкторе (выпадающий список) | ||
106 | - $header_array = Margins::getHeader(); | ||
107 | - | ||
108 | - return $this->render('results', | ||
109 | - ['model' => $data, | ||
110 | - 'header_model' => $header_model, | ||
111 | - // список колонок для выбора | ||
112 | - 'basic_column' => $header_array, | ||
113 | - 'dataProvider' => $provider]); | 87 | + // сборка динамической модели и её рендеринг |
88 | + return $this->renderResultView($data); | ||
114 | } | 89 | } |
115 | 90 | ||
116 | public function actionWrite() | 91 | public function actionWrite() |
117 | { | 92 | { |
118 | //получим колонки которые выбрал пользователь | 93 | //получим колонки которые выбрал пользователь |
119 | $arr_attributes = Yii::$app->request->post()['DynamicModel']; | 94 | $arr_attributes = Yii::$app->request->post()['DynamicModel']; |
95 | + $margin_model = new MarginsGroups(); | ||
120 | //соберем модель по полученным данным | 96 | //соберем модель по полученным данным |
121 | $model = DynamicFormHelper::CreateDynamicModel($arr_attributes); | 97 | $model = DynamicFormHelper::CreateDynamicModel($arr_attributes); |
122 | //добавим правила валидации (колонки должны быть те что в модели) | 98 | //добавим правила валидации (колонки должны быть те что в модели) |
123 | foreach ($arr_attributes as $key => $value) { | 99 | foreach ($arr_attributes as $key => $value) { |
124 | $model->addRule($key, 'in', ['range' => array_keys(Margins::getHeader())]); | 100 | $model->addRule($key, 'in', ['range' => array_keys(Margins::getHeader())]); |
125 | } | 101 | } |
126 | - | 102 | + // установим режим проверки обязательных полей |
103 | + $margin_model->setScenario('form_upload_validation'); | ||
104 | + $model_validator = new ModelArrayValidator($margin_model); | ||
127 | // провалидируем выбранные колонки | 105 | // провалидируем выбранные колонки |
128 | - if ( $model->validate() ) { | 106 | + if ($model->validate() && $model_validator->validateRow($this->getAttributesForValidate($arr_attributes))) { |
129 | 107 | ||
130 | // валидация успешна у нас есть соответсвие колонок, преобразуем в массив данное соответсвие для дальнейшей работы | 108 | // валидация успешна у нас есть соответсвие колонок, преобразуем в массив данное соответсвие для дальнейшей работы |
131 | $arr = $model->toArray(); | 109 | $arr = $model->toArray(); |
132 | 110 | ||
133 | // получим данные из кеша | 111 | // получим данные из кеша |
134 | - if (Yii::$app->getCache()->get('parser_data') && Yii::$app->getCache()->get('parser_configuration')) { | ||
135 | - $data = json_decode(Yii::$app->getCache()->get('parser_data'), true); | ||
136 | - $configuration = unserialize(Yii::$app->getCache()->get('parser_configuration')); | ||
137 | - } else { | ||
138 | - throw new \ErrorException('Ошибка кеша'); | ||
139 | - } | 112 | + $this->parserCacheHandler(0, $data, $configuration); |
140 | 113 | ||
141 | array_walk($arr, function (&$val) { | 114 | array_walk($arr, function (&$val) { |
142 | $val = '!' . $val; | 115 | $val = '!' . $val; |
@@ -147,51 +120,85 @@ class RgGrupController extends BaseController | @@ -147,51 +120,85 @@ class RgGrupController extends BaseController | ||
147 | $data = CustomArrayHelper::createAssocArray($data, $arr, 'attr_'); | 120 | $data = CustomArrayHelper::createAssocArray($data, $arr, 'attr_'); |
148 | 121 | ||
149 | // в первой строке у нас заголовки - уберем | 122 | // в первой строке у нас заголовки - уберем |
150 | - unset( $data[0] ); | 123 | + unset($data[0]); |
151 | // подготовим данные для записи в таблицу w_margins_groups | 124 | // подготовим данные для записи в таблицу w_margins_groups |
152 | - $arr_values = []; | ||
153 | - $group = ''; | ||
154 | - $importer_id = $configuration['importer_id']; | ||
155 | - foreach ($data as $row_data) { | ||
156 | - | ||
157 | - if (isset($row_data['!group'])) { | ||
158 | - $group = $row_data['!group']; | ||
159 | - unset($row_data['!group']); | ||
160 | - } | ||
161 | - if (isset($row_data['!_null'])) { | ||
162 | - unset($row_data['!_null']); | 125 | + $data = $this->convertDataByConfiguration($data, $configuration); |
126 | + | ||
127 | + // валидируем отпарсенные данные моделью в которую будем записывать | ||
128 | + $margin_model->setScenario('default'); | ||
129 | + $data = $model_validator->validate($data); | ||
130 | + $msg = $model_validator->getMassage(); | ||
131 | + $type_msg = $model_validator->hasError() ? 'warning' : 'success'; | ||
132 | + $model_validator->close(); | ||
133 | + // сохраним подготовленные данные | ||
134 | + if (!empty($data)) { | ||
135 | + if (MarginsGroups::ManualInsertWithUpdate($data, ['group', 'importer_id', 'margin_id'])) { | ||
136 | + // все прошло успешно - очищаем кеш | ||
137 | + $this->parserCacheHandler(2); | ||
138 | + | ||
139 | + if (file_exists($configuration['file_path'])) | ||
140 | + unlink($configuration['file_path']); | ||
163 | } | 141 | } |
164 | 142 | ||
165 | - foreach ($row_data as $key => $value) { | ||
166 | - if ($group) | ||
167 | - $row['group'] = trim($group); | 143 | + } |
144 | + Yii::$app->session->setFlash($type_msg, $msg); | ||
145 | + return $this->render('index', ['model' => $configuration]); | ||
168 | 146 | ||
169 | - $row['importer_id'] = trim($importer_id); | ||
170 | - $row['margin_id'] = ltrim($key, '!'); | ||
171 | - $row['koef'] = \Yii::$app->converter->convertTo('float', $value, ['precision' => 6]); | 147 | + } else { |
148 | + // не прошла валидация формы загрузки файлов | ||
149 | + $errors_str = "Ошибка валидации формы загрузки файлов. "; | ||
150 | + $this->throwStringErrorException($margin_model, 'common\components\exceptions\RgParsingException', $errors_str); | ||
151 | + } | ||
152 | + } | ||
172 | 153 | ||
154 | + protected function convertDataByConfiguration($data, $configuration) | ||
155 | + { | ||
156 | + $arr_values = []; | ||
157 | + $group = ''; | ||
158 | + $importer_id = $configuration['importer_id']; | ||
159 | + foreach ($data as $row_data) { | ||
160 | + | ||
161 | + if (isset($row_data['!group'])) { | ||
162 | + $group = $row_data['!group']; | ||
163 | + unset($row_data['!group']); | ||
164 | + } | ||
165 | + if (isset($row_data['!_null'])) { | ||
166 | + unset($row_data['!_null']); | ||
167 | + } | ||
173 | 168 | ||
174 | - $arr_values[] = $row; | 169 | + foreach ($row_data as $key => $value) { |
170 | + if ($group) | ||
171 | + $row['group'] = trim($group); | ||
175 | 172 | ||
176 | - } | 173 | + $row['importer_id'] = trim($importer_id); |
174 | + $row['margin_id'] = ltrim($key, '!'); | ||
175 | + $row['koef'] = \Yii::$app->converter->convertTo('float', $value, ['precision' => 6]); | ||
177 | 176 | ||
177 | + $arr_values[] = $row; | ||
178 | } | 178 | } |
179 | - // сохраним подготовленные данные | ||
180 | - MarginsGroups::ManualInsertWithUpdate( $arr_values, [ 'group','importer_id','margin_id' ] ); | ||
181 | - | ||
182 | - | ||
183 | - Yii::$app->session->setFlash('success', "Файл {$configuration['file']} успешно загружен"); | ||
184 | - // все прошло успешно - очищаем кеш | ||
185 | - Yii::$app->getCache()->delete('parser_data'); | ||
186 | - Yii::$app->getCache()->delete('parser_configuration'); | 179 | + } |
180 | + return $arr_values; | ||
181 | + } | ||
187 | 182 | ||
188 | - if (file_exists($configuration['file_path'])) | ||
189 | - unlink($configuration['file_path']); | 183 | + protected function getBasicColumns() |
184 | + { | ||
185 | + return Margins::getHeader(); | ||
186 | + } | ||
190 | 187 | ||
191 | - return $this->render('index', ['model' => $configuration]); | 188 | + // подготавливает массив для валидирования моделью - MarginsGroups |
189 | + // для этого меняем выбранные значения именем поля - margin_id | ||
190 | + protected function getAttributesForValidate($arr) | ||
191 | + { | ||
192 | + $base_columns_arr = Margins::find()->select('id')->asArray()->all(); | ||
193 | + $base_columns_arr = array_column($base_columns_arr,'id'); | ||
192 | 194 | ||
193 | - } | 195 | + array_walk( $arr, function (&$value, $key, $base_columns_arr) { |
196 | + if (in_array( $value, $base_columns_arr )){ | ||
197 | + $value = 'margin_id'; | ||
198 | + } | ||
199 | + }, $base_columns_arr ); | ||
194 | 200 | ||
201 | + return array_flip( $arr ); | ||
195 | } | 202 | } |
196 | 203 | ||
197 | // public function actionMail() | 204 | // public function actionMail() |
backend/models/Details.php
@@ -55,13 +55,13 @@ class Details extends BaseActiveRecord | @@ -55,13 +55,13 @@ class Details extends BaseActiveRecord | ||
55 | public function rules() | 55 | public function rules() |
56 | { | 56 | { |
57 | return [ | 57 | return [ |
58 | - [['BRAND', 'ARTICLE', 'PRICE', 'DESCR', 'BOX'], 'required'], | ||
59 | - [['PRICE'], 'number'], | ||
60 | - [['BOX'], 'integer'], | ||
61 | - [['timestamp'], 'safe'], | ||
62 | - [['BRAND', 'ARTICLE'], 'string', 'max' => 100], | ||
63 | - [['FULL_ARTICLE'], 'string', 'max' => 150], | ||
64 | - [['DESCR', 'GROUP'], 'string', 'max' => 200] | 58 | + [['BRAND', 'ARTICLE', 'PRICE', 'DESCR', 'BOX'], 'required' , 'on' => ['default','form_upload_validation']], |
59 | + [['PRICE'], 'number', 'on' => 'default'], | ||
60 | + [['BOX'], 'integer' , 'on' => 'default'], | ||
61 | + [['timestamp'], 'safe' , 'on' => 'default'], | ||
62 | + [['BRAND', 'ARTICLE'], 'string', 'max' => 100 , 'on' => 'default'], | ||
63 | + [['FULL_ARTICLE'], 'string', 'max' => 150 , 'on' => 'default'], | ||
64 | + [['DESCR', 'GROUP'], 'string', 'max' => 200 , 'on' => 'default'] | ||
65 | ]; | 65 | ]; |
66 | } | 66 | } |
67 | 67 |
backend/models/DetailsCrosses.php
@@ -35,9 +35,9 @@ class DetailsCrosses extends \backend\components\base\BaseActiveRecord | @@ -35,9 +35,9 @@ class DetailsCrosses extends \backend\components\base\BaseActiveRecord | ||
35 | public function rules() | 35 | public function rules() |
36 | { | 36 | { |
37 | return [ | 37 | return [ |
38 | - [['ARTICLE', 'BRAND', 'CROSS_BRAND', 'CROSS_ARTICLE'], 'required'], | ||
39 | - [['timestamp'], 'safe'], | ||
40 | - [['ARTICLE', 'BRAND', 'CROSS_BRAND', 'CROSS_ARTICLE'], 'string', 'max' => 100] | 38 | + [['ARTICLE', 'BRAND', 'CROSS_BRAND', 'CROSS_ARTICLE'], 'required', 'on' => ['default','form_upload_validation']], |
39 | + [['timestamp'], 'safe' , 'on' => 'default'], | ||
40 | + [['ARTICLE', 'BRAND', 'CROSS_BRAND', 'CROSS_ARTICLE'], 'string', 'max' => 100 , 'on' => 'default'] | ||
41 | ]; | 41 | ]; |
42 | } | 42 | } |
43 | 43 |
backend/models/Details_old.php deleted
1 | -<?php | ||
2 | -/** | ||
3 | - * Created by PhpStorm. | ||
4 | - * User: Cibermag | ||
5 | - * Date: 15.09.2015 | ||
6 | - * Time: 16:49 | ||
7 | - */ | ||
8 | - | ||
9 | -namespace backend\models; | ||
10 | - | ||
11 | -use yii\base\Model; | ||
12 | -use Yii; | ||
13 | - | ||
14 | -class Details_old extends Model{ | ||
15 | - const KEY_COLUMN = ['IMPORT_ID','BRAND','ARTICLE']; | ||
16 | - const BATCH = 500; | ||
17 | - | ||
18 | - private $mode; | ||
19 | - | ||
20 | - // обязательные поля модели | ||
21 | - public $BRAND; | ||
22 | - public $ARTICLE; | ||
23 | - public $PRICE; | ||
24 | - public $BOX; | ||
25 | - | ||
26 | - function __construct($mode) | ||
27 | - { | ||
28 | - $this->mode = $mode; | ||
29 | - } | ||
30 | - | ||
31 | - public function rules() | ||
32 | - { | ||
33 | - return [ | ||
34 | - [['BRAND','ARTICLE', 'PRICE', 'BOX'], 'required' ], | ||
35 | - ]; | ||
36 | - } | ||
37 | - | ||
38 | - public function formName() | ||
39 | - { | ||
40 | - return 'Details'; | ||
41 | - } | ||
42 | - | ||
43 | - | ||
44 | - public static function tableName() | ||
45 | - { | ||
46 | - return '{{%details}}'; | ||
47 | - } | ||
48 | - | ||
49 | -// //@todo вероятно этой функции не место здесь | ||
50 | -// public function prepareData ( $data, $configuration ) | ||
51 | -// { | ||
52 | -// if ( isset($configuration['importer_id']) && $configuration['importer_id']) { | ||
53 | -// $data = \Yii::$app->multiparser->addColumn( $data, 'IMPORT_ID', $configuration['importer_id'] ); | ||
54 | -// } | ||
55 | -// // \common\components\CustomVarDamp::dumpAndDie($data); | ||
56 | -// return $data; | ||
57 | -// } | ||
58 | - | ||
59 | - /** | ||
60 | - * @param $data - двумерный массив данных для записи в таблицу details | ||
61 | - * @throws \yii\db\Exception | ||
62 | - * вставляет записи с апдейтом при дубляже ключей | ||
63 | - */ | ||
64 | - public function save ($data) | ||
65 | - { | ||
66 | - $table_name = self::tableName(); | ||
67 | - $keys_arr = array_keys( $data[0] ); | ||
68 | - // найдем те поля которые не являются ключами. Их нужно будет при дубляже апдейтить | ||
69 | - $fields_arr_to_update = array_diff( $keys_arr, $this::KEY_COLUMN ); | ||
70 | - | ||
71 | - $query_update = ' on duplicate key update '; | ||
72 | - foreach ($fields_arr_to_update as $field) { | ||
73 | - $query_update .= "{$field} = values({$field}),"; | ||
74 | - } | ||
75 | - // удалим последнюю запятую | ||
76 | - $query_update = substr($query_update, 0, strlen($query_update) - 1); | ||
77 | - | ||
78 | - // запросы будем выполнять пакетами | ||
79 | - // размер пакета установлен в константе | ||
80 | - // разобъем массив на пакеты и будем их проходить | ||
81 | - $data = array_chunk($data, $this::BATCH ); | ||
82 | - foreach( $data as $current_batch_array ){ | ||
83 | - | ||
84 | - //воспользуемся пакетной вставкой от фреймворка, плюс сразу с экранированием и защитой от инъекций | ||
85 | - $query_insert = Yii::$app->db->createCommand()->batchInsert($table_name, $keys_arr, $current_batch_array)->sql; | ||
86 | - // добавим фрагмент с апдейтом при дубляже | ||
87 | - $query = "{$query_insert} {$query_update}"; | ||
88 | - // \common\components\CustomVarDamp::dumpAndDie($query); | ||
89 | - $res = Yii::$app->db->createCommand($query)->execute(); | ||
90 | - | ||
91 | - } | ||
92 | - | ||
93 | - } | ||
94 | -} | ||
95 | - | ||
96 | -// | ||
97 | - | ||
98 | -//$q = " INSERT INTO {$table_name} ({$keys_string}) VALUES ("; | ||
99 | - | ||
100 | -//$q .= " on duplicate key update `FULL_ARTICLE` = values (`FULL_ARTICLE`), | ||
101 | -// `PRICE` = values (`PRICE`), | ||
102 | -// `DESCR` = values(`DESCR`), | ||
103 | -// `BOX` = values(`BOX`), | ||
104 | -// `ADD_BOX` = values(`ADD_BOX`), | ||
105 | -// `GROUP` = values(`GROUP`);"; | ||
106 | - | ||
107 | -// INSERT INTO table (a,b,c) VALUES (1,2,3),(4,5,6) | ||
108 | -// ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b); | ||
109 | - | ||
110 | - | ||
111 | - | ||
112 | -//INSERT INTO `books` (`UserId`, `BookId`, `Count`) VALUES (13, 1001, 3) | ||
113 | -//ON DUPLICATE KEY UPDATE `Count` = `Count` + VALUES(`Count`); | ||
114 | - | ||
115 | -//$values_string = ''; | ||
116 | -//$keys_arr = array_keys( $data[0] ); | ||
117 | -//$keys_string = implode( ',', $keys_arr); | ||
118 | -//$table_name = self::tableName(); | ||
119 | -//$current_batch = 0; | ||
120 | -//for ($i = $current_batch; $i < $this::BATCH AND $i < count($data); $i++) { | ||
121 | -// $values_string .= '(' . implode( ',', $data[$i]) . '),'; | ||
122 | -//} | ||
123 | -// for ($current_batch = $this::BATCH; $current_batch<count($data); $current_batch + $this::BATCH ) | ||
124 | -//// удалим последнюю запятую | ||
125 | -//$values_string = substr($values_string, 0, strlen($values_string) - 1) . ' '; | ||
126 | -////\common\components\CustomVarDamp::dumpAndDie($values_string); | ||
127 | -//// $query = "INSERT INTO {$table_name}({$keys_string}) VALUES {$values_string}"; | ||
128 | -//// on duplicate key update `PRICE` = values (`PRICE`),`DESCR` = values(`DESCR`),`BOX` = values(`BOX`)"; | ||
129 | -//$query_insert = Yii::$app->db->createCommand()->batchInsert($table_name, $keys_arr, $data)->sql; | ||
130 | -//$query = "{$query_insert} on duplicate key update `PRICE` = values (`PRICE`),`DESCR` = values(`DESCR`),`BOX` = values(`BOX`)"; | ||
131 | -//$res = Yii::$app->db->createCommand($query)->execute(); | ||
132 | - | ||
133 | - | ||
134 | - | ||
135 | -// Yii::$app->db->createCommand()->batchInsert($table_name, $keys_arr, $data)->sql execute(); | ||
136 | \ No newline at end of file | 0 | \ No newline at end of file |
backend/models/Importer.php deleted
1 | -<?php | ||
2 | - | ||
3 | -namespace backend\models; | ||
4 | - | ||
5 | -use Yii; | ||
6 | -use backend\components\base\BaseActiveRecord; | ||
7 | - | ||
8 | -/** | ||
9 | - * This is the model class for table "{{%importer}}". | ||
10 | - * | ||
11 | - * @property integer $id | ||
12 | - * @property string $code | ||
13 | - * @property string $name | ||
14 | - * @property string $name_price | ||
15 | - * @property string $currency_id | ||
16 | - * @property string $delivery | ||
17 | - * @property string $email | ||
18 | - * @property string $info | ||
19 | - * @property integer $active | ||
20 | - * @property integer $PARSER_IS_ACTIVE | ||
21 | - * @property string $PARSER_COLUMN_COUNT | ||
22 | - * @property string $PARSER_FIELD_BRAND | ||
23 | - * @property string $PARSER_FIELD_ARTICLE | ||
24 | - * @property integer $PARSER_FIELD_ARTICLE_PREFIX | ||
25 | - * @property string $PARSER_FIELD_PRICE | ||
26 | - * @property string $PARSER_FIELD_DESCR | ||
27 | - * @property string $PARSER_FIELD_BOX | ||
28 | - * @property string $PARSER_FIELD_ADD_BOX | ||
29 | - * @property string $PARSER_FIELD_GROUP_RG | ||
30 | - * @property string $PARSER_FIELD_SIGN | ||
31 | - * @property double $PARSER_FIELD_MULTIPLIER | ||
32 | - * @property string $price_date_update | ||
33 | - */ | ||
34 | -class Importer extends BaseActiveRecord | ||
35 | -{ | ||
36 | - /** | ||
37 | - * @inheritdoc | ||
38 | - */ | ||
39 | - public static function tableName() | ||
40 | - { | ||
41 | - return '{{%importer}}'; | ||
42 | - } | ||
43 | - | ||
44 | - /** | ||
45 | - * @inheritdoc | ||
46 | - */ | ||
47 | - public function rules() | ||
48 | - { | ||
49 | - return [ | ||
50 | - [['code', 'name', 'currency_id', 'delivery', 'price_date_update'], 'required'], | ||
51 | - [['name_price', 'email', 'PARSER_FIELD_SIGN', 'info'], 'safe'], | ||
52 | - [['currency_id', 'active', 'PARSER_IS_ACTIVE', 'PARSER_COLUMN_COUNT', 'PARSER_FIELD_BRAND', 'PARSER_FIELD_ARTICLE', 'PARSER_FIELD_ARTICLE_PREFIX', 'PARSER_FIELD_PRICE', 'PARSER_FIELD_DESCR', 'PARSER_FIELD_BOX', 'PARSER_FIELD_ADD_BOX', 'PARSER_FIELD_GROUP_RG'], 'integer'], | ||
53 | - [['info'], 'string'], | ||
54 | - [['PARSER_FIELD_MULTIPLIER'], 'number'], | ||
55 | - [['code', 'name', 'name_price', 'delivery', 'email'], 'string', 'max' => 254], | ||
56 | - [['PARSER_FIELD_SIGN'], 'string', 'max' => 1], | ||
57 | - // [['price_date_update'], 'string', 'max' => 15], | ||
58 | - [['code'], 'unique'], | ||
59 | - [['name'], 'unique'] | ||
60 | - ]; | ||
61 | - } | ||
62 | - | ||
63 | - /** | ||
64 | - * @inheritdoc | ||
65 | - */ | ||
66 | - public function attributeLabels() | ||
67 | - { | ||
68 | - return [ | ||
69 | - 'id' => Yii::t('app', 'ID'), | ||
70 | - 'code' => Yii::t('app', 'Code'), | ||
71 | - 'name' => Yii::t('app', 'Name'), | ||
72 | - 'name_price' => Yii::t('app', 'Name Price'), | ||
73 | - 'currency_id' => Yii::t('app', 'Currency ID'), | ||
74 | - 'delivery' => Yii::t('app', 'Delivery'), | ||
75 | - 'email' => Yii::t('app', 'Email'), | ||
76 | - 'info' => Yii::t('app', 'Info'), | ||
77 | - 'active' => Yii::t('app', 'Active'), | ||
78 | - 'PARSER_IS_ACTIVE' => Yii::t('app', 'Parser Is Active'), | ||
79 | - 'PARSER_COLUMN_COUNT' => Yii::t('app', 'Parser Column Count'), | ||
80 | - 'PARSER_FIELD_BRAND' => Yii::t('app', 'Parser Field Brand'), | ||
81 | - 'PARSER_FIELD_ARTICLE' => Yii::t('app', 'Parser Field Article'), | ||
82 | - 'PARSER_FIELD_ARTICLE_PREFIX' => Yii::t('app', 'Parser Field Article Prefix'), | ||
83 | - 'PARSER_FIELD_PRICE' => Yii::t('app', 'Parser Field Price'), | ||
84 | - 'PARSER_FIELD_DESCR' => Yii::t('app', 'Parser Field Descr'), | ||
85 | - 'PARSER_FIELD_BOX' => Yii::t('app', 'Parser Field Box'), | ||
86 | - 'PARSER_FIELD_ADD_BOX' => Yii::t('app', 'Parser Field Add Box'), | ||
87 | - 'PARSER_FIELD_GROUP_RG' => Yii::t('app', 'Parser Field Group Rg'), | ||
88 | - 'PARSER_FIELD_SIGN' => Yii::t('app', 'Parser Field Sign'), | ||
89 | - 'PARSER_FIELD_MULTIPLIER' => Yii::t('app', 'Parser Field Multiplier'), | ||
90 | - 'price_date_update' => Yii::t('app', 'Price Date Update'), | ||
91 | - ]; | ||
92 | - } | ||
93 | - | ||
94 | - | ||
95 | - | ||
96 | -} |
backend/models/Importers.php
@@ -95,14 +95,14 @@ class Importers extends BaseActiveRecord | @@ -95,14 +95,14 @@ class Importers extends BaseActiveRecord | ||
95 | // возьмем только поля описанные в fields() - там как раз наши настройки парсера | 95 | // возьмем только поля описанные в fields() - там как раз наши настройки парсера |
96 | $arr = $this->toArray(); | 96 | $arr = $this->toArray(); |
97 | 97 | ||
98 | - // отсортируем по ключам с учетом преобразования в число | ||
99 | - asort($arr, SORT_NUMERIC); | ||
100 | // уберем нулевые колонки | 98 | // уберем нулевые колонки |
101 | $arr = array_filter($arr, function($val){ | 99 | $arr = array_filter($arr, function($val){ |
102 | return $val <> '0'; | 100 | return $val <> '0'; |
103 | }); | 101 | }); |
104 | - // нам нужны именно ключи | ||
105 | - $arr = array_keys($arr); | 102 | + // нам нужны именно массив в виде 'номер колонки в файле'=>'имя колонки в БД' |
103 | + $arr = array_flip( $arr ); | ||
104 | + // отсортируем по ключам | ||
105 | + ksort($arr); | ||
106 | 106 | ||
107 | return $arr; | 107 | return $arr; |
108 | } | 108 | } |
@@ -121,13 +121,27 @@ class Importers extends BaseActiveRecord | @@ -121,13 +121,27 @@ class Importers extends BaseActiveRecord | ||
121 | public function fields() | 121 | public function fields() |
122 | { | 122 | { |
123 | return [ | 123 | return [ |
124 | - 'BRAND' => 'PARSER_FIELD_BRAND', | ||
125 | - 'ARTICLE' => 'PARSER_FIELD_ARTICLE', | ||
126 | - 'PRICE' => 'PARSER_FIELD_PRICE', | ||
127 | - 'DESCR' => 'PARSER_FIELD_DESCR', | ||
128 | - 'BOX' => 'PARSER_FIELD_BOX', | ||
129 | - 'ADD_BOX' => 'PARSER_FIELD_ADD_BOX', | ||
130 | - 'GROUP_RG' => 'PARSER_FIELD_GROUP_RG' | 124 | + 'BRAND' => function () { |
125 | + return $this->PARSER_FIELD_BRAND == '0'? '0' : (int)$this->PARSER_FIELD_BRAND - 1; | ||
126 | + }, | ||
127 | + 'ARTICLE' => function () { | ||
128 | + return $this->PARSER_FIELD_ARTICLE == '0'? '0' : (int)$this->PARSER_FIELD_ARTICLE - 1; | ||
129 | + }, | ||
130 | + 'PRICE' => function () { | ||
131 | + return $this->PARSER_FIELD_PRICE == '0'? '0' : (int)$this->PARSER_FIELD_PRICE - 1; | ||
132 | + }, | ||
133 | + 'DESCR' => function () { | ||
134 | + return $this->PARSER_FIELD_DESCR == '0'? '0' : (int)$this->PARSER_FIELD_DESCR - 1; | ||
135 | + }, | ||
136 | + 'BOX' => function () { | ||
137 | + return $this->PARSER_FIELD_BOX == '0'? '0' : (int)$this->PARSER_FIELD_BOX - 1; | ||
138 | + }, | ||
139 | + 'ADD_BOX' => function () { | ||
140 | + return $this->PARSER_FIELD_ADD_BOX == '0'? '0' : (int)$this->PARSER_FIELD_ADD_BOX - 1; | ||
141 | + }, | ||
142 | + 'GROUP_RG' => function () { | ||
143 | + return $this->PARSER_FIELD_GROUP_RG == '0'? '0' : (int)$this->PARSER_FIELD_GROUP_RG - 1; | ||
144 | + }, | ||
131 | ]; | 145 | ]; |
132 | 146 | ||
133 | } | 147 | } |
backend/views/accounts-vin/_form.php
@@ -29,7 +29,7 @@ use yii\widgets\ActiveForm; | @@ -29,7 +29,7 @@ use yii\widgets\ActiveForm; | ||
29 | <?= $form->field($model, 'timestamp')->textInput() ?> | 29 | <?= $form->field($model, 'timestamp')->textInput() ?> |
30 | 30 | ||
31 | <div class="form-group"> | 31 | <div class="form-group"> |
32 | - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | 32 | + <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
33 | </div> | 33 | </div> |
34 | 34 | ||
35 | <?php ActiveForm::end(); ?> | 35 | <?php ActiveForm::end(); ?> |
backend/views/accounts-vin/create.php
@@ -6,7 +6,7 @@ use yii\helpers\Html; | @@ -6,7 +6,7 @@ use yii\helpers\Html; | ||
6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
7 | /* @var $model common\models\AccountsVin */ | 7 | /* @var $model common\models\AccountsVin */ |
8 | 8 | ||
9 | -$this->title = 'Create Accounts Vin'; | 9 | +$this->title = 'Добавить Accounts Vin'; |
10 | $this->params['breadcrumbs'][] = ['label' => 'Accounts Vins', 'url' => ['index']]; | 10 | $this->params['breadcrumbs'][] = ['label' => 'Accounts Vins', 'url' => ['index']]; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
backend/views/accounts-vin/index.php
@@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | 16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> |
17 | 17 | ||
18 | <p> | 18 | <p> |
19 | - <?= Html::a('Create Accounts Vin', ['create'], ['class' => 'btn btn-success']) ?> | 19 | + <?= Html::a('Добавить Accounts Vin', ['create'], ['class' => 'btn btn-success']) ?> |
20 | </p> | 20 | </p> |
21 | 21 | ||
22 | <?= GridView::widget([ | 22 | <?= GridView::widget([ |
backend/views/accounts/_form.php
@@ -85,7 +85,7 @@ use kartik\date\DatePicker; | @@ -85,7 +85,7 @@ use kartik\date\DatePicker; | ||
85 | 85 | ||
86 | 86 | ||
87 | <div class="form-group"> | 87 | <div class="form-group"> |
88 | - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | 88 | + <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
89 | </div> | 89 | </div> |
90 | 90 | ||
91 | <?php ActiveForm::end(); ?> | 91 | <?php ActiveForm::end(); ?> |
backend/views/accounts/create.php
@@ -6,7 +6,7 @@ use yii\helpers\Html; | @@ -6,7 +6,7 @@ use yii\helpers\Html; | ||
6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
7 | /* @var $model common\models\Accounts */ | 7 | /* @var $model common\models\Accounts */ |
8 | 8 | ||
9 | -$this->title = 'Create Accounts'; | 9 | +$this->title = 'Добавить Accounts'; |
10 | $this->params['breadcrumbs'][] = ['label' => 'Accounts', 'url' => ['index']]; | 10 | $this->params['breadcrumbs'][] = ['label' => 'Accounts', 'url' => ['index']]; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
backend/views/accounts/index.php
@@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | 16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> |
17 | 17 | ||
18 | <p> | 18 | <p> |
19 | - <?= Html::a('Create Accounts', ['create'], ['class' => 'btn btn-success']) ?> | 19 | + <?= Html::a('Добавить Accounts', ['create'], ['class' => 'btn btn-success']) ?> |
20 | </p> | 20 | </p> |
21 | 21 | ||
22 | <?= GridView::widget([ | 22 | <?= GridView::widget([ |
backend/views/art-history/_form.php
@@ -19,7 +19,7 @@ use yii\widgets\ActiveForm; | @@ -19,7 +19,7 @@ use yii\widgets\ActiveForm; | ||
19 | <?= $form->field($model, 'dt')->textInput(['maxlength' => true]) ?> | 19 | <?= $form->field($model, 'dt')->textInput(['maxlength' => true]) ?> |
20 | 20 | ||
21 | <div class="form-group"> | 21 | <div class="form-group"> |
22 | - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | 22 | + <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
23 | </div> | 23 | </div> |
24 | 24 | ||
25 | <?php ActiveForm::end(); ?> | 25 | <?php ActiveForm::end(); ?> |
backend/views/art-history/create.php
@@ -6,7 +6,7 @@ use yii\helpers\Html; | @@ -6,7 +6,7 @@ use yii\helpers\Html; | ||
6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
7 | /* @var $model common\models\ArtHistory */ | 7 | /* @var $model common\models\ArtHistory */ |
8 | 8 | ||
9 | -$this->title = 'Create Art History'; | 9 | +$this->title = 'Добавить Art History'; |
10 | $this->params['breadcrumbs'][] = ['label' => 'Art Histories', 'url' => ['index']]; | 10 | $this->params['breadcrumbs'][] = ['label' => 'Art Histories', 'url' => ['index']]; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
backend/views/art-history/index.php
@@ -17,7 +17,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -17,7 +17,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
17 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | 17 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> |
18 | 18 | ||
19 | <p> | 19 | <p> |
20 | - <?= Html::a('Create Art History', ['create'], ['class' => 'btn btn-success']) ?> | 20 | + <?= Html::a('Добавить Art History', ['create'], ['class' => 'btn btn-success']) ?> |
21 | </p> | 21 | </p> |
22 | 22 | ||
23 | <?= GridView::widget([ | 23 | <?= GridView::widget([ |
backend/views/brands-replace/_form.php
@@ -21,7 +21,7 @@ use yii\widgets\ActiveForm; | @@ -21,7 +21,7 @@ use yii\widgets\ActiveForm; | ||
21 | <?= $form->field($model, 'timestamp')->textInput() ?> | 21 | <?= $form->field($model, 'timestamp')->textInput() ?> |
22 | 22 | ||
23 | <div class="form-group"> | 23 | <div class="form-group"> |
24 | - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | 24 | + <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
25 | </div> | 25 | </div> |
26 | 26 | ||
27 | <?php ActiveForm::end(); ?> | 27 | <?php ActiveForm::end(); ?> |
backend/views/brands-replace/create.php
@@ -6,7 +6,7 @@ use yii\helpers\Html; | @@ -6,7 +6,7 @@ use yii\helpers\Html; | ||
6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
7 | /* @var $model common\models\BrandsReplace */ | 7 | /* @var $model common\models\BrandsReplace */ |
8 | 8 | ||
9 | -$this->title = 'Create Brands Replace'; | 9 | +$this->title = 'Добавить Brands Replace'; |
10 | $this->params['breadcrumbs'][] = ['label' => 'Brands Replaces', 'url' => ['index']]; | 10 | $this->params['breadcrumbs'][] = ['label' => 'Brands Replaces', 'url' => ['index']]; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
backend/views/brands-replace/index.php
@@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | 16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> |
17 | 17 | ||
18 | <p> | 18 | <p> |
19 | - <?= Html::a('Create Brands Replace', ['create'], ['class' => 'btn btn-success']) ?> | 19 | + <?= Html::a('Добавить Brands Replace', ['create'], ['class' => 'btn btn-success']) ?> |
20 | </p> | 20 | </p> |
21 | 21 | ||
22 | <?= GridView::widget([ | 22 | <?= GridView::widget([ |
backend/views/brands/_form.php
@@ -29,7 +29,7 @@ use yii\widgets\ActiveForm; | @@ -29,7 +29,7 @@ use yii\widgets\ActiveForm; | ||
29 | <?= $form->field($model, 'timestamp')->textInput() ?> | 29 | <?= $form->field($model, 'timestamp')->textInput() ?> |
30 | 30 | ||
31 | <div class="form-group"> | 31 | <div class="form-group"> |
32 | - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | 32 | + <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
33 | </div> | 33 | </div> |
34 | 34 | ||
35 | <?php ActiveForm::end(); ?> | 35 | <?php ActiveForm::end(); ?> |
backend/views/brands/create.php
@@ -6,7 +6,7 @@ use yii\helpers\Html; | @@ -6,7 +6,7 @@ use yii\helpers\Html; | ||
6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
7 | /* @var $model common\models\Brands */ | 7 | /* @var $model common\models\Brands */ |
8 | 8 | ||
9 | -$this->title = 'Create Brands'; | 9 | +$this->title = 'Добавить Brands'; |
10 | $this->params['breadcrumbs'][] = ['label' => 'Brands', 'url' => ['index']]; | 10 | $this->params['breadcrumbs'][] = ['label' => 'Brands', 'url' => ['index']]; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
backend/views/cat/create.php
@@ -6,7 +6,7 @@ use yii\helpers\Html; | @@ -6,7 +6,7 @@ use yii\helpers\Html; | ||
6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
7 | /* @var $model common\models\Cat */ | 7 | /* @var $model common\models\Cat */ |
8 | 8 | ||
9 | -$this->title = 'Create Cat'; | 9 | +$this->title = 'Добавить Cat'; |
10 | $this->params['breadcrumbs'][] = ['label' => 'Cats', 'url' => ['index']]; | 10 | $this->params['breadcrumbs'][] = ['label' => 'Cats', 'url' => ['index']]; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
backend/views/cat/index.php
@@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | 16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> |
17 | 17 | ||
18 | <p> | 18 | <p> |
19 | - <?= Html::a('Create Cat', ['create'], ['class' => 'btn btn-success']) ?> | 19 | + <?= Html::a('Добавить Cat', ['create'], ['class' => 'btn btn-success']) ?> |
20 | </p> | 20 | </p> |
21 | 21 | ||
22 | <?= GridView::widget([ | 22 | <?= GridView::widget([ |
backend/views/crossing-upload/index.php
@@ -14,9 +14,10 @@ use yii\helpers\ArrayHelper; | @@ -14,9 +14,10 @@ use yii\helpers\ArrayHelper; | ||
14 | <?= $form->field($model, 'delete_prefix1')->checkbox() ?> | 14 | <?= $form->field($model, 'delete_prefix1')->checkbox() ?> |
15 | <?= $form->field($model, 'delete_prefix2')->checkbox() ?> | 15 | <?= $form->field($model, 'delete_prefix2')->checkbox() ?> |
16 | <?= $form->field($model, 'file')->fileInput()->label(false) ?> | 16 | <?= $form->field($model, 'file')->fileInput()->label(false) ?> |
17 | + <?= Html::tag('p','допустимый формат - csv') ?> | ||
17 | 18 | ||
18 | <div class="form-group"> | 19 | <div class="form-group"> |
19 | - <?= Html::submitButton(Yii::t( 'app', 'Прочитать' ), ['class' => 'btn btn-primary']) ?> | 20 | + <?= Html::submitButton(Yii::t( 'app', 'Выполнить' ), ['class' => 'btn btn-primary']) ?> |
20 | </div> | 21 | </div> |
21 | 22 | ||
22 | <?php ActiveForm::end(); | 23 | <?php ActiveForm::end(); |
backend/views/crossing-upload/results.php
backend/views/deliveries/index.php
@@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | 16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> |
17 | 17 | ||
18 | <p> | 18 | <p> |
19 | - <?= Html::a('Create Deliveries', ['create'], ['class' => 'btn btn-success']) ?> | 19 | + <?= Html::a('Добавить Deliveries', ['create'], ['class' => 'btn btn-success']) ?> |
20 | </p> | 20 | </p> |
21 | 21 | ||
22 | <?= GridView::widget([ | 22 | <?= GridView::widget([ |
backend/views/details-crosses/_form.php
@@ -23,7 +23,7 @@ use yii\widgets\ActiveForm; | @@ -23,7 +23,7 @@ use yii\widgets\ActiveForm; | ||
23 | <?= $form->field($model, 'timestamp')->textInput() ?> | 23 | <?= $form->field($model, 'timestamp')->textInput() ?> |
24 | 24 | ||
25 | <div class="form-group"> | 25 | <div class="form-group"> |
26 | - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | 26 | + <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
27 | </div> | 27 | </div> |
28 | 28 | ||
29 | <?php ActiveForm::end(); ?> | 29 | <?php ActiveForm::end(); ?> |
backend/views/details-crosses/create.php
@@ -6,7 +6,7 @@ use yii\helpers\Html; | @@ -6,7 +6,7 @@ use yii\helpers\Html; | ||
6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
7 | /* @var $model common\models\DetailsCrosses */ | 7 | /* @var $model common\models\DetailsCrosses */ |
8 | 8 | ||
9 | -$this->title = 'Create Details Crosses'; | 9 | +$this->title = 'Добавить Details Crosses'; |
10 | $this->params['breadcrumbs'][] = ['label' => 'Details Crosses', 'url' => ['index']]; | 10 | $this->params['breadcrumbs'][] = ['label' => 'Details Crosses', 'url' => ['index']]; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
backend/views/details/_form.php
@@ -33,7 +33,7 @@ use yii\widgets\ActiveForm; | @@ -33,7 +33,7 @@ use yii\widgets\ActiveForm; | ||
33 | <?= $form->field($model, 'timestamp')->textInput() ?> | 33 | <?= $form->field($model, 'timestamp')->textInput() ?> |
34 | 34 | ||
35 | <div class="form-group"> | 35 | <div class="form-group"> |
36 | - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | 36 | + <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
37 | </div> | 37 | </div> |
38 | 38 | ||
39 | <?php ActiveForm::end(); ?> | 39 | <?php ActiveForm::end(); ?> |
backend/views/details/create.php
@@ -6,7 +6,7 @@ use yii\helpers\Html; | @@ -6,7 +6,7 @@ use yii\helpers\Html; | ||
6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
7 | /* @var $model common\models\Details */ | 7 | /* @var $model common\models\Details */ |
8 | 8 | ||
9 | -$this->title = 'Create Details'; | 9 | +$this->title = 'Добавить Details'; |
10 | $this->params['breadcrumbs'][] = ['label' => 'Details', 'url' => ['index']]; | 10 | $this->params['breadcrumbs'][] = ['label' => 'Details', 'url' => ['index']]; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
backend/views/dic-statuses/_form.php
@@ -23,7 +23,7 @@ use yii\widgets\ActiveForm; | @@ -23,7 +23,7 @@ use yii\widgets\ActiveForm; | ||
23 | <?= $form->field($model, 'if_mail')->textInput() ?> | 23 | <?= $form->field($model, 'if_mail')->textInput() ?> |
24 | 24 | ||
25 | <div class="form-group"> | 25 | <div class="form-group"> |
26 | - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | 26 | + <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
27 | </div> | 27 | </div> |
28 | 28 | ||
29 | <?php ActiveForm::end(); ?> | 29 | <?php ActiveForm::end(); ?> |
backend/views/dic-statuses/create.php
@@ -6,7 +6,7 @@ use yii\helpers\Html; | @@ -6,7 +6,7 @@ use yii\helpers\Html; | ||
6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
7 | /* @var $model common\models\DicStatuses */ | 7 | /* @var $model common\models\DicStatuses */ |
8 | 8 | ||
9 | -$this->title = 'Create Dic Statuses'; | 9 | +$this->title = 'Добавить Dic Statuses'; |
10 | $this->params['breadcrumbs'][] = ['label' => 'Dic Statuses', 'url' => ['index']]; | 10 | $this->params['breadcrumbs'][] = ['label' => 'Dic Statuses', 'url' => ['index']]; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
backend/views/dic-statuses/index.php
@@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | 16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> |
17 | 17 | ||
18 | <p> | 18 | <p> |
19 | - <?= Html::a('Create Dic Statuses', ['create'], ['class' => 'btn btn-success']) ?> | 19 | + <?= Html::a('Добавить Dic Statuses', ['create'], ['class' => 'btn btn-success']) ?> |
20 | </p> | 20 | </p> |
21 | 21 | ||
22 | <?= GridView::widget([ | 22 | <?= GridView::widget([ |
backend/views/emails/_form.php
@@ -29,7 +29,7 @@ use yii\widgets\ActiveForm; | @@ -29,7 +29,7 @@ use yii\widgets\ActiveForm; | ||
29 | <?= $form->field($model, 'who_comment')->textInput(['maxlength' => true]) ?> | 29 | <?= $form->field($model, 'who_comment')->textInput(['maxlength' => true]) ?> |
30 | 30 | ||
31 | <div class="form-group"> | 31 | <div class="form-group"> |
32 | - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | 32 | + <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
33 | </div> | 33 | </div> |
34 | 34 | ||
35 | <?php ActiveForm::end(); ?> | 35 | <?php ActiveForm::end(); ?> |
backend/views/emails/create.php
@@ -6,7 +6,7 @@ use yii\helpers\Html; | @@ -6,7 +6,7 @@ use yii\helpers\Html; | ||
6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
7 | /* @var $model common\models\Emails */ | 7 | /* @var $model common\models\Emails */ |
8 | 8 | ||
9 | -$this->title = 'Create Emails'; | 9 | +$this->title = 'Добавить Emails'; |
10 | $this->params['breadcrumbs'][] = ['label' => 'Emails', 'url' => ['index']]; | 10 | $this->params['breadcrumbs'][] = ['label' => 'Emails', 'url' => ['index']]; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
backend/views/emails/index.php
@@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | 16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> |
17 | 17 | ||
18 | <p> | 18 | <p> |
19 | - <?= Html::a('Create Emails', ['create'], ['class' => 'btn btn-success']) ?> | 19 | + <?= Html::a('Добавить Emails', ['create'], ['class' => 'btn btn-success']) ?> |
20 | </p> | 20 | </p> |
21 | 21 | ||
22 | <?= GridView::widget([ | 22 | <?= GridView::widget([ |
backend/views/importers/_form.php
@@ -63,7 +63,7 @@ use common\models\Currency; | @@ -63,7 +63,7 @@ use common\models\Currency; | ||
63 | </div> | 63 | </div> |
64 | 64 | ||
65 | <div class="form-group"> | 65 | <div class="form-group"> |
66 | - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | 66 | + <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
67 | </div> | 67 | </div> |
68 | 68 | ||
69 | <?php ActiveForm::end(); ?> | 69 | <?php ActiveForm::end(); ?> |
backend/views/importers/create.php
@@ -6,7 +6,7 @@ use yii\helpers\Html; | @@ -6,7 +6,7 @@ use yii\helpers\Html; | ||
6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
7 | /* @var $model backend\models\Importers */ | 7 | /* @var $model backend\models\Importers */ |
8 | 8 | ||
9 | -$this->title = 'Create Importers'; | 9 | +$this->title = 'Добавить Importers'; |
10 | $this->params['breadcrumbs'][] = ['label' => 'Importers', 'url' => ['index']]; | 10 | $this->params['breadcrumbs'][] = ['label' => 'Importers', 'url' => ['index']]; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
backend/views/importers/index.php
@@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | 16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> |
17 | 17 | ||
18 | <p> | 18 | <p> |
19 | - <?= Html::a('Create Importers', ['create'], ['class' => 'btn btn-success']) ?> | 19 | + <?= Html::a('Добавить Importers', ['create'], ['class' => 'btn btn-success']) ?> |
20 | </p> | 20 | </p> |
21 | 21 | ||
22 | <?= GridView::widget([ | 22 | <?= GridView::widget([ |
backend/views/layouts/main.php
@@ -8,6 +8,7 @@ use yii\helpers\Html; | @@ -8,6 +8,7 @@ use yii\helpers\Html; | ||
8 | 8 | ||
9 | MyAsset::register($this); | 9 | MyAsset::register($this); |
10 | ?> | 10 | ?> |
11 | + | ||
11 | <?php $this->beginPage() ?> | 12 | <?php $this->beginPage() ?> |
12 | <!DOCTYPE html><html lang="<?= Yii::$app->language ?>" > | 13 | <!DOCTYPE html><html lang="<?= Yii::$app->language ?>" > |
13 | <head> | 14 | <head> |
backend/views/manufacturers/_form.php
@@ -53,7 +53,7 @@ use yii\widgets\ActiveForm; | @@ -53,7 +53,7 @@ use yii\widgets\ActiveForm; | ||
53 | <?= $form->field($model, 'original_url')->textInput(['maxlength' => true]) ?> | 53 | <?= $form->field($model, 'original_url')->textInput(['maxlength' => true]) ?> |
54 | 54 | ||
55 | <div class="form-group"> | 55 | <div class="form-group"> |
56 | - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | 56 | + <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
57 | </div> | 57 | </div> |
58 | 58 | ||
59 | <?php ActiveForm::end(); ?> | 59 | <?php ActiveForm::end(); ?> |
backend/views/manufacturers/create.php
@@ -6,7 +6,7 @@ use yii\helpers\Html; | @@ -6,7 +6,7 @@ use yii\helpers\Html; | ||
6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
7 | /* @var $model common\models\Manufacturers */ | 7 | /* @var $model common\models\Manufacturers */ |
8 | 8 | ||
9 | -$this->title = 'Create Manufacturers'; | 9 | +$this->title = 'Добавить Manufacturers'; |
10 | $this->params['breadcrumbs'][] = ['label' => 'Manufacturers', 'url' => ['index']]; | 10 | $this->params['breadcrumbs'][] = ['label' => 'Manufacturers', 'url' => ['index']]; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
backend/views/margins-groups/_form.php
@@ -21,7 +21,7 @@ use yii\helpers\ArrayHelper; | @@ -21,7 +21,7 @@ use yii\helpers\ArrayHelper; | ||
21 | 21 | ||
22 | 22 | ||
23 | <div class="form-group"> | 23 | <div class="form-group"> |
24 | - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | 24 | + <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
25 | </div> | 25 | </div> |
26 | 26 | ||
27 | <?php ActiveForm::end(); ?> | 27 | <?php ActiveForm::end(); ?> |
backend/views/margins-groups/create.php
@@ -6,7 +6,7 @@ use yii\helpers\Html; | @@ -6,7 +6,7 @@ use yii\helpers\Html; | ||
6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
7 | /* @var $model common\models\MarginsGroups */ | 7 | /* @var $model common\models\MarginsGroups */ |
8 | 8 | ||
9 | -$this->title = 'Create Margins Groups'; | 9 | +$this->title = 'Добавить Margins Groups'; |
10 | $this->params['breadcrumbs'][] = ['label' => 'Margins Groups', 'url' => ['index']]; | 10 | $this->params['breadcrumbs'][] = ['label' => 'Margins Groups', 'url' => ['index']]; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
backend/views/margins-groups/index.php
@@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | 16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> |
17 | 17 | ||
18 | <p> | 18 | <p> |
19 | - <?= Html::a('Create Margins Groups', ['create'], ['class' => 'btn btn-success']) ?> | 19 | + <?= Html::a('Добавить Margins Groups', ['create'], ['class' => 'btn btn-success']) ?> |
20 | </p> | 20 | </p> |
21 | 21 | ||
22 | <?= GridView::widget([ | 22 | <?= GridView::widget([ |
backend/views/margins-importers-import/_form.php
@@ -20,7 +20,7 @@ use \yii\helpers\ArrayHelper; | @@ -20,7 +20,7 @@ use \yii\helpers\ArrayHelper; | ||
20 | 20 | ||
21 | <?= $form->field($model, 'finish')->checkbox() ?> | 21 | <?= $form->field($model, 'finish')->checkbox() ?> |
22 | <div class="form-group"> | 22 | <div class="form-group"> |
23 | - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | 23 | + <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
24 | </div> | 24 | </div> |
25 | 25 | ||
26 | <?php ActiveForm::end(); ?> | 26 | <?php ActiveForm::end(); ?> |
backend/views/margins-importers-import/create.php
@@ -6,7 +6,7 @@ use yii\helpers\Html; | @@ -6,7 +6,7 @@ use yii\helpers\Html; | ||
6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
7 | /* @var $model common\models\MarginsImportersImport */ | 7 | /* @var $model common\models\MarginsImportersImport */ |
8 | 8 | ||
9 | -$this->title = 'Create Margins Importers Import'; | 9 | +$this->title = 'Добавить Margins Importers Import'; |
10 | $this->params['breadcrumbs'][] = ['label' => 'Margins Importers Imports', 'url' => ['index']]; | 10 | $this->params['breadcrumbs'][] = ['label' => 'Margins Importers Imports', 'url' => ['index']]; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
backend/views/margins-importers-import/index.php
@@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | 16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> |
17 | 17 | ||
18 | <p> | 18 | <p> |
19 | - <?= Html::a('Create Margins Importers Import', ['create'], ['class' => 'btn btn-success']) ?> | 19 | + <?= Html::a('Добавить Margins Importers Import', ['create'], ['class' => 'btn btn-success']) ?> |
20 | </p> | 20 | </p> |
21 | 21 | ||
22 | <?= GridView::widget([ | 22 | <?= GridView::widget([ |
backend/views/margins-importers/_form.php
@@ -19,7 +19,7 @@ use yii\helpers\ArrayHelper; | @@ -19,7 +19,7 @@ use yii\helpers\ArrayHelper; | ||
19 | <?= $form->field($model, 'koef')->textInput() ?> | 19 | <?= $form->field($model, 'koef')->textInput() ?> |
20 | 20 | ||
21 | <div class="form-group"> | 21 | <div class="form-group"> |
22 | - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | 22 | + <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
23 | </div> | 23 | </div> |
24 | 24 | ||
25 | <?php ActiveForm::end(); ?> | 25 | <?php ActiveForm::end(); ?> |
backend/views/margins-importers/create.php
@@ -6,7 +6,7 @@ use yii\helpers\Html; | @@ -6,7 +6,7 @@ use yii\helpers\Html; | ||
6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
7 | /* @var $model common\models\MarginsImporters */ | 7 | /* @var $model common\models\MarginsImporters */ |
8 | 8 | ||
9 | -$this->title = 'Create Margins Importers'; | 9 | +$this->title = 'Добавить Margins Importers'; |
10 | $this->params['breadcrumbs'][] = ['label' => 'Margins Importers', 'url' => ['index']]; | 10 | $this->params['breadcrumbs'][] = ['label' => 'Margins Importers', 'url' => ['index']]; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
backend/views/margins-importers/index.php
@@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | 16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> |
17 | 17 | ||
18 | <p> | 18 | <p> |
19 | - <?= Html::a('Create Margins Importers', ['create'], ['class' => 'btn btn-success']) ?> | 19 | + <?= Html::a('Добавить Margins Importers', ['create'], ['class' => 'btn btn-success']) ?> |
20 | </p> | 20 | </p> |
21 | 21 | ||
22 | <?= GridView::widget([ | 22 | <?= GridView::widget([ |
backend/views/margins/_form.php
@@ -17,7 +17,7 @@ use yii\widgets\ActiveForm; | @@ -17,7 +17,7 @@ use yii\widgets\ActiveForm; | ||
17 | <?= $form->field($model, 'koef')->textInput() ?> | 17 | <?= $form->field($model, 'koef')->textInput() ?> |
18 | 18 | ||
19 | <div class="form-group"> | 19 | <div class="form-group"> |
20 | - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | 20 | + <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
21 | </div> | 21 | </div> |
22 | 22 | ||
23 | <?php ActiveForm::end(); ?> | 23 | <?php ActiveForm::end(); ?> |
backend/views/margins/create.php
@@ -6,7 +6,7 @@ use yii\helpers\Html; | @@ -6,7 +6,7 @@ use yii\helpers\Html; | ||
6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
7 | /* @var $model common\models\Margins */ | 7 | /* @var $model common\models\Margins */ |
8 | 8 | ||
9 | -$this->title = 'Create Margins'; | 9 | +$this->title = 'Добавить Margins'; |
10 | $this->params['breadcrumbs'][] = ['label' => 'Margins', 'url' => ['index']]; | 10 | $this->params['breadcrumbs'][] = ['label' => 'Margins', 'url' => ['index']]; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
backend/views/margins/index.php
@@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | 16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> |
17 | 17 | ||
18 | <p> | 18 | <p> |
19 | - <?= Html::a('Create Margins', ['create'], ['class' => 'btn btn-success']) ?> | 19 | + <?= Html::a('Добавить Margins', ['create'], ['class' => 'btn btn-success']) ?> |
20 | </p> | 20 | </p> |
21 | 21 | ||
22 | <?= GridView::widget([ | 22 | <?= GridView::widget([ |
backend/views/page/_form.php
@@ -21,6 +21,7 @@ use mihaildev\elfinder\ElFinder; | @@ -21,6 +21,7 @@ use mihaildev\elfinder\ElFinder; | ||
21 | 'editorOptions' => ElFinder::ckeditorOptions('elfinder',[ | 21 | 'editorOptions' => ElFinder::ckeditorOptions('elfinder',[ |
22 | 'preset' => 'full', //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать | 22 | 'preset' => 'full', //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать |
23 | 'inline' => false, //по умолчанию false]), | 23 | 'inline' => false, //по умолчанию false]), |
24 | + 'allowedContent' => true, | ||
24 | 'filebrowserUploadUrl'=>Yii::$app->getUrlManager()->createUrl('page/images-upload') | 25 | 'filebrowserUploadUrl'=>Yii::$app->getUrlManager()->createUrl('page/images-upload') |
25 | ] | 26 | ] |
26 | ) | 27 | ) |
backend/views/page/_search.php
@@ -34,8 +34,8 @@ use yii\widgets\ActiveForm; | @@ -34,8 +34,8 @@ use yii\widgets\ActiveForm; | ||
34 | <?php // echo $form->field($model, 'is_active') ?> | 34 | <?php // echo $form->field($model, 'is_active') ?> |
35 | 35 | ||
36 | <div class="form-group"> | 36 | <div class="form-group"> |
37 | - <?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?> | ||
38 | - <?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?> | 37 | + <?= Html::submitButton('Поиск', ['class' => 'btn btn-primary']) ?> |
38 | + <?= Html::resetButton('Обновить', ['class' => 'btn btn-default']) ?> | ||
39 | </div> | 39 | </div> |
40 | 40 | ||
41 | <?php ActiveForm::end(); ?> | 41 | <?php ActiveForm::end(); ?> |
backend/views/page/create.php
@@ -6,8 +6,8 @@ use yii\helpers\Html; | @@ -6,8 +6,8 @@ use yii\helpers\Html; | ||
6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
7 | /* @var $model common\models\Page */ | 7 | /* @var $model common\models\Page */ |
8 | 8 | ||
9 | -$this->title = 'Create Page'; | ||
10 | -$this->params['breadcrumbs'][] = ['label' => 'Pages', 'url' => ['index']]; | 9 | +$this->title = 'Создать'; |
10 | +$this->params['breadcrumbs'][] = ['label' => 'Текстовые страницы', 'url' => ['index']]; | ||
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
13 | <div class="page-create"> | 13 | <div class="page-create"> |
backend/views/page/index.php
@@ -7,7 +7,7 @@ use yii\grid\GridView; | @@ -7,7 +7,7 @@ use yii\grid\GridView; | ||
7 | /* @var $searchModel common\models\PageSearch */ | 7 | /* @var $searchModel common\models\PageSearch */ |
8 | /* @var $dataProvider yii\data\ActiveDataProvider */ | 8 | /* @var $dataProvider yii\data\ActiveDataProvider */ |
9 | 9 | ||
10 | -$this->title = 'Pages'; | 10 | +$this->title = 'Текстовые страницы'; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
13 | <div class="page-index"> | 13 | <div class="page-index"> |
@@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | 16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> |
17 | 17 | ||
18 | <p> | 18 | <p> |
19 | - <?= Html::a('Create Page', ['create'], ['class' => 'btn btn-success']) ?> | 19 | + <?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?> |
20 | </p> | 20 | </p> |
21 | 21 | ||
22 | <?= GridView::widget([ | 22 | <?= GridView::widget([ |
backend/views/page/update.php
@@ -6,9 +6,9 @@ use yii\helpers\Html; | @@ -6,9 +6,9 @@ use yii\helpers\Html; | ||
6 | /* @var $model common\models\Page */ | 6 | /* @var $model common\models\Page */ |
7 | 7 | ||
8 | $this->title = 'Update Page: ' . ' ' . $model->name; | 8 | $this->title = 'Update Page: ' . ' ' . $model->name; |
9 | -$this->params['breadcrumbs'][] = ['label' => 'Pages', 'url' => ['index']]; | 9 | +$this->params['breadcrumbs'][] = ['label' => 'Текстовые страницы', 'url' => ['index']]; |
10 | $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; | 10 | $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; |
11 | -$this->params['breadcrumbs'][] = 'Update'; | 11 | +$this->params['breadcrumbs'][] = 'Обновить'; |
12 | ?> | 12 | ?> |
13 | <div class="page-update"> | 13 | <div class="page-update"> |
14 | 14 |
backend/views/page/view.php
@@ -7,7 +7,7 @@ use yii\widgets\DetailView; | @@ -7,7 +7,7 @@ use yii\widgets\DetailView; | ||
7 | /* @var $model common\models\Page */ | 7 | /* @var $model common\models\Page */ |
8 | 8 | ||
9 | $this->title = $model->name; | 9 | $this->title = $model->name; |
10 | -$this->params['breadcrumbs'][] = ['label' => 'Pages', 'url' => ['index']]; | 10 | +$this->params['breadcrumbs'][] = ['label' => 'Текстовые страницы', 'url' => ['index']]; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
13 | <div class="page-view"> | 13 | <div class="page-view"> |
@@ -15,11 +15,11 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -15,11 +15,11 @@ $this->params['breadcrumbs'][] = $this->title; | ||
15 | <h1><?= Html::encode($this->title) ?></h1> | 15 | <h1><?= Html::encode($this->title) ?></h1> |
16 | 16 | ||
17 | <p> | 17 | <p> |
18 | - <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> | ||
19 | - <?= Html::a('Delete', ['delete', 'id' => $model->id], [ | 18 | + <?= Html::a('Обновить', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> |
19 | + <?= Html::a('Удалить', ['delete', 'id' => $model->id], [ | ||
20 | 'class' => 'btn btn-danger', | 20 | 'class' => 'btn btn-danger', |
21 | 'data' => [ | 21 | 'data' => [ |
22 | - 'confirm' => 'Are you sure you want to delete this item?', | 22 | + 'confirm' => 'Вы увереннны что хотите удалить этот элемент?', |
23 | 'method' => 'post', | 23 | 'method' => 'post', |
24 | ], | 24 | ], |
25 | ]) ?> | 25 | ]) ?> |
backend/views/parser/error.php
@@ -7,14 +7,21 @@ | @@ -7,14 +7,21 @@ | ||
7 | 7 | ||
8 | use yii\helpers\Html; | 8 | use yii\helpers\Html; |
9 | 9 | ||
10 | -$this->title = $name; | 10 | +$this->title = 'Ошибка'; |
11 | ?> | 11 | ?> |
12 | <div class="site-error"> | 12 | <div class="site-error"> |
13 | 13 | ||
14 | <h1><?= Html::encode($this->title) ?></h1> | 14 | <h1><?= Html::encode($this->title) ?></h1> |
15 | 15 | ||
16 | <div class="alert alert-danger"> | 16 | <div class="alert alert-danger"> |
17 | - <?= nl2br(Html::encode($message)) ?> | 17 | + <?php |
18 | + echo nl2br(Html::encode($message)); | ||
19 | + if ( $action_name ) { | ||
20 | + echo "<br/>"; | ||
21 | + echo "<br/>"; | ||
22 | + echo Html::a('Вернуться', $action_name, ['class' => 'btn btn-info', 'name' => 'Return',]); | ||
23 | + } | ||
24 | + ?> | ||
18 | </div> | 25 | </div> |
19 | 26 | ||
20 | <p> | 27 | <p> |
backend/views/parser/results.php
backend/views/rg-grup/index.php
@@ -4,17 +4,13 @@ use yii\helpers\Html; | @@ -4,17 +4,13 @@ use yii\helpers\Html; | ||
4 | use backend\models\Importers; | 4 | use backend\models\Importers; |
5 | use yii\helpers\ArrayHelper; | 5 | use yii\helpers\ArrayHelper; |
6 | 6 | ||
7 | -$button_label = 'Прочитать'; | 7 | +$button_label = 'Выполнить'; |
8 | 8 | ||
9 | 9 | ||
10 | ?> | 10 | ?> |
11 | <div class="row"> | 11 | <div class="row"> |
12 | <div class="col-lg-5"> | 12 | <div class="col-lg-5"> |
13 | <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data',],'action'=>['rg-grup/results']]); | 13 | <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data',],'action'=>['rg-grup/results']]); |
14 | - | ||
15 | - if ($msg = \Yii::$app->session->getFlash('success')) { // вернулись после успешной загрузки данного файла | ||
16 | - echo Html::tag('h3', $msg ,['class'=>'bg-success']); | ||
17 | - } | ||
18 | ?> | 14 | ?> |
19 | <h3>Загрузка RG групп поставщиков</h3> | 15 | <h3>Загрузка RG групп поставщиков</h3> |
20 | 16 | ||
@@ -25,9 +21,13 @@ $button_label = 'Прочитать'; | @@ -25,9 +21,13 @@ $button_label = 'Прочитать'; | ||
25 | <?= $form->field($model, 'file')->fileInput()->label(false) ?> | 21 | <?= $form->field($model, 'file')->fileInput()->label(false) ?> |
26 | <div class="form-group"> | 22 | <div class="form-group"> |
27 | <?= Html::submitButton(Yii::t( 'app', $button_label ), ['class' => 'btn btn-primary']) ?> | 23 | <?= Html::submitButton(Yii::t( 'app', $button_label ), ['class' => 'btn btn-primary']) ?> |
24 | + <?= Html::tag( 'p', 'допустимый формат xlsx') ?> | ||
25 | + | ||
28 | </div> | 26 | </div> |
29 | 27 | ||
30 | - <?php ActiveForm::end() ?> | 28 | + <?php ActiveForm::end(); |
29 | + // подключим шаблон сообщения | ||
30 | + echo $this->render('../templates/parser_massage');?> | ||
31 | </div> | 31 | </div> |
32 | </div> | 32 | </div> |
33 | 33 |
backend/views/rg-grup/results.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | use yii\helpers\Html; | 3 | use yii\helpers\Html; |
4 | -use yii\multiparser\DynamicFormHelper; | 4 | +use common\components\parsers\DynamicFormHelper; |
5 | use yii\widgets\ActiveForm; | 5 | use yii\widgets\ActiveForm; |
6 | 6 | ||
7 | 7 | ||
@@ -27,6 +27,6 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -27,6 +27,6 @@ $this->params['breadcrumbs'][] = $this->title; | ||
27 | </div> | 27 | </div> |
28 | 28 | ||
29 | <?php ActiveForm::end() ?> | 29 | <?php ActiveForm::end() ?> |
30 | - <?= Html::a('Вернуться', ['rg-grup/index'], ['class' => 'btn btn-primary', 'name' => 'Return',]) ?> | 30 | + <?= Html::a('Отмена', ['rg-grup/index'], ['class' => 'btn btn-primary', 'name' => 'Return',]) ?> |
31 | 31 | ||
32 | </div> | 32 | </div> |
33 | \ No newline at end of file | 33 | \ No newline at end of file |
common/components/ModelArrayValidator.php
@@ -76,20 +76,33 @@ class ModelArrayValidator | @@ -76,20 +76,33 @@ class ModelArrayValidator | ||
76 | { | 76 | { |
77 | foreach ( $data as $row ) { | 77 | foreach ( $data as $row ) { |
78 | $this->total_rows++; | 78 | $this->total_rows++; |
79 | - $validate_row[$this->model->formName()] = $row; | ||
80 | - // clear previous loading | ||
81 | - $this->clearModelAttributes(); | ||
82 | - if ( $this->model->load( $validate_row ) && $this->model->validate() ) { | 79 | + |
80 | + if ( $this->validateRow( $row ) ) { | ||
83 | // everything OK, registred row to valid data | 81 | // everything OK, registred row to valid data |
84 | $this->valid_data[] = $row; | 82 | $this->valid_data[] = $row; |
85 | } else{ | 83 | } else{ |
86 | // we have errors | 84 | // we have errors |
87 | $this->registredError( $this->total_rows ); | 85 | $this->registredError( $this->total_rows ); |
88 | } | 86 | } |
87 | + | ||
89 | } | 88 | } |
90 | 89 | ||
91 | return $this->valid_data; | 90 | return $this->valid_data; |
92 | } | 91 | } |
92 | + public function validateRow( $row ) | ||
93 | + { | ||
94 | + $validate_row[$this->model->formName()] = $row; | ||
95 | + // clear previous loading | ||
96 | + $this->clearModelAttributes(); | ||
97 | + if ( $this->model->load( $validate_row ) && $this->model->validate() ) { | ||
98 | + | ||
99 | + return true; | ||
100 | + } else{ | ||
101 | + | ||
102 | + return false; | ||
103 | + } | ||
104 | + | ||
105 | + } | ||
93 | 106 | ||
94 | protected function registredError ($index) | 107 | protected function registredError ($index) |
95 | { | 108 | { |
@@ -117,11 +130,17 @@ class ModelArrayValidator | @@ -117,11 +130,17 @@ class ModelArrayValidator | ||
117 | 130 | ||
118 | } | 131 | } |
119 | 132 | ||
133 | + public function clearErrors(){ | ||
134 | + | ||
135 | + $this->arr_errors = []; | ||
136 | + | ||
137 | + } | ||
138 | + | ||
120 | public function close(){ | 139 | public function close(){ |
121 | 140 | ||
122 | - unset( $this->valid_data ); | ||
123 | - unset( $this->arr_errors ); | ||
124 | - unset( $this->model ); | 141 | + $this->valid_data = []; |
142 | + $this->clearErrors(); | ||
143 | + $this->total_rows = 0; | ||
125 | 144 | ||
126 | } | 145 | } |
127 | } | 146 | } |
128 | \ No newline at end of file | 147 | \ No newline at end of file |
common/components/PriceWriter.php
@@ -43,15 +43,15 @@ class PriceWriter | @@ -43,15 +43,15 @@ class PriceWriter | ||
43 | */ | 43 | */ |
44 | protected $validated_msg; | 44 | protected $validated_msg; |
45 | /** | 45 | /** |
46 | - * @var - тип сообщения валидатора - success, warning | 46 | + * @var - bool - есть ли ошибки валидации |
47 | */ | 47 | */ |
48 | - protected $validated_type_msg; | 48 | + protected $hasValidationError; |
49 | 49 | ||
50 | 50 | ||
51 | 51 | ||
52 | function __construct() | 52 | function __construct() |
53 | { | 53 | { |
54 | - set_time_limit(300); | 54 | + set_time_limit(600); |
55 | } | 55 | } |
56 | 56 | ||
57 | /** | 57 | /** |
@@ -89,9 +89,9 @@ class PriceWriter | @@ -89,9 +89,9 @@ class PriceWriter | ||
89 | /** | 89 | /** |
90 | * @return mixed | 90 | * @return mixed |
91 | */ | 91 | */ |
92 | - public function getValidatedTypeMsg() | 92 | + public function hasValidationError() |
93 | { | 93 | { |
94 | - return $this->validated_type_msg; | 94 | + return $this->hasValidationError; |
95 | } | 95 | } |
96 | 96 | ||
97 | 97 | ||
@@ -117,12 +117,16 @@ class PriceWriter | @@ -117,12 +117,16 @@ class PriceWriter | ||
117 | } | 117 | } |
118 | //3. провалидируем полученные данные моделью - Details | 118 | //3. провалидируем полученные данные моделью - Details |
119 | $details_model = $this->validateByDetailsModel(); | 119 | $details_model = $this->validateByDetailsModel(); |
120 | + if ( empty($this->data) ) { | ||
121 | + // после валидации не осталось валидных данных для записи | ||
122 | + return false; | ||
123 | + } | ||
124 | + //4. дополним данные значением импортера и даты обновления цены | ||
125 | + $this->data = CustomArrayHelper::addColumns($this->data, ['IMPORT_ID' => $this->configuration['importer_id'], 'timestamp' => $update_date]); | ||
120 | 126 | ||
121 | - //4. дополним данные значением импортера и даты обновления цены | ||
122 | - $this->data = CustomArrayHelper::addColumns($this->data, ['IMPORT_ID' => $this->configuration['importer_id'], 'timestamp' => $update_date]); | 127 | + //5. запишем данные в связанные таблицы |
128 | + $this->writePriceInTransaction($details_model, $files_model, $update_date); | ||
123 | 129 | ||
124 | - //5. запишем данные в связанные таблицы | ||
125 | - $this->writePriceInTransaction($details_model, $files_model, $update_date); | ||
126 | 130 | ||
127 | return true; | 131 | return true; |
128 | } | 132 | } |
@@ -255,7 +259,7 @@ class PriceWriter | @@ -255,7 +259,7 @@ class PriceWriter | ||
255 | $model_validator = new ModelArrayValidator( $details_model ); | 259 | $model_validator = new ModelArrayValidator( $details_model ); |
256 | $this->data = $model_validator->validate( $this->data ); | 260 | $this->data = $model_validator->validate( $this->data ); |
257 | $this->validated_msg = $model_validator->getMassage(); | 261 | $this->validated_msg = $model_validator->getMassage(); |
258 | - $this->validated_type_msg = $model_validator->hasError() ? 'warning' : 'success'; | 262 | + $this->hasValidationError = $model_validator->hasError(); |
259 | 263 | ||
260 | $model_validator->close(); | 264 | $model_validator->close(); |
261 | 265 |
common/components/exceptions/CrossParsingException.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Tsurkanov | ||
5 | + * Date: 30.11.2015 | ||
6 | + * Time: 17:36 | ||
7 | + */ | ||
8 | + | ||
9 | +namespace common\components\exceptions; | ||
10 | + | ||
11 | + | ||
12 | +use yii\base\UserException; | ||
13 | + | ||
14 | +class CrossParsingException extends UserException { | ||
15 | + | ||
16 | +} | ||
0 | \ No newline at end of file | 17 | \ No newline at end of file |
common/components/exceptions/PriceParsingException.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Tsurkanov | ||
5 | + * Date: 30.11.2015 | ||
6 | + * Time: 17:36 | ||
7 | + */ | ||
8 | + | ||
9 | +namespace common\components\exceptions; | ||
10 | + | ||
11 | + | ||
12 | +use yii\base\UserException; | ||
13 | + | ||
14 | +class PriceParsingException extends UserException { | ||
15 | + | ||
16 | +} | ||
0 | \ No newline at end of file | 17 | \ No newline at end of file |
common/components/exceptions/RgParsingException.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Tsurkanov | ||
5 | + * Date: 30.11.2015 | ||
6 | + * Time: 17:36 | ||
7 | + */ | ||
8 | + | ||
9 | +namespace common\components\exceptions; | ||
10 | + | ||
11 | + | ||
12 | +use yii\base\UserException; | ||
13 | + | ||
14 | +class RgParsingException extends UserException { | ||
15 | + | ||
16 | +} | ||
0 | \ No newline at end of file | 17 | \ No newline at end of file |
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Cibermag | ||
5 | + * Date: 31.08.2015 | ||
6 | + * Time: 12:50 | ||
7 | + */ | ||
8 | + | ||
9 | +namespace common\components\parsers; | ||
10 | + | ||
11 | +// класс который содержит преобразователи значений (фильтры) используемые при парсинге | ||
12 | + | ||
13 | + | ||
14 | +class Converter implements ConverterInterface | ||
15 | +{ | ||
16 | + | ||
17 | + const METHOD_PREFIX = 'convertTo'; | ||
18 | + | ||
19 | + //public $configuration = []; | ||
20 | + | ||
21 | + public static function convertToFloat($value) | ||
22 | + { | ||
23 | + if ($value == '') { | ||
24 | + $value = 0; | ||
25 | + } | ||
26 | + $value = trim(str_replace(",", ".", $value)); | ||
27 | + $value = preg_replace("/[^0-9.]+/", "", strtoupper($value)); | ||
28 | + | ||
29 | + if ($value == '') { | ||
30 | + return ''; | ||
31 | + } | ||
32 | + $value = round((float)$value, 2); | ||
33 | + | ||
34 | + return $value; | ||
35 | + } | ||
36 | + | ||
37 | + public static function convertToInteger($value) | ||
38 | + { | ||
39 | + if ($value == '') { | ||
40 | + $value = 0; | ||
41 | + } | ||
42 | + $value = trim(str_replace(",", ".", $value)); | ||
43 | + $value = preg_replace("/[^0-9.]+/", "", strtoupper($value)); | ||
44 | + if ($value == '') { | ||
45 | + return ''; | ||
46 | + } | ||
47 | + $value = round((int)$value, 2); | ||
48 | + | ||
49 | + return $value; | ||
50 | + } | ||
51 | + | ||
52 | + public static function convertToEncode($value) | ||
53 | + { | ||
54 | + $res = $value; | ||
55 | + if (is_array($value)) { | ||
56 | + | ||
57 | + $res = Encoder::encodeArray($value); | ||
58 | + | ||
59 | + } elseif (is_string($value)) { | ||
60 | + | ||
61 | + $res = Encoder::encodeString($value); | ||
62 | + | ||
63 | + } | ||
64 | + return $res; | ||
65 | + } | ||
66 | + | ||
67 | + public static function convertToString($value) | ||
68 | + { | ||
69 | + $convert_func = function ($value_to_convert) { | ||
70 | + return str_replace(array('!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '=', '-', '~', '`', '"', "'", ' ', '№', '%', ';', ':', '[', ']', '{', '}', '*', '?', '/', '\'', '|', '.', ',', '<', '>', '\\'), '', $value_to_convert); | ||
71 | + }; | ||
72 | + | ||
73 | + if( is_string( $value ) ){ | ||
74 | + $value = $convert_func( $value ); | ||
75 | + } | ||
76 | + | ||
77 | + if( is_array( $value ) ){ | ||
78 | + array_walk( $value, $convert_func ); | ||
79 | + } | ||
80 | + | ||
81 | + return $value; | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * @param $name - имя метода конвертации | ||
86 | + * @param $value - значение на конвертацию | ||
87 | + * @return mixed | ||
88 | + */ | ||
89 | + public static function __callStatic($name, $value) | ||
90 | + { | ||
91 | + $method_name = self::METHOD_PREFIX . $name; | ||
92 | + if (method_exists(static::class, $method_name)) { | ||
93 | + return static::$method_name($value[0]); | ||
94 | + | ||
95 | + } else { | ||
96 | + // если такого метода конвертации не предусмотрено, то возвращаем не конвертируя | ||
97 | + return $value[0]; | ||
98 | + | ||
99 | + } | ||
100 | + } | ||
101 | + | ||
102 | + public function __call($name, $params) | ||
103 | + { | ||
104 | + return self::__callStatic($name, $params); | ||
105 | + } | ||
106 | + | ||
107 | + | ||
108 | + /** | ||
109 | + * @param $arr - массив для конвертирования | ||
110 | + * @param $configuration - массив конфигурация конвертирования | ||
111 | + * @return mixed | ||
112 | + * конвертирует массив по полученным настройкам, вызывая последовательно функции конвертации (указанные в конфигурации) | ||
113 | + */ | ||
114 | + public static function convertByConfiguration($arr, $configuration) | ||
115 | + { | ||
116 | + if ($hasKey = isset($configuration['hasKey'])) | ||
117 | + unset($configuration['hasKey']); | ||
118 | + | ||
119 | + if (isset($configuration['configuration'])) { | ||
120 | + $arr_config = $configuration['configuration']; | ||
121 | + unset($configuration['configuration']); | ||
122 | + } else { | ||
123 | + throw new \Exception('Не указан обязательный параметр конфигурационного файла - converter_conf[configuration]'); | ||
124 | + } | ||
125 | + | ||
126 | + // проставим аттрибуты из конфига{}{} | ||
127 | + self::setAttributes($configuration); | ||
128 | + | ||
129 | + foreach ($arr_config as $key => $value) { | ||
130 | + if ($hasKey) { | ||
131 | + // у нас ассоциативный массив, и мы можем конвертировать каждое значение в отдельности | ||
132 | + if (is_array($value)) { | ||
133 | + //если пустой массив то конвертируем всю строку | ||
134 | + if (count($value) === 0) { | ||
135 | + | ||
136 | + $arr = self::$key($arr); | ||
137 | + continue; | ||
138 | + } | ||
139 | + // иначе конвертируем каждую ячейку в отдельности | ||
140 | + foreach ($value as $sub_value) { | ||
141 | + if (isset($arr[$sub_value])) { | ||
142 | + // конвертируем только те ячейки которые сопоставлены в прочитанном массиве с колонками в конфигурационном файле | ||
143 | + $arr[$sub_value] = self::$key($arr[$sub_value]); | ||
144 | + } | ||
145 | + | ||
146 | + } | ||
147 | + } else { | ||
148 | + | ||
149 | + if (isset($arr[$value])) { | ||
150 | + // конвертируем только те ячейки которые сопоставлены в прочитанном массиве с колонками в конфигурационном файле | ||
151 | + $arr[$value] = self::$key($arr[$value]); | ||
152 | + // CustomVarDamp::dump($result); | ||
153 | + } | ||
154 | + | ||
155 | + } | ||
156 | + | ||
157 | + } else { | ||
158 | + // нет заголовка - мы можем конвертировать только строку в целом | ||
159 | + $arr = self::$key($arr); | ||
160 | + } | ||
161 | + | ||
162 | + } | ||
163 | + | ||
164 | + return $arr; | ||
165 | + } | ||
166 | + | ||
167 | + public static function setAttributes($configuration) | ||
168 | + { | ||
169 | + foreach ($configuration as $key_setting => $setting) { | ||
170 | + if (property_exists(static::class, $key_setting)) | ||
171 | + static::$$key_setting = $setting; | ||
172 | + } | ||
173 | + | ||
174 | + } | ||
175 | + | ||
176 | + | ||
177 | +} | ||
0 | \ No newline at end of file | 178 | \ No newline at end of file |
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Tsurkanov | ||
5 | + * Date: 20.10.2015 | ||
6 | + * Time: 13:38 | ||
7 | + */ | ||
8 | + | ||
9 | +namespace common\components\parsers; | ||
10 | + | ||
11 | + | ||
12 | +interface ConverterInterface { | ||
13 | + | ||
14 | + public static function convertByConfiguration( $arr_values_to_convert, $configuration ); | ||
15 | + | ||
16 | +} | ||
0 | \ No newline at end of file | 17 | \ No newline at end of file |
1 | +<?php | ||
2 | +/** | ||
3 | + | ||
4 | + */ | ||
5 | +namespace common\components\parsers; | ||
6 | + | ||
7 | +/** | ||
8 | + * Class CsvParser | ||
9 | + * @package yii\multiparser | ||
10 | + * @todo - перевести на анг. яз. | ||
11 | + */ | ||
12 | +class CsvParser extends TableParser | ||
13 | +{ | ||
14 | + /** @var string - разделитель csv */ | ||
15 | + public $delimiter = ';'; | ||
16 | + | ||
17 | + | ||
18 | + | ||
19 | + /** | ||
20 | + * метод устанвливает нужные настройки объекта SplFileObject, для работы с csv | ||
21 | + */ | ||
22 | + public function setup() | ||
23 | + { | ||
24 | + parent::setup(); | ||
25 | + | ||
26 | + } | ||
27 | + | ||
28 | + public function read() | ||
29 | + { | ||
30 | + parent::read(); | ||
31 | + | ||
32 | + $this->cleanUp(); | ||
33 | + | ||
34 | + return $this->result; | ||
35 | + } | ||
36 | + | ||
37 | + | ||
38 | + protected function readRow( ) | ||
39 | + { | ||
40 | + $this->row = fgetcsv( $this->file, 0, $this->delimiter ); | ||
41 | + } | ||
42 | + | ||
43 | + protected function isEmptyRow(){ | ||
44 | + | ||
45 | + $is_empty = false; | ||
46 | + | ||
47 | + if ($this->row === false || $this->row === NULL ) { | ||
48 | + return true; | ||
49 | + } | ||
50 | + | ||
51 | + $j = 0; | ||
52 | + for ($i = 1; $i <= count( $this->row ); $i++) { | ||
53 | + | ||
54 | + if ( !isset( $this->row[ $i - 1 ] ) ) { | ||
55 | + continue; | ||
56 | + } | ||
57 | + | ||
58 | + if ( $this->isEmptyColumn( $this->row[$i - 1] ) ) { | ||
59 | + $j++; | ||
60 | + } | ||
61 | + | ||
62 | + if ( $j >= $this->min_column_quantity ) { | ||
63 | + $is_empty = true; | ||
64 | + break; | ||
65 | + } | ||
66 | + } | ||
67 | + | ||
68 | + return $is_empty; | ||
69 | + } | ||
70 | + | ||
71 | + protected function isEmptyColumn( $val ){ | ||
72 | + return $val == ''; | ||
73 | + } | ||
74 | + | ||
75 | + protected function setResult( ){ | ||
76 | + $this->result[] = $this->row; | ||
77 | + } | ||
78 | +} | ||
0 | \ No newline at end of file | 79 | \ No newline at end of file |
common/components/parsers/CustomConverter.php
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | namespace common\components\parsers; | 2 | namespace common\components\parsers; |
3 | 3 | ||
4 | use common\components\CustomVarDamp; | 4 | use common\components\CustomVarDamp; |
5 | -use yii\multiparser\Converter; | 5 | +use common\components\parsers\Converter; |
6 | use backend\models\Details; | 6 | use backend\models\Details; |
7 | use backend\models\DetailsCrosses; | 7 | use backend\models\DetailsCrosses; |
8 | use backend\models\ImportersPrefix; | 8 | use backend\models\ImportersPrefix; |
common/components/parsers/CustomCsvParser.php
@@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
8 | 8 | ||
9 | namespace common\components\parsers; | 9 | namespace common\components\parsers; |
10 | 10 | ||
11 | -class CustomCsvParser extends \yii\multiparser\CsvParser { | 11 | +class CustomCsvParser extends \common\components\parsers\CsvParser { |
12 | 12 | ||
13 | // public $last_line = 10; | 13 | // public $last_line = 10; |
14 | //public $hasHeaderRow = true; | 14 | //public $hasHeaderRow = true; |
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Cibermag | ||
5 | + * Date: 08.09.2015 | ||
6 | + * Time: 14:50 | ||
7 | + */ | ||
8 | + | ||
9 | +namespace common\components\parsers; | ||
10 | + | ||
11 | +use yii\base\DynamicModel; | ||
12 | +use yii\grid\GridView; | ||
13 | +use yii\grid\SerialColumn; | ||
14 | +use yii\helpers\ArrayHelper; | ||
15 | + | ||
16 | +/** | ||
17 | + * Class DynamicFormHelper | ||
18 | + * @package backend\components\parsers | ||
19 | + * Содержит процедуры генерации компонентов с динамическим количеством аттрибутов | ||
20 | + */ | ||
21 | +class DynamicFormHelper | ||
22 | +{ | ||
23 | + | ||
24 | + const KEY_PREFIX = 'attr_'; | ||
25 | + | ||
26 | + /** | ||
27 | + * @param $source - int or array | ||
28 | + * если передан массив, то создается модель с атрибутами переданными в массиве, | ||
29 | + * ключ - имя, значение - значение аттрибута | ||
30 | + * если передано число, то создается переданное количество аттрибутов с именами - attr_0, attr_1... | ||
31 | + */ | ||
32 | + public static function CreateDynamicModel( $source ) | ||
33 | + { | ||
34 | + $arr_keys = []; | ||
35 | + if (is_array($source)) { | ||
36 | + $arr_keys = $source; | ||
37 | + } elseif (is_int($source)) { | ||
38 | + | ||
39 | + $i = 0; | ||
40 | + while ($source > $i) { | ||
41 | + $arr_keys[] = self::KEY_PREFIX . $i; | ||
42 | + $i++; | ||
43 | + } | ||
44 | + array_flip($arr_keys); | ||
45 | + | ||
46 | + } | ||
47 | + | ||
48 | + $model = new DynamicModel($arr_keys); | ||
49 | + | ||
50 | + return $model; | ||
51 | + } | ||
52 | + | ||
53 | + // @todo add comments | ||
54 | + public static function CreateGridWithDropDownListHeader( $dataProvider, $form, $header_model, $arr_header_values ) | ||
55 | + { | ||
56 | + $columns_config = [['class' => SerialColumn::className()]]; | ||
57 | + $i = 0; | ||
58 | + foreach( $header_model as $key => $value ) { | ||
59 | + | ||
60 | + $columns_config[] = ['header' => $form->field($header_model, $key, ['inputOptions' => ['label' => '']])->dropDownList($arr_header_values), 'attribute' => $i]; | ||
61 | + $i++; | ||
62 | + } | ||
63 | + $dynamic_grid_view = GridView::widget( ['dataProvider' => $dataProvider, | ||
64 | + 'columns' => $columns_config ] ); | ||
65 | + | ||
66 | + return $dynamic_grid_view; | ||
67 | + | ||
68 | + } | ||
69 | + | ||
70 | +} | ||
0 | \ No newline at end of file | 71 | \ No newline at end of file |
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Cibermag | ||
5 | + * Date: 27.08.2015 | ||
6 | + * Time: 13:36 | ||
7 | + */ | ||
8 | + | ||
9 | +namespace common\components\parsers; | ||
10 | + | ||
11 | +// @todo add comments | ||
12 | +class Encoder | ||
13 | +{ | ||
14 | + /** @var out encoding charset */ | ||
15 | + public static $out_charset = 'UTF-8'; | ||
16 | + /** @var out encoding charset */ | ||
17 | + public static $in_charset = 'windows-1251'; | ||
18 | + | ||
19 | + public static function encodeFile($in_charset, $out_charset, $filePath) | ||
20 | + { | ||
21 | + | ||
22 | + $old_content = file_get_contents($filePath); | ||
23 | + $encode_content = self::encodeString( $old_content, $in_charset, $out_charset ); | ||
24 | + $file = @fopen($filePath, "w"); | ||
25 | + fwrite($file, $encode_content); | ||
26 | + @fclose($file); | ||
27 | + } | ||
28 | + | ||
29 | + public static function encodeArray( $array, $in_charset = '', $out_charset = '') | ||
30 | + { | ||
31 | + if ($in_charset) | ||
32 | + self::$in_charset = $in_charset; | ||
33 | + | ||
34 | + if ($out_charset) | ||
35 | + self::$out_charset = $out_charset; | ||
36 | + | ||
37 | + $result = array_map( | ||
38 | + function ($value) { | ||
39 | + | ||
40 | + return self::encodeString( $value, self::$in_charset, self::$out_charset ); | ||
41 | + | ||
42 | + }, | ||
43 | + $array); | ||
44 | + | ||
45 | + return $result; | ||
46 | + } | ||
47 | + | ||
48 | + public static function encodeString( $source, $in_charset = '', $out_charset = '' ){ | ||
49 | + | ||
50 | + if ($in_charset) | ||
51 | + self::$in_charset = $in_charset; | ||
52 | + | ||
53 | + if ($out_charset) | ||
54 | + self::$out_charset = $out_charset; | ||
55 | + | ||
56 | + return iconv( self::$in_charset, self::$out_charset, $source ); | ||
57 | + | ||
58 | + } | ||
59 | +} | ||
0 | \ No newline at end of file | 60 | \ No newline at end of file |
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Tsurkanov | ||
5 | + * Date: 20.10.2015 | ||
6 | + * Time: 16:24 | ||
7 | + */ | ||
8 | + | ||
9 | +namespace common\components\parsers; | ||
10 | + | ||
11 | + | ||
12 | +class ObjectCreator { | ||
13 | + public static function build( array $configuration ){ | ||
14 | + if ( isset( $configuration['class'] ) ) { | ||
15 | + $class = trim( $configuration['class'] ); | ||
16 | + unset( $configuration['class'] ); | ||
17 | + } else{ | ||
18 | + throw new \ErrorException('Error configuration - undefined class'); | ||
19 | + } | ||
20 | + | ||
21 | + $object = new $class(); | ||
22 | + foreach ($configuration as $name => $value) { | ||
23 | + $object->$name = $value; | ||
24 | + } | ||
25 | + | ||
26 | + return $object; | ||
27 | + } | ||
28 | +} | ||
0 | \ No newline at end of file | 29 | \ No newline at end of file |
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Cibermag | ||
5 | + * Date: 04.09.2015 | ||
6 | + * Time: 18:25 | ||
7 | + */ | ||
8 | + | ||
9 | +namespace common\components\parsers; | ||
10 | + | ||
11 | +//@todo - заменить read на parse | ||
12 | +//@todo - xml - убрать из названий функций xml и array - это и так понятно | ||
13 | + | ||
14 | + | ||
15 | +use common\components\CustomVarDamp; | ||
16 | + | ||
17 | +abstract class Parser | ||
18 | +{ | ||
19 | + public $converter_conf = []; | ||
20 | + protected $converter = NULL; | ||
21 | + | ||
22 | + /** @var file-resource читаемого файла */ | ||
23 | + public $file; | ||
24 | + /** @var string путь читаемого файла */ | ||
25 | + public $file_path; | ||
26 | + | ||
27 | + /** | ||
28 | + * @var array - результирующий массив с отпарсенными значениями | ||
29 | + */ | ||
30 | + protected $result = []; | ||
31 | + | ||
32 | + /** @var array - массив с заголовком, | ||
33 | + * */ | ||
34 | + public $keys = NULL; | ||
35 | + /** @var bool | ||
36 | + имеет ли файл заголовок который будет установлен ключами возвращемого массива*/ | ||
37 | + public $has_header_row = false; | ||
38 | + /* | ||
39 | + *если есть ключи, то колонки с пустыми значениями будут пропускаться (из ряда такие значения будут удаляться), | ||
40 | + * например если в файле вторая колонка пустая то она будет удалена | ||
41 | + * если есть $has_header_row - то первая значимая строка становится ключами, но пустые колонки не удаляются из ряда | ||
42 | + * например если в файле вторая колонка пустая то ей будет назначен соответсвующий ключ (второй) из первой строки | ||
43 | + * все описаное выше реализуется в дочернем семействе классов TableParser в методе filterRow() | ||
44 | + * для xml происходит просто сопоставление переданных ключей с прочитанными | ||
45 | + */ | ||
46 | + | ||
47 | + | ||
48 | + | ||
49 | + | ||
50 | + public function setup() | ||
51 | + { | ||
52 | + $this->setupConverter(); | ||
53 | + } | ||
54 | + | ||
55 | + protected function setupConverter() | ||
56 | + { | ||
57 | + if ( $this->has_header_row || $this->keys !== NULL ) { | ||
58 | + // если у файла есть заголовок, то в результате имеем ассоциативный массив | ||
59 | + $this->converter_conf['hasKey'] = 1; | ||
60 | + } | ||
61 | + | ||
62 | + if ( $this->converter_conf ) { | ||
63 | + $converter = ObjectCreator::build( $this->converter_conf ); | ||
64 | + if ( $converter instanceof ConverterInterface ) { | ||
65 | + | ||
66 | + $this->converter = $converter; | ||
67 | + | ||
68 | + } | ||
69 | + } | ||
70 | + | ||
71 | + | ||
72 | + } | ||
73 | + | ||
74 | + public abstract function read(); | ||
75 | + | ||
76 | + /** | ||
77 | + * @param $arr | ||
78 | + * @return mixed | ||
79 | + * преобразовует значения прочитанного массива в нужные типы, согласно конфигурации конвертера | ||
80 | + */ | ||
81 | + protected function convert( $arr ) | ||
82 | + { | ||
83 | + | ||
84 | + if ($this->converter !== NULL) { | ||
85 | + | ||
86 | + $arr = $this->converter->convertByConfiguration( $arr, $this->converter_conf ); | ||
87 | + | ||
88 | + } | ||
89 | + | ||
90 | + | ||
91 | + return $arr; | ||
92 | + | ||
93 | + } | ||
94 | + | ||
95 | + protected function cleanUp( ) | ||
96 | + { | ||
97 | + | ||
98 | + unset( $this->file ); | ||
99 | + unset( $this->converter ); | ||
100 | + unset( $this->converter_conf ); | ||
101 | + | ||
102 | + | ||
103 | + } | ||
104 | + | ||
105 | + | ||
106 | +} | ||
0 | \ No newline at end of file | 107 | \ No newline at end of file |
1 | +<?php | ||
2 | + | ||
3 | +namespace common\components\parsers; | ||
4 | + | ||
5 | + | ||
6 | +use common\components\CustomVarDamp; | ||
7 | + | ||
8 | +class ParserHandler | ||
9 | +{ | ||
10 | + //@todo - добавить комменты на анг язе (ошибки выкидывать тоже на англ яз.) | ||
11 | + //@todo - сделать универсальную обработку ошибок | ||
12 | + //@todo - возможно отказаться от YiiParserHandler | ||
13 | + const DEFAULT_MODE = 'web'; | ||
14 | + | ||
15 | + | ||
16 | + /** @var string */ | ||
17 | + protected $configuration = []; | ||
18 | + /** @var string */ | ||
19 | + protected $custom_configuration = []; | ||
20 | + | ||
21 | + /** @var file handle */ | ||
22 | + protected $file; | ||
23 | + | ||
24 | + /** @var string - extension of file $file_path */ | ||
25 | + protected $extension; | ||
26 | + | ||
27 | + /** @var string - */ | ||
28 | + protected $mode; | ||
29 | + | ||
30 | + /** @var string - */ | ||
31 | + protected $options; | ||
32 | + | ||
33 | + /** | ||
34 | + * @param string first line in file for parsing | ||
35 | + */ | ||
36 | + public function setup($file_path, $options = []) | ||
37 | + { | ||
38 | + //$this->file_path = $file_path; | ||
39 | + if (isset($options['mode'])) { | ||
40 | + | ||
41 | + $this->mode = $options['mode']; | ||
42 | + unset($options['mode']); | ||
43 | + | ||
44 | + } else { | ||
45 | + | ||
46 | + $this->mode = self::DEFAULT_MODE; | ||
47 | + | ||
48 | + } | ||
49 | + | ||
50 | + $this->options = $options; | ||
51 | + $this->file = fopen($file_path, 'r'); | ||
52 | + $options['file'] = $this->file; | ||
53 | + $options['file_path'] = $file_path; | ||
54 | + $this->extension = pathinfo( $file_path, PATHINFO_EXTENSION ); | ||
55 | + $this->custom_configuration = $this->getCustomConfiguration($this->extension, $this->mode); | ||
56 | + $this->custom_configuration = array_merge_recursive($this->custom_configuration, $options); | ||
57 | + | ||
58 | + } | ||
59 | + | ||
60 | + public function run() | ||
61 | + { | ||
62 | + $parser = $this->createObjectByConfiguration( $this->custom_configuration ); | ||
63 | + | ||
64 | + $parser->setup(); | ||
65 | + $result = $parser->read(); | ||
66 | + | ||
67 | + unset($parser); | ||
68 | + fclose( $this->file ); | ||
69 | + | ||
70 | + return $result; | ||
71 | + } | ||
72 | + | ||
73 | + public function getCustomConfiguration($extension, $parameter) | ||
74 | + { | ||
75 | + if (!count($this->configuration)) { | ||
76 | + $this->setConfiguration(require(__DIR__ . '/config.php')); | ||
77 | + } | ||
78 | + | ||
79 | + if (!isset($this->configuration[$extension])) { | ||
80 | + throw new \ErrorException("Parser do not maintain file with extension {$extension}"); | ||
81 | + } | ||
82 | + if (!isset($this->configuration[$extension][$parameter])) { | ||
83 | + throw new \ErrorException("Parser configurator do not have settings for {$parameter} parameter"); | ||
84 | + } | ||
85 | + | ||
86 | + return $this->configuration[$extension][$parameter]; | ||
87 | + } | ||
88 | + | ||
89 | + public function setConfiguration($configuration) | ||
90 | + { | ||
91 | + $this->configuration = $configuration; | ||
92 | + } | ||
93 | + | ||
94 | + protected function createObjectByConfiguration($configuration) | ||
95 | + { | ||
96 | + return ObjectCreator::build($configuration); | ||
97 | + } | ||
98 | + | ||
99 | + | ||
100 | + | ||
101 | + | ||
102 | +} | ||
103 | + | ||
104 | + |
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Tsurkanov | ||
5 | + * Date: 22.10.2015 | ||
6 | + * Time: 15:53 | ||
7 | + */ | ||
8 | + | ||
9 | +namespace common\components\parsers; | ||
10 | + | ||
11 | + | ||
12 | +use common\components\CustomVarDamp; | ||
13 | + | ||
14 | +abstract class TableParser extends Parser | ||
15 | +{ | ||
16 | + | ||
17 | + | ||
18 | + /** | ||
19 | + * @var array - текущий отпарсенный ряд | ||
20 | + */ | ||
21 | + protected $row = []; | ||
22 | + | ||
23 | + /** @var int - первая строка с которой начинать парсить */ | ||
24 | + public $first_line = 0; | ||
25 | + | ||
26 | + /** @var int - последняя строка до которой парсить | ||
27 | + * если не указана, то парсинг происходит до конца файла*/ | ||
28 | + public $last_line = 0; | ||
29 | + | ||
30 | + /** @var int - первая колонка файла с которой начнется парсинг */ | ||
31 | + public $first_column = 0; | ||
32 | + | ||
33 | + | ||
34 | + /** @var bool | ||
35 | + нужно ли искать автоматически первоую значисмую строку (не пустая строка) | ||
36 | + * иначе первая строка будет взята из аттрибута $first_line */ | ||
37 | + public $auto_detect_first_line = false; | ||
38 | + | ||
39 | + /** @var int - количество значимых колонок, что бы определить первую значимую строку | ||
40 | + * используется при автоопределении первой строки*/ | ||
41 | + public $min_column_quantity = 5; | ||
42 | + /** @var int - количество пустых строк, что бы определить конец файла, | ||
43 | + * такое количеество подряд пустых строк считается концом файла*/ | ||
44 | + public $empty_lines_quantity = 3; | ||
45 | + | ||
46 | + | ||
47 | + /** @var int - номер текущей строки парсера */ | ||
48 | + protected $current_row_number = 0; | ||
49 | + | ||
50 | + | ||
51 | + protected abstract function isEmptyRow(); | ||
52 | + | ||
53 | + protected abstract function isEmptyColumn($column_value); | ||
54 | + | ||
55 | + protected abstract function readRow(); | ||
56 | + | ||
57 | + protected abstract function setResult(); | ||
58 | + | ||
59 | + | ||
60 | + public function read() | ||
61 | + { | ||
62 | + if ($this->auto_detect_first_line) { | ||
63 | + $this->shiftToFirstValuableLine(); | ||
64 | + } | ||
65 | + | ||
66 | + // будем считать количество пустых строк подряд - при достижении $empty_lines_quantity - считаем что это конец файла и выходим | ||
67 | + $empty_lines = 0; | ||
68 | + while ($empty_lines < $this->empty_lines_quantity) { | ||
69 | + // прочтем строку из файла | ||
70 | + $this->readRow(); | ||
71 | + | ||
72 | + if ($this->isEmptyRow()) { | ||
73 | + //счетчик пустых строк | ||
74 | + //CustomVarDamp::dump($this->current_row_number); | ||
75 | + $empty_lines++; | ||
76 | + continue; | ||
77 | + } | ||
78 | + | ||
79 | + // уберем пустые колонки из ряда | ||
80 | + if ($this->keys === NULL) { | ||
81 | + $this->filterRow(); | ||
82 | + } | ||
83 | + | ||
84 | + | ||
85 | + $this->adjustRowToSettings(); | ||
86 | + | ||
87 | + // строка не пустая, имеем прочитанный массив значений | ||
88 | + $this->current_row_number++; | ||
89 | + | ||
90 | + // для первой строки утановим ключи из заголовка | ||
91 | + if (!$this->setKeysFromHeader()) { | ||
92 | + $this->setResult(); | ||
93 | + } | ||
94 | + | ||
95 | + | ||
96 | + // если у нас установлен лимит, при его достижении прекращаем парсинг | ||
97 | + if ($this->isLastLine()) | ||
98 | + break; | ||
99 | + | ||
100 | + // обнуляем счетчик, так как считаюся пустые строки ПОДРЯД | ||
101 | + $empty_lines = 0; | ||
102 | + | ||
103 | + } | ||
104 | + | ||
105 | + } | ||
106 | + | ||
107 | + /** | ||
108 | + * определяет первую значимую строку, | ||
109 | + * считывается файл пока в нем не встретится строка с непустыми колонками | ||
110 | + * в количестве указанном в атрибуте min_column_quantity | ||
111 | + * в результате выполнения $current_row_number будет находится на последней незначимой строке | ||
112 | + */ | ||
113 | + protected function shiftToFirstValuableLine() | ||
114 | + { | ||
115 | + do { | ||
116 | + | ||
117 | + $this->current_row_number++; | ||
118 | + $this->readRow(); | ||
119 | + | ||
120 | + } while ($this->isEmptyRow()); | ||
121 | + | ||
122 | + // @todo - сделать опционально | ||
123 | + // код для того что бы парсить первую строку, закомментировано как предполагается что первая значимая строка это заголовок | ||
124 | + // $this->current_row_number --; | ||
125 | +// $this->file->seek( $this->current_row_number ); | ||
126 | + } | ||
127 | + | ||
128 | + /** | ||
129 | + * @return array - одномерный массив результата парсинга строки | ||
130 | + */ | ||
131 | + protected function adjustRowToSettings() | ||
132 | + { | ||
133 | + | ||
134 | + // если есть заголовок, то перед конвертацией его нужно назначить | ||
135 | + if ($this->keys !== NULL) { | ||
136 | + // adjust row to keys | ||
137 | + $this->adjustRowToKeys(); | ||
138 | + // назначим заголовок | ||
139 | + $this->row = array_combine($this->keys, $this->row); | ||
140 | + } | ||
141 | + | ||
142 | + // попытаемся конвертировать прочитанные значения согласно конфигурации котнвертера значений | ||
143 | + $this->row = $this->convert($this->row); | ||
144 | + | ||
145 | + // обрежем массив к первой значимой колонке | ||
146 | + if ($this->first_column) { | ||
147 | + | ||
148 | + $this->row = array_slice($this->row, $this->first_column); | ||
149 | + | ||
150 | + } | ||
151 | + | ||
152 | + } | ||
153 | + | ||
154 | + protected function setKeysFromHeader() | ||
155 | + { | ||
156 | + if ($this->has_header_row) { | ||
157 | + // в файле есть заголовок, но он еще не назначен - назначим | ||
158 | + if ($this->keys === NULL) { | ||
159 | + $this->keys = array_values($this->row); | ||
160 | + return true; | ||
161 | + } | ||
162 | + } | ||
163 | + return false; | ||
164 | + } | ||
165 | + | ||
166 | + protected function filterRow() | ||
167 | + { | ||
168 | + // если есть заголовок - все значения нужны, не фильтруем | ||
169 | + if ($this->has_header_row || !is_array($this->row)) { | ||
170 | + return; | ||
171 | + } | ||
172 | + $this->row = array_filter($this->row, function ($val) { | ||
173 | + return !$this->isEmptyColumn($val); | ||
174 | + }); | ||
175 | + } | ||
176 | + | ||
177 | + protected function isLastLine() | ||
178 | + { | ||
179 | + | ||
180 | + if (($this->last_line) && ($this->current_row_number > $this->last_line)) { | ||
181 | + return true; | ||
182 | + } | ||
183 | + return false; | ||
184 | + } | ||
185 | + | ||
186 | + protected function adjustRowToKeys() | ||
187 | + { | ||
188 | + //уберем из ряда те колонки которых нет в ключах | ||
189 | + $this->row = array_intersect_key($this->row, $this->keys); | ||
190 | + | ||
191 | + $keys_count = count($this->keys); | ||
192 | + $column_count = count($this->row); | ||
193 | + if ($keys_count != $column_count) { | ||
194 | + // найдем колонки которых нет в ряде но есть ключах | ||
195 | + $arr_diff = array_diff_key($this->keys, $this->row); | ||
196 | + foreach ($arr_diff as $key => $value) { | ||
197 | + // колонки которых нет в ряде но есть ключах, добавим их с пустым значением | ||
198 | + $this->row[$key] = ''; | ||
199 | + } | ||
200 | + } | ||
201 | + } | ||
202 | + | ||
203 | +} | ||
0 | \ No newline at end of file | 204 | \ No newline at end of file |
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Tsurkanov | ||
5 | + * Date: 21.10.2015 | ||
6 | + * Time: 15:44 | ||
7 | + */ | ||
8 | + | ||
9 | +namespace common\components\parsers; | ||
10 | + | ||
11 | +use common\components\CustomVarDamp; | ||
12 | + | ||
13 | + | ||
14 | +/** | ||
15 | + * Class XlsxParser | ||
16 | + * @package yii\multiparser | ||
17 | + */ | ||
18 | +class XlsxParser extends TableParser | ||
19 | +{ | ||
20 | + | ||
21 | + /** | ||
22 | + * @var string - путь куда будут распаковываться файлы, если не указанно - во временный каталог сервера | ||
23 | + */ | ||
24 | + public $path_for_extract_files = ''; | ||
25 | + | ||
26 | + | ||
27 | + /** | ||
28 | + * @var int - если указано то считывание будет производиться с этого листа, иначе со всех листов | ||
29 | + * при чтении со всех листов - выходной массив будет иметь номера листов первыми элементами | ||
30 | + */ | ||
31 | + public $active_sheet = 0; | ||
32 | + | ||
33 | + protected $strings_arr = []; | ||
34 | + protected $sheets_arr = []; | ||
35 | + | ||
36 | + protected $current_node; | ||
37 | + protected $current_sheet; | ||
38 | + | ||
39 | + // глубина округления для флоата | ||
40 | + // @todo - перенести вродительский класс и применить в дочерних классах | ||
41 | + protected $float_precision = 6; | ||
42 | + | ||
43 | + public function setup() | ||
44 | + { | ||
45 | + | ||
46 | + parent::setup(); | ||
47 | + | ||
48 | + if ($this->path_for_extract_files == '') { | ||
49 | + $this->path_for_extract_files = sys_get_temp_dir(); | ||
50 | + } | ||
51 | + } | ||
52 | + | ||
53 | + | ||
54 | + public function read() | ||
55 | + { | ||
56 | + $this->extractFiles(); | ||
57 | + $this->readSheets(); | ||
58 | + $this->readStrings(); | ||
59 | + foreach ($this->sheets_arr as $sheet) { | ||
60 | + //проходим по всем файлам из директории /xl/worksheets/ | ||
61 | + $this->current_sheet = $sheet; | ||
62 | + $sheet_path = $this->path_for_extract_files . '/xl/worksheets/' . $sheet . '.xml'; | ||
63 | + if (file_exists($sheet_path) && is_readable($sheet_path)) { | ||
64 | + $xml = simplexml_load_file($sheet_path, "SimpleXMLIterator"); | ||
65 | + $this->current_node = $xml->sheetData->row; | ||
66 | + $this->current_node->rewind(); | ||
67 | + if ($this->current_node->valid()) { | ||
68 | + parent::read(); | ||
69 | + } | ||
70 | + } | ||
71 | + } | ||
72 | + | ||
73 | + $this->cleanUp(); | ||
74 | + | ||
75 | + if ($this->active_sheet) { | ||
76 | + // в настройках указан конкретный лист с которого будем производить чтение, поэтому и возвращаем подмассив | ||
77 | + return $this->result[$this->current_sheet]; | ||
78 | + } else { | ||
79 | + return $this->result; | ||
80 | + } | ||
81 | + | ||
82 | + } | ||
83 | + | ||
84 | + protected function extractFiles() | ||
85 | + { | ||
86 | + $this->path_for_extract_files = $this->path_for_extract_files . session_id(); | ||
87 | + if (!file_exists($this->path_for_extract_files)) { | ||
88 | + if (!mkdir($this->path_for_extract_files)) { | ||
89 | + throw new \Exception('Ошибка создания временного каталога - ' . $this->path_for_extract_files); | ||
90 | + } | ||
91 | + } | ||
92 | + | ||
93 | + $zip = new \ZipArchive; | ||
94 | + if ($zip->open($this->file_path) === TRUE) { | ||
95 | + $zip->extractTo($this->path_for_extract_files . '/'); | ||
96 | + $zip->close(); | ||
97 | + } else { | ||
98 | + | ||
99 | + throw new \Exception('Ошибка чтения xlsx файла'); | ||
100 | + } | ||
101 | + unset($zip); | ||
102 | + } | ||
103 | + | ||
104 | + protected function readSheets() | ||
105 | + { | ||
106 | + if ($this->active_sheet) { | ||
107 | + $this->sheets_arr[] = 'sheet' . $this->active_sheet; | ||
108 | + return; | ||
109 | + } | ||
110 | + | ||
111 | + $xml = simplexml_load_file($this->path_for_extract_files . '/xl/workbook.xml'); | ||
112 | + foreach ($xml->sheets->children() as $sheet) { | ||
113 | + $sheet_name = ''; | ||
114 | + $sheet_id = 0; | ||
115 | + $attr = $sheet->attributes(); | ||
116 | + foreach ($attr as $name => $value) { | ||
117 | + if ($name == 'name') | ||
118 | + $sheet_name = (string)$value; | ||
119 | + | ||
120 | + if ($name == 'sheetId') | ||
121 | + $sheet_id = $value; | ||
122 | + | ||
123 | + } | ||
124 | + if ($sheet_name && $sheet_id) { | ||
125 | + $this->sheets_arr[$sheet_name] = 'Sheet' . $sheet_id; | ||
126 | + } | ||
127 | +// | ||
128 | + } | ||
129 | + } | ||
130 | + | ||
131 | + protected function readStrings() | ||
132 | + { | ||
133 | + $xml = simplexml_load_file($this->path_for_extract_files . '/xl/sharedStrings.xml'); | ||
134 | + foreach ($xml->children() as $item) { | ||
135 | + $this->strings_arr[] = (string)$item->t; | ||
136 | + } | ||
137 | + } | ||
138 | + | ||
139 | + | ||
140 | + protected function readRow() | ||
141 | + { | ||
142 | + $this->row = []; | ||
143 | + $node = $this->current_node->getChildren(); | ||
144 | + if ($node === NULL) { | ||
145 | + return; | ||
146 | + } | ||
147 | + | ||
148 | + for ($node->rewind(), $i = 0; $node->valid(); $node->next(), $i++) { | ||
149 | + $child = $node->current(); | ||
150 | + $attr = $child->attributes(); | ||
151 | + | ||
152 | + // define the index of result array | ||
153 | + // $attr['r'] - contain the address of cells - A1, B1 ... | ||
154 | + if (isset($attr['r'])) { | ||
155 | + // override index | ||
156 | + $i = $this->convertCellToIndex( $attr['r'] ); | ||
157 | + | ||
158 | + if ( $this->keys !== Null ){ | ||
159 | + if( isset( $this->keys[$i] ) ){ | ||
160 | + //$i = $this->keys[$i]; | ||
161 | + } else { | ||
162 | + // we have a keys, but this one we didn't find, so skip it | ||
163 | + continue; | ||
164 | + } | ||
165 | + } | ||
166 | + } | ||
167 | + // define the value of result array | ||
168 | + if (isset($child->v)) { | ||
169 | + $value = (string)$child->v; | ||
170 | + | ||
171 | + if ( isset($attr['t']) ){ | ||
172 | + // it's not a value it's a string, so fetch it from string array | ||
173 | + $value = $this->strings_arr[$value]; | ||
174 | + } else { | ||
175 | + $value = (string)round( $value, $this->float_precision ); | ||
176 | + } | ||
177 | + | ||
178 | + | ||
179 | + } else { | ||
180 | + $value = ''; | ||
181 | + } | ||
182 | + | ||
183 | + // set | ||
184 | + $this->row[$i] = $value; | ||
185 | + | ||
186 | + } | ||
187 | +// // fill the row by empty values for keys that we are missed in previous step | ||
188 | + // only for 'has_header_row = true' mode | ||
189 | + if ( $this->has_header_row && $this->keys !== Null ) { | ||
190 | + $extra_column = count( $this->keys ) - count( $this->row ); | ||
191 | + if ( $extra_column ) { | ||
192 | + foreach ( $this->keys as $key => $key ) { | ||
193 | + | ||
194 | + if ( isset( $this->row[$key] ) ) { | ||
195 | + continue; | ||
196 | + } | ||
197 | + $this->row[$key] = ''; | ||
198 | + } | ||
199 | + } | ||
200 | + | ||
201 | + } | ||
202 | + ksort( $this->row ); | ||
203 | + $this->current_node->next(); | ||
204 | + } | ||
205 | + | ||
206 | + protected function isEmptyRow() | ||
207 | + { | ||
208 | + | ||
209 | + $is_empty = false; | ||
210 | + | ||
211 | + if (!count($this->row) || !$this->current_node->valid()) { | ||
212 | + return true; | ||
213 | + } | ||
214 | + | ||
215 | + $j = 0; | ||
216 | + for ($i = 1; $i <= count($this->row); $i++) { | ||
217 | + | ||
218 | + if (isset($this->row[$i - 1]) && $this->isEmptyColumn($this->row[$i - 1])) { | ||
219 | + $j++; | ||
220 | + } | ||
221 | + | ||
222 | + if ($j >= $this->min_column_quantity) { | ||
223 | + $is_empty = true; | ||
224 | + break; | ||
225 | + } | ||
226 | + } | ||
227 | + | ||
228 | + return $is_empty; | ||
229 | + } | ||
230 | + | ||
231 | + protected function isEmptyColumn($val) | ||
232 | + { | ||
233 | + return $val == ''; | ||
234 | + } | ||
235 | + | ||
236 | + protected function setResult() | ||
237 | + { | ||
238 | + $this->result[$this->current_sheet][] = $this->row; | ||
239 | + } | ||
240 | + | ||
241 | + protected function deleteExtractFiles() | ||
242 | + { | ||
243 | + $this->removeDir($this->path_for_extract_files); | ||
244 | + | ||
245 | + } | ||
246 | + | ||
247 | + protected function removeDir($dir) | ||
248 | + { | ||
249 | + if (is_dir($dir)) { | ||
250 | + $objects = scandir($dir); | ||
251 | + foreach ($objects as $object) { | ||
252 | + if ($object != "." && $object != "..") { | ||
253 | + if (filetype($dir . "/" . $object) == "dir") | ||
254 | + $this->removeDir($dir . "/" . $object); | ||
255 | + else | ||
256 | + unlink($dir . "/" . $object); | ||
257 | + } | ||
258 | + } | ||
259 | + reset($objects); | ||
260 | + rmdir($dir); | ||
261 | + } | ||
262 | + } | ||
263 | + | ||
264 | + | ||
265 | + /** | ||
266 | + * @param $cell_address - string with address like A1, B1 ... | ||
267 | + * @return int - integer index | ||
268 | + * this method has a constraint - 'Z' - it's a last column to convert, | ||
269 | + * column with 'AA..' address and bigger - return index = 0 | ||
270 | + */ | ||
271 | + protected function convertCellToIndex($cell_address) | ||
272 | + { | ||
273 | + $index = 0; | ||
274 | + | ||
275 | + $address_letter = substr($cell_address, 0, 1); | ||
276 | + $address_arr = range('A', 'Z'); | ||
277 | + | ||
278 | + if ( $search_value = array_search( $address_letter, $address_arr ) ) | ||
279 | + $index = $search_value; | ||
280 | + | ||
281 | + return $index; | ||
282 | + | ||
283 | + } | ||
284 | +// @todo - переписать родительский метод в универсальной манере а не переопределять его | ||
285 | + protected function setKeysFromHeader(){ | ||
286 | + if ( $this->has_header_row ) { | ||
287 | + | ||
288 | + if ($this->keys === NULL) { | ||
289 | + $this->keys = $this->row; | ||
290 | + return true; | ||
291 | + } | ||
292 | + } | ||
293 | + return false; | ||
294 | + } | ||
295 | + protected function cleanUp() | ||
296 | + { | ||
297 | + parent::cleanUp(); | ||
298 | + unset($this->strings_arr); | ||
299 | + unset($this->sheets_arr); | ||
300 | + unset($this->current_node); | ||
301 | + | ||
302 | + | ||
303 | + } | ||
304 | + | ||
305 | + function __destruct() | ||
306 | + { | ||
307 | + $this->deleteExtractFiles(); | ||
308 | + } | ||
309 | + | ||
310 | + | ||
311 | +} | ||
0 | \ No newline at end of file | 312 | \ No newline at end of file |
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Cibermag | ||
5 | + * Date: 10.09.2015 | ||
6 | + * Time: 17:47 | ||
7 | + */ | ||
8 | + | ||
9 | +namespace common\components\parsers; | ||
10 | + | ||
11 | + | ||
12 | +class XmlParser extends Parser{ | ||
13 | + | ||
14 | + public $node; | ||
15 | + | ||
16 | + public function read() | ||
17 | + { | ||
18 | + //$file = $this->file; | ||
19 | + $result = $this->xmlToArray( ); | ||
20 | + | ||
21 | + if ( isset($this->node) ) { | ||
22 | + | ||
23 | + $result = $result[ $this->node ]; | ||
24 | + | ||
25 | + } | ||
26 | + | ||
27 | + $this->cleanUp(); | ||
28 | + return $result; | ||
29 | + } | ||
30 | + | ||
31 | + | ||
32 | + /** | ||
33 | + * Converts an XML string to a PHP array | ||
34 | + * @param $file_path | ||
35 | + * @return mixed | ||
36 | + * @throws Exception | ||
37 | + * @throws \Exception | ||
38 | + */ | ||
39 | + protected function xmlToArray( ) { | ||
40 | + | ||
41 | + try { | ||
42 | + $xml = new \SimpleXMLElement( $this->file_path, 0, true ); | ||
43 | + //\common\components\CustomVarDamp::dumpAndDie($xml->children()->children()); | ||
44 | + $result = $this->recursiveXMLToArray( $xml ); | ||
45 | + } catch(\Exception $ex) { | ||
46 | + | ||
47 | + throw $ex; | ||
48 | + } | ||
49 | + | ||
50 | + return $result; | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * Convert a XML string to a PHP array recursively. Do not | ||
55 | + * call this function directly | ||
56 | + * | ||
57 | + * @param SimpleXMLElement | ||
58 | + * | ||
59 | + * @return mixed | ||
60 | + */ | ||
61 | + protected function recursiveXMLToArray($xml) { | ||
62 | + if( $xml instanceof \SimpleXMLElement ) { | ||
63 | + $attributes = $xml->attributes(); | ||
64 | + | ||
65 | + foreach( $attributes as $key => $value ) { | ||
66 | + if( $value ) { | ||
67 | + $attribute_array[$key] = (string) $value; | ||
68 | + } | ||
69 | + } | ||
70 | + $previous_xml = $xml; | ||
71 | + $xml = get_object_vars($xml); | ||
72 | + } | ||
73 | + | ||
74 | + if(is_array($xml)) { | ||
75 | + | ||
76 | + if( count($xml) == 0 ) | ||
77 | + return (string) $previous_xml; // for CDATA | ||
78 | + | ||
79 | + foreach($xml as $key => $value) { | ||
80 | + $row[$key] = $this->recursiveXMLToArray($value); | ||
81 | + } | ||
82 | + if ( is_string($value) ) { | ||
83 | + // дошли до конца рекурсии | ||
84 | + // преобразуем ряд согласно конфигурации | ||
85 | + if ( $this->keys !== NULL ) { | ||
86 | + // назначим ключи из конфигурации, согласно массиву $keys | ||
87 | + $row = $this->compareArrayWithKeys( $row ); | ||
88 | + } | ||
89 | + $row = $this->convert( $row ); | ||
90 | + | ||
91 | + } | ||
92 | + | ||
93 | + | ||
94 | + if( isset( $attribute_array ) ) | ||
95 | + $row['@'] = $attribute_array; // Attributes | ||
96 | + | ||
97 | + return $row; | ||
98 | + } | ||
99 | + return (string) $xml; | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * @param array $value_arr - текущий ряд, массив, которому нужно назначить конфигурационные ключи ($keys) | ||
104 | + * @return array | ||
105 | + */ | ||
106 | + protected function compareArrayWithKeys( array $value_arr ){ | ||
107 | + $res = $this->keys; | ||
108 | + foreach ( $this->keys as $key => $value ) { | ||
109 | + if ( array_key_exists( $value, $value_arr ) ) { | ||
110 | + $res[$key] = $value_arr[$value]; | ||
111 | + } | ||
112 | + } | ||
113 | + return $res; | ||
114 | + } | ||
115 | + | ||
116 | +} | ||
0 | \ No newline at end of file | 117 | \ No newline at end of file |
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Cibermag | ||
5 | + * Date: 07.09.2015 | ||
6 | + * Time: 15:56 | ||
7 | + */ | ||
8 | + | ||
9 | +namespace common\components\parsers; | ||
10 | + | ||
11 | +use yii\base\Component; | ||
12 | +use yii\base\ErrorException; | ||
13 | + | ||
14 | + | ||
15 | +class YiiConverter extends Component{ | ||
16 | + | ||
17 | +public $configuration; | ||
18 | +public $converter; | ||
19 | + | ||
20 | + public function init() | ||
21 | + { | ||
22 | + parent::init(); | ||
23 | + $converter = \Yii::createObject( $this->configuration ); | ||
24 | + if ( $converter instanceof ConverterInterface ) { | ||
25 | + | ||
26 | + $this->converter = $converter; | ||
27 | + }else{ | ||
28 | + throw new ErrorException('Wrong type of converter'); | ||
29 | + } | ||
30 | + | ||
31 | + | ||
32 | + } | ||
33 | + | ||
34 | + public function convertTo( $method, $value, $attributes = [] ){ | ||
35 | + | ||
36 | + if ( $attributes ) { | ||
37 | + $this->converter->setAttributes($attributes); | ||
38 | + } | ||
39 | + return $this->converter->$method( $value ); | ||
40 | + | ||
41 | + } | ||
42 | + | ||
43 | + public function convertByConfiguration( $value, $configuration ){ | ||
44 | + | ||
45 | + return $this->converter->convertByConfiguration( $value, $configuration ); | ||
46 | + | ||
47 | + } | ||
48 | + | ||
49 | + | ||
50 | +} | ||
0 | \ No newline at end of file | 51 | \ No newline at end of file |
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Cibermag | ||
5 | + * Date: 07.09.2015 | ||
6 | + * Time: 15:56 | ||
7 | + */ | ||
8 | + | ||
9 | +namespace common\components\parsers; | ||
10 | + | ||
11 | +use yii\base\Component; | ||
12 | + | ||
13 | + | ||
14 | + | ||
15 | + | ||
16 | +class YiiMultiparser extends Component{ | ||
17 | + | ||
18 | +public $configuration; | ||
19 | +public $parserHandler; | ||
20 | +//public $file_path; | ||
21 | + | ||
22 | + public function init() | ||
23 | + { | ||
24 | + parent::init(); | ||
25 | + $this->parserHandler = new YiiParserHandler( ); | ||
26 | + $this->parserHandler->setConfiguration( $this->configuration ); | ||
27 | + | ||
28 | + } | ||
29 | + | ||
30 | + | ||
31 | + public function parse( $filePath, $options = [] ){ | ||
32 | + | ||
33 | + // $this->file_path = $file_path; | ||
34 | + $this->parserHandler->setup( $filePath, $options ); | ||
35 | + | ||
36 | + return $this->parserHandler->run(); | ||
37 | + | ||
38 | + } | ||
39 | + | ||
40 | + public function getConfiguration( $extension, $parameter ){ | ||
41 | + | ||
42 | + return $this->parserHandler->getCustomConfiguration( $extension, $parameter ); | ||
43 | + | ||
44 | + } | ||
45 | + | ||
46 | +} | ||
0 | \ No newline at end of file | 47 | \ No newline at end of file |
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Cibermag | ||
5 | + * Date: 07.09.2015 | ||
6 | + * Time: 15:53 | ||
7 | + */ | ||
8 | + | ||
9 | +namespace common\components\parsers; | ||
10 | + | ||
11 | + | ||
12 | + | ||
13 | +class YiiParserHandler extends ParserHandler{ | ||
14 | + | ||
15 | + | ||
16 | + /** | ||
17 | + * @param $filePath | ||
18 | + * @param array $options | ||
19 | + * проверяет читабельность переданного файла, а также наличие настроек парсера в конфигурационном файле для данного типа файла | ||
20 | + */ | ||
21 | +// public function setup($file_path, $options = []) | ||
22 | +// { | ||
23 | +// $this->file_path = $file_path; | ||
24 | +// if (isset($options['mode'])) { | ||
25 | +// | ||
26 | +// $this->mode = $options['mode']; | ||
27 | +// unset($options['mode']); | ||
28 | +// | ||
29 | +// } else { | ||
30 | +// | ||
31 | +// $this->mode = self::DEFAULT_MODE; | ||
32 | +// | ||
33 | +// } | ||
34 | +// | ||
35 | +// $this->options = $options; | ||
36 | +// | ||
37 | +// try { | ||
38 | +// $this->fileObject = new \SplFileObject($this->file_path, 'r'); | ||
39 | +// } catch (\ErrorException $e) { | ||
40 | +// // Yii::warning("Ошибка открытия файла {$this->file_path}"); | ||
41 | +// echo "Ошибка открытия файла {$this->file_path}"; | ||
42 | +// return []; | ||
43 | +// } | ||
44 | +// | ||
45 | +// $options['file'] = $this->fileObject; | ||
46 | +// $this->extension = $this->fileObject->getExtension(); | ||
47 | +// | ||
48 | +// try { | ||
49 | +// | ||
50 | +// $this->configuration = array_merge_recursive ($this->configuration, $options); | ||
51 | +// | ||
52 | +// } catch (\ErrorException $e) { | ||
53 | +// echo $e->getMessage(); | ||
54 | +// return []; | ||
55 | +// } | ||
56 | +// | ||
57 | +// } | ||
58 | +// | ||
59 | +// public function run() | ||
60 | +// { | ||
61 | +// | ||
62 | +// $result = []; | ||
63 | +// | ||
64 | +// // \common\components\CustomVarDamp::dumpAndDie($this); | ||
65 | +// if (count($this->configuration)) { | ||
66 | +// $parser = \Yii::createObject($this->configuration); | ||
67 | +// | ||
68 | +// try { | ||
69 | +// | ||
70 | +// $parser->setup(); | ||
71 | +// $result = $parser->read(); | ||
72 | +// | ||
73 | +// } catch (\ErrorException $e) { | ||
74 | +// | ||
75 | +// echo $e->getMessage(); | ||
76 | +// | ||
77 | +// } | ||
78 | +// | ||
79 | +// } | ||
80 | +// | ||
81 | +// return $result; | ||
82 | +// } | ||
83 | + protected function createObjectByConfiguration($configuration) | ||
84 | + { | ||
85 | + return \Yii::createObject($configuration); | ||
86 | + } | ||
87 | + | ||
88 | + | ||
89 | +} | ||
0 | \ No newline at end of file | 90 | \ No newline at end of file |
common/components/parsers/config.php
@@ -6,7 +6,8 @@ | @@ -6,7 +6,8 @@ | ||
6 | 'auto_detect_first_line' => true, | 6 | 'auto_detect_first_line' => true, |
7 | 'converter_conf' => [ | 7 | 'converter_conf' => [ |
8 | 'class' => 'common\components\parsers\CustomConverter', | 8 | 'class' => 'common\components\parsers\CustomConverter', |
9 | - 'configuration' => ["encode" => 'DESCR'],] | 9 | + 'configuration' => ["encode" => 'DESCR'], |
10 | + ] | ||
10 | ], | 11 | ], |
11 | 'console' => | 12 | 'console' => |
12 | ['class' => 'common\components\parsers\CustomCsvParser', | 13 | ['class' => 'common\components\parsers\CustomCsvParser', |
@@ -39,7 +40,6 @@ | @@ -39,7 +40,6 @@ | ||
39 | 'crosses' => ['class' => 'common\components\parsers\CustomCsvParser', | 40 | 'crosses' => ['class' => 'common\components\parsers\CustomCsvParser', |
40 | 'auto_detect_first_line' => true, | 41 | 'auto_detect_first_line' => true, |
41 | 'min_column_quantity' => 4, | 42 | 'min_column_quantity' => 4, |
42 | - // 'keys' =>['ARTICLE', 'CROSS_ARTICLE', 'BRAND', 'CROSS_BRAND'], | ||
43 | 'converter_conf' => [ | 43 | 'converter_conf' => [ |
44 | 'class' => ' common\components\parsers\CustomConverter', | 44 | 'class' => ' common\components\parsers\CustomConverter', |
45 | 'hasKey' => 1, | 45 | 'hasKey' => 1, |
@@ -58,7 +58,7 @@ | @@ -58,7 +58,7 @@ | ||
58 | ], | 58 | ], |
59 | 'xml' => | 59 | 'xml' => |
60 | ['console' => | 60 | ['console' => |
61 | - ['class' => 'yii\multiparser\XmlParser', | 61 | + ['class' => 'common\components\parsers\XmlParser', |
62 | 'node' => 'Товар', | 62 | 'node' => 'Товар', |
63 | 'has_header_row' => true, | 63 | 'has_header_row' => true, |
64 | 'keys' => [ | 64 | 'keys' => [ |
@@ -78,7 +78,7 @@ | @@ -78,7 +78,7 @@ | ||
78 | ], | 78 | ], |
79 | 'xlsx' => | 79 | 'xlsx' => |
80 | ['web' => | 80 | ['web' => |
81 | - ['class' => 'yii\multiparser\XlsxParser', | 81 | + ['class' => 'common\components\parsers\XlsxParser', |
82 | 'path_for_extract_files' => \Yii::getAlias('@temp_upload') . '/xlsx/', | 82 | 'path_for_extract_files' => \Yii::getAlias('@temp_upload') . '/xlsx/', |
83 | //'auto_detect_first_line' => true, | 83 | //'auto_detect_first_line' => true, |
84 | //'has_header_row' => true, | 84 | //'has_header_row' => true, |
common/config/main.php
@@ -15,11 +15,11 @@ return [ | @@ -15,11 +15,11 @@ return [ | ||
15 | ] | 15 | ] |
16 | ], | 16 | ], |
17 | 'multiparser'=>[ | 17 | 'multiparser'=>[ |
18 | - 'class' => 'yii\multiparser\YiiMultiparser', | 18 | + 'class' => 'common\components\parsers\YiiMultiparser', |
19 | 'configuration' => $mp_configuration, | 19 | 'configuration' => $mp_configuration, |
20 | ], | 20 | ], |
21 | 'converter'=>[ | 21 | 'converter'=>[ |
22 | - 'class' => 'yii\multiparser\YiiConverter', | 22 | + 'class' => 'common\components\parsers\YiiConverter', |
23 | 'configuration' => [ | 23 | 'configuration' => [ |
24 | 'class' => 'common\components\parsers\CustomConverter' | 24 | 'class' => 'common\components\parsers\CustomConverter' |
25 | ], | 25 | ], |
common/models/Accounts.php
@@ -13,6 +13,7 @@ use yii\db\ActiveRecord; | @@ -13,6 +13,7 @@ use yii\db\ActiveRecord; | ||
13 | * @property integer $id | 13 | * @property integer $id |
14 | * @property integer $if_manager | 14 | * @property integer $if_manager |
15 | * @property string $email | 15 | * @property string $email |
16 | + * @property string $auth_key | ||
16 | * @property string $pass | 17 | * @property string $pass |
17 | * @property integer $margin_id | 18 | * @property integer $margin_id |
18 | * @property string $name | 19 | * @property string $name |
@@ -53,6 +54,11 @@ class Accounts extends ActiveRecord implements IdentityInterface | @@ -53,6 +54,11 @@ class Accounts extends ActiveRecord implements IdentityInterface | ||
53 | public $re_pass; | 54 | public $re_pass; |
54 | public $surname; | 55 | public $surname; |
55 | public $country_region; | 56 | public $country_region; |
57 | + public $verifyCode; | ||
58 | + public $auth_key; | ||
59 | + public $password_hash; | ||
60 | + public $password_reset_token; | ||
61 | + | ||
56 | 62 | ||
57 | /** | 63 | /** |
58 | * @inheritdoc | 64 | * @inheritdoc |
@@ -66,6 +72,7 @@ class Accounts extends ActiveRecord implements IdentityInterface | @@ -66,6 +72,7 @@ class Accounts extends ActiveRecord implements IdentityInterface | ||
66 | public function beforeSave() | 72 | public function beforeSave() |
67 | { | 73 | { |
68 | $this->dt = time(); | 74 | $this->dt = time(); |
75 | + $this->name = $this->surname.' '.$this->name; | ||
69 | return true; | 76 | return true; |
70 | 77 | ||
71 | } | 78 | } |
@@ -89,7 +96,11 @@ class Accounts extends ActiveRecord implements IdentityInterface | @@ -89,7 +96,11 @@ class Accounts extends ActiveRecord implements IdentityInterface | ||
89 | [['email'], 'unique'], | 96 | [['email'], 'unique'], |
90 | [['email'], 'email'], | 97 | [['email'], 'email'], |
91 | ['re_pass', 'compare', 'compareAttribute' => 'pass'], | 98 | ['re_pass', 'compare', 'compareAttribute' => 'pass'], |
92 | - ['dt', 'date', 'format' => 'Y.m.d'] | 99 | + ['verifyCode', 'captcha'], |
100 | + ['dt', 'date', 'format' => 'Y.m.d'], | ||
101 | + [['rating','if_manager','set_manager_id','balance'], 'default', 'value' => '0'], | ||
102 | + [['is_active','margin_id','office_id','is_scribe'], 'default', 'value' => '1'], | ||
103 | + [['comment'], 'default', 'value' => 'Новый пользователь'], | ||
93 | ]; | 104 | ]; |
94 | } | 105 | } |
95 | 106 | ||
@@ -149,56 +160,7 @@ class Accounts extends ActiveRecord implements IdentityInterface | @@ -149,56 +160,7 @@ class Accounts extends ActiveRecord implements IdentityInterface | ||
149 | { | 160 | { |
150 | 161 | ||
151 | if ($this->validate()) { | 162 | if ($this->validate()) { |
152 | - $this->name = $this->surname.' '.$this->name; | ||
153 | - | ||
154 | - if( $this->is_firm ){ | ||
155 | - $this->if_manager = '0'; | ||
156 | - $this->margin_id = '1'; | ||
157 | - $this->address = ''; | ||
158 | - $this->comment = 'Новый пользователь'; | ||
159 | - $this->rating = '0'; | ||
160 | - $this->is_active = '1'; | ||
161 | - $this->last_loginin = ''; | ||
162 | - $this->firm_inn = ''; | ||
163 | - $this->firm_bank =''; | ||
164 | - $this->balance ='0.00'; | ||
165 | - $this->office_id ='1'; | ||
166 | - $this->is_scribe ='1'; | ||
167 | - $this->set_manager_id ='0'; | ||
168 | - $this->phones2=''; | ||
169 | - $this->phones3 =''; | ||
170 | - $this->snumb =''; | ||
171 | - $this->firm_ur_adr =''; | ||
172 | - $this->firm_fiz_adr = ''; | ||
173 | - $this->firm_code_eg = ''; | ||
174 | - $this->firm_rs = ''; | ||
175 | - $this->firm_mfo = ''; | ||
176 | - $this->firm_site = ''; | ||
177 | - }else{ | ||
178 | - | ||
179 | - $this->if_manager = '0'; | ||
180 | - $this->margin_id = '1'; | ||
181 | - $this->address = ''; | ||
182 | - $this->comment = 'Новый пользователь'; | ||
183 | - $this->rating = '0'; | ||
184 | - $this->is_active = '1'; | ||
185 | - $this->last_loginin = ''; | ||
186 | - $this->firm_inn = ''; | ||
187 | - $this->firm_bank =''; | ||
188 | - $this->balance ='0.00'; | ||
189 | - $this->office_id ='1'; | ||
190 | - $this->is_scribe ='1'; | ||
191 | - $this->set_manager_id ='0'; | ||
192 | - $this->phones2=''; | ||
193 | - $this->phones3 =''; | ||
194 | - $this->snumb =''; | ||
195 | - $this->firm_ur_adr =''; | ||
196 | - $this->firm_fiz_adr = ''; | ||
197 | - $this->firm_code_eg = ''; | ||
198 | - $this->firm_rs = ''; | ||
199 | - $this->firm_mfo = ''; | ||
200 | - $this->firm_site = ''; | ||
201 | - } | 163 | + |
202 | 164 | ||
203 | if ($this->save()) { | 165 | if ($this->save()) { |
204 | return $this; | 166 | return $this; |
@@ -224,14 +186,14 @@ class Accounts extends ActiveRecord implements IdentityInterface | @@ -224,14 +186,14 @@ class Accounts extends ActiveRecord implements IdentityInterface | ||
224 | } | 186 | } |
225 | 187 | ||
226 | /** | 188 | /** |
227 | - * Finds user by username | 189 | + * Finds user by email |
228 | * | 190 | * |
229 | - * @param string $username | 191 | + * @param string $email |
230 | * @return static|null | 192 | * @return static|null |
231 | */ | 193 | */ |
232 | - public static function findByUsername($username) | 194 | + public static function findByEmail($email) |
233 | { | 195 | { |
234 | - return static::findOne(['name' => $username]); | 196 | + return static::findOne(['email' => $email]); |
235 | } | 197 | } |
236 | 198 | ||
237 | /** | 199 | /** |
@@ -283,4 +245,27 @@ class Accounts extends ActiveRecord implements IdentityInterface | @@ -283,4 +245,27 @@ class Accounts extends ActiveRecord implements IdentityInterface | ||
283 | { | 245 | { |
284 | $this->password_reset_token = null; | 246 | $this->password_reset_token = null; |
285 | } | 247 | } |
248 | + | ||
249 | + /** | ||
250 | + * Finds out if password reset token is valid | ||
251 | + * | ||
252 | + * @param string $token password reset token | ||
253 | + * @return boolean | ||
254 | + */ | ||
255 | + public static function isPasswordResetTokenValid($token) | ||
256 | + { | ||
257 | + if (empty($token)) { | ||
258 | + return false; | ||
259 | + } | ||
260 | + $expire = Yii::$app->params['user.passwordResetTokenExpire']; | ||
261 | + $parts = explode('_', $token); | ||
262 | + $timestamp = (int) end($parts); | ||
263 | + return $timestamp + $expire >= time(); | ||
264 | + } | ||
265 | + | ||
266 | + | ||
267 | + | ||
268 | + | ||
269 | + | ||
270 | + | ||
286 | } | 271 | } |
common/models/AccountsForm.php deleted
1 | -<?php | ||
2 | - | ||
3 | -namespace common\models; | ||
4 | - | ||
5 | -use Yii; | ||
6 | -use yii\web\IdentityInterface; | ||
7 | -use yii\base\NotSupportedException; | ||
8 | -use yii\db\ActiveRecord; | ||
9 | -/** | ||
10 | - * This is the model class for table "w_accounts". | ||
11 | - * | ||
12 | - * | ||
13 | - * @property integer $id | ||
14 | - * @property integer $if_manager | ||
15 | - * @property string $email | ||
16 | - * @property string $pass | ||
17 | - * @property integer $margin_id | ||
18 | - * @property string $name | ||
19 | - * @property string $phones | ||
20 | - * @property integer $country | ||
21 | - * @property integer $city | ||
22 | - * @property string $address | ||
23 | - * @property string $comment | ||
24 | - * @property integer $rating | ||
25 | - * @property string $dt | ||
26 | - * @property integer $is_active | ||
27 | - * @property integer $is_firm | ||
28 | - * @property string $last_loginin | ||
29 | - * @property string $firm_inn | ||
30 | - * @property string $firm_bank | ||
31 | - * @property double $balance | ||
32 | - * @property integer $office_id | ||
33 | - * @property integer $is_scribe | ||
34 | - * @property integer $set_manager_id | ||
35 | - * @property string $phones2 | ||
36 | - * @property string $phones3 | ||
37 | - * @property integer $car | ||
38 | - * @property integer $mod | ||
39 | - * @property string $snumb | ||
40 | - * @property integer $deliveries | ||
41 | - * @property integer $scode | ||
42 | - * @property string $firm_ur_adr | ||
43 | - * @property string $firm_fiz_adr | ||
44 | - * @property string $firm_code_eg | ||
45 | - * @property string $firm_rs | ||
46 | - * @property string $firm_mfo | ||
47 | - * @property string $firm_site | ||
48 | - * @property string $company | ||
49 | - */ | ||
50 | -class AccountsForm extends ActiveRecord | ||
51 | -{ | ||
52 | - | ||
53 | - public $re_pass; | ||
54 | - public $surname; | ||
55 | - public $verifyCode; | ||
56 | - public $country_region; | ||
57 | - | ||
58 | - /** | ||
59 | - * @inheritdoc | ||
60 | - */ | ||
61 | - public static function tableName() | ||
62 | - { | ||
63 | - return 'w_accounts'; | ||
64 | - } | ||
65 | - | ||
66 | - | ||
67 | - | ||
68 | - /** | ||
69 | - * @inheritdoc | ||
70 | - */ | ||
71 | - public function rules() | ||
72 | - { | ||
73 | - return [ | ||
74 | - [['if_manager', 'margin_id', 'country', 'city', 'rating', 'is_active', 'is_firm', 'office_id', 'is_scribe', 'set_manager_id', 'car', 'mod', 'deliveries', 'scode'], 'integer'], | ||
75 | - [['company','email', 'pass', 'name','surname', 'phones',], 'required'], | ||
76 | - [['comment'], 'string'], | ||
77 | - [['balance'], 'number'], | ||
78 | - [['email', 'name','surname', 'firm_site'], 'string', 'max' => 150], | ||
79 | - [['pass','re_pass'], 'string', 'max' => 30], | ||
80 | - [['phones', 'phones2', 'phones3'], 'string', 'max' => 50], | ||
81 | - [['address', 'firm_inn', 'firm_bank'], 'string', 'max' => 254], | ||
82 | - [['last_loginin'], 'string', 'max' => 15], | ||
83 | - [['snumb', 'firm_ur_adr', 'firm_fiz_adr', 'firm_code_eg', 'firm_rs', 'firm_mfo', 'company'], 'string', 'max' => 255], | ||
84 | - [['email'], 'unique'], | ||
85 | - [['email'], 'email'], | ||
86 | - ['re_pass', 'compare', 'compareAttribute' => 'pass'], | ||
87 | - ['verifyCode', 'captcha'], | ||
88 | - ['dt', 'date', 'format' => 'Y.m.d'] | ||
89 | - ]; | ||
90 | - } | ||
91 | - | ||
92 | - /** | ||
93 | - * @inheritdoc | ||
94 | - */ | ||
95 | - public function attributeLabels() | ||
96 | - { | ||
97 | - return [ | ||
98 | - 'id' => 'ID', | ||
99 | - 'if_manager' => 'Статус менеджера', | ||
100 | - 'email' => 'E-mail (Логин)', | ||
101 | - 'pass' => 'Пароль', | ||
102 | - 'margin_id' => 'Тип цены', | ||
103 | - 'name' => 'Имя', | ||
104 | - 'phones' => 'Телефоны', | ||
105 | - 'country' => Yii::t('app', 'Country'), | ||
106 | - 'city' =>'Город', | ||
107 | - 'address' => 'Адрес', | ||
108 | - 'comment' => 'Комментарий', | ||
109 | - 'rating' => Yii::t('app', 'Rating'), | ||
110 | - 'dt' =>'Дата регистрации', | ||
111 | - 'is_active' => 'Активный', | ||
112 | - 'is_firm' => 'Юридическое лицо', | ||
113 | - 'last_loginin' => Yii::t('app', 'Last Loginin'), | ||
114 | - 'firm_inn' => 'ИНН', | ||
115 | - 'firm_bank' => 'Банк', | ||
116 | - 'balance' => Yii::t('app', 'Balance'), | ||
117 | - 'office_id' => Yii::t('app', 'Office ID'), | ||
118 | - 'is_scribe' => 'Подписка', | ||
119 | - 'set_manager_id' => 'Персональный менеджер', | ||
120 | - 'phones2' => 'Телефоны 2', | ||
121 | - 'phones3' => 'Телефоны 3', | ||
122 | - 'car' => Yii::t('app', 'Car'), | ||
123 | - 'mod' => Yii::t('app', 'Mod'), | ||
124 | - 'snumb' => 'snumb', | ||
125 | - 'deliveries' => Yii::t('app', 'Deliveries'), | ||
126 | - 'scode' => 'Код в 1С', | ||
127 | - 'firm_ur_adr' => 'Юридический адрес', | ||
128 | - 'firm_fiz_adr' => 'Физический адрес', | ||
129 | - 'firm_code_eg' => 'Код ЭГ', | ||
130 | - 'firm_rs' => 'Расчётный счёт', | ||
131 | - 'firm_mfo' => 'МФО', | ||
132 | - 'firm_site' => 'Сайт', | ||
133 | - 'company' => 'Название фирмы', | ||
134 | - 'country_region' => 'Регион' | ||
135 | - ]; | ||
136 | - } | ||
137 | - | ||
138 | - | ||
139 | -} |
common/models/MarginsGroups.php
@@ -31,12 +31,13 @@ class MarginsGroups extends \yii\db\ActiveRecord | @@ -31,12 +31,13 @@ class MarginsGroups extends \yii\db\ActiveRecord | ||
31 | public function rules() | 31 | public function rules() |
32 | { | 32 | { |
33 | return [ | 33 | return [ |
34 | - [['importer_id', 'margin_id', 'group', 'koef'], 'required'], | ||
35 | - [['importer_id', 'margin_id'], 'integer'], | ||
36 | - [['koef'], 'number'], | ||
37 | - [['timestamp'], 'safe'], | ||
38 | - [['group'], 'string', 'max' => 200], | ||
39 | - [['importer_id', 'margin_id', 'group'], 'unique', 'targetAttribute' => ['importer_id', 'margin_id', 'group'], 'message' => 'The combination of Importer ID, Margin ID and Group has already been taken.'] | 34 | + [['group','importer_id', 'margin_id', 'koef'], 'required', 'on' => 'default'], |
35 | + [['margin_id'], 'required', 'on' => 'form_upload_validation', 'message' => 'Должен быть указан хотя бы один тип цен.'], | ||
36 | + [['group'], 'required', 'on' => 'form_upload_validation', 'message' => 'Группа RG - обязательное поле.'], | ||
37 | + [['importer_id', 'margin_id'], 'integer' , 'on' => 'default'], | ||
38 | + [['koef'], 'number' , 'on' => 'default'], | ||
39 | + [['timestamp'], 'safe' , 'on' => 'default'], | ||
40 | + [['group'], 'string', 'max' => 200 , 'on' => 'default'], | ||
40 | ]; | 41 | ]; |
41 | } | 42 | } |
42 | 43 | ||
@@ -83,7 +84,6 @@ class MarginsGroups extends \yii\db\ActiveRecord | @@ -83,7 +84,6 @@ class MarginsGroups extends \yii\db\ActiveRecord | ||
83 | //@todo - вынести все ручные инсерты в отдельный класс | 84 | //@todo - вынести все ручные инсерты в отдельный класс |
84 | public static function ManualInsertWithUpdate($data, $keys) | 85 | public static function ManualInsertWithUpdate($data, $keys) |
85 | { | 86 | { |
86 | - // \common\components\CustomVarDamp::dumpAndDie($data); | ||
87 | $table_name = self::tableName(); | 87 | $table_name = self::tableName(); |
88 | $keys_arr = array_keys($data[0]); | 88 | $keys_arr = array_keys($data[0]); |
89 | // найдем те поля которые не являются ключами. Их нужно будет при дубляже апдейтить | 89 | // найдем те поля которые не являются ключами. Их нужно будет при дубляже апдейтить |
@@ -107,9 +107,9 @@ class MarginsGroups extends \yii\db\ActiveRecord | @@ -107,9 +107,9 @@ class MarginsGroups extends \yii\db\ActiveRecord | ||
107 | 107 | ||
108 | // добавим фрагмент с апдейтом при дубляже | 108 | // добавим фрагмент с апдейтом при дубляже |
109 | $query = "{$query_insert} {$query_update}"; | 109 | $query = "{$query_insert} {$query_update}"; |
110 | - // \common\components\CustomVarDamp::dumpAndDie($query); | ||
111 | Yii::$app->db->createCommand($query)->execute(); | 110 | Yii::$app->db->createCommand($query)->execute(); |
112 | 111 | ||
113 | } | 112 | } |
113 | + return true; | ||
114 | } | 114 | } |
115 | } | 115 | } |
common/models/News.php
@@ -107,4 +107,9 @@ class News extends \yii\db\ActiveRecord | @@ -107,4 +107,9 @@ class News extends \yii\db\ActiveRecord | ||
107 | 'price_list' => 'Прайс лист', | 107 | 'price_list' => 'Прайс лист', |
108 | ]; | 108 | ]; |
109 | } | 109 | } |
110 | + | ||
111 | + public function pregStr($str){ | ||
112 | + $vowels = array("<strong>", "</strong>"); | ||
113 | + return str_replace($vowels, "", $str); | ||
114 | + } | ||
110 | } | 115 | } |
common/models/Page.php
@@ -33,7 +33,7 @@ class Page extends \yii\db\ActiveRecord | @@ -33,7 +33,7 @@ class Page extends \yii\db\ActiveRecord | ||
33 | public function rules() | 33 | public function rules() |
34 | { | 34 | { |
35 | return [ | 35 | return [ |
36 | - [['name', 'code', 'content', 'title', 'kwords', 'descr'], 'required'], | 36 | + [['name', 'code', 'content'], 'required'], |
37 | [['content'], 'string'], | 37 | [['content'], 'string'], |
38 | [['sort', 'is_active'], 'integer'], | 38 | [['sort', 'is_active'], 'integer'], |
39 | [['name'], 'string', 'max' => 100], | 39 | [['name'], 'string', 'max' => 100], |
common/models/User.php
@@ -130,6 +130,7 @@ class User extends ActiveRecord implements IdentityInterface | @@ -130,6 +130,7 @@ class User extends ActiveRecord implements IdentityInterface | ||
130 | */ | 130 | */ |
131 | public function getAuthKey() | 131 | public function getAuthKey() |
132 | { | 132 | { |
133 | + | ||
133 | return $this->auth_key; | 134 | return $this->auth_key; |
134 | } | 135 | } |
135 | 136 | ||
@@ -138,6 +139,7 @@ class User extends ActiveRecord implements IdentityInterface | @@ -138,6 +139,7 @@ class User extends ActiveRecord implements IdentityInterface | ||
138 | */ | 139 | */ |
139 | public function validateAuthKey($authKey) | 140 | public function validateAuthKey($authKey) |
140 | { | 141 | { |
142 | + | ||
141 | return $this->getAuthKey() === $authKey; | 143 | return $this->getAuthKey() === $authKey; |
142 | } | 144 | } |
143 | 145 |
1 | +<?php | ||
2 | +namespace common\models; | ||
3 | + | ||
4 | +use Yii; | ||
5 | +use yii\base\Model; | ||
6 | +use yii\web\IdentityInterface; | ||
7 | +/** | ||
8 | + * Login form | ||
9 | + */ | ||
10 | +class UserLoginForm extends Model | ||
11 | +{ | ||
12 | + public $email; | ||
13 | + public $pass; | ||
14 | + public $rememberMe = true; | ||
15 | + | ||
16 | + private $_user; | ||
17 | + | ||
18 | + | ||
19 | + /** | ||
20 | + * @inheritdoc | ||
21 | + */ | ||
22 | + public function rules() | ||
23 | + { | ||
24 | + return [ | ||
25 | + // email and password are both required | ||
26 | + [['email', 'pass'], 'required'], | ||
27 | + // rememberMe must be a boolean value | ||
28 | + ['rememberMe', 'boolean'], | ||
29 | + // password is validated by validatePassword() | ||
30 | + ['pass', 'validatePassword'], | ||
31 | + ]; | ||
32 | + } | ||
33 | + | ||
34 | + /** | ||
35 | + * Validates the password. | ||
36 | + * This method serves as the inline validation for password. | ||
37 | + * | ||
38 | + * @param string $attribute the attribute currently being validated | ||
39 | + * @param array $params the additional name-value pairs given in the rule | ||
40 | + */ | ||
41 | + public function validatePassword($attribute, $params) | ||
42 | + { | ||
43 | + if (!$this->hasErrors()) { | ||
44 | + $user = $this->getUser(); | ||
45 | + if (!$user || $user->pass != $this->pass) { | ||
46 | + $this->addError($attribute, 'Неправильный логин или пароль'); | ||
47 | + } | ||
48 | + } | ||
49 | + } | ||
50 | + | ||
51 | + /** | ||
52 | + * Logs in a user using the provided email and password. | ||
53 | + * | ||
54 | + * @return boolean whether the user is logged in successfully | ||
55 | + */ | ||
56 | + public function login() | ||
57 | + { | ||
58 | + | ||
59 | + if ($this->validate()) { | ||
60 | + return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0); | ||
61 | + } else { | ||
62 | + return false; | ||
63 | + } | ||
64 | + | ||
65 | + } | ||
66 | + | ||
67 | + /** | ||
68 | + * Finds user by [[email]] | ||
69 | + * | ||
70 | + * @return User|null | ||
71 | + */ | ||
72 | + protected function getUser() | ||
73 | + { | ||
74 | + if ($this->_user === null) { | ||
75 | + $this->_user = Accounts::findByEmail($this->email); | ||
76 | + } | ||
77 | + | ||
78 | + return $this->_user; | ||
79 | + } | ||
80 | +} |