/** * Finalizes the query, executes it and hydrates results * * @return array List of Propel objects */ public function doFind() { if ($cache = $this->cache) { $key = $this->getUniqueIdentifier(); $ret = $cache->getIfSet($key); if ($ret !== false) { return $ret; } } if ($this->getWithClasses() || $this->getWithColumns()) { $c = $this->prepareCompositeCriteria(); if (method_exists($this->peerClass, 'doSelectRS')) { $resultSet = call_user_func(array($this->peerClass, 'doSelectRS'), $c, $this->getConnection()); $propelVersion = '1.2'; $nextFunction = 'next'; $nextParam = null; } else { $resultSet = call_user_func(array($this->peerClass, 'doSelectStmt'), $c, $this->getConnection()); $propelVersion = '1.3'; $nextFunction = 'fetch'; $nextParam = PDO::FETCH_NUM; } // Hydrate the objects based on the resultset $omClass = call_user_func(array($this->peerClass, 'getOMClass')); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $objects = array(); $withObjs = array(); while ($row = $resultSet->{$nextFunction}($nextParam)) { // First come the columns of the main class $obj = new $cls(); if ($propelVersion == '1.2') { $startCol = $obj->hydrate($resultSet, 1); } else { $startCol = $obj->hydrate($row, 0); } if ($this->culture) { $obj->setCulture($this->culture); } // Then the related classes added by way of 'with' $objectsInJoin = array($obj); foreach ($this->getWithClasses() as $className) { $withObj = new $className(); if ($propelVersion == '1.2') { $startCol = $withObj->hydrate($resultSet, $startCol); } else { $startCol = $withObj->hydrate($row, $startCol); } // As we can be in a left join, there is a possibility that the hydrated related object is null // In this case, we must not relate it to the main object $isEmpty = true; foreach ($withObj->toArray() as $value) { if ($value !== null) { $isEmpty = false; } } if ($isEmpty) { continue; } // initialize our object directory if (!isset($withObjs[$className])) { $withObjs[$className] = array(); } // check if object is not already referenced in allObjects directory $isNewObject = true; foreach ($withObjs[$className] as $otherObject) { if ($otherObject->getPrimaryKey() === $withObj->getPrimaryKey()) { $isNewObject = false; $withObj = $otherObject; break; } } if (strpos(get_class($withObj), 'I18n') !== false) { sfPropelFinderUtils::relateI18nObjects($withObj, $objectsInJoin, $this->culture); } else { sfPropelFinderUtils::relateObjects($withObj, $objectsInJoin, $isNewObject); } $objectsInJoin[] = $withObj; if ($isNewObject) { $withObjs[$className][] = $withObj; } } // Then the columns added one by one by way of 'withColumn' foreach ($this->getWithColumns() as $alias => $column) { // Additional columns are stored in the object, in a special 'namespace' // see getColumn() for how to retrieve the value afterwards // Using the third parameter of withColumn() as a type. defaults to $rs->get() (= $rs->getString()) $typedGetter = 'get' . ucfirst($column['type']); if ($propelVersion == '1.2') { $this->setColumn($obj, $alias, $resultSet->{$typedGetter}($startCol)); } else { $this->setColumn($obj, $alias, $row[$startCol]); } $startCol++; } $objects[] = $obj; } // activate custom column getter if asColumns were added if ($this->getWithColumns() && !sfMixer::getCallable('Base' . $cls . ':getColumn')) { sfMixer::register('Base' . $cls, array($this, 'getColumn')); } } else { // No 'with', so we use the native Propel doSelect() $objects = call_user_func(array($this->peerClass, 'doSelect'), $this->buildCriteria(), $this->getConnection()); } if ($cache) { $cache->set($key, $objects); } return $objects; }