Blame view

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