/** * Create a removable badge from a query tree node * * @param Node $node The node to create the badge for * @return string The html for the badge */ private function nodeToBadge(Node $node) { $basePath = $this->baseUrl->getAbsoluteUrl(); $allParams = $this->baseUrl->getParams(); if ($node->type === Node::TYPE_OPERATOR) { $newTree = $this->tree->withoutNode($node); $url = $this->urlFilter->fromTree($newTree); $url = $basePath . (empty($allParams) ? '?' : '&') . $url; $sumText = $this->getSummarizedText($node); $tpl = str_replace('{{FILTER_SUM}}', $sumText, $this->tpl); $tpl = str_replace('{{REMOVE_FILTER}}', $url, $tpl); if (count($node->right) > 1) { $tpl = str_replace('{{SUBLIST}}', $this->getSubEntries($node), $tpl); } else { $tpl = str_replace('{{SUBLIST}}', '', $tpl); } return $tpl; } $result = ''; $result .= $this->nodeToBadge($node->left); $this->conjunctionCellar = $node->type; $result .= $this->nodeToBadge($node->right); return $result; }