/**
  * Executes a DQL query and returns resources as entities or arrays.
  * If it returns arrays, it add a "pathfordisplay" field to each item.
  *
  * @param Query   $query   The query to execute
  * @param integer $offset  First row to start with
  * @param integer $numrows Maximum number of rows to return
  * @param boolean $asArray Whether the resources must be returned as arrays or as objects
  *
  * @return array[AbstractResource|array]
  */
 private function executeQuery($query, $offset = null, $numrows = null, $asArray = true)
 {
     $query->setFirstResult($offset);
     $query->setMaxResults($numrows);
     if ($asArray) {
         $resources = $query->getArrayResult();
         $return = $resources;
         // Add a field "pathfordisplay" in each entity (as array) of the given array.
         foreach ($resources as $key => $resource) {
             if (isset($resource['path'])) {
                 $return[$key]['path_for_display'] = ResourceNode::convertPathForDisplay($resource['path']);
             }
         }
         return $return;
     }
     return $query->getResult();
 }
Example #2
0
 /**
  * MAX RESULTS keyword
  *
  * @param Query  $query
  * @param string $inputString
  *
  * @return string
  */
 private function maxResults(Query $query, $inputString)
 {
     $maxResults = $this->getWord($inputString);
     $inputString = $this->trimString($inputString, $maxResults);
     $query->setMaxResults($maxResults);
     return $inputString;
 }