[Piwik-svn] r380 - in trunk: modules modules/API modules/ArchiveProcessing modules/DataTable modules/DataTable/Filter modules/DataTable/Row modules/ViewDataTable modules/Visualization plugins/UserSettings tests/modules

svnmaster at piwik.org svnmaster at piwik.org
Mon Mar 17 15:59:26 CET 2008


Author: matt
Date: 2008-03-17 15:59:24 +0100 (Mon, 17 Mar 2008)
New Revision: 380

Modified:
   trunk/modules/API/Request.php
   trunk/modules/ArchiveProcessing/Day.php
   trunk/modules/DataTable.php
   trunk/modules/DataTable/Filter.php
   trunk/modules/DataTable/Filter/Limit.php
   trunk/modules/DataTable/Row/DataTableSummary.php
   trunk/modules/ViewDataTable.php
   trunk/modules/ViewDataTable/GenerateGraphData.php
   trunk/modules/Visualization/ChartPie.php
   trunk/plugins/UserSettings/Controller.php
   trunk/tests/modules/DataTable.test.php
Log:
- fix #110 Added new Filter to create a Summary row in a given datatable. See Piwik_DataTable_Filter_AddSummaryRow
- fix #111 Applied patch, thanks mauser :)

Modified: trunk/modules/API/Request.php
===================================================================
--- trunk/modules/API/Request.php	2008-03-17 10:15:44 UTC (rev 379)
+++ trunk/modules/API/Request.php	2008-03-17 14:59:24 UTC (rev 380)
@@ -237,9 +237,8 @@
 				{
 					$this->applyDataTableGenericFilters($table);
 				}
-			}			
-//			echo($returnedValue);exit;
-		
+			}
+			
 			// if the flag disable_queued_filters is defined we skip the filters that were queued
 			// useful in some very rare cases but better to use this than a bad hack on the data returned...
 			if(Piwik_Common::getRequestVar('disable_queued_filters', 'false', 'string', $this->requestToUse) == 'false')

Modified: trunk/modules/ArchiveProcessing/Day.php
===================================================================
--- trunk/modules/ArchiveProcessing/Day.php	2008-03-17 10:15:44 UTC (rev 379)
+++ trunk/modules/ArchiveProcessing/Day.php	2008-03-17 14:59:24 UTC (rev 380)
@@ -186,6 +186,7 @@
 			{
 				$subTable = self::generateDataTable($maybeDatatableRow);
 				$row = new Piwik_DataTable_Row_DataTableSummary( $subTable );
+				$row->addSubtable($subTable);
 				$row->setColumn('label', $label);
 			}
 			// if aInfo is a simple Row we build it

