本文整理汇总了PHP中Piwik\DataTable\Manager类的典型用法代码示例。如果您正苦于以下问题:PHP Manager类的具体用法?PHP Manager怎么用?PHP Manager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Manager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filter
/**
* See {@link PatternRecursive}.
*
* @param DataTable $table
* @return int The number of deleted rows.
*/
public function filter($table)
{
$rows = $table->getRows();
foreach ($rows as $key => $row) {
// A row is deleted if
// 1 - its label doesnt contain the pattern
// AND 2 - the label is not found in the children
$patternNotFoundInChildren = false;
try {
$idSubTable = $row->getIdSubDataTable();
$subTable = Manager::getInstance()->getTable($idSubTable);
// we delete the row if we couldn't find the pattern in any row in the
// children hierarchy
if ($this->filter($subTable) == 0) {
$patternNotFoundInChildren = true;
}
} catch (Exception $e) {
// there is no subtable loaded for example
$patternNotFoundInChildren = true;
}
if ($patternNotFoundInChildren && !Pattern::match($this->patternToSearchQuoted, $row->getColumn($this->columnToFilter), $invertedMatch = false)) {
$table->deleteRow($key);
}
}
return $table->getRowsCount();
}
示例2: recalculate
/**
* Reset this row to an empty one and sums the associated subtable again.
*/
public function recalculate()
{
$id = $this->getIdSubDataTable();
if ($id !== null) {
$subTable = Manager::getInstance()->getTable($id);
$this->sumTable($subTable);
}
}
示例3: filterSubTable
/**
* Filters a row's subtable, if one exists and is loaded in memory.
*
* @param Row $row The row whose subtable should be filter.
*/
public function filterSubTable(Row $row)
{
if (!$this->enableRecursive) {
return;
}
if ($row->isSubtableLoaded()) {
$subTable = Manager::getInstance()->getTable($row->getIdSubDataTable());
$this->filter($subTable);
}
}
示例4: filter
/**
* See {@link ReplaceSummaryRowLabel}.
*
* @param DataTable $table
*/
public function filter($table)
{
$rows = $table->getRows();
foreach ($rows as $id => $row) {
if ($row->getColumn('label') == DataTable::LABEL_SUMMARY_ROW || $id == DataTable::ID_SUMMARY_ROW) {
$row->setColumn('label', $this->newLabel);
break;
}
}
// recurse
foreach ($rows as $row) {
if ($row->isSubtableLoaded()) {
$subTable = Manager::getInstance()->getTable($row->getIdSubDataTable());
$this->filter($subTable);
}
}
}
示例5: callAggregateAllPlugins
/**
* Instantiates the Archiver class in each plugin that defines it,
* and triggers Aggregation processing on these plugins.
*/
public function callAggregateAllPlugins($visits, $visitsConverted)
{
$this->archiveProcessor->setNumberOfVisits($visits, $visitsConverted);
$archivers = $this->getPluginArchivers();
foreach ($archivers as $pluginName => $archiverClass) {
// We clean up below all tables created during this function call (and recursive calls)
$latestUsedTableId = Manager::getInstance()->getMostRecentTableId();
/** @var Archiver $archiver */
$archiver = new $archiverClass($this->archiveProcessor);
if (!$archiver->isEnabled()) {
continue;
}
if ($this->shouldProcessReportsForPlugin($pluginName)) {
if ($this->isSingleSiteDayArchive) {
$archiver->aggregateDayReport();
} else {
$archiver->aggregateMultipleReports();
}
}
Manager::getInstance()->deleteAll($latestUsedTableId);
unset($archiver);
}
}
示例6: clearInMemoryCaches
public function clearInMemoryCaches()
{
Archive::clearStaticCache();
DataTableManager::getInstance()->deleteAll();
Option::clearCache();
Site::clearCache();
Cache::deleteTrackerCache();
PiwikCache::getTransientCache()->flushAll();
PiwikCache::getEagerCache()->flushAll();
PiwikCache::getLazyCache()->flushAll();
ArchiveTableCreator::clear();
\Piwik\Plugins\ScheduledReports\API::$cache = array();
Singleton::clearAll();
PluginsArchiver::$archivers = array();
$_GET = $_REQUEST = array();
Translate::reset();
self::getConfig()->Plugins;
// make sure Plugins exists in a config object for next tests that use Plugin\Manager
// since Plugin\Manager uses getFromGlobalConfig which doesn't init the config object
}
示例7: aggregateDataTableRecords
/**
* Sums records for every subperiod of the current period and inserts the result as the record
* for this period.
*
* DataTables are summed recursively so subtables will be summed as well.
*
* @param string|array $recordNames Name(s) of the report we are aggregating, eg, `'Referrers_type'`.
* @param int $maximumRowsInDataTableLevelZero Maximum number of rows allowed in the top level DataTable.
* @param int $maximumRowsInSubDataTable Maximum number of rows allowed in each subtable.
* @param string $columnToSortByBeforeTruncation The name of the column to sort by before truncating a DataTable.
* @param array $columnsAggregationOperation Operations for aggregating columns, see {@link Row::sumRow()}.
* @param array $columnsToRenameAfterAggregation Columns mapped to new names for columns that must change names
* when summed because they cannot be summed, eg,
* `array('nb_uniq_visitors' => 'sum_daily_nb_uniq_visitors')`.
* @return array Returns the row counts of each aggregated report before truncation, eg,
*
* array(
* 'report1' => array('level0' => $report1->getRowsCount,
* 'recursive' => $report1->getRowsCountRecursive()),
* 'report2' => array('level0' => $report2->getRowsCount,
* 'recursive' => $report2->getRowsCountRecursive()),
* ...
* )
* @api
*/
public function aggregateDataTableRecords($recordNames, $maximumRowsInDataTableLevelZero = null, $maximumRowsInSubDataTable = null, $columnToSortByBeforeTruncation = null, &$columnsAggregationOperation = null, $columnsToRenameAfterAggregation = null)
{
if (!is_array($recordNames)) {
$recordNames = array($recordNames);
}
$nameToCount = array();
foreach ($recordNames as $recordName) {
$latestUsedTableId = Manager::getInstance()->getMostRecentTableId();
$table = $this->aggregateDataTableRecord($recordName, $columnsAggregationOperation, $columnsToRenameAfterAggregation);
$rowsCount = $table->getRowsCount();
$nameToCount[$recordName]['level0'] = $rowsCount;
$rowsCountRecursive = $rowsCount;
if ($this->isAggregateSubTables()) {
$rowsCountRecursive = $table->getRowsCountRecursive();
}
$nameToCount[$recordName]['recursive'] = $rowsCountRecursive;
$blob = $table->getSerialized($maximumRowsInDataTableLevelZero, $maximumRowsInSubDataTable, $columnToSortByBeforeTruncation);
Common::destroy($table);
$this->insertBlobRecord($recordName, $blob);
unset($blob);
DataTable\Manager::getInstance()->deleteAll($latestUsedTableId);
}
return $nameToCount;
}
示例8: test_serializeFails_onSubTableNotFound
public function test_serializeFails_onSubTableNotFound()
{
// create a simple table with a subtable
$table1 = $this->_getDataTable1ForTest();
$table2 = $this->_getDataTable2ForTest();
$table2->getFirstRow()->setSubtable($table1);
$idSubtable = 1;
// subtableIds are consecutive, we cannot use $table->getId()
/* Check it looks good:
$renderer = DataTable\Renderer::factory('xml');
$renderer->setTable($table2);
$renderer->setRenderSubTables(true);
echo $renderer->render();
*/
// test serialize:
// - subtable is serialized as expected
$serializedStrings = $table2->getSerialized();
// both the main table and the sub table are serialized
$this->assertEquals(sizeof($serializedStrings), 2);
// the serialized string references the id subtable
$unserialized = unserialize($serializedStrings[0]);
$this->assertSame($idSubtable, $unserialized[0][3], "not found the id sub table in the serialized, not expected");
// KABOOM, we delete the subtable, reproducing a "random data issue"
Manager::getInstance()->deleteTable($table1->getId());
// Now we will serialize this "broken datatable" and check it works.
// - it does not throw an exception
$serializedStrings = $table2->getSerialized();
// - the serialized table does NOT contain the sub table
$this->assertEquals(sizeof($serializedStrings), 1);
// main table only is serialized
$unserialized = unserialize($serializedStrings[0]);
// - the serialized string does NOT contain the id subtable (the row was cleaned up as expected)
$this->assertNull($unserialized[0][3], "found the id sub table in the serialized, not expected");
}
示例9: getSubtable
/**
* Returns the associated subtable, if one exists. Returns `false` if none exists.
*
* @return DataTable|bool
*/
public function getSubtable()
{
if ($this->isSubtableLoaded()) {
return Manager::getInstance()->getTable($this->getIdSubDataTable());
}
return false;
}
示例10: addExternalReferrers
/**
* Add the external referrers to the report:
* direct entries, websites, campaigns, search engines
*
* @param LogAggregator $logAggregator
* @param $report
* @param $idaction
* @param string $actionType
* @param $limitBeforeGrouping
*/
private function addExternalReferrers($logAggregator, &$report, $idaction, $actionType, $limitBeforeGrouping)
{
$data = $this->queryExternalReferrers($idaction, $actionType, $logAggregator, $limitBeforeGrouping);
$report['pageMetrics']['entries'] = 0;
$report['referrers'] = array();
foreach ($data->getRows() as $row) {
$referrerId = $row->getColumn('label');
$visits = $row->getColumn(Metrics::INDEX_NB_VISITS);
if ($visits) {
// load details (i.e. subtables)
$details = array();
if ($idSubTable = $row->getIdSubDataTable()) {
$subTable = Manager::getInstance()->getTable($idSubTable);
foreach ($subTable->getRows() as $subRow) {
$details[] = array('label' => $subRow->getColumn('label'), 'referrals' => $subRow->getColumn(Metrics::INDEX_NB_VISITS));
}
}
$report['referrers'][] = array('label' => $this->getReferrerLabel($referrerId), 'shortName' => \Piwik\Plugins\Referrers\getReferrerTypeFromShortName($referrerId), 'visits' => $visits, 'details' => $details);
$report['pageMetrics']['entries'] += $visits;
}
}
// if there's no data for referrers, ResponseBuilder::handleMultiDimensionalArray
// does not detect the multi dimensional array and the data is rendered differently, which
// causes an exception.
if (count($report['referrers']) == 0) {
$report['referrers'][] = array('label' => $this->getReferrerLabel(Common::REFERRER_TYPE_DIRECT_ENTRY), 'shortName' => \Piwik\Plugins\Referrers\getReferrerTypeLabel(Common::REFERRER_TYPE_DIRECT_ENTRY), 'visits' => 0);
}
}
示例11: setUp
public function setUp()
{
$this->builder = $this->makeBuilder(array('method' => 'MultiSites_getAll'));
DataTable\Manager::getInstance()->deleteAll();
}
示例12: __clone
/**
* Clone. Called when cloning the datatable. We need to make sure to create a new datatableId.
* If we do not increase tableId it can result in segmentation faults when destructing a datatable.
*/
public function __clone()
{
// registers this instance to the manager
$this->currentId = Manager::getInstance()->addTable($this);
}
示例13: setUp
public function setUp()
{
parent::setUp();
Manager::getInstance()->deleteAll();
}
示例14: performTearDown
public function performTearDown()
{
// Note: avoid run SQL in the *tearDown() metohds because it randomly fails on Travis CI
// with error Error while sending QUERY packet. PID=XX
$this->tearDown();
self::unloadAllPlugins();
if ($this->dropDatabaseInTearDown) {
$this->dropDatabase();
}
DataTableManager::getInstance()->deleteAll();
Option::clearCache();
Site::clearCache();
Cache::deleteTrackerCache();
Config::getInstance()->clear();
ArchiveTableCreator::clear();
\Piwik\Plugins\ScheduledReports\API::$cache = array();
\Piwik\Registry::unsetInstance();
\Piwik\EventDispatcher::getInstance()->clearAllObservers();
$_GET = $_REQUEST = array();
Translate::unloadEnglishTranslation();
Config::unsetInstance();
\Piwik\Config::getInstance()->Plugins;
// make sure Plugins exists in a config object for next tests that use Plugin\Manager
// since Plugin\Manager uses getFromGlobalConfig which doesn't init the config object
}
示例15: tearDown
public function tearDown()
{
parent::tearDown();
Manager::getInstance()->deleteAll();
Option::clearCache();
Site::clearCache();
Cache::deleteTrackerCache();
ArchiveTableCreator::clear();
$tempTableName = Common::prefixTable(LogDataPurger::TEMP_TABLE_NAME);
Db::query("DROP TABLE IF EXISTS " . $tempTableName);
}