private function makeSitesFlatAndApplyGenericFilters(DataTable $table, $request)
    {
        // we handle limit here as we have to apply sort filter, then make sites flat, then apply limit filter.
        $filterOffset = $request['filter_offset'];
        $filterLimit  = $request['filter_limit'];
        unset($request['filter_offset']);
        unset($request['filter_limit']);

        // filter_sort_column does not work correctly is a bug in MultiSites.getAll
        if (!empty($request['filter_sort_column']) && $request['filter_sort_column'] === 'nb_pageviews') {
            $request['filter_sort_column'] = 'Actions_nb_pageviews';
        } elseif (!empty($request['filter_sort_column']) && $request['filter_sort_column'] === 'revenue') {
            $request['filter_sort_column'] = 'Goal_revenue';
        }

        // make sure no limit filter is applied, we will do this manually
        $table->disableFilter('Limit');

        // this will apply the sort filter
        /** @var DataTable $table */
        $genericFilter = new DataTablePostProcessor('MultiSites', 'getAll', $request);
        $table = $genericFilter->applyGenericFilters($table);

        // make sure from now on the sites will be no longer sorted, they were already sorted
        $table->disableFilter('Sort');

        // make sites flat and limit
        $table->filter('Piwik\Plugins\MultiSites\DataTable\Filter\NestedSitesLimiter', array($filterOffset, $filterLimit));
    }