public static function findPublishedByArchives(array $archives, array $ids = [], array $aliases = [])
    {
        if (0 === \count($archives) || false === ($relation = Relations::getRelation('tl_news', 'categories'))) {
            return null;
        }

        $t = static::getTableAlias();
        $values = [];

        // Start sub select query for relations
        $subSelect = "SELECT {$relation['related_field']} 
FROM {$relation['table']} 
WHERE {$relation['reference_field']} IN (SELECT id FROM tl_news WHERE pid IN (".\implode(',', \array_map('intval', $archives)).')';

        // Include only the published news items
        if (!BE_USER_LOGGED_IN) {
            $time = Date::floorToMinute();
            $subSelect .= ' AND (start=? OR start<=?) AND (stop=? OR stop>?) AND published=?';
            $values = \array_merge($values, ['', $time, '', $time + 60, 1]);
        }

        // Finish sub select query for relations
        $subSelect .= ')';

        // Columns definition start
        $columns = ["$t.id IN ($subSelect)"];

        // Filter by custom categories
        if (\count($ids) > 0) {
            $columns[] = "$t.id IN (".\implode(',', \array_map('intval', $ids)).')';
        }

        // Filter by custom aliases
        if (\count($aliases) > 0) {
            $columns[] = "$t.alias IN ('".\implode("','", $aliases)."')";
        }

        if (!BE_USER_LOGGED_IN) {
            $columns[] = "$t.published=?";
            $values[] = 1;
        }

        return static::findBy($columns, $values, ['order' => "$t.sorting"]);
    }
public static function findPublishedByArchives(array $archives, array $ids = [], array $aliases = [])
    {
        if (0 === \count($archives) || false === ($relation = Relations::getRelation('tl_news', 'categories'))) {
            return null;
        }

        $t = static::getTableAlias();
        $values = [];

        // Start sub select query for relations
        $subSelect = "SELECT {$relation['related_field']} 
FROM {$relation['table']} 
WHERE {$relation['reference_field']} IN (SELECT id FROM tl_news WHERE pid IN (".\implode(',', \array_map('intval', $archives)).')';

        // Include only the published news items
        if (!BE_USER_LOGGED_IN) {
            $time = Date::floorToMinute();
            $subSelect .= ' AND (start=? OR start<=?) AND (stop=? OR stop>?) AND published=?';
            $values = \array_merge($values, ['', $time, '', $time + 60, 1]);
        }

        // Finish sub select query for relations
        $subSelect .= ')';

        // Columns definition start
        $columns = ["$t.id IN ($subSelect)"];

        // Filter by custom categories
        if (\count($ids) > 0) {
            $columns[] = "$t.id IN (".\implode(',', \array_map('intval', $ids)).')';
        }

        // Filter by custom aliases
        if (\count($aliases) > 0) {
            $columns[] = "$t.alias IN ('".\implode("','", $aliases)."')";
        }

        if (!BE_USER_LOGGED_IN) {
            $columns[] = "$t.published=?";
            $values[] = 1;
        }

        return static::findBy($columns, $values, ['order' => "$t.sorting"]);
    }
public static function findPublishedByArchives ( array $ archives , array $ ids = [ ] , array $ aliases = [ ] ) { if ( 0 === \ count ( $ archives ) || false === ( $ relation = Relations :: getRelation ( 'tl_news' , 'categories' ) ) ) { return null ; } $ t = static :: getTableAlias ( ) ; $ values = [ ] ; // Start sub select query for relations $ subSelect = "SELECT {$relation['related_field']} 
FROM {$relation['table']} 
WHERE {$relation['reference_field']} IN (SELECT id FROM tl_news WHERE pid IN (" . \ implode ( ',' , \ array_map ( 'intval' , $ archives ) ) . ')' ; // Include only the published news items if ( ! BE_USER_LOGGED_IN ) { $ time = Date :: floorToMinute ( ) ; $ subSelect .= ' AND (start=? OR start<=?) AND (stop=? OR stop>?) AND published=?' ; $ values = \ array_merge ( $ values , [ '' , $ time , '' , $ time + 60 , 1 ] ) ; } // Finish sub select query for relations $ subSelect .= ')' ; // Columns definition start $ columns = [ "$t.id IN ($subSelect)" ] ; // Filter by custom categories if ( \ count ( $ ids ) > 0 ) { $ columns [ ] = "$t.id IN (" . \ implode ( ',' , \ array_map ( 'intval' , $ ids ) ) . ')' ; } // Filter by custom aliases if ( \ count ( $ aliases ) > 0 ) { $ columns [ ] = "$t.alias IN ('" . \ implode ( "','" , $ aliases ) . "')" ; } if ( ! BE_USER_LOGGED_IN ) { $ columns [ ] = "$t.published=?" ; $ values [ ] = 1 ; } return static :: findBy ( $ columns , $ values , [ 'order' => "$t.sorting" ] ) ; }
Find published news categories by news criteria.

@param array $archives
@param array $ids
@param array $aliases

@return Collection|null
Find published news categories by news criteria .