This filter is used to handle the **hideColumn** and **showColumn** query parameters. **Basic usage example** $columnsToRemove = array('nb_hits', 'nb_pageviews'); $dataTable->filter('ColumnDelete', array($columnsToRemove)); $columnsToKeep = array('nb_visits'); $dataTable->filter('ColumnDelete', array(array(), $columnsToKeep));
Inheritance: extends Piwik\DataTable\BaseFilter
Example #1
0
 private function handleArray($array)
 {
     $firstArray = null;
     $firstKey = null;
     if (!empty($array)) {
         $firstArray = reset($array);
         $firstKey = key($array);
     }
     $isAssoc = !empty($firstArray) && is_numeric($firstKey) && is_array($firstArray) && count(array_filter(array_keys($firstArray), 'is_string'));
     if (is_numeric($firstKey)) {
         $columns = Common::getRequestVar('filter_column', false, 'array', $this->request);
         $pattern = Common::getRequestVar('filter_pattern', '', 'string', $this->request);
         if ($columns != array(false) && $pattern !== '') {
             $pattern = new Pattern(new DataTable(), $columns, $pattern);
             $array = $pattern->filterArray($array);
         }
         $limit = Common::getRequestVar('filter_limit', -1, 'integer', $this->request);
         $offset = Common::getRequestVar('filter_offset', '0', 'integer', $this->request);
         if ($this->shouldApplyLimitOnArray($limit, $offset)) {
             $array = array_slice($array, $offset, $limit, $preserveKeys = false);
         }
     }
     if ($isAssoc) {
         $hideColumns = Common::getRequestVar('hideColumns', '', 'string', $this->request);
         $showColumns = Common::getRequestVar('showColumns', '', 'string', $this->request);
         if ($hideColumns !== '' || $showColumns !== '') {
             $columnDelete = new ColumnDelete(new DataTable(), $hideColumns, $showColumns);
             $array = $columnDelete->filter($array);
         }
     }
     return $this->apiRenderer->renderArray($array);
 }
 protected function handleArray($array)
 {
     $firstArray = null;
     $firstKey = null;
     if (!empty($array)) {
         $firstArray = reset($array);
         $firstKey = key($array);
     }
     $isAssoc = !empty($firstArray) && is_numeric($firstKey) && is_array($firstArray) && !Piwik::isMultiDimensionalArray($array) && count(array_filter(array_keys($firstArray), 'is_string'));
     if ($isAssoc) {
         $hideColumns = Common::getRequestVar('hideColumns', '', 'string', $this->request);
         $showColumns = Common::getRequestVar('showColumns', '', 'string', $this->request);
         if ($hideColumns !== '' || $showColumns !== '') {
             $columnDelete = new ColumnDelete(new DataTable(), $hideColumns, $showColumns);
             $array = $columnDelete->filter($array);
         }
     }
     return $this->apiRenderer->renderArray($array);
 }
Example #3
0
 protected function handleArray($array)
 {
     $firstArray = null;
     $firstKey = null;
     if (!empty($array)) {
         $firstArray = reset($array);
         $firstKey = key($array);
     }
     $isAssoc = !empty($firstArray) && is_numeric($firstKey) && is_array($firstArray) && count(array_filter(array_keys($firstArray), 'is_string'));
     if ($isAssoc) {
         $hideColumns = Common::getRequestVar('hideColumns', '', 'string', $this->request);
         $showColumns = Common::getRequestVar('showColumns', '', 'string', $this->request);
         if ($hideColumns !== '' || $showColumns !== '') {
             $columnDelete = new ColumnDelete(new DataTable(), $hideColumns, $showColumns);
             $array = $columnDelete->filter($array);
         }
     } else {
         if (is_numeric($firstKey)) {
             $limit = Common::getRequestVar('filter_limit', -1, 'integer', $this->request);
             $offset = Common::getRequestVar('filter_offset', '0', 'integer', $this->request);
             if (-1 !== $limit) {
                 $array = array_slice($array, $offset, $limit);
             }
         }
     }
     return $this->apiRenderer->renderArray($array);
 }