/** * Appends query parts from registered mappers * * @param \Krystal\Db\Sql\QueryBuilderInterface $db Query builder * @return void */ private function appendFromMappers(QueryBuilderInterface $qb) { // Amount of registered mappers we have $amount = count($this->mappers); // Iteration counter $i = 0; foreach ($this->mappers as $mapper) { $qb->openBracket(); $mapper->appendQuery($qb, self::PARAM_QUERY_PLACEHOLDER); $qb->closeBracket(); ++$i; // Comparing iteration against number of mappers, tells whether this iteration is last $last = $i == $amount; // If we have more that one mapper, then we need to union results // And also, we should never append UNION in last iteration if ($amount > 1 && !$last) { $qb->union(); } } }
/** * {@inheritDoc} */ public function appendQuery(QueryBuilderInterface $queryBuilder, $placeholder) { $queryBuilder->select($this->getWithDefaults(array('description' => 'content')))->from(ProductMapper::getTableName())->whereEquals('lang_id', "'{$this->getLangId()}'")->andWhereEquals('published', '1')->andWhereLike('title', $placeholder)->orWhereLike('description', $placeholder); }
/** * {@inheritDoc} */ public function appendQuery(QueryBuilderInterface $queryBuilder, $placeholder) { $queryBuilder->select($this->getWithDefaults(array('content')))->from(PageMapper::getTableName())->whereEquals('seo', '1')->andWhereEquals('lang_id', "'{$this->getLangId()}'")->rawAnd()->openBracket()->like('title', $placeholder)->rawOr()->like('content', $placeholder)->closeBracket(); }