TODO: should really work something like this, but also
needs update to the UrlAliasService etc.

@param array $languageFilter

@return array|null
333151
protected function getTodoFieldFilter(array $languageFilter)
    {
        $translationFilter = null;

        if (!empty($languageFilter['languages'])) {
            $translationFilter = array(
                'terms' => array(
                    'fields_doc.meta_language_code_s' => $languageFilter['languages'],
                ),
            );

            if (isset($languageFilter['defaultTranslationToMainLanguage'])) {
                switch ($languageFilter['defaultTranslationToMainLanguage']) {
                    case true:
                        $translationFilter = array(
                            'or' => array(
                                $translationFilter,
                                'term' => array(
                                    'meta_is_main_translation_b' => true,
                                ),
                            ),
                        );
                        break;

                    case 'use_always_available':
                        $translationFilter = array(
                            'or' => array(
                                $translationFilter,
                                'and' => array(
                                    array(
                                        'term' => array(
                                            'always_available_b' => true,
                                        ),
                                    ),
                                    array(
                                        'term' => array(
                                            'meta_is_main_translation_b' => true,
                                        ),
                                    ),
                                ),
                            ),
                        );
                        break;

                    case false:
                        // Nothing to do
                        break;

                    default:
                        throw new \RuntimeException(
                            "Invalid value for 'defaultTranslationToMainLanguage' field filter: expected one of: " .
                            "true, 'use_always_available', false, got: " .
                            var_export($languageFilter['defaultTranslationToMainLanguage'], true)
                        );
                }
            }
        }

        return $translationFilter;
    }
18397
public function filter(ODataQueryFilterInterface $filter = NULL) {
        if (isset($filter)) {
            $this->setFilter($filter);
            return $this;
        }
        return $this->getFilter();
    }
46575
public function getDefaultUrl($language = null)
    {
        foreach ($this->urls as $url) {
            if ($url->isDefault()) {
                return $url;
            }
        }

        return null;
    }
1044714
private static function determineFilterAndOr(array $filter, QueryBuilder $queryBuilder)
    {
        if (!\in_array($filter['operation'], ['AND', 'OR'])) {
            return null;
        }

        static::filterAndOr($filter, $queryBuilder);

        return '';
    }
1355847
private function resolveFromLanguage(array $parameters): ?Language
    {
        if (isset($parameters['fromLanguage'])) {
            return $parameters['fromLanguage'];
        }

        if (isset($parameters['fromLanguageCode'])) {
            return $this->loadLanguage($parameters['fromLanguageCode']);
        }

        return null;
    }
714741
private static function determineFilterComparing(array $filter, QueryBuilder $queryBuilder)
    {
        if (!\in_array($filter['operation'], ['=', '>', '>=', '<', '<=', '<>'])) {
            return null;
        }

        return static::filterComparing($filter, $queryBuilder);
    }
285318
public function findOne(array $filter = [], array $options = [])
    {
        $documents = $this->findAll($filter, ['limit' => 1] + $options);

        return $documents->valid() ? $documents->current() : null;
    }
343627
protected function getTotalCount(Criterion $criterion, array $languageFilter)
    {
        $query = $this->handler->createSelectQuery();
        $query
            ->select($query->alias($query->expr->count('*'), 'count'))
            ->from($this->handler->quoteTable('ezcontentobject_tree'))
            ->innerJoin(
                'ezcontentobject',
                'ezcontentobject_tree.contentobject_id',
                'ezcontentobject.id'
            )
            ->innerJoin(
                'ezcontentobject_version',
                'ezcontentobject.id',
                'ezcontentobject_version.contentobject_id'
            );

        $query->where(
            $this->criteriaConverter->convertCriteria($query, $criterion, $languageFilter),
            $query->expr->eq(
                'ezcontentobject.status',
                //ContentInfo::STATUS_PUBLISHED
                $query->bindValue(1, null, PDO::PARAM_INT)
            ),
            $query->expr->eq(
                'ezcontentobject_version.status',
                //VersionInfo::STATUS_PUBLISHED
                $query->bindValue(1, null, PDO::PARAM_INT)
            ),
            $query->expr->neq(
                $this->handler->quoteColumn('depth', 'ezcontentobject_tree'),
                $query->bindValue(0, null, PDO::PARAM_INT)
            )
        );

        // If not main-languages query
        if (!empty($languageFilter['languages'])) {
            $query->where(
                $query->expr->gt(
                    $query->expr->bitAnd(
                        $this->handler->quoteColumn('language_mask', 'ezcontentobject'),
                        $query->bindValue(
                            $this->getLanguageMask($languageFilter),
                            null,
                            PDO::PARAM_INT
                        )
                    ),
                    $query->bindValue(0, null, PDO::PARAM_INT)
                )
            );
        }

        $statement = $query->prepare();
        $statement->execute();

        return (int)$statement->fetchColumn();
    }
1100325
public function find(array $filter = [], array $options = [])
    {
        $options += ['typeMap' => $this->typeMap];
        $options = QueryOptionsResolver::resolveStatic($options);
        $typeMap = $options['typeMap'];
        unset($options['typeMap']);

        if (isset($options['readPreference'])) {
            $readPreference = $options['readPreference'];
            unset($options['readPreference']);
        } else {
            $readPreference = $this->readPreference;
        }

        $query = new Query($filter, $options);
        $query->setDefaultReadConcern($this->readConcern);

        $cursor = $this->manager->executeQuery(
            $this->getNamespace(),
            $query,
            $readPreference
        );

        $cursor->setTypeMap($typeMap);

        return $cursor;
    }
