当前位置: 首页>>代码示例>>PHP>>正文


PHP Piwik_DataTable::addRowsFromSerializedArray方法代码示例

本文整理汇总了PHP中Piwik_DataTable::addRowsFromSerializedArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Piwik_DataTable::addRowsFromSerializedArray方法的具体用法?PHP Piwik_DataTable::addRowsFromSerializedArray怎么用?PHP Piwik_DataTable::addRowsFromSerializedArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Piwik_DataTable的用法示例。


在下文中一共展示了Piwik_DataTable::addRowsFromSerializedArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getDataTable

 /**
  * Returns a DataTable that has the name '$name' from the current Archive.
  * If $idSubTable is specified, returns the subDataTable called '$name_$idSubTable'
  *
  * @param string $name
  * @param int $idSubTable optional id SubDataTable
  * @return Piwik_DataTable
  */
 public function getDataTable($name, $idSubTable = null)
 {
     if (!is_null($idSubTable)) {
         $name .= "_{$idSubTable}";
     }
     $this->setRequestedReport($name);
     $data = $this->get($name, 'blob');
     $table = new Piwik_DataTable();
     if ($data !== false) {
         $table->addRowsFromSerializedArray($data);
     }
     if ($data === false && $idSubTable !== null) {
         // This is not expected, but somehow happens in some unknown cases and very rarely.
         // Do not throw error in this case
         // throw new Exception("not expected");
         return new Piwik_DataTable();
     }
     return $table;
 }
开发者ID:0h546f6f78696342756e4e59,项目名称:piwik,代码行数:27,代码来源:Single.php

示例2: testGeneral

 /**
  * General tests that tries to test the normal behaviour of DataTable
  * 
  * We create some tables, add rows, some of the rows link to sub tables
  * 
  * Then we serialize everything, and we check that the unserialize give the same object back
  * 
  * @group Core
  * @group DataTable
  */
 public function testGeneral()
 {
     /*
      * create some fake tables to make sure that the serialized array of the first TABLE
      * does not take in consideration those tables
      */
     $useless1 = new Piwik_DataTable();
     $useless1->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(13)));
     /*
      * end fake tables
      */
     /*
      * MAIN TABLE
      */
     $table = new Piwik_DataTable();
     $subtable = new Piwik_DataTable();
     $idtable = $table->getId();
     $idsubtable = $subtable->getId();
     /*
      * create some fake tables to make sure that the serialized array of the first TABLE
      * does not take in consideration those tables
      * -> we check that the DataTable_Manager is not impacting DataTable 
      */
     $useless2 = new Piwik_DataTable();
     $useless1->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(8487)));
     $useless3 = new Piwik_DataTable();
     $useless3->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(8487)));
     /*
      * end fake tables
      */
     $row = array(Piwik_DataTable_Row::COLUMNS => array(0 => 1554, 1 => 42, 2 => 657, 3 => 155744), Piwik_DataTable_Row::METADATA => array('logo' => 'test.png'));
     $row = new Piwik_DataTable_Row($row);
     $table->addRow($row);
     $table->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(0 => 1554, 1 => 42), Piwik_DataTable_Row::METADATA => array('url' => 'piwik.org')));
     $table->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(0 => 787877888787.0), Piwik_DataTable_Row::METADATA => array('url' => 'OUPLA ADDED'), Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subtable));
     /*
      * SUB TABLE
      */
     $row = array(Piwik_DataTable_Row::COLUMNS => array(0 => 1554), Piwik_DataTable_Row::METADATA => array('searchengine' => 'google'));
     $subtable->addRowFromArray($row);
     $row = array(Piwik_DataTable_Row::COLUMNS => array(0 => 84894), Piwik_DataTable_Row::METADATA => array('searchengine' => 'yahoo'));
     $subtable->addRowFromArray($row);
     $row = array(Piwik_DataTable_Row::COLUMNS => array(0 => 4898978989.0), Piwik_DataTable_Row::METADATA => array('searchengine' => 'ask'));
     $subtable->addRowFromArray($row);
     /*
      * SUB SUB TABLE
      */
     $subsubtable = new Piwik_DataTable();
     $subsubtable->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(245), Piwik_DataTable_Row::METADATA => array('yes' => 'subsubmetadata1')));
     $subsubtable->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(13), Piwik_DataTable_Row::METADATA => array('yes' => 'subsubmetadata2')));
     $row = array(Piwik_DataTable_Row::COLUMNS => array(0 => 666666666666666.0), Piwik_DataTable_Row::METADATA => array('url' => 'NEW ROW ADDED'), Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subsubtable);
     $subtable->addRowFromArray($row);
     $idsubsubtable = $subsubtable->getId();
     $serialized = $table->getSerialized();
     $this->assertEquals(array_keys($serialized), array($idsubsubtable, $idsubtable, 0));
     // In the next test we compare an unserialized datatable with its original instance.
     // The unserialized datatable rows will have positive DATATABLE_ASSOCIATED ids.
     // Positive DATATABLE_ASSOCIATED ids mean that the associated sub-datatables are not loaded in memory.
     // In this case, this is NOT true: we know that the sub-datatable is loaded in memory.
     // HOWEVER, because of datatable id conflicts happening in the datatable manager, it is not yet
     // possible to know, after unserializing a datatable, if its sub-datatables are loaded in memory.
     $expectedTableRows = array();
     foreach ($table->getRows() as $currentRow) {
         $expectedTableRow = clone $currentRow;
         $currentRowAssociatedDatatableId = $currentRow->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED];
         if ($currentRowAssociatedDatatableId != null) {
             // making DATATABLE_ASSOCIATED ids positive
             $expectedTableRow->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] = -1 * $currentRowAssociatedDatatableId;
         }
         $expectedTableRows[] = $expectedTableRow;
     }
     $tableAfter = new Piwik_DataTable();
     $tableAfter->addRowsFromSerializedArray($serialized[0]);
     $this->assertEquals($expectedTableRows, $tableAfter->getRows());
     $subsubtableAfter = new Piwik_DataTable();
     $subsubtableAfter->addRowsFromSerializedArray($serialized[$idsubsubtable]);
     $this->assertEquals($subsubtable->getRows(), $subsubtableAfter->getRows());
     $this->assertEquals($table, Piwik_DataTable_Manager::getInstance()->getTable($idtable));
     $this->assertEquals($subsubtable, Piwik_DataTable_Manager::getInstance()->getTable($idsubsubtable));
 }
