protected function createTagFindQuery(array $translations = null, $useAlwaysAvailable = true)
    {
        /** @var \eZ\Publish\Core\Persistence\Database\SelectQuery $query */
        $query = $this->handler->createSelectQuery();
        $query->select(
            // Tag
            $this->handler->aliasedColumn($query, 'id', 'eztags'),
            $this->handler->aliasedColumn($query, 'parent_id', 'eztags'),
            $this->handler->aliasedColumn($query, 'main_tag_id', 'eztags'),
            $this->handler->aliasedColumn($query, 'keyword', 'eztags'),
            $this->handler->aliasedColumn($query, 'depth', 'eztags'),
            $this->handler->aliasedColumn($query, 'path_string', 'eztags'),
            $this->handler->aliasedColumn($query, 'modified', 'eztags'),
            $this->handler->aliasedColumn($query, 'remote_id', 'eztags'),
            $this->handler->aliasedColumn($query, 'main_language_id', 'eztags'),
            $this->handler->aliasedColumn($query, 'language_mask', 'eztags'),
            // Tag keywords
            $this->handler->aliasedColumn($query, 'keyword', 'eztags_keyword'),
            $this->handler->aliasedColumn($query, 'locale', 'eztags_keyword')
        )->from(
            $this->handler->quoteTable('eztags')
        )
        // @todo: Joining with eztags_keyword is probably a VERY bad way to gather that information
        // since it creates an additional cartesian product with translations.
        ->leftJoin(
            $this->handler->quoteTable('eztags_keyword'),
            $query->expr->lAnd(
                // eztags_keyword.locale is also part of the PK but can't be
                // easily joined with something at this level
                $query->expr->eq(
                    $this->handler->quoteColumn('keyword_id', 'eztags_keyword'),
                    $this->handler->quoteColumn('id', 'eztags')
                ),
                $query->expr->eq(
                    $this->handler->quoteColumn('status', 'eztags_keyword'),
                    $query->bindValue(1, null, PDO::PARAM_INT)
                )
            )
        );

        if (!empty($translations)) {
            if ($useAlwaysAvailable) {
                $query->where(
                    $query->expr->lOr(
                        $query->expr->in(
                            $this->handler->quoteColumn('locale', 'eztags_keyword'),
                            $translations
                        ),
                        $query->expr->lAnd(
                            $query->expr->gt(
                                $query->expr->bitAnd(
                                    $this->handler->quoteColumn('language_mask', 'eztags'),
                                    1
                                ),
                                0
                            ),
                            $query->expr->eq(
                                $this->handler->quoteColumn('main_language_id', 'eztags'),
                                $query->expr->bitAnd(
                                    $this->handler->quoteColumn('language_id', 'eztags_keyword'),
                                    -2 // -2 == PHP_INT_MAX << 1
                                )
                            )
                        )
                    )
                );
            } else {
                $query->where(
                    $query->expr->in(
                        $this->handler->quoteColumn('locale', 'eztags_keyword'),
                        $translations
                    )
                );
            }
        }

        return $query;
    }
protected function createTagFindQuery(array $translations = null, $useAlwaysAvailable = true)
    {
        /** @var \eZ\Publish\Core\Persistence\Database\SelectQuery $query */
        $query = $this->handler->createSelectQuery();
        $query->select(
            // Tag
            $this->handler->aliasedColumn($query, 'id', 'eztags'),
            $this->handler->aliasedColumn($query, 'parent_id', 'eztags'),
            $this->handler->aliasedColumn($query, 'main_tag_id', 'eztags'),
            $this->handler->aliasedColumn($query, 'keyword', 'eztags'),
            $this->handler->aliasedColumn($query, 'depth', 'eztags'),
            $this->handler->aliasedColumn($query, 'path_string', 'eztags'),
            $this->handler->aliasedColumn($query, 'modified', 'eztags'),
            $this->handler->aliasedColumn($query, 'remote_id', 'eztags'),
            $this->handler->aliasedColumn($query, 'main_language_id', 'eztags'),
            $this->handler->aliasedColumn($query, 'language_mask', 'eztags'),
            // Tag keywords
            $this->handler->aliasedColumn($query, 'keyword', 'eztags_keyword'),
            $this->handler->aliasedColumn($query, 'locale', 'eztags_keyword')
        )->from(
            $this->handler->quoteTable('eztags')
        )
        // @todo: Joining with eztags_keyword is probably a VERY bad way to gather that information
        // since it creates an additional cartesian product with translations.
        ->leftJoin(
            $this->handler->quoteTable('eztags_keyword'),
            $query->expr->lAnd(
                // eztags_keyword.locale is also part of the PK but can't be
                // easily joined with something at this level
                $query->expr->eq(
                    $this->handler->quoteColumn('keyword_id', 'eztags_keyword'),
                    $this->handler->quoteColumn('id', 'eztags')
                ),
                $query->expr->eq(
                    $this->handler->quoteColumn('status', 'eztags_keyword'),
                    $query->bindValue(1, null, PDO::PARAM_INT)
                )
            )
        );

        if (!empty($translations)) {
            if ($useAlwaysAvailable) {
                $query->where(
                    $query->expr->lOr(
                        $query->expr->in(
                            $this->handler->quoteColumn('locale', 'eztags_keyword'),
                            $translations
                        ),
                        $query->expr->lAnd(
                            $query->expr->gt(
                                $query->expr->bitAnd(
                                    $this->handler->quoteColumn('language_mask', 'eztags'),
                                    1
                                ),
                                0
                            ),
                            $query->expr->eq(
                                $this->handler->quoteColumn('main_language_id', 'eztags'),
                                $query->expr->bitAnd(
                                    $this->handler->quoteColumn('language_id', 'eztags_keyword'),
                                    -2 // -2 == PHP_INT_MAX << 1
                                )
                            )
                        )
                    )
                );
            } else {
                $query->where(
                    $query->expr->in(
                        $this->handler->quoteColumn('locale', 'eztags_keyword'),
                        $translations
                    )
                );
            }
        }

        return $query;
    }
