/** * Helper function used to iterate a statement and extract the columns * defined in $collectKeys * * @param \Cake\Database\StatementInterface $statement The statement to read from. * @param array $collectKeys The keys to collect * @return array */ protected function _groupKeys($statement, $collectKeys) { $keys = []; while ($result = $statement->fetch('assoc')) { foreach ($collectKeys as $parts) { // Missed joins will have null in the results. if ($parts[2] && !isset($result[$parts[1][0]])) { continue; } if ($parts[2]) { $keys[$parts[0]][] = $result[$parts[1][0]]; continue; } $collected = []; foreach ($parts[1] as $key) { $collected[] = $result[$key]; } $keys[$parts[0]][] = $collected; } } $statement->rewind(); return $keys; }
/** * Helper function used to iterate a statement and extract the columns * defined in $collectKeys * * @param \Cake\Database\StatementInterface $statement The statement to read from. * @param array $collectKeys The keys to collect * @return array */ protected function _groupKeys($statement, $collectKeys) { $keys = []; while ($result = $statement->fetch('assoc')) { foreach ($collectKeys as $nestKey => $parts) { // Missed joins will have null in the results. if ($parts[2] === true && !isset($result[$parts[1][0]])) { continue; } if ($parts[2] === true) { $value = $result[$parts[1][0]]; $keys[$nestKey][$parts[0]][$value] = $value; continue; } // Handle composite keys. $collected = []; foreach ($parts[1] as $key) { $collected[] = $result[$key]; } $keys[$nestKey][$parts[0]][implode(';', $collected)] = $collected; } } $statement->rewind(); return $keys; }
/** * Helper function used to iterate an statement and extract the columns * defined in $collectKeys * * @param \Cake\Database\StatementInterface $statement * @param array $collectKeys * @return array */ protected function _groupKeys($statement, $collectKeys) { $keys = []; while ($result = $statement->fetch('assoc')) { foreach ($collectKeys as $parts) { if ($parts[2]) { $keys[$parts[0]][] = $result[$parts[1][0]]; continue; } $collected = []; foreach ($parts[1] as $key) { $collected[] = $result[$key]; } $keys[$parts[0]][] = $collected; } } $statement->rewind(); return $keys; }