开发者ID:nnnnathann,项目名称:piwik,代码行数:90,代码来源:DataTableTest.php

示例3: getDataTable

 /**
  * Returns a DataTable that has the name '$name' from the current Archive.
  * If $idSubTable is specified, returns the subDataTable called '$name_$idSubTable'
  *
  * @param string $name
  * @param int $idSubTable optional id SubDataTable
  * @return Piwik_DataTable
  */
 public function getDataTable($name, $idSubTable = null)
 {
     if (!is_null($idSubTable)) {
         $name .= "_{$idSubTable}";
     }
     $data = $this->get($name, 'blob');
     $table = new Piwik_DataTable();
     if ($data !== false) {
         $table->addRowsFromSerializedArray($data);
     }
     if ($data === false && $idSubTable !== null) {
         throw new Exception("You are requesting a precise subTable but there is not such data in the Archive.");
     }
     return $table;
 }
开发者ID:BackupTheBerlios,项目名称:oos-svn,代码行数:23,代码来源:Single.php

示例4: array

 /**
  * General tests that tries to test the normal behaviour of DataTable
  * 
  * We create some tables, add rows, some of the rows link to sub tables
  * 
  * Then we serialize everything, and we check that the unserialize give the same object back
  */
 function test_general()
 {
     /*
      * create some fake tables to make sure that the serialized array of the first TABLE
      * does not take in consideration those tables
      */
     $useless1 = new Piwik_DataTable();
     $useless1->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(13)));
     /*
      * end fake tables
      */
     /*
      * MAIN TABLE
      */
     $table = new Piwik_DataTable();
     $subtable = new Piwik_DataTable();
     $idtable = $table->getId();
     $idsubtable = $subtable->getId();
     /*
      * create some fake tables to make sure that the serialized array of the first TABLE
      * does not take in consideration those tables
      * -> we check that the DataTable_Manager is not impacting DataTable 
      */
     $useless2 = new Piwik_DataTable();
     $useless1->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(8487)));
     $useless3 = new Piwik_DataTable();
     $useless3->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(8487)));
     /*
      * end fake tables
      */
     $row = array(Piwik_DataTable_Row::COLUMNS => array(0 => 1554, 1 => 42, 2 => 657, 3 => 155744), Piwik_DataTable_Row::METADATA => array('logo' => 'test.png'));
     $row = new Piwik_DataTable_Row($row);
     $table->addRow($row);
     $table->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(0 => 1554, 1 => 42), Piwik_DataTable_Row::METADATA => array('url' => 'piwik.org')));
     $table->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(0 => 787877888787), Piwik_DataTable_Row::METADATA => array('url' => 'OUPLA ADDED'), Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subtable));
     /*
      * SUB TABLE
      */
     $row = array(Piwik_DataTable_Row::COLUMNS => array(0 => 1554), Piwik_DataTable_Row::METADATA => array('searchengine' => 'google'));
     $subtable->addRowFromArray($row);
     $row = array(Piwik_DataTable_Row::COLUMNS => array(0 => 84894), Piwik_DataTable_Row::METADATA => array('searchengine' => 'yahoo'));
     $subtable->addRowFromArray($row);
     $row = array(Piwik_DataTable_Row::COLUMNS => array(0 => 4898978989), Piwik_DataTable_Row::METADATA => array('searchengine' => 'ask'));
     $subtable->addRowFromArray($row);
     /*
      * SUB SUB TABLE
      */
     $subsubtable = new Piwik_DataTable();
     $subsubtable->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(245), Piwik_DataTable_Row::METADATA => array('yes' => 'subsubmetadata1')));
     $subsubtable->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(13), Piwik_DataTable_Row::METADATA => array('yes' => 'subsubmetadata2')));
     $row = array(Piwik_DataTable_Row::COLUMNS => array(0 => 666666666666666), Piwik_DataTable_Row::METADATA => array('url' => 'NEW ROW ADDED'), Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subsubtable);
     $subtable->addRowFromArray($row);
     $idsubsubtable = $subsubtable->getId();
     $serialized = $table->getSerialized();
     $this->assertEqual(array_keys($serialized), array($idsubsubtable, $idsubtable, 0));
     $tableAfter = new Piwik_DataTable();
     $tableAfter->addRowsFromSerializedArray($serialized[0]);
     $this->assertEqual($table->getRows(), $tableAfter->getRows());
     $subsubtableAfter = new Piwik_DataTable();
     $subsubtableAfter->addRowsFromSerializedArray($serialized[$idsubsubtable]);
     $this->assertEqual($subsubtable->getRows(), $subsubtableAfter->getRows());
     $this->assertEqual($table, Piwik_DataTable_Manager::getInstance()->getTable($idtable));
     $this->assertEqual($subsubtable, Piwik_DataTable_Manager::getInstance()->getTable($idsubsubtable));
 }