protected function createTagFindQuery ( array $ translations = null , $ useAlwaysAvailable = true ) { /** @var \eZ\Publish\Core\Persistence\Database\SelectQuery $query */ $ query = $ this -> handler -> createSelectQuery ( ) ; $ query -> select ( // Tag $ this -> handler -> aliasedColumn ( $ query , 'id' , 'eztags' ) , $ this -> handler -> aliasedColumn ( $ query , 'parent_id' , 'eztags' ) , $ this -> handler -> aliasedColumn ( $ query , 'main_tag_id' , 'eztags' ) , $ this -> handler -> aliasedColumn ( $ query , 'keyword' , 'eztags' ) , $ this -> handler -> aliasedColumn ( $ query , 'depth' , 'eztags' ) , $ this -> handler -> aliasedColumn ( $ query , 'path_string' , 'eztags' ) , $ this -> handler -> aliasedColumn ( $ query , 'modified' , 'eztags' ) , $ this -> handler -> aliasedColumn ( $ query , 'remote_id' , 'eztags' ) , $ this -> handler -> aliasedColumn ( $ query , 'main_language_id' , 'eztags' ) , $ this -> handler -> aliasedColumn ( $ query , 'language_mask' , 'eztags' ) , // Tag keywords $ this -> handler -> aliasedColumn ( $ query , 'keyword' , 'eztags_keyword' ) , $ this -> handler -> aliasedColumn ( $ query , 'locale' , 'eztags_keyword' ) ) -> from ( $ this -> handler -> quoteTable ( 'eztags' ) ) // @todo: Joining with eztags_keyword is probably a VERY bad way to gather that information // since it creates an additional cartesian product with translations. -> leftJoin ( $ this -> handler -> quoteTable ( 'eztags_keyword' ) , $ query -> expr -> lAnd ( // eztags_keyword.locale is also part of the PK but can't be // easily joined with something at this level $ query -> expr -> eq ( $ this -> handler -> quoteColumn ( 'keyword_id' , 'eztags_keyword' ) , $ this -> handler -> quoteColumn ( 'id' , 'eztags' ) ) , $ query -> expr -> eq ( $ this -> handler -> quoteColumn ( 'status' , 'eztags_keyword' ) , $ query -> bindValue ( 1 , null , PDO :: PARAM_INT ) ) ) ) ; if ( ! empty ( $ translations ) ) { if ( $ useAlwaysAvailable ) { $ query -> where ( $ query -> expr -> lOr ( $ query -> expr -> in ( $ this -> handler -> quoteColumn ( 'locale' , 'eztags_keyword' ) , $ translations ) , $ query -> expr -> lAnd ( $ query -> expr -> gt ( $ query -> expr -> bitAnd ( $ this -> handler -> quoteColumn ( 'language_mask' , 'eztags' ) , 1 ) , 0 ) , $ query -> expr -> eq ( $ this -> handler -> quoteColumn ( 'main_language_id' , 'eztags' ) , $ query -> expr -> bitAnd ( $ this -> handler -> quoteColumn ( 'language_id' , 'eztags_keyword' ) , - 2 // -2 == PHP_INT_MAX << 1 ) ) ) ) ) ; } else { $ query -> where ( $ query -> expr -> in ( $ this -> handler -> quoteColumn ( 'locale' , 'eztags_keyword' ) , $ translations ) ) ; } } return $ query ; }
Creates a select query for tag objects.

Creates a select query with all necessary joins to fetch a complete
tag. Does not apply any WHERE conditions.

@param string[] $translations
@param bool $useAlwaysAvailable

@return \eZ\Publish\Core\Persistence\Database\SelectQuery
Creates a select query for tag objects .