本文整理汇总了PHP中Piwik_DataTable::addRowsFromSimpleArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Piwik_DataTable::addRowsFromSimpleArray方法的具体用法?PHP Piwik_DataTable::addRowsFromSimpleArray怎么用?PHP Piwik_DataTable::addRowsFromSimpleArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik_DataTable
的用法示例。
在下文中一共展示了Piwik_DataTable::addRowsFromSimpleArray方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMobileVsDesktop
/**
* Gets a DataTable displaying number of visits by device type (mobile vs. desktop).
*/
public function getMobileVsDesktop($idSite, $period, $date, $segment = false)
{
$dataTable = $this->getOS($idSite, $period, $date, $segment, $addShortLabel = false);
$dataTable->filter('GroupBy', array('label', 'Piwik_UserSettings_getDeviceTypeFromOS'));
// make sure the datatable has a row for mobile & desktop (if it has rows)
$empty = new Piwik_DataTable();
$empty->addRowsFromSimpleArray(array(array('label' => 'General_Desktop', Piwik_Archive::INDEX_NB_VISITS => 0), array('label' => 'General_Mobile', Piwik_Archive::INDEX_NB_VISITS => 0)));
if ($dataTable->getRowsCount() > 0) {
$dataTable->addDataTable($empty);
}
// set the logo metadata
$dataTable->queueFilter('MetadataCallbackReplace', array('logo', 'Piwik_UserSettings_getDeviceTypeImg', null, array('label')));
// translate the labels
$dataTable->queueFilter('ColumnCallbackReplace', array('label', 'Piwik_Translate'));
return $dataTable;
}
示例2: handleArray
protected function handleArray($array)
{
if($this->outputFormat == 'original')
{
// we handle the serialization. Because some php array have a very special structure that
// couldn't be converted with the automatic DataTable->addRowsFromSimpleArray
// the user may want to request the original PHP data structure serialized by the API
// in case he has to setup serialize=1 in the URL
if($this->caseRendererPHPSerialize( $defaultSerialize = 0))
{
return serialize($array);
}
return $array;
}
$multiDimensional = $this->handleMultiDimensionalArray($array);
if($multiDimensional !== false)
{
return $multiDimensional;
}
$dataTable = new Piwik_DataTable();
$dataTable->addRowsFromSimpleArray($array);
return $this->getRenderedDataTable($dataTable);
}
示例3: 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 string $segment The segment.
* @return Piwik_DataTable
*/
public function getByDayOfWeek($idSite, $period, $date, $segment = false)
{
Piwik::checkUserHasViewAccess($idSite);
// disabled for multiple sites/dates
if (Piwik_Archive::isMultipleSites($idSite)) {
throw new Exception("VisitTime.getByDayOfWeek does not support multiple sites.");
}
if (Piwik_Archive::isMultiplePeriod($date, $period)) {
throw new Exception("VisitTime.getByDayOfWeek does not support multiple dates.");
}
// metrics to query
$metrics = Piwik_ArchiveProcessing::getCoreMetrics();
// get metric data for every day within the supplied period
$oSite = new Piwik_Site($idSite);
$oPeriod = Piwik_Archive::makePeriodFromQueryParams($oSite, $period, $date);
$dateRange = $oPeriod->getDateStart()->toString() . ',' . $oPeriod->getDateEnd()->toString();
$archive = Piwik_Archive::build($idSite, 'day', $dateRange, $segment);
$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', 'Piwik_VisitTime_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 Piwik_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', 'Piwik_VisitTime_translateDayOfWeek'));
// set datatable metadata for period start & finish
$result->setMetadata('date_start', $oPeriod->getDateStart());
$result->setMetadata('date_end', $oPeriod->getDateEnd());
return $result;
}
示例4: 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;
}