예제 #1
0
 /**
  * Parse records value by its column data type
  *
  * @param array $records
  * @param $nonAliasSchemaColumns
  *
  * @return array
  */
 public function parseRecordValuesByType(array $records, $nonAliasSchemaColumns)
 {
     // hotfix: records sometimes are no set as an array of rows.
     $singleRecord = false;
     if (!is_numeric_keys_array($records)) {
         $records = [$records];
         $singleRecord = true;
     }
     foreach ($nonAliasSchemaColumns as $column) {
         foreach ($records as $index => $record) {
             $col = $column['id'];
             if (array_key_exists($col, $record)) {
                 $records[$index][$col] = $this->parseType($record[$col], $column['type']);
             }
         }
     }
     return $singleRecord ? reset($records) : $records;
 }
예제 #2
0
 public function testIsNumericKeyArray()
 {
     $array = ['name', 'age', 'country'];
     $this->assertTrue(is_numeric_keys_array($array));
     $this->assertFalse(is_numeric_keys_array(['name' => 'john', 'age' => 1, 'country' => 'yes']));
 }
예제 #3
0
 public function convertDates(array $records, array $schemaArray, $tableName = null)
 {
     $tableName = $tableName === null ? $this->table : $tableName;
     if (!SchemaManager::isDirectusTable($tableName)) {
         return $records;
     }
     // ==========================================================================
     // hotfix: records sometimes are no set as an array of rows.
     // NOTE: this code is duplicate @see: AbstractSchema::parseRecordValuesByType
     // ==========================================================================
     $singleRecord = false;
     if (!is_numeric_keys_array($records)) {
         $records = [$records];
         $singleRecord = true;
     }
     foreach ($records as $index => $row) {
         foreach ($schemaArray as $column) {
             if (in_array(strtolower($column['type']), ['timestamp', 'datetime'])) {
                 $columnName = $column['id'];
                 if (array_key_exists($columnName, $row)) {
                     $records[$index][$columnName] = DateUtils::convertToISOFormat($row[$columnName], 'UTC', get_user_timezone());
                 }
             }
         }
     }
     return $singleRecord ? reset($records) : $records;
 }