2007-11-20 17:26:42 +03:00
|
|
|
<?php
|
|
|
|
/*
|
2008-02-20 23:54:20 +03:00
|
|
|
* $Id$
|
2007-11-20 17:26:42 +03:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
|
|
|
* and is licensed under the LGPL. For more information, see
|
2008-01-23 01:52:53 +03:00
|
|
|
* <http://www.phpdoctrine.org>.
|
2007-11-20 17:26:42 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2008-02-20 23:54:20 +03:00
|
|
|
* The hydrator has the tedious task to construct object or array graphs out of
|
|
|
|
* a database result set.
|
2007-11-20 17:26:42 +03:00
|
|
|
*
|
|
|
|
* @package Doctrine
|
2008-03-05 14:24:33 +03:00
|
|
|
* @subpackage Hydrator
|
2007-11-20 17:26:42 +03:00
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
2008-02-22 21:11:35 +03:00
|
|
|
* @link www.phpdoctrine.org
|
2007-11-20 17:26:42 +03:00
|
|
|
* @since 1.0
|
|
|
|
* @version $Revision: 3192 $
|
|
|
|
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
2008-02-20 23:54:20 +03:00
|
|
|
* @author Roman Borschel <roman@code-factory.org>
|
2007-11-20 17:26:42 +03:00
|
|
|
*/
|
2007-11-25 18:57:08 +03:00
|
|
|
class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
|
2007-11-21 14:55:05 +03:00
|
|
|
{
|
2007-11-20 17:26:42 +03:00
|
|
|
/**
|
|
|
|
* hydrateResultSet
|
|
|
|
* parses the data returned by statement object
|
|
|
|
*
|
2007-11-21 17:29:59 +03:00
|
|
|
* This is method defines the core of Doctrine's object population algorithm
|
2007-11-20 17:26:42 +03:00
|
|
|
* hence this method strives to be as fast as possible
|
|
|
|
*
|
|
|
|
* The key idea is the loop over the rowset only once doing all the needed operations
|
|
|
|
* within this massive loop.
|
|
|
|
*
|
|
|
|
* @todo: Detailed documentation. Refactor (too long & nesting level).
|
|
|
|
*
|
|
|
|
* @param mixed $stmt
|
2007-11-21 14:55:05 +03:00
|
|
|
* @param array $tableAliases Array that maps table aliases (SQL alias => DQL alias)
|
|
|
|
* @param array $aliasMap Array that maps DQL aliases to their components
|
2007-11-21 17:29:59 +03:00
|
|
|
* (DQL alias => array(
|
|
|
|
* 'table' => Table object,
|
|
|
|
* 'parent' => Parent DQL alias (if any),
|
|
|
|
* 'relation' => Relation object (if any),
|
2007-11-25 22:07:30 +03:00
|
|
|
* 'map' => Custom index to use as the key in the result (if any)
|
2007-11-21 17:29:59 +03:00
|
|
|
* )
|
2007-11-21 14:55:05 +03:00
|
|
|
* )
|
2008-02-20 23:54:20 +03:00
|
|
|
* @return mixed The created object/array graph.
|
2007-11-20 17:26:42 +03:00
|
|
|
*/
|
2007-11-21 17:29:59 +03:00
|
|
|
public function hydrateResultSet($stmt, $tableAliases, $hydrationMode = null)
|
2007-11-20 17:26:42 +03:00
|
|
|
{
|
2008-02-04 00:29:57 +03:00
|
|
|
if ($hydrationMode === null) {
|
|
|
|
$hydrationMode = $this->_hydrationMode;
|
|
|
|
}
|
2007-11-20 17:26:42 +03:00
|
|
|
|
|
|
|
if ($hydrationMode == Doctrine::HYDRATE_NONE) {
|
|
|
|
return $stmt->fetchAll(PDO::FETCH_NUM);
|
|
|
|
}
|
|
|
|
|
2008-02-04 00:29:57 +03:00
|
|
|
$this->_tableAliases = $tableAliases;
|
2007-11-20 17:26:42 +03:00
|
|
|
|
2008-02-13 18:27:49 +03:00
|
|
|
if ($hydrationMode == Doctrine::HYDRATE_ARRAY) {
|
2007-11-25 18:57:08 +03:00
|
|
|
$driver = new Doctrine_Hydrator_ArrayDriver();
|
2007-11-20 17:26:42 +03:00
|
|
|
} else {
|
2007-11-25 18:57:08 +03:00
|
|
|
$driver = new Doctrine_Hydrator_RecordDriver();
|
2007-11-20 17:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$event = new Doctrine_Event(null, Doctrine_Event::HYDRATE, null);
|
|
|
|
|
|
|
|
|
|
|
|
// Used variables during hydration
|
2007-11-21 17:29:59 +03:00
|
|
|
reset($this->_queryComponents);
|
|
|
|
$rootAlias = key($this->_queryComponents);
|
2008-01-05 22:55:56 +03:00
|
|
|
$rootComponentName = $this->_queryComponents[$rootAlias]['mapper']->getComponentName();
|
2007-11-21 17:29:59 +03:00
|
|
|
// if only one component is involved we can make our lives easier
|
|
|
|
$isSimpleQuery = count($this->_queryComponents) <= 1;
|
|
|
|
// Holds the resulting hydrated data structure
|
|
|
|
$result = array();
|
|
|
|
// Holds hydration listeners that get called during hydration
|
|
|
|
$listeners = array();
|
|
|
|
// Lookup map to quickly discover/lookup existing records in the result
|
|
|
|
$identifierMap = array();
|
|
|
|
// Holds for each component the last previously seen element in the result set
|
|
|
|
$prev = array();
|
|
|
|
// holds the values of the identifier/primary key fields of components,
|
|
|
|
// separated by a pipe '|' and grouped by component alias (r, u, i, ... whatever)
|
|
|
|
$id = array();
|
2007-11-20 17:26:42 +03:00
|
|
|
|
2007-11-21 17:29:59 +03:00
|
|
|
$result = $driver->getElementCollection($rootComponentName);
|
2007-11-20 17:26:42 +03:00
|
|
|
|
|
|
|
if ($stmt === false || $stmt === 0) {
|
2007-11-21 14:55:05 +03:00
|
|
|
return $result;
|
2007-11-20 17:26:42 +03:00
|
|
|
}
|
|
|
|
|
2007-11-21 17:29:59 +03:00
|
|
|
// Initialize
|
2008-03-05 14:24:33 +03:00
|
|
|
foreach ($this->_queryComponents as $dqlAlias => $component) {
|
|
|
|
// disable lazy-loading of related elements during hydration
|
|
|
|
$component['mapper']->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false);
|
|
|
|
$componentName = $component['mapper']->getComponentName();
|
|
|
|
$listeners[$componentName] = $component['mapper']->getRecordListener();
|
2007-11-21 17:29:59 +03:00
|
|
|
$identifierMap[$dqlAlias] = array();
|
|
|
|
$prev[$dqlAlias] = array();
|
|
|
|
$id[$dqlAlias] = '';
|
2007-11-20 17:26:42 +03:00
|
|
|
}
|
|
|
|
|
2007-11-21 14:55:05 +03:00
|
|
|
// Process result set
|
|
|
|
$cache = array();
|
2007-11-20 17:26:42 +03:00
|
|
|
while ($data = $stmt->fetch(Doctrine::FETCH_ASSOC)) {
|
2007-11-21 17:29:59 +03:00
|
|
|
$nonemptyComponents = array();
|
|
|
|
$rowData = $this->_gatherRowData($data, $cache, $id, $nonemptyComponents);
|
2007-11-20 17:26:42 +03:00
|
|
|
|
2007-11-21 14:55:05 +03:00
|
|
|
//
|
|
|
|
// hydrate the data of the root component from the current row
|
|
|
|
//
|
2007-11-21 17:29:59 +03:00
|
|
|
$table = $this->_queryComponents[$rootAlias]['table'];
|
2008-01-05 22:55:56 +03:00
|
|
|
$mapper = $this->_queryComponents[$rootAlias]['mapper'];
|
|
|
|
$componentName = $mapper->getComponentName();
|
2007-11-21 14:55:05 +03:00
|
|
|
$event->set('data', $rowData[$rootAlias]);
|
2007-11-20 17:26:42 +03:00
|
|
|
$listeners[$componentName]->preHydrate($event);
|
2007-11-21 14:55:05 +03:00
|
|
|
$element = $driver->getElement($rowData[$rootAlias], $componentName);
|
|
|
|
$index = false;
|
|
|
|
|
|
|
|
// Check for an existing element
|
|
|
|
if ($isSimpleQuery || ! isset($identifierMap[$rootAlias][$id[$rootAlias]])) {
|
2007-11-20 17:26:42 +03:00
|
|
|
$event->set('data', $element);
|
|
|
|
$listeners[$componentName]->postHydrate($event);
|
|
|
|
|
2007-11-21 14:55:05 +03:00
|
|
|
// do we need to index by a custom field?
|
|
|
|
if ($field = $this->_getCustomIndexField($rootAlias)) {
|
|
|
|
if (isset($result[$field])) {
|
2007-11-21 17:29:59 +03:00
|
|
|
throw new Doctrine_Hydrator_Exception("Couldn't hydrate. Found non-unique key mapping.");
|
2007-11-21 14:55:05 +03:00
|
|
|
} else if ( ! isset($element[$field])) {
|
2007-11-21 17:29:59 +03:00
|
|
|
throw new Doctrine_Hydrator_Exception("Couldn't hydrate. Found a non-existent key.");
|
2007-11-20 17:26:42 +03:00
|
|
|
}
|
2007-11-21 14:55:05 +03:00
|
|
|
$result[$element[$field]] = $element;
|
2007-11-20 17:26:42 +03:00
|
|
|
} else {
|
2007-11-21 14:55:05 +03:00
|
|
|
$result[] = $element;
|
2007-11-20 17:26:42 +03:00
|
|
|
}
|
|
|
|
|
2007-11-21 14:55:05 +03:00
|
|
|
$identifierMap[$rootAlias][$id[$rootAlias]] = $driver->getLastKey($result);
|
|
|
|
} else {
|
|
|
|
$index = $identifierMap[$rootAlias][$id[$rootAlias]];
|
2007-11-20 17:26:42 +03:00
|
|
|
}
|
|
|
|
|
2007-11-21 14:55:05 +03:00
|
|
|
$this->_setLastElement($prev, $result, $index, $rootAlias, false);
|
|
|
|
unset($rowData[$rootAlias]);
|
|
|
|
|
|
|
|
// end hydrate data of the root component for the current row
|
|
|
|
|
2007-11-21 17:29:59 +03:00
|
|
|
|
|
|
|
// $prev[$rootAlias] now points to the last element in $result.
|
2007-11-21 14:55:05 +03:00
|
|
|
// now hydrate the rest of the data found in the current row, that belongs to other
|
2007-11-21 17:29:59 +03:00
|
|
|
// (related) components.
|
2007-11-21 14:55:05 +03:00
|
|
|
$oneToOne = false;
|
2007-11-21 17:29:59 +03:00
|
|
|
foreach ($rowData as $dqlAlias => $data) {
|
2007-11-20 17:26:42 +03:00
|
|
|
$index = false;
|
2007-11-21 17:29:59 +03:00
|
|
|
$map = $this->_queryComponents[$dqlAlias];
|
|
|
|
$table = $map['table'];
|
2008-01-05 22:55:56 +03:00
|
|
|
$mapper = $map['mapper'];
|
|
|
|
$componentName = $mapper->getComponentName();
|
2007-11-20 17:26:42 +03:00
|
|
|
$event->set('data', $data);
|
|
|
|
$listeners[$componentName]->preHydrate($event);
|
|
|
|
|
|
|
|
$element = $driver->getElement($data, $componentName);
|
|
|
|
|
|
|
|
$parent = $map['parent'];
|
|
|
|
$relation = $map['relation'];
|
2007-11-21 17:29:59 +03:00
|
|
|
$relationAlias = $map['relation']->getAlias();
|
2007-11-20 17:26:42 +03:00
|
|
|
|
2007-11-21 17:29:59 +03:00
|
|
|
$path = $parent . '.' . $dqlAlias;
|
2007-11-20 17:26:42 +03:00
|
|
|
|
|
|
|
if ( ! isset($prev[$parent])) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check the type of the relation
|
2007-11-21 17:29:59 +03:00
|
|
|
if ( ! $relation->isOneToOne() && $driver->initRelated($prev[$parent], $relationAlias)) {
|
2007-11-21 14:55:05 +03:00
|
|
|
// append element
|
2007-11-21 17:29:59 +03:00
|
|
|
if (isset($nonemptyComponents[$dqlAlias])) {
|
|
|
|
if ($isSimpleQuery || ! isset($identifierMap[$path][$id[$parent]][$id[$dqlAlias]])) {
|
2007-11-21 14:55:05 +03:00
|
|
|
$event->set('data', $element);
|
|
|
|
$listeners[$componentName]->postHydrate($event);
|
|
|
|
|
2007-11-21 17:29:59 +03:00
|
|
|
if ($field = $this->_getCustomIndexField($dqlAlias)) {
|
|
|
|
if (isset($prev[$parent][$relationAlias][$field])) {
|
2008-01-05 22:55:56 +03:00
|
|
|
throw new Doctrine_Hydrator_Exception("Hydration failed. Found non-unique key mapping.");
|
2007-11-21 14:55:05 +03:00
|
|
|
} else if ( ! isset($element[$field])) {
|
2008-01-05 22:55:56 +03:00
|
|
|
throw new Doctrine_Hydrator_Exception("Hydration failed. Found a non-existent field '$field'.");
|
2007-11-21 14:55:05 +03:00
|
|
|
}
|
2007-11-21 17:29:59 +03:00
|
|
|
$prev[$parent][$relationAlias][$element[$field]] = $element;
|
2007-11-20 17:26:42 +03:00
|
|
|
} else {
|
2007-11-21 17:29:59 +03:00
|
|
|
$prev[$parent][$relationAlias][] = $element;
|
2007-11-20 17:26:42 +03:00
|
|
|
}
|
|
|
|
|
2007-11-21 17:29:59 +03:00
|
|
|
$identifierMap[$path][$id[$parent]][$id[$dqlAlias]] = $driver->getLastKey($prev[$parent][$relationAlias]);
|
2007-11-21 14:55:05 +03:00
|
|
|
} else {
|
2007-11-21 17:29:59 +03:00
|
|
|
$index = $identifierMap[$path][$id[$parent]][$id[$dqlAlias]];
|
2007-11-20 17:26:42 +03:00
|
|
|
}
|
|
|
|
}
|
2007-11-21 14:55:05 +03:00
|
|
|
// register collection for later snapshots
|
2007-11-21 17:29:59 +03:00
|
|
|
$driver->registerCollection($prev[$parent][$relationAlias]);
|
2007-11-20 17:26:42 +03:00
|
|
|
} else {
|
2007-11-21 17:29:59 +03:00
|
|
|
// 1-1 relation
|
|
|
|
$oneToOne = true;
|
|
|
|
if ( ! isset($nonemptyComponents[$dqlAlias])) {
|
|
|
|
$prev[$parent][$relationAlias] = $driver->getNullPointer();
|
2007-11-20 17:26:42 +03:00
|
|
|
} else {
|
2007-11-21 17:29:59 +03:00
|
|
|
$prev[$parent][$relationAlias] = $element;
|
2007-11-20 17:26:42 +03:00
|
|
|
}
|
|
|
|
}
|
2007-11-21 17:29:59 +03:00
|
|
|
$coll =& $prev[$parent][$relationAlias];
|
|
|
|
$this->_setLastElement($prev, $coll, $index, $dqlAlias, $oneToOne);
|
|
|
|
$id[$dqlAlias] = '';
|
2007-11-20 17:26:42 +03:00
|
|
|
}
|
|
|
|
$id[$rootAlias] = '';
|
|
|
|
}
|
2008-02-20 23:54:20 +03:00
|
|
|
|
2007-11-20 17:26:42 +03:00
|
|
|
$stmt->closeCursor();
|
|
|
|
|
2007-11-21 17:29:59 +03:00
|
|
|
$driver->flush();
|
|
|
|
|
2008-01-12 22:49:11 +03:00
|
|
|
// re-enable lazy loading
|
|
|
|
foreach ($this->_queryComponents as $dqlAlias => $data) {
|
|
|
|
$data['mapper']->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, true);
|
|
|
|
}
|
|
|
|
|
2007-11-21 14:58:39 +03:00
|
|
|
//$e = microtime(true);
|
2007-11-21 14:55:05 +03:00
|
|
|
//echo 'Hydration took: ' . ($e - $s) . ' for '.count($result).' records<br />';
|
2007-11-21 17:29:59 +03:00
|
|
|
|
2007-11-21 14:55:05 +03:00
|
|
|
return $result;
|
2007-11-20 17:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _setLastElement
|
|
|
|
*
|
|
|
|
* sets the last element of given data array / collection
|
|
|
|
* as previous element
|
|
|
|
*
|
|
|
|
* @param boolean|integer $index
|
|
|
|
* @return void
|
|
|
|
* @todo Detailed documentation
|
|
|
|
*/
|
2007-11-21 17:29:59 +03:00
|
|
|
protected function _setLastElement(&$prev, &$coll, $index, $dqlAlias, $oneToOne)
|
2007-11-20 17:26:42 +03:00
|
|
|
{
|
|
|
|
if ($coll === self::$_null) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-11-21 14:55:05 +03:00
|
|
|
|
2007-11-20 17:26:42 +03:00
|
|
|
if ($index !== false) {
|
2007-11-21 17:29:59 +03:00
|
|
|
// Link element at $index to previous element for the component
|
2007-11-21 14:55:05 +03:00
|
|
|
// identified by the DQL alias $alias
|
2007-11-21 17:29:59 +03:00
|
|
|
$prev[$dqlAlias] =& $coll[$index];
|
2007-11-20 17:26:42 +03:00
|
|
|
return;
|
|
|
|
}
|
2007-11-21 14:55:05 +03:00
|
|
|
|
|
|
|
if (is_array($coll) && $coll) {
|
|
|
|
if ($oneToOne) {
|
2007-11-21 17:29:59 +03:00
|
|
|
$prev[$dqlAlias] =& $coll;
|
2007-11-20 17:26:42 +03:00
|
|
|
} else {
|
2007-11-21 14:55:05 +03:00
|
|
|
end($coll);
|
2007-11-21 17:29:59 +03:00
|
|
|
$prev[$dqlAlias] =& $coll[key($coll)];
|
2007-11-20 17:26:42 +03:00
|
|
|
}
|
2008-02-08 01:21:18 +03:00
|
|
|
} else if ($coll instanceof Doctrine_Record) {
|
|
|
|
$prev[$dqlAlias] = $coll;
|
2007-11-21 14:55:05 +03:00
|
|
|
} else if (count($coll) > 0) {
|
2007-11-21 17:29:59 +03:00
|
|
|
$prev[$dqlAlias] = $coll->getLast();
|
|
|
|
} else if (isset($prev[$dqlAlias])) {
|
|
|
|
unset($prev[$dqlAlias]);
|
2007-11-21 14:55:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Puts the fields of a data row into a new array, grouped by the component
|
|
|
|
* they belong to. The column names in the result set are mapped to their
|
|
|
|
* field names during this procedure.
|
|
|
|
*
|
|
|
|
* @return array An array with all the fields (name => value) of the data row,
|
|
|
|
* grouped by their component (alias).
|
|
|
|
*/
|
2007-11-21 17:29:59 +03:00
|
|
|
protected function _gatherRowData(&$data, &$cache, &$id, &$nonemptyComponents)
|
2007-11-21 14:55:05 +03:00
|
|
|
{
|
|
|
|
$rowData = array();
|
2008-03-05 14:24:33 +03:00
|
|
|
//$className = null;
|
2008-01-11 16:53:30 +03:00
|
|
|
|
2007-11-21 14:55:05 +03:00
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
// Parse each column name only once. Cache the results.
|
|
|
|
if ( ! isset($cache[$key])) {
|
2008-02-20 23:54:20 +03:00
|
|
|
// cache general information like the column name <-> field name mapping
|
2007-11-21 14:55:05 +03:00
|
|
|
$e = explode('__', $key);
|
2008-03-05 14:24:33 +03:00
|
|
|
$columnName = strtolower(array_pop($e));
|
2007-11-21 17:29:59 +03:00
|
|
|
$cache[$key]['dqlAlias'] = $this->_tableAliases[strtolower(implode('__', $e))];
|
2008-01-12 22:49:11 +03:00
|
|
|
$mapper = $this->_queryComponents[$cache[$key]['dqlAlias']]['mapper'];
|
2008-03-05 14:24:33 +03:00
|
|
|
$classMetadata = $mapper->getClassMetadata();
|
|
|
|
$fieldName = $mapper->getFieldName($columnName);
|
2007-11-21 14:55:05 +03:00
|
|
|
$cache[$key]['fieldName'] = $fieldName;
|
2008-02-20 23:54:20 +03:00
|
|
|
|
2008-03-05 14:24:33 +03:00
|
|
|
// determine the class name
|
|
|
|
/*if ( ! $className) {
|
|
|
|
if ($classMetadata->isDiscriminatorColumn($columnName)) {
|
|
|
|
$className = $this->_getClassnameToReturn();
|
|
|
|
} else if ( ! $className) {
|
|
|
|
$className = $classMetadata->getClassName();
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
2008-02-20 23:54:20 +03:00
|
|
|
// cache identifier information
|
2008-03-05 14:24:33 +03:00
|
|
|
if ($classMetadata->isIdentifier($fieldName)) {
|
2007-12-01 23:10:29 +03:00
|
|
|
$cache[$key]['isIdentifier'] = true;
|
2007-12-02 18:04:51 +03:00
|
|
|
} else {
|
|
|
|
$cache[$key]['isIdentifier'] = false;
|
|
|
|
}
|
2008-02-20 23:54:20 +03:00
|
|
|
|
|
|
|
// cache type information
|
2008-03-05 14:24:33 +03:00
|
|
|
$type = $classMetadata->getTypeOfColumn($columnName);
|
2007-12-02 18:04:51 +03:00
|
|
|
if ($type == 'integer' || $type == 'string') {
|
|
|
|
$cache[$key]['isSimpleType'] = true;
|
|
|
|
} else {
|
2008-02-20 23:54:20 +03:00
|
|
|
$cache[$key]['type'] = $type;
|
2007-12-02 18:04:51 +03:00
|
|
|
$cache[$key]['isSimpleType'] = false;
|
2007-12-01 23:10:29 +03:00
|
|
|
}
|
2007-11-21 14:55:05 +03:00
|
|
|
}
|
|
|
|
|
2008-01-12 22:49:11 +03:00
|
|
|
$mapper = $this->_queryComponents[$cache[$key]['dqlAlias']]['mapper'];
|
2007-11-21 17:29:59 +03:00
|
|
|
$dqlAlias = $cache[$key]['dqlAlias'];
|
2007-11-21 14:55:05 +03:00
|
|
|
$fieldName = $cache[$key]['fieldName'];
|
|
|
|
|
2007-11-21 17:29:59 +03:00
|
|
|
if (isset($this->_queryComponents[$dqlAlias]['agg'][$fieldName])) {
|
|
|
|
$fieldName = $this->_queryComponents[$dqlAlias]['agg'][$fieldName];
|
2007-11-21 14:55:05 +03:00
|
|
|
}
|
|
|
|
|
2007-12-02 18:04:51 +03:00
|
|
|
if ($cache[$key]['isIdentifier']) {
|
2007-11-21 17:29:59 +03:00
|
|
|
$id[$dqlAlias] .= '|' . $value;
|
2007-11-21 14:55:05 +03:00
|
|
|
}
|
|
|
|
|
2007-12-02 18:04:51 +03:00
|
|
|
if ($cache[$key]['isSimpleType']) {
|
|
|
|
$rowData[$dqlAlias][$fieldName] = $value;
|
|
|
|
} else {
|
2008-02-20 23:54:20 +03:00
|
|
|
$rowData[$dqlAlias][$fieldName] = $mapper->prepareValue(
|
|
|
|
$fieldName, $value, $cache[$key]['type']);
|
2007-12-02 18:04:51 +03:00
|
|
|
}
|
2007-11-21 14:55:05 +03:00
|
|
|
|
2007-11-21 17:29:59 +03:00
|
|
|
if ( ! isset($nonemptyComponents[$dqlAlias]) && $value !== null) {
|
|
|
|
$nonemptyComponents[$dqlAlias] = true;
|
2007-11-20 17:26:42 +03:00
|
|
|
}
|
|
|
|
}
|
2007-11-21 14:55:05 +03:00
|
|
|
|
|
|
|
return $rowData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the custom field used for indexing for the specified component alias.
|
|
|
|
*
|
|
|
|
* @return string The field name of the field used for indexing or NULL
|
|
|
|
* if the component does not use any custom field indices.
|
|
|
|
*/
|
|
|
|
protected function _getCustomIndexField($alias)
|
|
|
|
{
|
2007-11-21 17:29:59 +03:00
|
|
|
return isset($this->_queryComponents[$alias]['map']) ? $this->_queryComponents[$alias]['map'] : null;
|
2007-11-20 17:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|