Advertisement
Guest User

Truncate.php

a guest
Jun 29th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Piwik - Open source web analytics
  4.  *
  5.  * @link http://piwik.org
  6.  * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  7.  * @version $Id: Truncate.php 6353 2012-05-28 17:29:23Z SteveG $
  8.  *
  9.  * @category Piwik
  10.  * @package Piwik
  11.  */
  12.  
  13. /**
  14.  * @package Piwik
  15.  * @subpackage Piwik_DataTable
  16.  */
  17. class Piwik_DataTable_Filter_Truncate extends Piwik_DataTable_Filter
  18. {
  19.     /**
  20.      * @param Piwik_DataTable  $table
  21.      * @param int              $truncateAfter
  22.      */
  23.     public function __construct( $table, $truncateAfter)
  24.     {
  25.         parent::__construct($table);
  26.         $this->truncateAfter = $truncateAfter;
  27.     }  
  28.  
  29.     /**
  30.      * Truncates the table after X rows and adds a summary row
  31.      *
  32.      * @param Piwik_DataTable  $table
  33.      */
  34.     public function filter($table)
  35.     {
  36.         $table->filter('AddSummaryRow', array($this->truncateAfter));
  37.         $table->filter('ReplaceSummaryRowLabel');
  38.         $currentDataTableId = $table->getId();
  39.         foreach($table->getRows() as $row)
  40.         {
  41.             try {
  42.                 $idSubTable = $row->getIdSubDataTable();
  43.                 if($currentDataTableId == $idSubTable) { Piwik::log('PLEASE COMMUNICATE THIS LINE : ' . print_r($table, true) . ' | ' . print_r($row, true)); continue;}
  44.                 $subTable = Piwik_DataTable_Manager::getInstance()->getTable($idSubTable);
  45.                 $subTable->filter('Truncate', array($this->truncateAfter));
  46.             } catch(Exception $e) {
  47.                 // there is no subtable loaded for example
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement