예제 #1
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;
 }
예제 #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
  * @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;
 }