src/Repository/TranslationRepository.php
public function findDataByKeywords(string $locale, array $keywords, array $modCombinationIds = []): array
    {
        $result = [];
        if (count($keywords) > 0) {
            $concat = 'LOWER(CONCAT(t.type, t.name, t.value, t.description))';
            $priorityCase = 'CASE WHEN t.locale = :localePrimary THEN :priorityPrimary '
                . 'WHEN t.locale = :localeSecondary THEN :prioritySecondary ELSE :priorityAny END';

            $columns = [
                't.type AS type',
                't.name AS name',
                'MIN(' . $priorityCase . ') AS priority'
            ];

            $queryBuilder = $this->entityManager->createQueryBuilder();
            $queryBuilder->select($columns)
                         ->from(Translation::class, 't')
                         ->andWhere('t.type IN (:types)')
                         ->addGroupBy('t.type')
                         ->addGroupBy('t.name')
                         ->setParameter('localePrimary', $locale)
                         ->setParameter('localeSecondary', 'en')
                         ->setParameter('priorityPrimary', SearchResultPriority::PRIMARY_LOCALE_MATCH)
                         ->setParameter('prioritySecondary', SearchResultPriority::SECONDARY_LOCALE_MATCH)
                         ->setParameter('priorityAny', SearchResultPriority::ANY_MATCH)
                         ->setParameter('types', [
                             TranslationType::ITEM,
                             TranslationType::FLUID,
                             TranslationType::RECIPE
                         ]);

            $index = 0;
            foreach ($keywords as $keyword) {
                $queryBuilder->andWhere($concat . ' LIKE :keyword' . $index)
                             ->setParameter('keyword' . $index, '%' . addcslashes($keyword, '\\%_') . '%');
                ++$index;
            }

            if (count($modCombinationIds) > 0) {
                $queryBuilder->innerJoin('t.modCombination', 'mc')
                             ->andWhere('mc.id IN (:modCombinationIds)')
                             ->setParameter('modCombinationIds', array_values($modCombinationIds));
            }

            $result = $this->mapTranslationPriorityDataResult($queryBuilder->getQuery()->getResult());
        }
        return $result;
    }
public function findDataByKeywords(string $locale, array $keywords, array $modCombinationIds = []): array
    {
        $result = [];
        if (count($keywords) > 0) {
            $concat = 'LOWER(CONCAT(t.type, t.name, t.value, t.description))';
            $priorityCase = 'CASE WHEN t.locale = :localePrimary THEN :priorityPrimary '
                . 'WHEN t.locale = :localeSecondary THEN :prioritySecondary ELSE :priorityAny END';

            $columns = [
                't.type AS type',
                't.name AS name',
                'MIN(' . $priorityCase . ') AS priority'
            ];

            $queryBuilder = $this->entityManager->createQueryBuilder();
            $queryBuilder->select($columns)
                         ->from(Translation::class, 't')
                         ->andWhere('t.type IN (:types)')
                         ->addGroupBy('t.type')
                         ->addGroupBy('t.name')
                         ->setParameter('localePrimary', $locale)
                         ->setParameter('localeSecondary', 'en')
                         ->setParameter('priorityPrimary', SearchResultPriority::PRIMARY_LOCALE_MATCH)
                         ->setParameter('prioritySecondary', SearchResultPriority::SECONDARY_LOCALE_MATCH)
                         ->setParameter('priorityAny', SearchResultPriority::ANY_MATCH)
                         ->setParameter('types', [
                             TranslationType::ITEM,
                             TranslationType::FLUID,
                             TranslationType::RECIPE
                         ]);

            $index = 0;
            foreach ($keywords as $keyword) {
                $queryBuilder->andWhere($concat . ' LIKE :keyword' . $index)
                             ->setParameter('keyword' . $index, '%' . addcslashes($keyword, '\\%_') . '%');
                ++$index;
            }

            if (count($modCombinationIds) > 0) {
                $queryBuilder->innerJoin('t.modCombination', 'mc')
                             ->andWhere('mc.id IN (:modCombinationIds)')
                             ->setParameter('modCombinationIds', array_values($modCombinationIds));
            }

            $result = $this->mapTranslationPriorityDataResult($queryBuilder->getQuery()->getResult());
        }
        return $result;
    }
public function findDataByKeywords ( string $ locale , array $ keywords , array $ modCombinationIds = [ ] ) : array { $ result = [ ] ; if ( count ( $ keywords ) > 0 ) { $ concat = 'LOWER(CONCAT(t.type, t.name, t.value, t.description))' ; $ priorityCase = 'CASE WHEN t.locale = :localePrimary THEN :priorityPrimary ' . 'WHEN t.locale = :localeSecondary THEN :prioritySecondary ELSE :priorityAny END' ; $ columns = [ 't.type AS type' , 't.name AS name' , 'MIN(' . $ priorityCase . ') AS priority' ] ; $ queryBuilder = $ this -> entityManager -> createQueryBuilder ( ) ; $ queryBuilder -> select ( $ columns ) -> from ( Translation :: class , 't' ) -> andWhere ( 't.type IN (:types)' ) -> addGroupBy ( 't.type' ) -> addGroupBy ( 't.name' ) -> setParameter ( 'localePrimary' , $ locale ) -> setParameter ( 'localeSecondary' , 'en' ) -> setParameter ( 'priorityPrimary' , SearchResultPriority :: PRIMARY_LOCALE_MATCH ) -> setParameter ( 'prioritySecondary' , SearchResultPriority :: SECONDARY_LOCALE_MATCH ) -> setParameter ( 'priorityAny' , SearchResultPriority :: ANY_MATCH ) -> setParameter ( 'types' , [ TranslationType :: ITEM , TranslationType :: FLUID , TranslationType :: RECIPE ] ) ; $ index = 0 ; foreach ( $ keywords as $ keyword ) { $ queryBuilder -> andWhere ( $ concat . ' LIKE :keyword' . $ index ) -> setParameter ( 'keyword' . $ index , '%' . addcslashes ( $ keyword , '\\%_' ) . '%' ) ; ++ $ index ; } if ( count ( $ modCombinationIds ) > 0 ) { $ queryBuilder -> innerJoin ( 't.modCombination' , 'mc' ) -> andWhere ( 'mc.id IN (:modCombinationIds)' ) -> setParameter ( 'modCombinationIds' , array_values ( $ modCombinationIds ) ) ; } $ result = $ this -> mapTranslationPriorityDataResult ( $ queryBuilder -> getQuery ( ) -> getResult ( ) ) ; } return $ result ; }
Finds the types and names matching the specified keywords.
@param string $locale
@param array|string[] $keywords
@param array|int[] $modCombinationIds
@return array|TranslationPriorityData[]
Finds the types and names matching the specified keywords .