コード例 #1
0
 /**
  * Reads file content and convert into array or object
  * 
  * @params string	$filePath
  * @return object
  *  
  */
 private function parseData($filePath)
 {
     $catID = \app\models\Categories::getCategoryID('Construction');
     $content = file_get_contents($filePath);
     $data = array_map('str_getcsv', file($filePath));
     array_walk($data, function (&$a) use($data) {
         $a = array_combine($data[0], $a);
     });
     array_shift($data);
     $parsedData = array();
     foreach ($data as $key => $item) {
         $parsedData[$key] = (object) array();
         $parsedData[$key]->date = date("Y-m-d", strtotime($item['date']));
         $parsedData[$key]->lot_title = $item['lot title'];
         $parsedData[$key]->lot_location = $item['lot location'];
         $parsedData[$key]->pre_tax_amount = $item['pre-tax amount'];
         $parsedData[$key]->tax_amount = $item['tax amount'];
         $parsedData[$key]->category = \app\models\Categories::getCategoryID($item['category']);
         $parsedData[$key]->lot_condition = \app\models\LotCondition::getLotConditionID($item['lot condition']);
         $parsedData[$key]->tax_name = \app\models\TaxName::getTaxNameID($item['tax name']);
         if (is_null($parsedData[$key]->category)) {
             // category does not exist, so add it
             $parsedData[$key]->category = \app\models\Categories::addCategory($item['category']);
         }
         if (is_null($parsedData[$key]->lot_condition)) {
             // lot condition does not exist, so add it
             $parsedData[$key]->lot_condition = \app\models\LotCondition::addLotCondition($item['lot condition']);
         }
         if (is_null($parsedData[$key]->tax_name)) {
             // tax name does not exist, so add it
             $parsedData[$key]->tax_name = \app\models\TaxName::addTaxName($item['tax name']);
         }
     }
     return $parsedData;
 }