Beispiel #1
0
 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', $this->labelSummaryRow);
     $filter = new Piwik_DataTable_Filter_Limit($this->table, 0, $this->startRowToSummarize);
     $this->table->addRow($newRow);
 }
Beispiel #2
0
 /**
  * Generates a dataTable given a multidimensional PHP array that associates LABELS to Piwik_DataTableRows
  * This is used for the "Actions" DataTable, where a line is the aggregate of all the subtables
  * Example: the category /blog has 3 visits because it has /blog/index (2 visits) + /blog/about (1 visit) 
  *
  * @param array $table
  * @return Piwik_DataTable
  */
 public static function generateDataTable($table)
 {
     $dataTableToReturn = new Piwik_DataTable();
     foreach ($table as $label => $maybeDatatableRow) {
         // case the aInfo is a subtable-like array
         // it means that we have to go recursively and process it
         // then we build the row that is an aggregate of all the children
         // and we associate this row to the subtable
         if (!$maybeDatatableRow instanceof Piwik_DataTable_Row) {
             $subTable = self::generateDataTable($maybeDatatableRow);
             $row = new Piwik_DataTable_Row_DataTableSummary($subTable);
             $row->setColumns(array('label' => $label) + $row->getColumns());
             $row->addSubtable($subTable);
         } else {
             $row = $maybeDatatableRow;
         }
         $dataTableToReturn->addRow($row);
     }
     return $dataTableToReturn;
 }
Beispiel #3
0
 /**
  * Traverses a DataTable tree using an array of labels and returns the row
  * it finds or false if it cannot find one, and the number of segments of
  * the path successfully walked.
  * 
  * If $missingRowColumns is supplied, the specified path is created. When
  * a subtable is encountered w/o the queried label, a new row is created
  * with the label, and a subtable is added to the row.
  * 
  * @param array $path The path to walk. An array of label values.
  * @param array|false $missingRowColumns
  *						The default columns to use when creating new arrays.
  * 						If this parameter is supplied, new rows will be
  * 						created if labels cannot be found.
  * @param int $maxSubtableRows The maximum number of allowed rows in new
  *                             subtables.
  * @return array First element is the found row or false. Second element is
  *               the number of path segments walked. If a row is found, this
  *               will be == to count($path). Otherwise, it will be the index
  *               of the path segment that we could not find.
  */
 public function walkPath($path, $missingRowColumns = false, $maxSubtableRows = 0)
 {
     $pathLength = count($path);
     $table = $this;
     $next = false;
     for ($i = 0; $i < $pathLength; ++$i) {
         $segment = $path[$i];
         $next = $table->getRowFromLabel($segment);
         if ($next === false) {
             // if there is no table to advance to, and we're not adding missing rows, return false
             if ($missingRowColumns === false) {
                 return array(false, $i);
             } else {
                 $row = new Piwik_DataTable_Row_DataTableSummary();
                 $row->setColumns(array('label' => $segment) + $missingRowColumns);
                 $next = $table->addRow($row);
                 if ($next !== $row) {
                     // Summary row, has no metadata
                     $next->deleteMetadata();
                     return array($next, $i);
                 }
             }
         }
         $table = $next->getSubtable();
         if ($table === false) {
             // if the row has no table (and thus no child rows), and we're not adding
             // missing rows, return false
             if ($missingRowColumns === false) {
                 return array(false, $i);
             } else {
                 if ($i != $pathLength - 1) {
                     $table = new Piwik_DataTable();
                     $table->setMaximumAllowedRows($maxSubtableRows);
                     $next->setSubtable($table);
                     // Summary row, has no metadata
                     $next->deleteMetadata();
                 }
             }
         }
     }
     return array($next, $i);
 }
Beispiel #4
0
 /**
  * Generates a dataTable given a multidimensional PHP array that associates LABELS to Piwik_DataTableRows
  * This is used for the "Actions" DataTable, where a line is the aggregate of all the subtables
  * Example: the category /blog has 3 visits because it has /blog/index (2 visits) + /blog/about (1 visit)
  *
  * @param array  $table
  * @param array  $parents
  * @return Piwik_DataTable
  */
 public static function generateDataTable($table, $parents = array())
 {
     $dataTableToReturn = new Piwik_DataTable();
     foreach ($table as $label => $maybeDatatableRow) {
         // case the aInfo is a subtable-like array
         // it means that we have to go recursively and process it
         // then we build the row that is an aggregate of all the children
         // and we associate this row to the subtable
         if (!$maybeDatatableRow instanceof Piwik_DataTable_Row) {
             array_push($parents, array($dataTableToReturn->getId(), $label));
             $subTable = self::generateDataTable($maybeDatatableRow, $parents);
             $subTable->setParents($parents);
             $row = new Piwik_DataTable_Row_DataTableSummary($subTable);
             $row->setColumns(array('label' => $label) + $row->getColumns());
             $row->addSubtable($subTable);
             array_pop($parents);
         } else {
             $row = $maybeDatatableRow;
         }
         if ($row->getMetadata('issummaryrow') == true) {
             $row->deleteMetadata('issummaryrow');
             $dataTableToReturn->addSummaryRow($row);
         } else {
             $dataTableToReturn->addRow($row);
         }
     }
     return $dataTableToReturn;
 }