开发者ID:0h546f6f78696342756e4e59,项目名称:piwik,代码行数:71,代码来源:DataTable.test.php

示例5: getRowCountsByArchiveName

 /**
  * Utility function. Gets row count of a set of tables grouped by the 'name' column.
  * This is the implementation of the getRowCountsAndSizeBy... functions.
  */
 private function getRowCountsByArchiveName($statuses, $getRowSizeMethod, $forceCache = false, $otherSelects = array(), $otherDataTableColumns = array())
 {
     $extraCols = '';
     if (!empty($otherSelects)) {
         $extraCols = ', ' . implode(', ', $otherSelects);
     }
     $cols = array_merge(array('row_count'), $otherDataTableColumns);
     $dataTable = new Piwik_DataTable();
     foreach ($statuses as $status) {
         $dataTableOptionName = $this->getCachedOptionName($status['Name'], 'byArchiveName');
         // if option exists && !$forceCache, use the cached data, otherwise create the
         $cachedData = Piwik_GetOption($dataTableOptionName);
         if ($cachedData !== false && !$forceCache) {
             $table = new Piwik_DataTable();
             $table->addRowsFromSerializedArray($cachedData);
         } else {
             // otherwise, create data table & cache it
             $sql = "SELECT name as 'label', COUNT(*) as 'row_count'{$extraCols} FROM {$status['Name']} GROUP BY name";
             $table = new Piwik_DataTable();
             $table->addRowsFromSimpleArray(Piwik_FetchAll($sql));
             $reduceArchiveRowName = array($this, 'reduceArchiveRowName');
             $table->filter('GroupBy', array('label', $reduceArchiveRowName));
             $serializedTables = $table->getSerialized();
             $serializedTable = reset($serializedTables);
             Piwik_SetOption($dataTableOptionName, $serializedTable);
         }
         // add estimated_size column
         $getEstimatedSize = array($this, $getRowSizeMethod);
         $table->filter('ColumnCallbackAddColumn', array($cols, 'estimated_size', $getEstimatedSize, array($status)));
         $dataTable->addDataTable($table);
         destroy($table);
     }
     return $dataTable;
 }
开发者ID:nnnnathann,项目名称:piwik,代码行数:38,代码来源:MySQLMetadataProvider.php


注:本文中的Piwik_DataTable::addRowsFromSerializedArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。