From d8aa85f354b9f82004fbf6de9a4878ae1d15dfa9 Mon Sep 17 00:00:00 2001 From: Mihail Date: Tue, 15 Dec 2015 17:25:30 +0200 Subject: [PATCH] add examples for xls and txt parsers --- examples/UploadFileParsingForm.php | 6 ++++-- examples/_data/template.txt | 13 +++++++++++++ examples/_data/template.xls | Bin 0 -> 28672 bytes examples/config.php | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- examples/views/index.php | 26 ++++++++++++++++++++++++++ examples/views/results.php | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 examples/_data/template.txt create mode 100644 examples/_data/template.xls create mode 100644 examples/views/index.php create mode 100644 examples/views/results.php diff --git a/examples/UploadFileParsingForm.php b/examples/UploadFileParsingForm.php index 77def70..ea64421 100644 --- a/examples/UploadFileParsingForm.php +++ b/examples/UploadFileParsingForm.php @@ -23,6 +23,8 @@ class UploadFileParsingForm extends Model // 1 - csv template file from data/template.csv // 2 - xml template file from data/template.xml // 3 - xlsx template file from data/template.xlsx + // 4 - xls template file from data/template.xls + // 5 - txt template file from data/template.txt public $file_type = 0; @@ -34,11 +36,11 @@ class UploadFileParsingForm extends Model } JS; return [ - ['file_type', 'in', 'range' => range( 0, 3 ) ], + ['file_type', 'in', 'range' => range( 0, 5 ) ], ['file', 'required', 'when' => function(){ return !$this->file_type; } , 'whenClient' => $client_func], - [['file'], 'file', 'extensions' => ['csv', 'xlsx', 'xml'], 'checkExtensionByMimeType' => false ], + [['file'], 'file', 'extensions' => ['csv', 'xlsx', 'xml', 'xls', 'txt'], 'checkExtensionByMimeType' => false ], ['file_path', 'safe'], ]; diff --git a/examples/_data/template.txt b/examples/_data/template.txt new file mode 100644 index 0000000..e75e4be --- /dev/null +++ b/examples/_data/template.txt @@ -0,0 +1,13 @@ +Бренд Наименование Цена закупки Остаток +EL ZIP THERPR L Куртка чоловіча синтетична 2610.0000 2 +EL ZIP THERPR XL Куртка 2610.0000 3 +EL ZIP THERPR XXL Куртка 2610.0000 2 +ES REKL045 Секатор 433.6900 3 +ES REKL060 Сертифiкат подарунковий 476.8500 7 +ES REKL067 Сертифiкат подарунковий 866.7800 1 +ES REKL072 Сертифiкат подарунковий 1103.2500 4 +ES REKL083 Сертифiкат подарунковий 1892.2500 5 +ES REKL103 Сертифiкат подарунковий 3467.6500 2 +ES REKL115 Нiж господарський 790.0500 5 +ES REKL138 Подарунковий Сертифікат 2088.0000 2 + diff --git a/examples/_data/template.xls b/examples/_data/template.xls new file mode 100644 index 0000000..420fd41 Binary files /dev/null and b/examples/_data/template.xls differ diff --git a/examples/config.php b/examples/config.php index a00116c..2178d28 100644 --- a/examples/config.php +++ b/examples/config.php @@ -86,7 +86,7 @@ return [ ], 'template' => ['class' => 'yii\multiparser\XlsxParser', - 'path_for_extract_files' => $_SERVER["DOCUMENT_ROOT"] . 'tests/_data/xlsx_tmp', + 'path_for_extract_files' => $_SERVER["DOCUMENT_ROOT"] . '/tests/_data/xlsx_tmp/', 'keys' => [ 0 => 'Original', 1 => 'Replacement', @@ -101,5 +101,63 @@ return [ "Count" => 'Количество', ], ], + 'xls' => + ['custom' => + ['class' => 'yii\multiparser\XlsParser', + ], + 'template' => + ['class' => 'yii\multiparser\XlsParser', + 'converter_conf' => [ + 'class' => ' yii\multiparser\Converter', + 'configuration' => ["encode" => [], + ] + ],], + + 'basic_column' => [ + Null => 'Пусто', + "BRAND" => 'Бренд', + "ARTICLE" => 'Артикул', + "PRICE" => 'Цена', + "DESCR" => 'Наименование', + "BOX" => 'Колво', + "ADD_BOX" => 'Р’ пути', + "GROUP" => 'Группа RG' + ], + ], + 'txt' => + ['custom' => + ['class' => 'yii\multiparser\CsvParser', + 'delimiter' => "\t", + 'converter_conf' => [ + 'class' => 'yii\multiparser\Converter', + 'configuration' => ["encode" => []], + ] + ], + 'template' => + ['class' => 'yii\multiparser\CsvParser', + 'delimiter' => "\t", + 'keys' => [ + 0 => 'Brand', + 1 => 'Article', + 2 => 'Price', + 4 => 'Count', + ], + 'converter_conf' => [ + 'class' => 'yii\multiparser\Converter', + 'configuration' => ["encode" => 'Brand', + "float" => 'Price', + "integer" => 'Count' + ] + ],], + + 'basic_column' => [ + Null => 'null', + "Description" => 'Название', + "Article" => 'Артикул', + "Price" => 'Цена', + "Brand" => 'Производитель', + "Count" => 'Количество', + ], + ], ]; diff --git a/examples/views/index.php b/examples/views/index.php new file mode 100644 index 0000000..637f508 --- /dev/null +++ b/examples/views/index.php @@ -0,0 +1,26 @@ + +
+
+ ['enctype' => 'multipart/form-data',],'action'=>['parser/read']]); + ?> +

Choose file to parse

+ + field($model, 'file')->fileInput() ?> + + field($model, 'file_type')->radioList([0 => 'Custom file', 1 => 'csv template', 2 => 'xml template', 3 => 'xlsx template', 4 => 'xls template', 5 => 'txt template'])->label(false); + ?> + +
+ 'btn btn-primary']) ?> +
+ + +
+
+ diff --git a/examples/views/results.php b/examples/views/results.php new file mode 100644 index 0000000..9eb650f --- /dev/null +++ b/examples/views/results.php @@ -0,0 +1,38 @@ +title = 'Results'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ 'write']); + + if (empty( $header_model )) { + // выведем просто массив без колонок выбора + echo \yii\grid\GridView::widget([ + 'dataProvider' => $dataProvider, + // 'layout'=>"{pager}\n{items}", + + ]); + + } else { + echo DynamicFormHelper::CreateGridWithDropDownListHeader($dataProvider, $form, $header_model, $basic_column); + } + ?> + + + 'btn btn-primary', 'name' => 'Return',]) ?> + +
\ No newline at end of file -- libgit2 0.21.4