本文整理汇总了PHP中Piwik\Archive::build方法的典型用法代码示例。如果您正苦于以下问题:PHP Archive::build方法的具体用法?PHP Archive::build怎么用?PHP Archive::build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\Archive
的用法示例。
在下文中一共展示了Archive::build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getNumeric
protected function getNumeric($idSite, $period, $date, $segment, $toFetch)
{
Piwik::checkUserHasViewAccess($idSite);
$archive = Archive::build($idSite, $period, $date, $segment);
$dataTable = $archive->getDataTableFromNumeric($toFetch);
return $dataTable;
}
示例2: getDataTable
protected function getDataTable($name, $idSite, $period, $date, $segment, $column = Metrics::INDEX_NB_VISITS)
{
Piwik::checkUserHasViewAccess($idSite);
$archive = Archive::build($idSite, $period, $date, $segment);
$dataTable = $archive->getDataTable($name);
$dataTable->queueFilter('ReplaceColumnNames');
return $dataTable;
}
示例3: getUsers
/**
* Get a report of all User Ids.
*
* @param int $idSite
*
* @param string $period
* @param int $date
* @param string|bool $segment
*
* @return DataTable
*/
public function getUsers($idSite, $period, $date, $segment = false)
{
Piwik::checkUserHasViewAccess($idSite);
$archive = Archive::build($idSite, $period, $date, $segment);
$dataTable = $archive->getDataTable(Archiver::USERID_ARCHIVE_RECORD);
$dataTable->queueFilter('ReplaceColumnNames');
$dataTable->queueFilter('ReplaceSummaryRowLabel');
return $dataTable;
}
示例4: getDataTable
/**
* @param string $name
* @param int $idSite
* @param string $period
* @param string $date
* @param string $segment
* @return DataTable
*/
protected function getDataTable($name, $idSite, $period, $date, $segment)
{
Piwik::checkUserHasViewAccess($idSite);
$archive = Archive::build($idSite, $period, $date, $segment);
$dataTable = $archive->getDataTable($name);
$dataTable->queueFilter('ReplaceColumnNames');
$dataTable->queueFilter('ReplaceSummaryRowLabel');
return $dataTable;
}
示例5: testArchiveSitesWhenRestrictingToLogin
/**
* Test that restricting the number of sites to those viewable to another login
* works when building an archive query object.
*
* @group Integration
*/
public function testArchiveSitesWhenRestrictingToLogin()
{
try {
Archive::build('all', 'day', self::$fixture->dateTime, $segment = false, $_restrictToLogin = 'anotherLogin');
$this->fail("Restricting sites to invalid login did not return 0 sites.");
} catch (Exception $ex) {
// pass
}
}
示例6: getEvenUnevenTimes
/**
* API method that returns number of visits based on hour parity.
* @param int $idSite
* @param string $period
* @param string $date
* @param bool|string $segment
* @return DataTable
*/
public function getEvenUnevenTimes($idSite, $period, $date, $segment = false)
{
$archive = Archive::build($idSite, $period, $date);
$oddHoursCount = $archive->getNumeric(Archiver::ODD_HOURS_COUNT_RECORD_NAME);
$evenHoursCount = $archive->getNumeric(Archiver::EVEN_HOURS_COUNT_RECORD_NAME);
$table = new DataTable();
$table->setTableSortedBy('times');
$table->addRowFromArray(array(Row::COLUMNS => array('times' => Piwik::translate('HourParity_Oddhours'), 'nb_visits' => $oddHoursCount)));
$table->addRowFromArray(array(Row::COLUMNS => array('times' => Piwik::translate('HourParity_Evenhours'), 'nb_visits' => $evenHoursCount)));
return $table;
}
示例7: getProvider
public function getProvider($idSite, $period, $date, $segment = false)
{
Piwik::checkUserHasViewAccess($idSite);
$archive = Archive::build($idSite, $period, $date, $segment);
$dataTable = $archive->getDataTable(Archiver::PROVIDER_RECORD_NAME);
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'url', __NAMESPACE__ . '\\getHostnameUrl'));
$dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\\getPrettyProviderName'));
$dataTable->queueFilter('ReplaceColumnNames');
$dataTable->queueFilter('ReplaceSummaryRowLabel');
return $dataTable;
}
示例8: get
/**
* Returns the list of metrics (pages, downloads, outlinks)
*
* @param int $idSite
* @param string $period
* @param string $date
* @param bool|string $segment
* @param bool|array $columns
* @return DataTable
*/
public function get($idSite, $period, $date, $segment = false, $columns = false)
{
Piwik::checkUserHasViewAccess($idSite);
$archive = Archive::build($idSite, $period, $date, $segment);
$metrics = Archiver::$actionsAggregateMetrics;
$metrics['Actions_avg_time_generation'] = 'avg_time_generation';
// get requested columns
$columns = Piwik::getArrayFromApiParameter($columns);
if (!empty($columns)) {
// get the columns that are available and requested
$columns = array_intersect($columns, array_values($metrics));
$columns = array_values($columns);
// make sure indexes are right
$nameReplace = array();
foreach ($columns as $i => $column) {
$fullColumn = array_search($column, $metrics);
$columns[$i] = $fullColumn;
$nameReplace[$fullColumn] = $column;
}
if (false !== ($avgGenerationTimeRequested = array_search('Actions_avg_time_generation', $columns))) {
unset($columns[$avgGenerationTimeRequested]);
$avgGenerationTimeRequested = true;
}
} else {
// get all columns
unset($metrics['Actions_avg_time_generation']);
$columns = array_keys($metrics);
$nameReplace =& $metrics;
$avgGenerationTimeRequested = true;
}
if ($avgGenerationTimeRequested) {
$tempColumns[] = Archiver::METRIC_SUM_TIME_RECORD_NAME;
$tempColumns[] = Archiver::METRIC_HITS_TIMED_RECORD_NAME;
$columns = array_merge($columns, $tempColumns);
$columns = array_unique($columns);
$nameReplace[Archiver::METRIC_SUM_TIME_RECORD_NAME] = 'sum_time_generation';
$nameReplace[Archiver::METRIC_HITS_TIMED_RECORD_NAME] = 'nb_hits_with_time_generation';
}
$table = $archive->getDataTableFromNumeric($columns);
// replace labels (remove Actions_)
$table->filter('ReplaceColumnNames', array($nameReplace));
// compute avg generation time
if ($avgGenerationTimeRequested) {
$table->filter('ColumnCallbackAddColumnQuotient', array('avg_time_generation', 'sum_time_generation', 'nb_hits_with_time_generation', 3));
$table->deleteColumns(array('sum_time_generation', 'nb_hits_with_time_generation'));
}
return $table;
}
示例9: getPlugin
public function getPlugin($idSite, $period, $date, $segment = false)
{
// fetch all archive data required
$dataTable = $this->getDataTable(Archiver::PLUGIN_RECORD_NAME, $idSite, $period, $date, $segment);
$browserVersions = $this->getDataTable(DDArchiver::BROWSER_VERSION_RECORD_NAME, $idSite, $period, $date, $segment);
$archive = Archive::build($idSite, $period, $date, $segment);
$visitsSums = $archive->getDataTableFromNumeric('nb_visits');
// check whether given tables are arrays
if ($dataTable instanceof DataTable\Map) {
$dataTableMap = $dataTable->getDataTables();
$browserVersionsArray = $browserVersions->getDataTables();
$visitSumsArray = $visitsSums->getDataTables();
} else {
$dataTableMap = array($dataTable);
$browserVersionsArray = array($browserVersions);
$visitSumsArray = array($visitsSums);
}
// walk through the results and calculate the percentage
foreach ($dataTableMap as $key => $table) {
// Calculate percentage, but ignore IE users because plugin detection doesn't work on IE
$ieVisits = 0;
$browserVersionsToExclude = array('IE;10.0', 'IE;9.0', 'IE;8.0', 'IE;7.0', 'IE;6.0');
foreach ($browserVersionsToExclude as $browserVersionToExclude) {
$ieStats = $browserVersionsArray[$key]->getRowFromLabel($browserVersionToExclude);
if ($ieStats !== false) {
$ieVisits += $ieStats->getColumn(Metrics::INDEX_NB_VISITS);
}
}
// get according visitsSum
$visits = $visitSumsArray[$key];
if ($visits->getRowsCount() == 0) {
$visitsSumTotal = 0;
} else {
$visitsSumTotal = (double) $visits->getFirstRow()->getColumn('nb_visits');
}
$visitsSum = $visitsSumTotal - $ieVisits;
$extraProcessedMetrics = $table->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME);
$extraProcessedMetrics[] = new VisitsPercent($visitsSum);
$table->setMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME, $extraProcessedMetrics);
}
$dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\\getPluginsLogo'));
$dataTable->queueFilter('ColumnCallbackReplace', array('label', 'ucfirst'));
$dataTable->queueFilter('RangeCheck', array('nb_visits_percentage', 0, 1));
return $dataTable;
}
示例10: get
/**
* Returns the list of metrics (pages, downloads, outlinks)
*
* @param int $idSite
* @param string $period
* @param string $date
* @param bool|string $segment
* @param bool|array $columns
* @return DataTable
*/
public function get($idSite, $period, $date, $segment = false, $columns = false)
{
Piwik::checkUserHasViewAccess($idSite);
$report = Report::factory("Actions", "get");
$archive = Archive::build($idSite, $period, $date, $segment);
$requestedColumns = Piwik::getArrayFromApiParameter($columns);
$columns = $report->getMetricsRequiredForReport($allColumns = null, $requestedColumns);
$inDbColumnNames = array_map(function ($value) {
return 'Actions_' . $value;
}, $columns);
$dataTable = $archive->getDataTableFromNumeric($inDbColumnNames);
$dataTable->deleteColumns(array_diff($requestedColumns, $columns));
$newNameMapping = array_combine($inDbColumnNames, $columns);
$dataTable->filter('ReplaceColumnNames', array($newNameMapping));
$columnsToShow = $requestedColumns ?: $report->getAllMetrics();
$dataTable->queueFilter('ColumnDelete', array($columnsToRemove = array(), $columnsToShow));
return $dataTable;
}
示例11: getByDayOfWeek
/**
* Returns datatable describing the number of visits for each day of the week.
*
* @param string $idSite The site ID. Cannot refer to multiple sites.
* @param string $period The period type: day, week, year, range...
* @param string $date The start date of the period. Cannot refer to multiple dates.
* @param bool|string $segment The segment.
* @throws Exception
* @return DataTable
*/
public function getByDayOfWeek($idSite, $period, $date, $segment = false)
{
Piwik::checkUserHasViewAccess($idSite);
// metrics to query
$metrics = Metrics::getVisitsMetricNames();
unset($metrics[Metrics::INDEX_MAX_ACTIONS]);
// disabled for multiple dates
if (Period::isMultiplePeriod($date, $period)) {
throw new Exception("VisitTime.getByDayOfWeek does not support multiple dates.");
}
// get metric data for every day within the supplied period
$oPeriod = Period\Factory::makePeriodFromQueryParams(Site::getTimezoneFor($idSite), $period, $date);
$dateRange = $oPeriod->getDateStart()->toString() . ',' . $oPeriod->getDateEnd()->toString();
$archive = Archive::build($idSite, 'day', $dateRange, $segment);
// disabled for multiple sites
if (count($archive->getParams()->getIdSites()) > 1) {
throw new Exception("VisitTime.getByDayOfWeek does not support multiple sites.");
}
$dataTable = $archive->getDataTableFromNumeric($metrics)->mergeChildren();
// if there's no data for this report, don't bother w/ anything else
if ($dataTable->getRowsCount() == 0) {
return $dataTable;
}
// group by the day of the week (see below for dayOfWeekFromDate function)
$dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\\dayOfWeekFromDate'));
// create new datatable w/ empty rows, then add calculated datatable
$rows = array();
foreach (array(1, 2, 3, 4, 5, 6, 7) as $day) {
$rows[] = array('label' => $day, 'nb_visits' => 0);
}
$result = new DataTable();
$result->addRowsFromSimpleArray($rows);
$result->addDataTable($dataTable);
// set day of week integer as metadata
$result->filter('ColumnCallbackAddMetadata', array('label', 'day_of_week'));
// translate labels
$result->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\\translateDayOfWeek'));
// set datatable metadata for period start & finish
$result->setMetadata('date_start', $oPeriod->getDateStart());
$result->setMetadata('date_end', $oPeriod->getDateEnd());
return $result;
}
示例12: test_subtables_willBeSplitIntoChunks
public function test_subtables_willBeSplitIntoChunks()
{
$numSubtablesToGenerate = 1053;
$blobs = $this->generateDataTableWithManySubtables($numSubtablesToGenerate);
$this->assertCount($numSubtablesToGenerate + 1, $blobs);
// +1 for the root table
$recordName = 'Actions_MyRecord';
$archiver = $this->createPluginsArchiver();
$archiver->archiveProcessor->insertBlobRecord($recordName, $blobs);
$archiver->finalizeArchive();
// verify they were split into chunks
$archiveRows = $this->getAllRowsFromArchiveBlobTable('name');
$expectedArchiveNames = array($recordName, $recordName . '_chunk_0_99', $recordName . '_chunk_1000_1099', $recordName . '_chunk_100_199', $recordName . '_chunk_200_299', $recordName . '_chunk_300_399', $recordName . '_chunk_400_499', $recordName . '_chunk_500_599', $recordName . '_chunk_600_699', $recordName . '_chunk_700_799', $recordName . '_chunk_800_899', $recordName . '_chunk_900_999');
$this->assertEquals($expectedArchiveNames, array_column($archiveRows, 'name'));
// verify all have same archiveIds
$expectedArchiveIds = array_fill(0, count($expectedArchiveNames), $archiveId = '1');
$this->assertEquals($expectedArchiveIds, array_column($archiveRows, 'idarchive'));
// verify the subtables were actually splitted into chunks
foreach ($archiveRows as $row) {
$value = unserialize(gzuncompress($row['value']));
$this->assertTrue(is_array($value));
if ($row['name'] == $recordName) {
$this->assertCount($numSubtablesToGenerate, $value);
// 1053 rows
} elseif ($row['name'] == $recordName . '_chunk_1000_1099') {
$this->assertCount($numSubtablesToGenerate % Archive\Chunk::NUM_TABLES_IN_CHUNK + 1, $value);
// 53 subtables
} elseif ($row['name'] == $recordName . '_chunk_0_99') {
$this->assertCount(Archive\Chunk::NUM_TABLES_IN_CHUNK - 1, $value);
// one less as we do not store the root table here
} else {
$this->assertCount(Archive\Chunk::NUM_TABLES_IN_CHUNK, $value);
}
}
// should be able to rebuild the datatable
$archive = Archive::build(1, 'day', $this->date);
$table = $archive->getDataTable($recordName);
$this->assertSame(1053, $table->getRowsCount());
$this->assertSame('Label Test 1', $table->getFirstRow()->getColumn('label'));
$this->assertSame(1, $table->getFirstRow()->getColumn('nb_visits'));
}
示例13: getPlugin
public function getPlugin($idSite, $period, $date, $segment = false)
{
// fetch all archive data required
$dataTable = $this->getDataTable(Archiver::PLUGIN_RECORD_NAME, $idSite, $period, $date, $segment);
$browserTypes = $this->getDataTable(Archiver::BROWSER_TYPE_RECORD_NAME, $idSite, $period, $date, $segment);
$archive = Archive::build($idSite, $period, $date, $segment);
$visitsSums = $archive->getDataTableFromNumeric('nb_visits');
// check whether given tables are arrays
if ($dataTable instanceof DataTable\Map) {
$dataTableMap = $dataTable->getDataTables();
$browserTypesArray = $browserTypes->getDataTables();
$visitSumsArray = $visitsSums->getDataTables();
} else {
$dataTableMap = array($dataTable);
$browserTypesArray = array($browserTypes);
$visitSumsArray = array($visitsSums);
}
// walk through the results and calculate the percentage
foreach ($dataTableMap as $key => $table) {
// get according browserType table
foreach ($browserTypesArray as $k => $browsers) {
if ($k == $key) {
$browserType = $browsers;
}
}
// get according visitsSum
foreach ($visitSumsArray as $k => $visits) {
if ($k == $key) {
if (is_object($visits)) {
if ($visits->getRowsCount() == 0) {
$visitsSumTotal = 0;
} else {
$visitsSumTotal = (double) $visits->getFirstRow()->getColumn('nb_visits');
}
} else {
$visitsSumTotal = (double) $visits;
}
}
}
// Calculate percentage, but ignore IE users because plugin detection doesn't work on IE
$ieVisits = 0;
$ieStats = $browserType->getRowFromLabel('ie');
if ($ieStats !== false) {
$ieVisits = $ieStats->getColumn(Metrics::INDEX_NB_VISITS);
}
$visitsSum = $visitsSumTotal - $ieVisits;
// When Truncate filter is applied, it will call AddSummaryRow which tries to sum all rows.
// We tell the object to skip the column nb_visits_percentage when aggregating (since it's not correct to sum % values)
$columnAggregationOps = $table->getMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME);
$columnAggregationOps['nb_visits_percentage'] = 'skip';
$table->setMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME, $columnAggregationOps);
// The filter must be applied now so that the new column can
// be sorted by the generic filters (applied right after this loop exits)
$table->filter('ColumnCallbackAddColumnPercentage', array('nb_visits_percentage', Metrics::INDEX_NB_VISITS, $visitsSum, 1));
$table->filter('RangeCheck', array('nb_visits_percentage'));
}
$dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\\getPluginsLogo'));
$dataTable->queueFilter('ColumnCallbackReplace', array('label', 'ucfirst'));
return $dataTable;
}
示例14: test_Archive_getNumeric_shouldInvalidateRememberedReportsOncePerRequestIfNeeded
public function test_Archive_getNumeric_shouldInvalidateRememberedReportsOncePerRequestIfNeeded()
{
$this->markTestSkippedOnPhp53();
// Tests that getting a visits summary metric (nb_visits) & a Goal's metric (Goal_revenue)
// at the same time works.
$dateTimeRange = '2010-01-03,2010-01-06';
$columns = array('nb_visits', 'Goal_nb_conversions', 'nb_actions');
$idSite1 = self::$fixture->idSite1;
$archive = Archive::build($idSite1, 'range', $dateTimeRange);
$result = $archive->getNumeric($columns);
$this->assertEquals(array('nb_visits' => 5, 'Goal_nb_conversions' => 6, 'nb_actions' => 13), $result);
$cache = Cache::getTransientCache();
$this->assertEquals(array(self::$fixture->idSite1, self::$fixture->idSite2), $cache->fetch('Archive.SiteIdsOfRememberedReportsInvalidated'));
$invalidator = StaticContainer::get('Piwik\\Archive\\ArchiveInvalidator');
self::$fixture->trackVisits();
// trackVisits should remember to invalidate archived reports
$this->assertNotEmpty($invalidator->getRememberedArchivedReportsThatShouldBeInvalidated());
// although there were new tracked visists it doesn'T change as the report invalidation is cached and was
// already invalidated in previous Archive::get();
$archive = Archive::build($idSite1, 'range', $dateTimeRange);
$result = $archive->getNumeric($columns);
$this->assertEquals(array('nb_visits' => 5, 'Goal_nb_conversions' => 6, 'nb_actions' => 13), $result);
// make sure the caching in archive::get() worked and they are still to be invalidated
$this->assertCount(10, $invalidator->getRememberedArchivedReportsThatShouldBeInvalidated());
// now we force to actually invalidate archived reports again and then archive will be rebuilt for requsted siteId = 1
$cache->delete('Archive.SiteIdsOfRememberedReportsInvalidated');
$archive = Archive::build($idSite1, 'range', $dateTimeRange);
$result = $archive->getNumeric($columns);
// archive::get() should have invalidated siteId 1 and siteId 2 should be still to be done
$expectedArchiveReportsLeft = array('2010-01-04' => array(2));
$this->assertEquals($expectedArchiveReportsLeft, $invalidator->getRememberedArchivedReportsThatShouldBeInvalidated());
$this->assertEquals(array('nb_visits' => 6, 'Goal_nb_conversions' => 7, 'nb_actions' => 26), $result);
}
示例15: createDataTableFromArchive
/**
* Helper function that creates an Archive instance and queries for report data using
* query parameter data. API methods can use this method to reduce code redundancy.
*
* @param string $recordName The name of the report to return.
* @param int|string|array $idSite @see {@link build()}
* @param string $period @see {@link build()}
* @param string $date @see {@link build()}
* @param string $segment @see {@link build()}
* @param bool $expanded If true, loads all subtables. See {@link getDataTableExpanded()}
* @param bool $flat If true, loads all subtables and disabled all recursive filters.
* @param int|null $idSubtable See {@link getDataTableExpanded()}
* @param int|null $depth See {@link getDataTableExpanded()}
* @return DataTable|DataTable\Map
*/
public static function createDataTableFromArchive($recordName, $idSite, $period, $date, $segment, $expanded = false, $flat = false, $idSubtable = null, $depth = null)
{
Piwik::checkUserHasViewAccess($idSite);
if ($flat && !$idSubtable) {
$expanded = true;
}
$archive = Archive::build($idSite, $period, $date, $segment, $_restrictSitesToLogin = false);
if ($idSubtable === false) {
$idSubtable = null;
}
if ($expanded) {
$dataTable = $archive->getDataTableExpanded($recordName, $idSubtable, $depth);
} else {
$dataTable = $archive->getDataTable($recordName, $idSubtable);
}
$dataTable->queueFilter('ReplaceSummaryRowLabel');
$dataTable->queueFilter('ReplaceColumnNames');
if ($expanded) {
$dataTable->queueFilterSubtables('ReplaceColumnNames');
}
if ($flat) {
$dataTable->disableRecursiveFilters();
}
return $dataTable;
}