Beispiel #1
0
 /**
  * converts a Collection into a flat Array
  * properties are extracted from first item und inserted in first row
  *
  * @param mixed $collection \Cake\Collection\Collection | \Cake\ORM\Query
  * @return array
  */
 public function prepareCollectionData(Collection $collection = null)
 {
     /* extract keys from first item */
     $first = $collection->first();
     if (is_array($first)) {
         $data = [array_keys($first)];
     } else {
         $data = [array_keys($first->toArray())];
     }
     /* add data */
     foreach ($collection as $row) {
         if (is_array($row)) {
             $data[] = array_values($row);
         } else {
             $data[] = array_values($row->toArray());
         }
     }
     return $data;
 }