本文整理汇总了PHP中Piwik\DataTable::addRowFromSimpleArray方法的典型用法代码示例。如果您正苦于以下问题:PHP DataTable::addRowFromSimpleArray方法的具体用法?PHP DataTable::addRowFromSimpleArray怎么用?PHP DataTable::addRowFromSimpleArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\DataTable
的用法示例。
在下文中一共展示了DataTable::addRowFromSimpleArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_renderDataTable_shouldReturnResult
public function test_renderDataTable_shouldReturnResult()
{
$dataTable = new DataTable();
$dataTable->addRowFromSimpleArray(array('nb_visits' => 5, 'nb_random' => 10));
$response = $this->builder->renderDataTable($dataTable);
$this->assertSame("- 1 ['nb_visits' => 5, 'nb_random' => 10] [] [idsubtable = ]<br />\n", $response);
}
示例2: test_renderDataTable_shouldSerializeIfEnabled
public function test_renderDataTable_shouldSerializeIfEnabled()
{
$dataTable = new DataTable();
$dataTable->addRowFromSimpleArray(array('nb_visits' => 5, 'nb_random' => 10));
$builder = $this->makeBuilder(array('serialize' => 1));
$response = $builder->renderDataTable($dataTable);
$this->assertSame('O:15:"Piwik\\DataTable":2:{s:7:"*rows";a:1:{i:0;O:19:"Piwik\\DataTable\\Row":1:{s:1:"c";a:3:{i:0;a:2:{s:9:"nb_visits";i:5;s:9:"nb_random";i:10;}i:1;a:0:{}i:3;N;}}}s:13:"*summaryRow";N;}', $response);
}
示例3: test_renderDataTable_shouldSerializeIfEnabled
public function test_renderDataTable_shouldSerializeIfEnabled()
{
$dataTable = new DataTable();
$dataTable->addRowFromSimpleArray(array('nb_visits' => 5, 'nb_random' => 10));
$builder = $this->makeBuilder(array('serialize' => 1));
$response = $builder->renderDataTable($dataTable);
$builder = $this->makeBuilder(array('serialize' => 0));
$original = $builder->renderDataTable($dataTable);
$expected = serialize($original);
$this->assertEquals($expected, $response);
}
示例4: test_getResponse_shouldHandleDataTable
public function test_getResponse_shouldHandleDataTable()
{
$builder = new ResponseBuilder('xml', array());
$dataTable = new DataTable();
$dataTable->addRowFromSimpleArray(array('nb_visits' => 5, 'nb_random' => 10));
$response = $builder->getResponse($dataTable);
$this->assertEquals('<?xml version="1.0" encoding="utf-8" ?>
<result>
<row>
<nb_visits>5</nb_visits>
<nb_random>10</nb_random>
</row>
</result>', $response);
}
示例5: removeHoursInFuture
/**
* @param DataTable $table
* @param int $idSite
* @param string $period
* @param string $date
* @return mixed
*/
protected function removeHoursInFuture($table, $idSite, $period, $date)
{
$site = new Site($idSite);
if ($period == 'day' && ($date == 'today' || $date == Date::factory('now', $site->getTimezone())->toString())) {
$currentHour = Date::factory('now', $site->getTimezone())->toString('G');
// If no data for today, this is an exception to the API output rule, as we normally return nothing:
// we shall return all hours of the day, with nb_visits = 0
if ($table->getRowsCount() == 0) {
for ($hour = 0; $hour <= $currentHour; $hour++) {
$table->addRowFromSimpleArray(array('label' => $hour, 'nb_visits' => 0));
}
return $table;
}
$idsToDelete = array();
foreach ($table->getRows() as $id => $row) {
$hour = $row->getColumn('label');
if ($hour > $currentHour) {
$idsToDelete[] = $id;
}
}
$table->deleteRows($idsToDelete);
}
return $table;
}
示例6: test_generateReport_CatchesIndividualReportProcessExceptions_WithoutFailingToGenerateWholeReport
public function test_generateReport_CatchesIndividualReportProcessExceptions_WithoutFailingToGenerateWholeReport()
{
$realProxy = new Proxy();
$mockProxy = $this->getMock('Piwik\\API\\Proxy', array('call'));
$mockProxy->expects($this->any())->method('call')->willReturnCallback(function ($className, $methodName, $parametersRequest) use($realProxy) {
switch ($className) {
case '\\Piwik\\Plugins\\VisitsSummary\\API':
$result = new DataTable();
$result->addRowFromSimpleArray(array('label' => 'visits label', 'nb_visits' => 1));
return $result;
case '\\Piwik\\Plugins\\UserCountry\\API':
throw new \Exception("error");
case '\\Piwik\\Plugins\\Referrers\\API':
$result = new DataTable();
$result->addRowFromSimpleArray(array('label' => 'referrers label', 'nb_visits' => 1));
return $result;
case '\\Piwik\\Plugins\\API\\API':
return $realProxy->call($className, $methodName, $parametersRequest);
default:
throw new \Exception("Unexpected method {$className}::{$methodName}.");
}
});
Proxy::setSingletonInstance($mockProxy);
$idReport = APIScheduledReports::getInstance()->addReport(1, '', Schedule::PERIOD_DAY, 0, ScheduledReports::EMAIL_TYPE, ReportRenderer::HTML_FORMAT, array('VisitsSummary_get', 'UserCountry_getCountry', 'Referrers_getWebsites'), array(ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_TABLES_ONLY));
ob_start();
$result = APIScheduledReports::getInstance()->generateReport($idReport, Date::factory('now')->toString(), $language = false, $outputType = APIScheduledReports::OUTPUT_RETURN);
ob_end_clean();
$this->assertContains('id="VisitsSummary_get"', $result);
$this->assertContains('id="Referrers_getWebsites"', $result);
$this->assertNotContains('id="UserCountry_getCountry"', $result);
}
示例7: test_renderDataTable_shouldRenderDataTableMaps
public function test_renderDataTable_shouldRenderDataTableMaps()
{
$map = new DataTable\Map();
$dataTable = new DataTable();
$dataTable->addRowFromSimpleArray(array('nb_visits' => 5, 'nb_random' => 10));
$dataTable2 = new DataTable();
$dataTable2->addRowFromSimpleArray(array('nb_visits' => 3, 'nb_random' => 6));
$map->addTable($dataTable, 'table1');
$map->addTable($dataTable2, 'table2');
$response = $this->builder->renderDataTable($map);
$expected = array('table1' => array(array('nb_visits' => 5, 'nb_random' => 10)), 'table2' => array(array('nb_visits' => 3, 'nb_random' => 6)));
$this->assertEquals($expected, $response);
}
示例8: getCompetitionDatatable
/**
* Returns a custom data table.
* This data table will be converted to all available formats
* when requested in the API request.
*
* @return DataTable
*/
public function getCompetitionDatatable()
{
$dataTable = new DataTable();
$row1 = new Row();
$row1->setColumns(array('name' => 'piwik', 'license' => 'GPL'));
// Rows Metadata is useful to store non stats data for example (logos, urls, etc.)
// When printed out, they are simply merged with columns
$row1->setMetadata('logo', 'logo.png');
$dataTable->addRow($row1);
$dataTable->addRowFromSimpleArray(array('name' => 'google analytics', 'license' => 'commercial'));
return $dataTable;
}
示例9: getData
/**
* Another example method that returns a data table.
* @param int $idSite
* @param string $period
* @param string $date
* @param bool|string $segment
* @return DataTable
*/
public function getData($idSite, $period, $date, $segment = false)
{
// Not: \Piwik is \core
// TODO: Zugriffssteuerung !!!
\Piwik\Piwik::checkUserHasViewAccess($idSite);
// Read additional variables
$aLimit = (int) \Piwik\Common::getRequestVar('vlimit', 100, 'int');
if ($aLimit === 0) {
$aLimit = 100;
}
$getVar = trim((string) \Piwik\Common::getRequestVar('casevar', '', 'string'));
$clipServer = (string) \Piwik\Common::getRequestVar('server', 'no', 'string') !== 'yes';
$clipExtension = (string) \Piwik\Common::getRequestVar('noclip', 'no', 'string') !== 'yes';
$recodeIndex = (string) \Piwik\Common::getRequestVar('disindex', 'no', 'string') !== 'yes';
$skipNoID = (string) \Piwik\Common::getRequestVar('skipid', 'no', 'string') === 'yes';
$addAggregate = (string) \Piwik\Common::getRequestVar('aggregate', 'no', 'string') === 'yes';
$structure = (string) \Piwik\Common::getRequestVar('structure', 'case', 'string');
// [case|page]
// https://developer.piwik.org/guides/security-in-piwik
// https://developer.piwik.org/guides/persistence-and-the-mysql-backend
$sql = 'SELECT v.idvisit, l.server_time, l.time_spent_ref_action, a.name, a.idaction
FROM ' . \Piwik\Common::prefixTable('log_visit') . ' v
LEFT JOIN ' . \Piwik\Common::prefixTable('log_link_visit_action') . ' l ON (v.idvisit = l.idvisit)
LEFT JOIN ' . \Piwik\Common::prefixTable('log_action') . ' a ON (a.idaction = l.idaction_url)
WHERE (v.idsite = ?) AND (a.type = 1)
ORDER BY l.idvisit, l.server_time';
$res = \Piwik\Db::query($sql, array($idSite));
// error_log(var_export($idSite, true));
if (empty($getVar)) {
$getVarLen = 0;
$skipNoID = false;
} else {
$getVarLen = strlen($getVar) + 1;
}
$nAction = 0;
$nActionMax = 0;
// Number of actions per visit (max.)
$cvVisitID = null;
$cvCaseID = null;
$cvCaseStart = null;
$cvTimeSum = 0;
$cvCaseActions = array();
$cvCaseTimes = array();
$cvCaseStamps = array();
$visits = array();
$actionIDs = array();
// Collect IDs per action
do {
$row = $res->fetch();
// Stop processing for empty results
if ($row === false) {
if ($cvVisitID === null) {
// No data at all
$table->addRowFromSimpleArray(array('error' => 'no data available', 'site' => $idSite));
return $table;
}
}
$cvFirst = false;
// Store new visit
if ($row === false or $row['idvisit'] !== $cvVisitID and $cvVisitID !== null) {
if ($skipNoID and $cvCaseID === null) {
// Skip this case
} else {
$visits[] = array('id' => $cvVisitID, 'case' => $cvCaseID, 'start' => $cvCaseStart, 'actions' => $cvCaseActions, 'times' => $cvCaseTimes, 'stamps' => $cvCaseStamps, 'time sum' => $cvTimeSum);
if (count($cvCaseActions) > $nAction) {
$nAction = count($cvCaseActions);
}
if ($nAction > $nActionMax) {
$nActionMax = $nAction;
}
}
}
// Stop, if there is no more data
if ($row === false) {
break;
}
// Register new visit (group of actions/page views)
if ($row['idvisit'] !== $cvVisitID) {
$nAction = 1;
$cvVisitID = $row['idvisit'];
$cvCaseStart = $row['server_time'];
$cvTimeSum = 0;
$cvCaseID = null;
$cvCaseActions = array();
$cvCaseTimes = array();
$cvCaseStamps = array();
} else {
$nAction++;
}
// Decode the URL
$url = $row['name'];
if ($cvCaseID === null and $getVarLen !== 0) {
//.........这里部分代码省略.........
示例10: test_renderDataTable_shouldRenderDataTableMaps
public function test_renderDataTable_shouldRenderDataTableMaps()
{
$map = new DataTable\Map();
$dataTable = new DataTable();
$dataTable->addRowFromSimpleArray(array('nb_visits' => 5, 'nb_random' => 10));
$dataTable2 = new DataTable();
$dataTable2->addRowFromSimpleArray(array('nb_visits' => 3, 'nb_random' => 6));
$map->addTable($dataTable, 'table1');
$map->addTable($dataTable2, 'table2');
$response = $this->builder->renderDataTable($map);
$this->assertEquals('defaultKeyName,nb_visits,nb_random
table1,5,10
table2,3,6', $response);
}
示例11: getTablesSummary
/**
* Returns a datatable representation of a set of table statuses.
*
* @param array $statuses The table statuses to summarize.
* @return DataTable
*/
private function getTablesSummary($statuses)
{
$dataTable = new DataTable();
foreach ($statuses as $status) {
$dataTable->addRowFromSimpleArray(array('label' => $status['Name'], 'data_size' => $status['Data_length'], 'index_size' => $status['Index_length'], 'row_count' => $status['Rows']));
}
return $dataTable;
}
示例12: test_renderDataTable_shouldRenderDataTableMaps
public function test_renderDataTable_shouldRenderDataTableMaps()
{
$map = new DataTable\Map();
$dataTable = new DataTable();
$dataTable->addRowFromSimpleArray(array('nb_visits' => 5, 'nb_random' => 10));
$dataTable2 = new DataTable();
$dataTable2->addRowFromSimpleArray(array('nb_visits' => 3, 'nb_random' => 6));
$map->addTable($dataTable, 'table1');
$map->addTable($dataTable2, 'table2');
$response = $this->builder->renderDataTable($map);
$this->assertEquals('<table id="MultiSites_getAll" border="1">
<thead>
<tr>
<th>_defaultKeyName</th>
<th>nb_visits</th>
<th>nb_random</th>
</tr>
</thead>
<tbody>
<tr>
<td>table1</td>
<td>5</td>
<td>10</td>
</tr>
<tr>
<td>table2</td>
<td>3</td>
<td>6</td>
</tr>
</tbody>
</table>
', $response);
}
示例13: getDataTableWithUsers
private function getDataTableWithUsers()
{
$tableWithUsers = new DataTable();
$tableWithUsers->addRowFromSimpleArray(array('label' => 'test', 'nb_users' => 10));
return $tableWithUsers;
}
示例14: test_renderDataTable_shouldRenderDataTableMaps
public function test_renderDataTable_shouldRenderDataTableMaps()
{
$map = new DataTable\Map();
$dataTable = new DataTable();
$dataTable->addRowFromSimpleArray(array('nb_visits' => 5, 'nb_random' => 10));
$dataTable2 = new DataTable();
$dataTable2->addRowFromSimpleArray(array('nb_visits' => 3, 'nb_random' => 6));
$map->addTable($dataTable, 'table1');
$map->addTable($dataTable2, 'table2');
$response = $this->builder->renderDataTable($map);
$this->assertEquals('<?xml version="1.0" encoding="utf-8" ?>
<results>
<result defaultKeyName="table1">
<row>
<nb_visits>5</nb_visits>
<nb_random>10</nb_random>
</row>
</result>
<result defaultKeyName="table2">
<row>
<nb_visits>3</nb_visits>
<nb_random>6</nb_random>
</row>
</result>
</results>', $response);
}
示例15: addMissingWebsites
/**
* @param DataTable|DataTable\Map $dataTable
* @param $fieldsToGet
* @param $sitesToProblablyAdd
*/
private function addMissingWebsites($dataTable, $fieldsToGet, $sitesToProblablyAdd)
{
$siteIdsInDataTable = array();
foreach ($dataTable->getRows() as $row) {
/** @var DataTable\Row $row */
$siteIdsInDataTable[] = $row->getColumn('label');
}
foreach ($sitesToProblablyAdd as $site) {
if (!in_array($site['idsite'], $siteIdsInDataTable)) {
$siteRow = array_combine($fieldsToGet, array_pad(array(), count($fieldsToGet), 0));
$siteRow['label'] = (int) $site['idsite'];
$dataTable->addRowFromSimpleArray($siteRow);
}
}
}