Ejemplo n.º 1
0
 /**
  * Convert a node value to it's sql equivalent
  *
  * This currently only detects if the node is in the timestring context and calls strtotime if so and it replaces
  * '*' with '%'
  *
  * @param Node $node                The node to retrieve the sql string value from
  * @return String|int               The converted and quoted value
  */
 private function addValueToQuery(Node $node, $query)
 {
     $values = array();
     foreach ($node->right as $value) {
         if ($node->operator === Node::OPERATOR_EQUALS || $node->operator === Node::OPERATOR_EQUALS_NOT) {
             $value = str_replace('*', '%', $value);
         }
         if ($this->query->isTimestamp($node->left)) {
             $node->context = Node::CONTEXT_TIMESTRING;
         }
         if ($node->context === Node::CONTEXT_TIMESTRING && !is_numeric($value)) {
             $value = strtotime($value);
         }
         if (preg_match('/^\\d+$/', $value)) {
             $values[] = $value;
         } else {
             $values[] = $this->query->getDatasource()->getConnection()->quote($value);
         }
     }
     $valueString = join(',', $values);
     if (count($values) > 1) {
         return $query . '( ' . $valueString . ')';
     }
     return $query . $valueString;
 }
Ejemplo n.º 2
0
 /**
  * Return the pivot table as array
  *
  * @return  array
  */
 public function toArray()
 {
     $pivot = array();
     $xAxis = $this->xAxisQuery->fetchColumn();
     $yAxis = $this->yAxisQuery->fetchColumn();
     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->fetchAll() as $row) {
             $pivot[$row->{$this->yAxisColumn}][$row->{$this->xAxisColumn}] = $row;
         }
     }
     return $pivot;
 }