Modified: trunk/modules/DataTable/Filter/Limit.php
===================================================================
--- trunk/modules/DataTable/Filter/Limit.php	2008-03-17 10:15:44 UTC (rev 379)
+++ trunk/modules/DataTable/Filter/Limit.php	2008-03-17 14:59:24 UTC (rev 380)
@@ -18,11 +18,24 @@
 
 class Piwik_DataTable_Filter_Limit extends Piwik_DataTable_Filter
 {	
-	public function __construct( $table, $offset, $limit )
+	/**
+	 * 
+	 *
+	 * @param Piwik_DataTable $table
+	 * @param int $offset Starting row 
+	 * @param int $limit Number of rows to keep (specify -1 to keep all rows)
+	 */
+	public function __construct( $table, $offset, $limit = null )
 	{
 		parent::__construct($table);
 		$this->offset = $offset;
+		
+		if(is_null($limit))
+		{
+			$limit = -1;
+		}
 		$this->limit = $limit;
+		
 		$this->filter();
 	}
 	

Modified: trunk/modules/DataTable/Filter.php
===================================================================
--- trunk/modules/DataTable/Filter.php	2008-03-17 10:15:44 UTC (rev 379)
+++ trunk/modules/DataTable/Filter.php	2008-03-17 14:59:24 UTC (rev 380)
@@ -51,3 +51,4 @@
 require_once "DataTable/Filter/PatternRecursive.php";
 require_once "DataTable/Filter/ReplaceColumnNames.php";
 require_once "DataTable/Filter/Sort.php";
+require_once "DataTable/Filter/AddSummaryRow.php";

Modified: trunk/modules/DataTable/Row/DataTableSummary.php
===================================================================
--- trunk/modules/DataTable/Row/DataTableSummary.php	2008-03-17 10:15:44 UTC (rev 379)
+++ trunk/modules/DataTable/Row/DataTableSummary.php	2008-03-17 14:59:24 UTC (rev 380)
@@ -25,7 +25,6 @@
 	function __construct($subTable)
 	{
 		parent::__construct();
-		$this->addSubtable($subTable);
 		foreach($subTable->getRows() as $row)
 		{
 			$this->sumRow($row);

Modified: trunk/modules/DataTable.php
===================================================================
--- trunk/modules/DataTable.php	2008-03-17 10:15:44 UTC (rev 379)
+++ trunk/modules/DataTable.php	2008-03-17 14:59:24 UTC (rev 380)
@@ -162,6 +162,13 @@
 		$this->rowsCountBeforeLimitFilter = $this->getRowsCount();
 	}
 	
+	/**
+	 * Queue a DataTable_Filter that will be applied at the end of the process 
+	 * (just before sending the datatable back to the browser (or API, etc.)
+	 *
+	 * @param string $className The class name of the filter, eg. Piwik_DataTable_Filter_Limit
+	 * @param array $parameters The parameters to give to the filter, eg. array( $offset, $limit) for the filter Piwik_DataTable_Filter_Limit
+	 */
 	public function queueFilter( $className, $parameters = array() )
 	{
 		if(!is_array($parameters))

Modified: trunk/modules/ViewDataTable/GenerateGraphData.php
===================================================================
--- trunk/modules/ViewDataTable/GenerateGraphData.php	2008-03-17 10:15:44 UTC (rev 379)
+++ trunk/modules/ViewDataTable/GenerateGraphData.php	2008-03-17 14:59:24 UTC (rev 380)
@@ -26,7 +26,7 @@
 						$moduleNameAndMethod );
 	}
 	
-	protected $graphLimit;
+	protected $graphLimit = 5;
 	
 	function setGraphLimit( $limit )
 	{
@@ -36,8 +36,7 @@
 	function getGraphLimit()
 	{
 		return $this->graphLimit;
-	}
-	
+	}
 	public function main()
 	{
 		if($this->mainAlreadyExecuted)
@@ -46,12 +45,11 @@
 		}
 		$this->mainAlreadyExecuted = true;
 	
+		$this->setLimit(-1);
 		
-		$this->setLimit($this->getGraphLimit());
-		
 		// we load the data with the filters applied
 		$this->loadDataTableFromAPI();
-		
+		$this->dataTable->queueFilter('Piwik_DataTable_Filter_AddSummaryRow',array($this->getGraphLimit()));
 //		echo $this->dataTable;
 		$this->dataAvailable = $this->dataTable->getRowsCount() != 0;
 		
@@ -61,8 +59,7 @@
 			$this->view->title("No data for this graph", '{font-size: 25px;}');
 		}
 		else
-		{
-//			echo $this->dataTable;
+		{
 			$data = $this->generateDataFromDataTable();
 			$this->view->setData($data);
 			$this->view->customizeGraph();
@@ -71,6 +68,8 @@
 	
 	protected function generateDataFromDataTable()
 	{
+		$this->dataTable->applyQueuedFilters();
+		
 		// We apply a filter to the DataTable, decoding the label column (useful for keywords for example)
 		$filter = new Piwik_DataTable_Filter_ColumnCallbackReplace(
 									$this->dataTable, 
@@ -93,6 +92,7 @@
 				'url' 	=> $row->getDetail('url'),
 			);
 		}
+//		var_dump($data);exit;
 		return $data;
 	}
 }

Modified: trunk/modules/ViewDataTable.php
===================================================================
--- trunk/modules/ViewDataTable.php	2008-03-17 10:15:44 UTC (rev 379)
+++ trunk/modules/ViewDataTable.php	2008-03-17 14:59:24 UTC (rev 380)
@@ -33,7 +33,10 @@
 	protected $currentControllerName;
 	
 	protected $actionToLoadTheSubTable = null;
-	
+	
+	/**
+	 * @var Piwik_DataTable
+	 */
 	public $dataTable; // data table
 	
 	protected $moduleNameAndMethod;
@@ -334,7 +337,9 @@
 			'filter_excludelowpop',
 			'filter_excludelowpop_value',
 			'filter_column', 
