Example #1
0
 /**
  * Returns the current URL without generic filter query parameters.
  *
  * @param array $params Query parameter values to override in the new URL.
  * @return string
  */
 public static function getCurrentUrlWithoutGenericFilters($params)
 {
     // unset all filter query params so the related report will show up in its default state,
     // unless the filter param was in $queryParams
     $genericFiltersInfo = DataTableGenericFilter::getGenericFiltersInformation();
     foreach ($genericFiltersInfo as $filter) {
         foreach ($filter[1] as $queryParamName => $queryParamInfo) {
             if (!isset($params[$queryParamName])) {
                 $params[$queryParamName] = null;
             }
         }
     }
     return Url::getCurrentQueryStringWithParametersModified($params);
 }
 protected function handleDataTable($datatable)
 {
     $label = $this->getLabelFromRequest($this->request);
     // if requested, flatten nested tables
     if (Common::getRequestVar('flat', '0', 'string', $this->request) == '1') {
         $flattener = new Flattener($this->apiModule, $this->apiMethod, $this->request);
         if (Common::getRequestVar('include_aggregate_rows', '0', 'string', $this->request) == '1') {
             $flattener->includeAggregateRows();
         }
         $datatable = $flattener->flatten($datatable);
     }
     if (1 == Common::getRequestVar('totals', '1', 'integer', $this->request)) {
         $genericFilter = new ReportTotalsCalculator($this->apiModule, $this->apiMethod, $this->request);
         $datatable = $genericFilter->calculate($datatable);
     }
     // if the flag disable_generic_filters is defined we skip the generic filters
     if (0 == Common::getRequestVar('disable_generic_filters', '0', 'string', $this->request)) {
         $genericFilter = new DataTableGenericFilter($this->request);
         if (!empty($label)) {
             $genericFilter->disableFilters(array('Limit', 'Truncate'));
         }
         $genericFilter->filter($datatable);
     }
     // we automatically safe decode all datatable labels (against xss)
     $datatable->queueFilter('SafeDecodeLabel');
     // if the flag disable_queued_filters is defined we skip the filters that were queued
     if (Common::getRequestVar('disable_queued_filters', 0, 'int', $this->request) == 0) {
         $datatable->applyQueuedFilters();
     }
     // use the ColumnDelete filter if hideColumns/showColumns is provided (must be done
     // after queued filters are run so processed metrics can be removed, too)
     $hideColumns = Common::getRequestVar('hideColumns', '', 'string', $this->request);
     $showColumns = Common::getRequestVar('showColumns', '', 'string', $this->request);
     if ($hideColumns !== '' || $showColumns !== '') {
         $datatable->filter('ColumnDelete', array($hideColumns, $showColumns));
     }
     // apply label filter: only return rows matching the label parameter (more than one if more than one label)
     if (!empty($label)) {
         $addLabelIndex = Common::getRequestVar('labelFilterAddLabelIndex', 0, 'int', $this->request) == 1;
         $filter = new LabelFilter($this->apiModule, $this->apiMethod, $this->request);
         $datatable = $filter->filter($label, $datatable, $addLabelIndex);
     }
     return $this->apiRenderer->renderDataTable($datatable);
 }
 /**
  * @param DataTableInterface $dataTable
  * @return DataTableInterface
  */
 public function applyGenericFilters($dataTable)
 {
     // if the flag disable_generic_filters is defined we skip the generic filters
     if (0 == Common::getRequestVar('disable_generic_filters', '0', 'string', $this->request)) {
         $this->applyProcessedMetricsGenericFilters($dataTable);
         $genericFilter = new DataTableGenericFilter($this->request, $this->report);
         $self = $this;
         $report = $this->report;
         $dataTable->filter(function (DataTable $table) use($genericFilter, $report, $self) {
             $processedMetrics = Report::getProcessedMetricsForTable($table, $report);
             if ($genericFilter->areProcessedMetricsNeededFor($processedMetrics)) {
                 $self->computeProcessedMetrics($table);
             }
         });
         $label = self::getLabelFromRequest($this->request);
         if (!empty($label)) {
             $genericFilter->disableFilters(array('Limit', 'Truncate'));
         }
         $genericFilter->filter($dataTable);
     }
     return $dataTable;
 }