/** * Create filters according to any translation criteria OR argument. * * @param array $criteria * @param QueryBuilder $qb * @param Translation $translation */ protected function filterByTranslation(&$criteria, &$qb, &$translation = null) { if (isset($criteria['translation']) || isset($criteria['translation.locale']) || isset($criteria['translation.id'])) { $qb->innerJoin('d.documentTranslations', 'dt'); $qb->innerJoin('dt.translation', 't'); } else { if (null !== $translation) { /* * With a given translation */ $qb->innerJoin('d.documentTranslations', 'dt', 'WITH', 'dt.translation = :translation'); } else { /* * With a null translation, just take the default one. */ $qb->innerJoin('d.documentTranslations', 'dt'); $qb->innerJoin('dt.translation', 't', 'WITH', 't.defaultTranslation = true'); } } }
/** * Reimplementing findBy features… with extra things. * * * key => array('<=', $value) * * key => array('<', $value) * * key => array('>=', $value) * * key => array('>', $value) * * key => array('BETWEEN', $value, $value) * * key => array('LIKE', $value) * * key => array('NOT IN', $array) * * key => 'NOT NULL' * * You even can filter with node fields, examples: * * * `node.published => true` * * `node.nodeName => 'page1'` * * @param array $criteria * @param QueryBuilder $qb * @param boolean $joinedNode * @param boolean $joinedNodeType */ protected function filterByCriteria(&$criteria, &$qb, &$joinedNode = false, &$joinedNodeType = false) { /* * Reimplementing findBy features… */ foreach ($criteria as $key => $value) { if ($key == "tags" || $key == "tagExclusive") { continue; } /* * compute prefix for * filtering node relation fields */ $prefix = 'ns.'; // Dots are forbidden in field definitions $baseKey = str_replace('.', '_', $key); if (false !== strpos($key, 'node.nodeType.')) { if (!$joinedNode) { $qb->innerJoin('ns.node', 'n'); $joinedNode = true; } if (!$joinedNodeType) { $qb->innerJoin('n.nodeType', 'nt'); $joinedNodeType = true; } $prefix = 'nt.'; $key = str_replace('node.nodeType.', '', $key); } if (false !== strpos($key, 'node.')) { if (!$joinedNode) { $qb->innerJoin('ns.node', 'n'); $joinedNode = true; } $prefix = 'n.'; $key = str_replace('node.', '', $key); } $qb->andWhere($this->buildComparison($value, $prefix, $key, $baseKey, $qb)); } }
/** * Create filters according to any translation criteria OR argument. * * @param array $criteria * @param QueryBuilder $qb * @param Translation $translation */ protected function filterByTranslation(&$criteria, &$qb, &$translation = null) { if (isset($criteria['translation']) || isset($criteria['translation.locale']) || isset($criteria['translation.id']) || isset($criteria['translation.available'])) { $qb->innerJoin('n.nodeSources', 'ns'); $qb->innerJoin('ns.translation', 't'); } else { if (null !== $translation) { /* * With a given translation */ $qb->innerJoin('n.nodeSources', 'ns', 'WITH', 'ns.translation = :translation'); } else { /* * With a null translation, not filter by translation to enable * nodes with only one translation which is not the default one. */ $qb->innerJoin('n.nodeSources', 'ns'); } } }