-			'filter_pattern' 
+			'filter_pattern',
+			'disable_generic_filters',
+			'disable_queued_filters',
 		);
 		foreach($toSetEventually as $varToSet)
 		{
@@ -390,7 +395,11 @@
 	{
 		return $this->JSsortEnabled;		
 	}
-	
+
+	public function disableGenericFilters()
+	{
+		$this->variablesDefault['disable_generic_filters'] = true;
+	}
 	public function disableOffsetInformation()
 	{
 		$this->JSoffsetInformation = 'false';		

Modified: trunk/modules/Visualization/ChartPie.php
===================================================================
--- trunk/modules/Visualization/ChartPie.php	2008-03-17 10:15:44 UTC (rev 379)
+++ trunk/modules/Visualization/ChartPie.php	2008-03-17 14:59:24 UTC (rev 380)
@@ -22,7 +22,14 @@
 		
 		$this->prepareData();		
 //		$this->title( 'PIE Chart', '{font-size: 20px;}' );
-		
+	
+	    // strip labels
+	    for($i = 0, $cnt = count($this->arrayLabel); $i < $cnt; $i++) 
+	    {
+	    	$label = $this->arrayLabel[$i];
+			$this->arrayLabel[$i] = (strlen($label) > 20 ? substr($label, 0, 20).'...' : $label);
+	    }
+	    
 		//
 		$this->pie(60,'#505050','#142448', true);
 		//

Modified: trunk/plugins/UserSettings/Controller.php
===================================================================
--- trunk/plugins/UserSettings/Controller.php	2008-03-17 10:15:44 UTC (rev 379)
+++ trunk/plugins/UserSettings/Controller.php	2008-03-17 14:59:24 UTC (rev 380)
@@ -32,7 +32,7 @@
 		$view->disableSearchBox();
 		$view->disableExcludeLowPopulation();
 		
-		$view->setColumnsToDisplay( array(0,2) );
+		$view->setColumnsToDisplay( array(0,1) );
 		$view->setSortedColumn( 1 );
 		$view->setLimit( 5 );
 		$view->setGraphLimit(5);

Modified: trunk/tests/modules/DataTable.test.php
===================================================================
--- trunk/tests/modules/DataTable.test.php	2008-03-17 10:15:44 UTC (rev 379)
+++ trunk/tests/modules/DataTable.test.php	2008-03-17 14:59:24 UTC (rev 380)
@@ -503,7 +503,47 @@
 	  	
 	  	$this->assertEqual(array_values($table->getRows()), array_values($expectedtable->getRows()));
 	 }
+	 
+
 	/**
+	 * Test to summarize a given datatable's rows from N to M
+	 * Keep the row 0 to N-1
+	 * Add a new row summarizing the others
+	 */
+	 function test_filter_AddSummaryRow()
+	 {
+	 	$table = new Piwik_DataTable;
+	 	$idcol = Piwik_DataTable_Row::COLUMNS;
+	  	$rows = 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'=>'yahoo', 'hits' => 100)),//3
+	  		array( $idcol => array('label'=>'amazon', 'hits' => 10)),//4
+	  		array( $idcol => array('label'=>'238975247578949', 'hits' => 1)),//5
+	  		);
+	  	$table->loadFromArray( $rows );
+	  	
+  		$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
+	  		);
+	  	
+		$filter = new Piwik_DataTable_Filter_AddSummaryRow($table, $startRow);
+
+	  	$tableExpected = new Piwik_DataTable;
+	  	$tableExpected->loadFromArray( $expected );
+//	  	echo $table;
+//	  	echo $tableExpected;
+	  	$this->assertTrue( Piwik_DataTable::isEqual($table, $tableExpected) );
+	}
+	
+	
+	/**
 	 * Test to sort by label
 	 */
 	 function test_filter_SortString()
@@ -674,9 +714,6 @@
 	  	
 	 	$filter = new Piwik_DataTable_Filter_ExcludeLowPopulation($table, 'nb_visits', 1.4);
 
-//	  	echo $table;
-//	  	echo $expectedtable;
-//	  	dump($table);
 	  	$this->assertTrue(Piwik_DataTable::isEqual($table, $expectedtable));
 	 }
 	



More information about the Piwik-svn mailing list