Blame view

common/components/parsers/CustomCsvParser.php 1.26 KB
d0a7acb3   Mihail   refactor CsvParse...
1
2
3
4
5
6
7
8
  <?php
  /**
   * Created by PhpStorm.
   * User: Cibermag
   * Date: 04.09.2015
   * Time: 16:07
   */
  
912e6b15   Mihail   fixed Image class
9
  namespace common\components\parsers;
d0a7acb3   Mihail   refactor CsvParse...
10
11
  
  
1fe29bbe   Mihail   fixed parser and ...
12
  use common\components\CustomVarDamp;
4828b892   Mihail   after merge with ...
13
  
ef41533d   Mihail   temp commit - wor...
14
  use yii\base\ErrorException;
1fe29bbe   Mihail   fixed parser and ...
15
  
181d3f16   Mihail   merge with server
16
  
0c8b9dfc   Mihail   add error excepti...
17
  class CustomCsvParser extends  \yii\multiparser\CsvParser {
d0a7acb3   Mihail   refactor CsvParse...
18
  
a0d1ac87   Mihail   add articul filte...
19
      public $last_line = 100;
7a80e74c   Mihail   add DynamicFormHe...
20
21
      //public $hasHeaderRow = true;
     // public $keys = ['first','second', 'third', 'forth', 'fifth'];
2a7a75b8   Mihail   add first version...
22
      public function setupConverter()
d0a7acb3   Mihail   refactor CsvParse...
23
      {
d7f6bdbb   Mihail   add Importers fil...
24
          if (!count($this->converter_conf)) {
33d902b8   Mihail   add converter as ...
25
26
27
              if ($this->hasHeaderRow) {
                  // если у файла есть заголовок, то в результате имеем ассоциативный массив
                  $this->converter_conf['hasKey'] = 1;
78684ed4   Mihail   add multiply pric...
28
  
33d902b8   Mihail   add converter as ...
29
30
              }
  
d0a7acb3   Mihail   refactor CsvParse...
31
          }
78684ed4   Mihail   add multiply pric...
32
33
  //        $this->converter = \Yii::createObject( $this->converter_conf );
  //        CustomVarDamp::dumpAndDie($this->converter);
d0a7acb3   Mihail   refactor CsvParse...
34
35
      }
  
d7f6bdbb   Mihail   add Importers fil...
36
37
38
39
40
41
42
      /**
       * @param $arr
       * @return mixed
       * преобразовует значения прочитанного массива в нужные типы, согласно конфигурации конвертера
       */
      protected function convert($arr)
      {
78684ed4   Mihail   add multiply pric...
43
          $arr = \Yii::$app->multiparser->convertByConfiguration( $arr, $this->converter_conf );
ef41533d   Mihail   temp commit - wor...
44
  
1fe29bbe   Mihail   fixed parser and ...
45
          return $arr;
d7f6bdbb   Mihail   add Importers fil...
46
47
  
      }
2a7a75b8   Mihail   add first version...
48
  
d0a7acb3   Mihail   refactor CsvParse...
49
  }