Skip to content
Extraits de code Groupes Projets
Valider ea0858cf rédigé par BeezyT's avatar BeezyT
Parcourir les fichiers

refs #2697 parent reference can be archived with nested datatables

git-svn-id: http://dev.piwik.org/svn/trunk@5286 59fd770c-687e-43c8-a1e3-f5a4ff64c105
parent 56e7be3c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -130,6 +130,10 @@ time_before_today_archive_considered_outdated = 10 ...@@ -130,6 +130,10 @@ time_before_today_archive_considered_outdated = 10
; to trigger the Piwik archiving process. ; to trigger the Piwik archiving process.
enable_browser_archiving_triggering = 1 enable_browser_archiving_triggering = 1
; If set to 1, nested reports will be archived with parent references in the datatables
; At the moment, this is not needed in core but it can be handy for plugins
enable_archive_parents_of_datatable = 0
; MySQL minimum required version ; MySQL minimum required version
; note: timezone support added in 4.1.3 ; note: timezone support added in 4.1.3
minimum_mysql_version = 4.1 minimum_mysql_version = 4.1
......
...@@ -443,7 +443,7 @@ class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing ...@@ -443,7 +443,7 @@ class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing
* @param array $table * @param array $table
* @return Piwik_DataTable * @return Piwik_DataTable
*/ */
static public function generateDataTable( $table ) static public function generateDataTable( $table, $parents=array() )
{ {
$dataTableToReturn = new Piwik_DataTable(); $dataTableToReturn = new Piwik_DataTable();
foreach($table as $label => $maybeDatatableRow) foreach($table as $label => $maybeDatatableRow)
...@@ -454,10 +454,15 @@ class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing ...@@ -454,10 +454,15 @@ class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing
// and we associate this row to the subtable // and we associate this row to the subtable
if( !($maybeDatatableRow instanceof Piwik_DataTable_Row) ) if( !($maybeDatatableRow instanceof Piwik_DataTable_Row) )
{ {
$subTable = self::generateDataTable($maybeDatatableRow); array_push($parents, array($dataTableToReturn->getId(), $label));
$subTable = self::generateDataTable($maybeDatatableRow, $parents);
$subTable->setParents($parents);
$row = new Piwik_DataTable_Row_DataTableSummary( $subTable ); $row = new Piwik_DataTable_Row_DataTableSummary( $subTable );
$row->setColumns( array('label' => $label) + $row->getColumns()); $row->setColumns( array('label' => $label) + $row->getColumns());
$row->addSubtable($subTable); $row->addSubtable($subTable);
array_pop($parents);
} }
// if aInfo is a simple Row we build it // if aInfo is a simple Row we build it
else else
......
...@@ -145,6 +145,13 @@ class Piwik_DataTable ...@@ -145,6 +145,13 @@ class Piwik_DataTable
*/ */
protected $rows = array(); protected $rows = array();
/**
* Array of parent IDs
*
* @var array
*/
protected $parents = null;
/** /**
* Id assigned to the DataTable, used to lookup the table using the DataTable_Manager * Id assigned to the DataTable, used to lookup the table using the DataTable_Manager
* *
...@@ -219,6 +226,7 @@ class Piwik_DataTable ...@@ -219,6 +226,7 @@ class Piwik_DataTable
const ID_SUMMARY_ROW = -1; const ID_SUMMARY_ROW = -1;
const LABEL_SUMMARY_ROW = -1; const LABEL_SUMMARY_ROW = -1;
const ID_PARENTS = -2;
/** /**
* Maximum nesting level * Maximum nesting level
...@@ -469,15 +477,27 @@ class Piwik_DataTable ...@@ -469,15 +477,27 @@ class Piwik_DataTable
*/ */
public function getFilteredTableFromLabel($label) public function getFilteredTableFromLabel($label)
{ {
$newTable = new Piwik_DataTable; $newTable = $this->getEmptyClone();
$row = $this->getRowFromLabel($label); $row = $this->getRowFromLabel($label);
if ($row !== false) if ($row !== false)
{ {
$newTable->addRow($row); $newTable->addRow($row);
$newTable->queuedFilters = $this->queuedFilters;
} }
return $newTable; return $newTable;
} }
/**
* Get an empty table with the same properties as this one
*
* @return Piwik_DataTable
*/
public function getEmptyClone()
{
$clone = new Piwik_DataTable;
$clone->queuedFilters = $this->queuedFilters;
return $clone;
}
/** /**
* Rebuilds the index used to lookup a row by label * Rebuilds the index used to lookup a row by label
...@@ -978,8 +998,12 @@ class Piwik_DataTable ...@@ -978,8 +998,12 @@ class Piwik_DataTable
} }
// we then serialize the rows and store them in the serialized dataTable // we then serialize the rows and store them in the serialized dataTable
$aSerializedDataTable[$forcedId] = serialize($this->rows + array( self::ID_SUMMARY_ROW => $this->summaryRow)); $addToRows = array( self::ID_SUMMARY_ROW => $this->summaryRow );
if ($this->parents && Zend_Registry::get('config')->General->enable_archive_parents_of_datatable)
{
$addToRows[self::ID_PARENTS] = $this->parents;
}
$aSerializedDataTable[$forcedId] = serialize($this->rows + $addToRows);
return $aSerializedDataTable; return $aSerializedDataTable;
} }
...@@ -1024,6 +1048,12 @@ class Piwik_DataTable ...@@ -1024,6 +1048,12 @@ class Piwik_DataTable
{ {
foreach($array as $id => $row) foreach($array as $id => $row)
{ {
if($id == self::ID_PARENTS)
{
$this->parents = $row;
continue;
}
if(is_array($row)) if(is_array($row))
{ {
$row = new Piwik_DataTable_Row($row); $row = new Piwik_DataTable_Row($row);
...@@ -1200,4 +1230,26 @@ class Piwik_DataTable ...@@ -1200,4 +1230,26 @@ class Piwik_DataTable
$this->addRow( new Piwik_DataTable_Row($cleanRow) ); $this->addRow( new Piwik_DataTable_Row($cleanRow) );
} }
} }
/**
* Set the array of parent ids
* @param array $parents
*/
public function setParents($parents)
{
$this->parents = $parents;
}
/**
* Get parents
* @return array of all parents, root level first
*/
public function getParents() {
if ($this->parents == null)
{
return array();
}
return $this->parents;
}
} }
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter