Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Processes a SQL query and returns proper objects
- * @param resource $mySqlResourceId The Pointer to the mySql resource of the query
- * @param string $objectType The object type the result rows shall get mapped on. Is falling back to objectType of the repository if not defined otherwhise.
- * @param string $returnAs The type the result shall be returned as. Valid are "array" and "Tx_Extbase_Persistence_ObjectStorage"
- * @return array/Tx_Extbase_Persistence_ObjectStorage depending on configuration
- */
- public function mapQueryResultsToObjects($mySqlResourceId, $offset=NULL, $limit=NULL, $objectType = NULL, $returnAs = 'array') {
- $returnAs = strtolower($returnAs);
- $objectType = $objectType ? $objectType : $this->objectType;
- $result = NULL;
- if($mySqlResourceId) {
- $result = ($returnAs == 'array' ? array() : t3lib_div::makeInstance('Tx_Extbase_Persistence_ObjectStorage'));
- $rowIterator = t3lib_div::makeInstance('Tx_Extbase_Persistence_RowIterator');
- if ($this->getEnableResultCount()) {
- $count = $GLOBALS['TYPO3_DB']->sql_num_rows($mySqlResourceId);
- $this->setLastResultCount($count);
- if ($count) {
- if ($offset && $offset > 0) {
- $GLOBALS['TYPO3_DB']->sql_data_seek($mySqlResourceId,intval($offset));
- }
- $iterationLimit = min($limit,$count);
- $cycle = 0;
- # fetch query results and map them to persistence rows expected by the dataMapper
- while ($cycle < $iterationLimit && $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mySqlResourceId)) {
- $cycle++;
- $rowIterator->append(t3lib_div::makeInstance('Tx_Extbase_Persistence_Row',$row));
- }
- }
- } else {
- # fetch query results and map them to persistence rows expected by the dataMapper
- while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mySqlResourceId)) {
- $rowIterator->append(t3lib_div::makeInstance('Tx_Extbase_Persistence_Row',$row));
- }
- }
- $GLOBALS['TYPO3_DB']->sql_free_result($mySqlResourceId);
- # map the query results to objects
- $dataMapper = Tx_Extbase_Dispatcher::getPersistenceManager()->getBackend()->getDataMapper();
- $objects = $dataMapper->map($objectType,$rowIterator);
- # prepare objects for the correct return type
- if(is_object($result)) {
- $result->addAll($objects);
- $result->_memorizeCleanState();
- } else {
- $result = $objects;
- }
- }
- return $result;
- }
Advertisement
Add Comment
Please, Sign In to add comment