Source of file GroupbyHydrator.php
Size: 1,070 Bytes - Last Modified: 2023-11-16T22:56:02+01:00
/home/websites/teicee/packagist/site/phpdoc/conf/../vendor/teicee/dorm-bundle/src/Hydration/GroupbyHydrator.php
| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 | <?phpnamespace TIC\DormBundle\Hydration; use Doctrine\ORM\Internal\Hydration\AbstractHydrator; /** * Récupération des résultats groupés par les valeurs de la 1ère colonne (en index). * * Exemple: * > SELECT a, b, c FROM t * < array( * a1 => array( * array('b' => b1, 'c' => c1), * ), * a2 => array( * array('b' => b2, 'c' => c2), * array('b' => b22, 'c' => c22), * ), * ... * ) */class GroupbyHydrator extends AbstractHydrator {/** * Hydrates all rows from the current statement instance at once. * * @return mixed[] */protected function hydrateAllData(): array { # return $this->_stmt->fetchAll(\PDO::FETCH_ASSOC|\PDO::FETCH_GROUP); $result = array(); while ($data = $this->statement()->fetchAssociative()) { $key = \array_shift($data); if ($key === null) $key = '[_NULL_]'; elseif ($key === '') $key = '[_EMPTY_]'; if (! isset($result[ $key ])) $result[ $key ] = array(); $result[ $key ][] = $data; } return $result; } } |