Beispiel #1
0
 /**
  * Query vertical (y) axis
  *
  * @return  SimpleQuery
  */
 protected function queryYAxis()
 {
     if ($this->yAxisQuery === null) {
         $this->yAxisQuery = clone $this->baseQuery;
         $this->yAxisQuery->group($this->yAxisColumn);
         $this->yAxisQuery->columns(array($this->yAxisColumn));
         $this->yAxisQuery->setUseSubqueryCount();
         if ($this->yAxisFilter !== null) {
             $this->yAxisQuery->addFilter($this->yAxisFilter);
         }
         if (!$this->yAxisQuery->hasOrder($this->yAxisColumn)) {
             $this->yAxisQuery->order($this->yAxisColumn, 'asc');
         }
     }
     return $this->yAxisQuery;
 }
Beispiel #2
0
 /**
  * Create and return the result for the given query
  *
  * @param   SimpleQuery     $query
  *
  * @return  array
  */
 protected function createResult(SimpleQuery $query)
 {
     $columns = $query->getColumns();
     $filter = $query->getFilter();
     $offset = $query->hasOffset() ? $query->getOffset() : 0;
     $limit = $query->hasLimit() ? $query->getLimit() : 0;
     $foundStringKey = false;
     $result = array();
     $skipped = 0;
     foreach ($this->data as $key => $row) {
         if (is_string($key) && $this->keyColumn !== null && !isset($row->{$this->keyColumn})) {
             $row = clone $row;
             // Make sure that this won't affect the actual data
             $row->{$this->keyColumn} = $key;
         }
         if (!$filter->matches($row)) {
             continue;
         } elseif ($skipped < $offset) {
             $skipped++;
             continue;
         }
         // Get only desired columns if asked so
         if (!empty($columns)) {
             $filteredRow = (object) array();
             foreach ($columns as $alias => $name) {
                 if (!is_string($alias)) {
                     $alias = $name;
                 }
                 if (isset($row->{$name})) {
                     $filteredRow->{$alias} = $row->{$name};
                 } else {
                     $filteredRow->{$alias} = null;
                 }
             }
         } else {
             $filteredRow = $row;
         }
         $foundStringKey |= is_string($key);
         $result[$key] = $filteredRow;
         if (count($result) === $limit) {
             break;
         }
     }
     // Sort the result
     if ($query->hasOrder()) {
         if ($foundStringKey) {
             uasort($result, array($query, 'compare'));
         } else {
             usort($result, array($query, 'compare'));
         }
     } elseif (!$foundStringKey) {
         $result = array_values($result);
     }
     return $result;
 }