202836
public function getFilters()
    {
        $language = $this->container->get('language');

        return [
            new \Twig_SimpleFilter('trans', [$language, 'translate']),
            new \Twig_SimpleFilter('lang', [$language, 'translate']),
            new \Twig_SimpleFilter('translate', [$language, 'translate']),
            new \Twig_SimpleFilter('_', [$language, 'translate']),
            new \Twig_SimpleFilter('sprintf', function (...$args) use ($language) {
                return $language->sprintf(...$args);
            }),
            new \Twig_SimpleFilter('plural', function (...$args) use ($language) {
                return $language->plural(...$args);
            }),
        ];
    }
1127004
protected function getAnnouncementsFilter(string $filter = null)
    {
        $mappingConfiguration = new PropertyMappingConfiguration();
        $mappingConfiguration->setTypeConverter($this->typeConverterObjectConverter);
        $mappingConfiguration->setTypeConverterOption(\RGU\Dvoconnector\Property\TypeConverter\ObjectConverter::class, \RGU\Dvoconnector\Property\TypeConverter\ObjectConverter::CONFIGURATION_OBJECT, $this->getDefaultAnnouncementsFilter());

        return $this->convertAnnouncementsFilter($mappingConfiguration, $filter);
    }
306666
private function getTranslation()
    {
        $filterTranslation = null;
        foreach ($this->entity->getTranslations() as $translation) {
            if ($translation->getLocale() == $this->locale) {
                $filterTranslation = $translation;
            }
        }
        if (!$filterTranslation) {
            $filterTranslation = new FilterTranslation();
            $filterTranslation->setLocale($this->locale);
            $filterTranslation->setFilter($this->entity);
            $this->entity->addTranslation($filterTranslation);
        }

        return $filterTranslation;
    }
1195368
private static function determineFilterIsNullOrIsNotNull(array $filter, QueryBuilder $queryBuilder)
    {
        if (!\in_array($filter['operation'], ['IS NULL', 'IS NOT NULL'])) {
            return null;
        }

        return static::filterIsNullOrIsNotNull($filter, $queryBuilder);
    }
1081907
protected function getUserAssociationsFilter(string $filter = null)
    {
        $mappingConfiguration = new PropertyMappingConfiguration();
        return $this->convertAssociationsFilter($mappingConfiguration, $filter);
    }
972233
public function getRootAssociations($associationsFilter = null)
    {
        $arrayWithChilds = $this->associationsApiService->getRootAssociations($associationsFilter);

        $associations = new Associations();

        foreach ($arrayWithChilds as $xmlQuery) {
            $association = new Association();

            $mapper = new \RGU\Dvoconnector\Mapper\Association($xmlQuery);
            $mapper->mapToAbstractEntity($association);

            $associations->addAssociation($this->completeEntity($association));
        }

        return $this->completeEntity($associations);
    }
737218
private function getLanguages($forcedLanguage = null, $fallbackLanguage = null)
    {
        if ($forcedLanguage !== null) {
            $languages = array($forcedLanguage);
        } else {
            $languages = $this->configResolver->getParameter('languages');
        }

        // Always add $fallbackLanguage, even if null, as last entry so that we can fallback to
        // main/initial language if domain supports it.
        $languages[] = $fallbackLanguage;

        return $languages;
    }
906829
public function findFiltered(array $filters)
    {
        /* @var Unit[] $units */
        if (!isset($filters['domain']) || is_null($filters['domain']) || empty($filters['domain'])) {
            $units = $this->findAll();
        } else {
            $units = $this->findByDomain($filters['domain']);
        }

        foreach ($units as $k => $u) {
            $filterEmpty = isset($filters['empty']) && $filters['empty'];
            $filterKey = isset($filters['key']) && strlen(trim($filters['key'])) > 0 ? trim($filters['key']) : null;
            $filterValue = isset($filters['value']) && strlen(trim($filters['value'])) > 0 ? trim($filters['value']) : null;
            if (empty($filters['locale'])) {
                $filters['locale'] = $this->getLocaleList();
            }

            if ($filterKey && strpos($u->getKey(), $filterKey) === false) {
                unset($units[$k]);
                continue;
            }

            $nonEmptyCount = 0;
            $valueCount = 0;
            foreach ($u->getTranslations() as $t) {
                // Remove translations not required
                if (!in_array($t->getLocale(), $filters['locale'])) {
                    unset($u[$t->getLocale()]);
                    continue;
                }

                // Count empty or match values
                $value = $t->getValue();
                if ($value !== null && strlen($value) > 0) {
                    ++$nonEmptyCount;
                }
                if ($filterValue && strpos($value, $filterValue) !== false) {
                    ++$valueCount;
                }
            }

            // For empty filtering, remove unit with non empty translations
            if ($filterEmpty && $nonEmptyCount >= count($filters['locale'])) {
                unset($units[$k]);
                continue;
            }

            // For value filtering, remove unit when there is no match
            if ($filterValue && $valueCount == 0) {
                unset($units[$k]);
                continue;
            }
        }

        return $units;
    }