/** * Return the pivot table as array * * @return array */ public function toArray() { if ($this->xAxisFilter === null && $this->yAxisFilter === null || $this->xAxisFilter !== null && $this->yAxisFilter !== null) { $xAxis = $this->queryXAxis()->fetchColumn(); $yAxis = $this->queryYAxis()->fetchColumn(); } else { if ($this->xAxisFilter !== null) { $xAxis = $this->queryXAxis()->fetchColumn(); $yAxis = $this->queryYAxis()->where($this->xAxisColumn, $xAxis)->fetchColumn(); } else { // $this->yAxisFilter !== null $yAxis = $this->queryYAxis()->fetchColumn(); $xAxis = $this->queryXAxis()->where($this->yAxisColumn, $yAxis)->fetchColumn(); } } $pivot = array(); if (!empty($xAxis) && !empty($yAxis)) { $this->baseQuery->where($this->xAxisColumn, $xAxis)->where($this->yAxisColumn, $yAxis); foreach ($yAxis as $yLabel) { foreach ($xAxis as $xLabel) { $pivot[$yLabel][$xLabel] = null; } } foreach ($this->baseQuery as $row) { $pivot[$row->{$this->yAxisColumn}][$row->{$this->xAxisColumn}] = $row; } } return $pivot; }
/** * Return the pivot table as an array of pivot data and pivot header * * @return array */ public function toArray() { if ($this->xAxisFilter === null && $this->yAxisFilter === null || $this->xAxisFilter !== null && $this->yAxisFilter !== null) { $xAxis = $this->queryXAxis()->fetchPairs(); $yAxis = $this->queryYAxis()->fetchPairs(); } else { if ($this->xAxisFilter !== null) { $xAxis = $this->queryXAxis()->fetchPairs(); $yAxis = $this->queryYAxis()->where($this->xAxisColumn, $xAxis)->fetchPairs(); } else { // $this->yAxisFilter !== null $yAxis = $this->queryYAxis()->fetchPairs(); $xAxis = $this->queryXAxis()->where($this->yAxisColumn, $yAxis)->fetchPairs(); } } $pivotData = array(); $pivotHeader = array('cols' => $xAxis, 'rows' => $yAxis); if (!empty($xAxis) && !empty($yAxis)) { $xAxisKeys = array_keys($xAxis); $yAxisKeys = array_keys($yAxis); $this->baseQuery->where($this->xAxisColumn, $xAxisKeys)->where($this->yAxisColumn, $yAxisKeys); foreach ($yAxisKeys as $yAxisKey) { foreach ($xAxisKeys as $xAxisKey) { $pivotData[$yAxisKey][$xAxisKey] = null; } } foreach ($this->baseQuery as $row) { $pivotData[$row->{$this->yAxisColumn}][$row->{$this->xAxisColumn}] = $row; } } return array($pivotData, $pivotHeader); }
public function __clone() { parent::__clone(); $this->select = clone $this->select; }
/** * Choose an objectClass and the columns you are interested in * * {@inheritdoc} This creates an objectClass filter. */ public function from($target, array $fields = null) { $this->where('objectClass', $target); return parent::from($target, $fields); }
/** * 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; }
/** * Choose a document type and the fields you are interested in * * {@inheritdoc} This registers the given target as type filter. */ public function from($target, array $fields = null) { $this->setTypes(array($target)); return parent::from($target, $fields); }
/** * Choose an objectClass and the columns you are interested in * * {@inheritdoc} This creates an objectClass filter. */ public function from($target, array $fields = null) { $this->filters['objectClass'] = $target; return parent::from($target, $fields); }