/** * Add a filter to this query * * This is the implementation for the Filterable, use where instead * * @param $filter */ public function addFilter($filter) { if (is_string($filter)) { $this->addFilter(call_user_func_array(array($this, 'parseFilterExpression'), func_get_args())); } elseif ($filter instanceof Node) { $this->filter->insert($filter); } }
/** * Renders this widget via the given view and returns the * HTML as a string * * @param \Zend_View_Abstract $view * @return string */ public function render(Zend_View_Abstract $view) { $this->urlFilter = new UrlViewFilter(); if ($this->tree->root == null) { return ''; } $this->buildBaseUrl(); return $this->nodeToBadge(Tree::normalizeTree($this->tree->root)); }
/** * Apply the given tree to the query, either as where or as having clause * * @param Tree $tree The tree representing the filter * @param \Zend_Db_Select $baseQuery The query to apply the filter on */ public function treeToSql(Tree $tree, $baseQuery) { if ($tree->root == null) { return; } $sql = $this->nodeToSqlQuery($tree->normalizeTree($tree->root)); if ($this->filtersAggregate()) { $baseQuery->having($sql); } else { $baseQuery->where($sql); } }
/** * Create a query tree containing this filter * * Query parts that couldn't be parsed can be retrieved with Filter::getIgnoredQueryParts * * @param String $query The query string to parse into a query tree * @return Tree The resulting query tree (empty for invalid queries) */ public function createQueryTreeForFilter($query) { $this->ignoredQueryParts = array(); $right = $query; $domain = null; $tree = new Tree(); do { list($left, $conjunction, $right) = $this->splitQueryAtNextConjunction($right); $domain = $this->getFirstDomainForQuery($left); if ($domain === null) { $this->ignoredQueryParts[] = $left; continue; } $node = $domain->convertToTreeNode($left); if (!$node) { $this->ignoredQueryParts[] = $left; continue; } $tree->insert($node); if ($conjunction === 'AND') { $tree->insert(Node::createAndNode()); } elseif ($conjunction === 'OR') { $tree->insert(Node::createOrNode()); } } while ($right !== null); return $tree; }
/** * Copy the given node or branch into the given tree * * @param Node $node The node to copy * @param Tree $tree The tree to insert the copied node and it's subnodes to */ private function copyBranch(Node $node, Tree &$tree) { if ($node->type === Node::TYPE_OPERATOR) { $copy = Node::createOperatorNode($node->operator, $node->left, $node->right); $copy->context = $node->context; $tree->insert($copy); } else { if ($node->left) { $this->copyBranch($node->left, $tree); } $tree->insert($node->type === Node::TYPE_OR ? Node::createOrNode() : Node::createAndNode()); if ($node->right) { $this->copyBranch($node->right, $tree); } } }