Blame view

backend/components/parsers/CustomCsvParser.php 1.08 KB
d0a7acb3   Mihail   refactor CsvParse...
1
2
3
4
5
6
7
8
9
10
11
  <?php
  /**
   * Created by PhpStorm.
   * User: Cibermag
   * Date: 04.09.2015
   * Time: 16:07
   */
  
  namespace backend\components\parsers;
  
  
0c8b9dfc   Mihail   add error excepti...
12
  class CustomCsvParser extends  \yii\multiparser\CsvParser {
d0a7acb3   Mihail   refactor CsvParse...
13
  
3b7211a0   Mihail   change query for ...
14
      //public $last_line = 10;
7a80e74c   Mihail   add DynamicFormHe...
15
16
      //public $hasHeaderRow = true;
     // public $keys = ['first','second', 'third', 'forth', 'fifth'];
2a7a75b8   Mihail   add first version...
17
      public function setupConverter()
d0a7acb3   Mihail   refactor CsvParse...
18
      {
d7f6bdbb   Mihail   add Importers fil...
19
          if (!count($this->converter_conf)) {
33d902b8   Mihail   add converter as ...
20
21
22
23
24
              if ($this->hasHeaderRow) {
                  // если у файла есть заголовок, то в результате имеем ассоциативный массив
                  $this->converter_conf['hasKey'] = 1;
              }
  
d0a7acb3   Mihail   refactor CsvParse...
25
26
          }
  
d0a7acb3   Mihail   refactor CsvParse...
27
28
      }
  
d7f6bdbb   Mihail   add Importers fil...
29
30
31
32
33
34
35
36
37
38
39
40
      /**
       * @param $arr
       * @return mixed
       * преобразовует значения прочитанного массива в нужные типы, согласно конфигурации конвертера
       */
      protected function convert($arr)
      {
          $result = \Yii::$app->multiparser->convertByConfiguration( $arr, $this->converter_conf );
  
          return $result;
  
      }
2a7a75b8   Mihail   add first version...
41
  
d0a7acb3   Mihail   refactor CsvParse...
42
  }