src/Repository/TranslationRepository.php
public function findDataByTypesAndNames(string $locale, array $namesByTypes, array $modCombinationIds = []): array
    {
        $columns = [
            't.locale AS locale',
            't.type AS type',
            't.name AS name',
            't.value AS value',
            't.description AS description',
            't.isDuplicatedByRecipe AS isDuplicatedByRecipe',
            't.isDuplicatedByMachine AS isDuplicatedByMachine',
            'mc.order AS order'
        ];

        $queryBuilder = $this->entityManager->createQueryBuilder();
        $queryBuilder->select($columns)
                     ->from(Translation::class, 't')
                     ->innerJoin('t.modCombination', 'mc')
                     ->andWhere('t.locale IN (:locales)')
                     ->setParameter('locales', [$locale, 'en']);

        $conditions = [];
        foreach ($namesByTypes as $type => $names) {
            if (count($names) > 0) {
                $index = count($conditions);
                switch ($type) {
                    case TranslationType::RECIPE:
                        // Special case: Recipes may re-use the translations provided by the item with the same name.
                        $conditions[] = '((t.type = :type' . $index . ' OR t.isDuplicatedByRecipe = 1) '
                            . 'AND t.name IN (:names' . $index . '))';
                        break;

                    case TranslationType::MACHINE:
                        // Special case: Machines may re-use the translations provided by the item with the same name.
                        $conditions[] = '((t.type = :type' . $index . ' OR t.isDuplicatedByMachine = 1) '
                            . 'AND t.name IN (:names' . $index . '))';
                        break;

                    default:
                        $conditions[] = '(t.type = :type' . $index . ' AND t.name IN (:names' . $index . '))';
                        break;
                }
                $queryBuilder->setParameter('type' . $index, $type)
                             ->setParameter('names' . $index, array_values($names));
            }
        }

        $result = [];
        if (count($conditions) > 0) {
            $queryBuilder->andWhere('(' . implode(' OR ', $conditions) . ')');

            if (count($modCombinationIds) > 0) {
                $queryBuilder->andWhere('(t.modCombination IN (:modCombinationIds) OR t.type = :typeMod)')
                             ->setParameter('modCombinationIds', array_values($modCombinationIds))
                             ->setParameter('typeMod', 'mod');
            }

            $result = $this->mapTranslationDataResult($queryBuilder->getQuery()->getResult());
        }
        return $result;
    }
public function findDataByTypesAndNames(string $locale, array $namesByTypes, array $modCombinationIds = []): array
    {
        $columns = [
            't.locale AS locale',
            't.type AS type',
            't.name AS name',
            't.value AS value',
            't.description AS description',
            't.isDuplicatedByRecipe AS isDuplicatedByRecipe',
            't.isDuplicatedByMachine AS isDuplicatedByMachine',
            'mc.order AS order'
        ];

        $queryBuilder = $this->entityManager->createQueryBuilder();
        $queryBuilder->select($columns)
                     ->from(Translation::class, 't')
                     ->innerJoin('t.modCombination', 'mc')
                     ->andWhere('t.locale IN (:locales)')
                     ->setParameter('locales', [$locale, 'en']);

        $conditions = [];
        foreach ($namesByTypes as $type => $names) {
            if (count($names) > 0) {
                $index = count($conditions);
                switch ($type) {
                    case TranslationType::RECIPE:
                        // Special case: Recipes may re-use the translations provided by the item with the same name.
                        $conditions[] = '((t.type = :type' . $index . ' OR t.isDuplicatedByRecipe = 1) '
                            . 'AND t.name IN (:names' . $index . '))';
                        break;

                    case TranslationType::MACHINE:
                        // Special case: Machines may re-use the translations provided by the item with the same name.
                        $conditions[] = '((t.type = :type' . $index . ' OR t.isDuplicatedByMachine = 1) '
                            . 'AND t.name IN (:names' . $index . '))';
                        break;

                    default:
                        $conditions[] = '(t.type = :type' . $index . ' AND t.name IN (:names' . $index . '))';
                        break;
                }
                $queryBuilder->setParameter('type' . $index, $type)
                             ->setParameter('names' . $index, array_values($names));
            }
        }

        $result = [];
        if (count($conditions) > 0) {
            $queryBuilder->andWhere('(' . implode(' OR ', $conditions) . ')');

            if (count($modCombinationIds) > 0) {
                $queryBuilder->andWhere('(t.modCombination IN (:modCombinationIds) OR t.type = :typeMod)')
                             ->setParameter('modCombinationIds', array_values($modCombinationIds))
                             ->setParameter('typeMod', 'mod');
            }

            $result = $this->mapTranslationDataResult($queryBuilder->getQuery()->getResult());
        }
        return $result;
    }
public function findDataByTypesAndNames ( string $ locale , array $ namesByTypes , array $ modCombinationIds = [ ] ) : array { $ columns = [ 't.locale AS locale' , 't.type AS type' , 't.name AS name' , 't.value AS value' , 't.description AS description' , 't.isDuplicatedByRecipe AS isDuplicatedByRecipe' , 't.isDuplicatedByMachine AS isDuplicatedByMachine' , 'mc.order AS order' ] ; $ queryBuilder = $ this -> entityManager -> createQueryBuilder ( ) ; $ queryBuilder -> select ( $ columns ) -> from ( Translation :: class , 't' ) -> innerJoin ( 't.modCombination' , 'mc' ) -> andWhere ( 't.locale IN (:locales)' ) -> setParameter ( 'locales' , [ $ locale , 'en' ] ) ; $ conditions = [ ] ; foreach ( $ namesByTypes as $ type => $ names ) { if ( count ( $ names ) > 0 ) { $ index = count ( $ conditions ) ; switch ( $ type ) { case TranslationType :: RECIPE : // Special case: Recipes may re-use the translations provided by the item with the same name. $ conditions [ ] = '((t.type = :type' . $ index . ' OR t.isDuplicatedByRecipe = 1) ' . 'AND t.name IN (:names' . $ index . '))' ; break ; case TranslationType :: MACHINE : // Special case: Machines may re-use the translations provided by the item with the same name. $ conditions [ ] = '((t.type = :type' . $ index . ' OR t.isDuplicatedByMachine = 1) ' . 'AND t.name IN (:names' . $ index . '))' ; break ; default : $ conditions [ ] = '(t.type = :type' . $ index . ' AND t.name IN (:names' . $ index . '))' ; break ; } $ queryBuilder -> setParameter ( 'type' . $ index , $ type ) -> setParameter ( 'names' . $ index , array_values ( $ names ) ) ; } } $ result = [ ] ; if ( count ( $ conditions ) > 0 ) { $ queryBuilder -> andWhere ( '(' . implode ( ' OR ' , $ conditions ) . ')' ) ; if ( count ( $ modCombinationIds ) > 0 ) { $ queryBuilder -> andWhere ( '(t.modCombination IN (:modCombinationIds) OR t.type = :typeMod)' ) -> setParameter ( 'modCombinationIds' , array_values ( $ modCombinationIds ) ) -> setParameter ( 'typeMod' , 'mod' ) ; } $ result = $ this -> mapTranslationDataResult ( $ queryBuilder -> getQuery ( ) -> getResult ( ) ) ; } return $ result ; }
Finds the translation data with the specified types and names.
@param string $locale The locale to prefer in the results.
@param array|string[][] $namesByTypes The names to search, grouped by their types.
@param array|int[] $modCombinationIds The IDs of the mod combinations, or empty to use all translations.
@return array|TranslationData[]
Finds the translation data with the specified types and names .