Blame view

common/components/parsers/CustomCsvParser.php 1.13 KB
40ff24a1   Mihail   refactor CsvParse...
1
2
3
4
5
6
7
8
  <?php
  /**
   * Created by PhpStorm.
   * User: Cibermag
   * Date: 04.09.2015
   * Time: 16:07
   */
  
bedb55fe   Mihail   fixed Image class
9
  namespace common\components\parsers;
40ff24a1   Mihail   refactor CsvParse...
10
11
  
  
93e39994   Mihail   fixed parser and ...
12
  use common\components\CustomVarDamp;
f7ab7644   Mihail   after merge with ...
13
  
34d480b7   Mihail   temp commit - wor...
14
  use yii\base\ErrorException;
93e39994   Mihail   fixed parser and ...
15
  
98533894   Mihail   merge with server
16
  
036717a1   Mihail   add error excepti...
17
  class CustomCsvParser extends  \yii\multiparser\CsvParser {
40ff24a1   Mihail   refactor CsvParse...
18
  
9e481998   Mihail   add auto upload a...
19
      public $last_line = 10;
474f35bf   Mihail   add DynamicFormHe...
20
21
      //public $hasHeaderRow = true;
     // public $keys = ['first','second', 'third', 'forth', 'fifth'];
74072a2a   Mihail   add first version...
22
      public function setupConverter()
40ff24a1   Mihail   refactor CsvParse...
23
      {
8894c93a   Mihail   add Importers fil...
24
          if (!count($this->converter_conf)) {
28253169   Mihail   add converter as ...
25
26
27
28
29
              if ($this->hasHeaderRow) {
                  // если у файла есть заголовок, то в результате имеем ассоциативный массив
                  $this->converter_conf['hasKey'] = 1;
              }
  
40ff24a1   Mihail   refactor CsvParse...
30
31
          }
  
40ff24a1   Mihail   refactor CsvParse...
32
33
      }
  
8894c93a   Mihail   add Importers fil...
34
35
36
37
38
39
40
      /**
       * @param $arr
       * @return mixed
       * преобразовует значения прочитанного массива в нужные типы, согласно конфигурации конвертера
       */
      protected function convert($arr)
      {
df629228   Mihail   console csv parsing
41
          $arr = \Yii::$app->multiparser->convertByConfiguration($arr, $this->converter_conf);
34d480b7   Mihail   temp commit - wor...
42
  
93e39994   Mihail   fixed parser and ...
43
          return $arr;
8894c93a   Mihail   add Importers fil...
44
45
  
      }
74072a2a   Mihail   add first version...
46
  
40ff24a1   Mihail   refactor CsvParse...
47
  }