Ejemplo n.º 1
0
 /**
  * Adds a summary row to the given data table
  *
  * @param Piwik_DataTable  $table
  */
 public function filter($table)
 {
     if ($table->getRowsCount() <= $this->startRowToSummarize + 1) {
         return;
     }
     $table->filter('Sort', array($this->columnToSortByBeforeTruncating, 'desc'));
     $rows = $table->getRows();
     $count = $table->getRowsCount();
     $newRow = new Piwik_DataTable_Row();
     for ($i = $this->startRowToSummarize; $i < $count; $i++) {
         if (!isset($rows[$i])) {
             // case when the last row is a summary row, it is not indexed by $cout but by Piwik_DataTable::ID_SUMMARY_ROW
             $summaryRow = $table->getRowFromId(Piwik_DataTable::ID_SUMMARY_ROW);
             //FIXME: I'm not sure why it could return false, but it was reported in: http://forum.piwik.org/read.php?2,89324,page=1#msg-89442
             if ($summaryRow) {
                 $newRow->sumRow($summaryRow, $enableCopyMetadata = false);
             }
         } else {
             $newRow->sumRow($rows[$i], $enableCopyMetadata = false);
         }
     }
     $newRow->setColumns(array('label' => $this->labelSummaryRow) + $newRow->getColumns());
     if ($this->deleteRows) {
         $table->filter('Limit', array(0, $this->startRowToSummarize));
     }
     $table->addSummaryRow($newRow);
     unset($rows);
 }
Ejemplo n.º 2
0
	public function filter($table)
	{
		if($table->getRowsCount() <= $this->startRowToSummarize + 1)
		{
			return;
		}
		$table->filter('Sort', 
							array( $this->columnToSortByBeforeTruncating, 'desc'));
		
		$rows = $table->getRows();
		$count = $table->getRowsCount();
		$newRow = new Piwik_DataTable_Row();
		for($i = $this->startRowToSummarize; $i < $count; $i++)
		{
			if(!isset($rows[$i]))
			{
				// case when the last row is a summary row, it is not indexed by $cout but by Piwik_DataTable::ID_SUMMARY_ROW
				$summaryRow = $table->getRowFromId(Piwik_DataTable::ID_SUMMARY_ROW);
				$newRow->sumRow($summaryRow);
			}
			else
			{
				$newRow->sumRow($rows[$i]);
			}
		}
		
		$newRow->setColumns(array('label' => $this->labelSummaryRow) + $newRow->getColumns());
		$table->filter('Limit', array(0, $this->startRowToSummarize));
		$table->addSummaryRow($newRow);
		unset($rows);
	}
Ejemplo n.º 3
0
 /**
  * Test that adding two string column values results in an exception.
  * 
  * @group Core
  * @group DataTable
  */
 public function testSumRow_stringException()
 {
     $columns = array('super' => array('this column has an array string that will be 0 when algorithm sums the value'));
     $row1 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $columns));
     $columns2 = array('super' => array('this column has geagaean array value, amazing'));
     $row2 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $columns2));
     // TODO: when phpunit 3.7 is released, can do check w/ "@expectedException Exception"
     try {
         $row2->sumRow($row1);
         $this->fail("sumRow did not throw when adding two string columns.");
     } catch (Exception $ex) {
         // pass
     }
 }
 /**
  * Simple test of the DataTable_Row
  */
 function test_sumRow()
 {
     $columns = array('test_int' => 145, 'test_float' => 145.5, 'test_float3' => 1.5, 'test_stringint' => "145", "test" => 'string fake', 'super' => array('this column has an array string that will be 0 when algorithm sums the value'), 'integerArrayToSum' => array(1 => 1, 2 => 10.0, 3 => array(1 => 2, 2 => 3)));
     $metadata = array('logo' => 'piwik.png', 'super' => array('this column has an array value, amazing'));
     $arrayRow = array(Piwik_DataTable_Row::COLUMNS => $columns, Piwik_DataTable_Row::METADATA => $metadata, 'fake useless key' => 38959, 43905724897 => 'value');
     $row1 = new Piwik_DataTable_Row($arrayRow);
     $columns2 = array('test_int' => 5, 'test_float' => 4.5, 'test_float2' => 14.5, 'test_stringint' => "5", 00 => 'toto', 'super' => array('this column has geagaean array value, amazing'), 'integerArrayToSum' => array(1 => 5, 2 => 5.5, 3 => array(2 => 4)));
     $finalRow = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $columns2));
     $finalRow->sumRow($row1);
     $columnsWanted = array('test_int' => 150, 'test_float' => 150.0, 'test_float2' => 14.5, 'test_float3' => 1.5, 'test_stringint' => 150, 'super' => array(0), 'test' => 0, 'integerArrayToSum' => array(1 => 6, 2 => 15.5, 3 => array(1 => 2, 2 => 7)), 00 => 'toto');
     $rowWanted = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $columnsWanted));
     $this->assertTrue(Piwik_DataTable_Row::isEqual($rowWanted, $finalRow));
 }
Ejemplo n.º 5
0
 /**
  * Add a row to the table and rebuild the index if necessary
  * 
  * @param Piwik_DataTable_Row  $row  to add at the end of the array
  */
 public function addRow(Piwik_DataTable_Row $row)
 {
     // if there is a upper limit on the number of allowed rows and the table is full,
     // add the new row to the summary row
     if ($this->maximumAllowedRows > 0 && $this->getRowsCount() >= $this->maximumAllowedRows - 1) {
         if ($this->summaryRow === null) {
             $this->addSummaryRow(new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $row->getColumns())));
             $this->summaryRow->setColumn('label', self::LABEL_SUMMARY_ROW);
         } else {
             $this->summaryRow->sumRow($row, $enableCopyMetadata = false);
         }
         return $this->summaryRow;
     }
     $this->rows[] = $row;
     if (!$this->indexNotUpToDate && $this->rebuildIndexContinuously) {
         $label = $row->getColumn('label');
         if ($label !== false) {
             $this->rowsIndexByLabel[$label] = count($this->rows) - 1;
         }
         $this->indexNotUpToDate = false;
     }
     return $row;
 }