[Piwik-svn] r381 - in trunk: modules modules/DataTable/Filter plugins/VisitTime tests/modules

svnmaster at piwik.org svnmaster at piwik.org
Mon Mar 17 16:25:52 CET 2008


Author: matt
Date: 2008-03-17 16:25:51 +0100 (Mon, 17 Mar 2008)
New Revision: 381

Added:
   trunk/modules/DataTable/Filter/AddSummaryRow.php
Modified:
   trunk/modules/DataTable.php
   trunk/plugins/VisitTime/Controller.php
   trunk/tests/modules/DataTable.test.php
Log:
- refs #110 end of fix, adding file

Added: trunk/modules/DataTable/Filter/AddSummaryRow.php
===================================================================
--- trunk/modules/DataTable/Filter/AddSummaryRow.php	                        (rev 0)
+++ trunk/modules/DataTable/Filter/AddSummaryRow.php	2008-03-17 15:25:51 UTC (rev 381)
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ * 
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
+ * @version $Id: Limit.php 168 2008-01-14 05:26:43Z matt $
+ * 
+ * @package Piwik_DataTable
+ */
+
+/**
+ * Add a new row to the table containing a summary 
+ * of the rows from StartRowToSummarize to EndRowToSummarize.
+ * It then deletes the rows from StartRowToSummarize to EndRowToSummarize.
+ * The new row created has a label = 'other'
+ * 
+ * This filter is useful to build a more compact view of a table, keeping the first records unchanged.
+ * 
+ * @package Piwik_DataTable
+ * @subpackage Piwik_DataTable_Filter 
+ */
+
+class Piwik_DataTable_Filter_AddSummaryRow extends Piwik_DataTable_Filter
+{	
+	public function __construct( $table, $startRowToSummarize )
+	{
+		parent::__construct($table);
+		$this->startRowToSummarize = $startRowToSummarize;
+		
+		if($table->getRowsCount() > $startRowToSummarize + 1)
+		{
+			$this->filter();
+		}
+	}
+	
+	protected function filter()
+	{
+		$copied = clone $this->table;
+		$filter = new Piwik_DataTable_Filter_Limit($copied, $this->startRowToSummarize);
+		$newRow = new Piwik_DataTable_Row_DataTableSummary($copied);
+		$newRow->addColumn('label','Others');
+		$filter = new Piwik_DataTable_Filter_Limit($this->table, 0, $this->startRowToSummarize);
+		$this->table->addRow($newRow);
+	}
+}
+
+

Modified: trunk/modules/DataTable.php
===================================================================
--- trunk/modules/DataTable.php	2008-03-17 14:59:24 UTC (rev 380)
+++ trunk/modules/DataTable.php	2008-03-17 15:25:51 UTC (rev 381)
@@ -255,6 +255,12 @@
 		}
 	}
 	
+	/**
+	 * Returns the Piwik_DataTable_Row that has a column 'label' with the value $label
+	 *
+	 * @param string $label
+	 * @return Piwik_DataTable_Row|false The row
+	 */
 	public function getRowFromLabel( $label )
 	{
 		if($this->indexNotUpToDate)
@@ -418,7 +424,11 @@
 		
 		foreach($rows1 as $row1)
 		{
-			$row2 = $table2->getRowFromLabel($row1->getColumn('label'));	
+			$row2 = $table2->getRowFromLabel($row1->getColumn('label'));
+			if($row2 === false)
+			{
+				return false;
+			}
 			if( !Piwik_DataTable_Row::isEqual($row1,$row2) )
 			{
 				return false;

Modified: trunk/plugins/VisitTime/Controller.php
===================================================================
--- trunk/plugins/VisitTime/Controller.php	2008-03-17 14:59:24 UTC (rev 380)
+++ trunk/plugins/VisitTime/Controller.php	2008-03-17 15:25:51 UTC (rev 381)
@@ -26,6 +26,7 @@
 		$view->setColumnsToDisplay( array(0,2) );
 		$view->setSortedColumn( 0, 'asc' );
 		$view->setLimit( 24 );
+		$view->setGraphLimit( 24 );
 		$view->disableSearchBox();
 		$view->disableExcludeLowPopulation();
 		$view->disableOffsetInformation();

Modified: trunk/tests/modules/DataTable.test.php
===================================================================
--- trunk/tests/modules/DataTable.test.php	2008-03-17 14:59:24 UTC (rev 380)
+++ trunk/tests/modules/DataTable.test.php	2008-03-17 15:25:51 UTC (rev 381)
@@ -524,15 +524,20 @@
 	  		);
 	  	$table->loadFromArray( $rows );
 	  	
+	  	$startRow = 5;
+		$filter = new Piwik_DataTable_Filter_AddSummaryRow($table, $startRow);
+	  	$tableExpected = clone $table;
+	  	$this->assertTrue( Piwik_DataTable::isEqual($table, $tableExpected) );
+//	  	echo $table;
+//	  	echo $tableExpected;
+  		
   		$startRow = 3;
-  		
 	  	$expected = array(
 	  		array( $idcol => array('label'=>'google', 'hits' => 100000)),//0
 	  		array( $idcol => array('label'=>'ask', 'hits' => 10000)),//1
 	  		array( $idcol => array('label'=>'piwik', 'hits' => 1000)),//2
-	  		array( $idcol => array('label'=>'other', 'hits' => 111)),//3
-	  		);
-	  	
+	  		array( $idcol => array('label'=>'Others', 'hits' => 111)),//3
+	  		);	  	
 		$filter = new Piwik_DataTable_Filter_AddSummaryRow($table, $startRow);
 
 	  	$tableExpected = new Piwik_DataTable;
@@ -540,6 +545,8 @@
 //	  	echo $table;
 //	  	echo $tableExpected;
 	  	$this->assertTrue( Piwik_DataTable::isEqual($table, $tableExpected) );
+	  	
+	  	
 	}
 	
 	



More information about the Piwik-svn mailing list