| @@ 8-43 (lines=36) @@ | ||
| 5 | use Doctrine\ORM\Internal\Hydration\AbstractHydrator; |
|
| 6 | use PDO; |
|
| 7 | ||
| 8 | class ListHydrator extends AbstractHydrator |
|
| 9 | { |
|
| 10 | protected function hydrateAllData() |
|
| 11 | { |
|
| 12 | $result = $cache = array(); |
|
| 13 | ||
| 14 | foreach ($this->_stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
| 15 | $this->hydrateRowData($row, $cache, $result); |
|
| 16 | } |
|
| 17 | ||
| 18 | return $result; |
|
| 19 | } |
|
| 20 | ||
| 21 | protected function hydrateRowData(array $data, array &$cache, array &$result) |
|
| 22 | { |
|
| 23 | if (count($data) == 0) { |
|
| 24 | return false; |
|
| 25 | } |
|
| 26 | ||
| 27 | $keys = array_keys($data); |
|
| 28 | ||
| 29 | // Assume first column is id field |
|
| 30 | $id = $data[$keys[0]]; |
|
| 31 | ||
| 32 | if (count($data) == 2) { |
|
| 33 | // If only one more field assume that this is the value field |
|
| 34 | $value = $data[$keys[1]]; |
|
| 35 | } else { |
|
| 36 | // Remove ID field and add remaining fields as value array |
|
| 37 | array_shift($data); |
|
| 38 | $value = $data; |
|
| 39 | } |
|
| 40 | ||
| 41 | $result[$id] = $value; |
|
| 42 | } |
|
| 43 | } |
|
| @@ 11-46 (lines=36) @@ | ||
| 8 | /** |
|
| 9 | * Compatible with Doctrine ORM 2.5 |
|
| 10 | */ |
|
| 11 | class ListHydrator25 extends AbstractHydrator |
|
| 12 | { |
|
| 13 | protected function hydrateAllData() |
|
| 14 | { |
|
| 15 | $result = $cache = array(); |
|
| 16 | ||
| 17 | foreach ($this->_stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
| 18 | $this->hydrateRowData($row, $result); |
|
| 19 | } |
|
| 20 | ||
| 21 | return $result; |
|
| 22 | } |
|
| 23 | ||
| 24 | protected function hydrateRowData(array $data, array &$result) |
|
| 25 | { |
|
| 26 | if (count($data) == 0) { |
|
| 27 | return false; |
|
| 28 | } |
|
| 29 | ||
| 30 | $keys = array_keys($data); |
|
| 31 | ||
| 32 | // Assume first column is id field |
|
| 33 | $id = $data[$keys[0]]; |
|
| 34 | ||
| 35 | if (count($data) == 2) { |
|
| 36 | // If only one more field assume that this is the value field |
|
| 37 | $value = $data[$keys[1]]; |
|
| 38 | } else { |
|
| 39 | // Remove ID field and add remaining fields as value array |
|
| 40 | array_shift($data); |
|
| 41 | $value = $data; |
|
| 42 | } |
|
| 43 | ||
| 44 | $result[$id] = $value; |
|
| 45 | } |
|
| 46 | } |
|