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


PHP DataTable::addRowsFromSimpleArray方法代码示例

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


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

示例1: makeFromSimpleArray

 /**
  * Returns a new DataTable created with data from a 'simple' array.
  *
  * See {@link addRowsFromSimpleArray()}.
  *
  * @param array $array
  * @return \Piwik\DataTable
  */
 public static function makeFromSimpleArray($array)
 {
     $dataTable = new DataTable();
     $dataTable->addRowsFromSimpleArray($array);
     return $dataTable;
 }
开发者ID:piwik,项目名称:piwik,代码行数:14,代码来源:DataTable.php

示例2: 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;
 }
开发者ID:carriercomm,项目名称:piwik,代码行数:52,代码来源:API.php

示例3: makeVisitorTableFromArray

 /**
  * @param $data
  * @return DataTable
  * @throws Exception
  */
 private function makeVisitorTableFromArray($data)
 {
     $dataTable = new DataTable();
     $dataTable->addRowsFromSimpleArray($data);
     if (!empty($data[0])) {
         $columnsToNotAggregate = array_map(function () {
             return 'skip';
         }, $data[0]);
         $dataTable->setMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME, $columnsToNotAggregate);
     }
     return $dataTable;
 }
开发者ID:dorelljames,项目名称:piwik,代码行数:17,代码来源:API.php

示例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 DataTable();
     foreach ($statuses as $status) {
         $dataTableOptionName = $this->getCachedOptionName($status['Name'], 'byArchiveName');
         // if option exists && !$forceCache, use the cached data, otherwise create the
         $cachedData = Option::get($dataTableOptionName);
         if ($cachedData !== false && !$forceCache) {
             $table = DataTable::fromSerializedArray($cachedData);
         } else {
             $table = new DataTable();
             $table->addRowsFromSimpleArray($this->dataAccess->getRowCountsByArchiveName($status['Name'], $extraCols));
             $reduceArchiveRowName = array($this, 'reduceArchiveRowName');
             $table->filter('GroupBy', array('label', $reduceArchiveRowName));
             $serializedTables = $table->getSerialized();
             $serializedTable = reset($serializedTables);
             Option::set($dataTableOptionName, $serializedTable);
         }
         // add estimated_size column
         $getEstimatedSize = array($this, $getRowSizeMethod);
         $table->filter('ColumnCallbackAddColumn', array($cols, 'estimated_size', $getEstimatedSize, array($status)));
         $dataTable->addDataTable($table);
     }
     return $dataTable;
 }
开发者ID:carriercomm,项目名称:piwik,代码行数:34,代码来源:MySQLMetadataProvider.php

示例5: _getDataTableSimpleWithCommasInCells

 private function _getDataTableSimpleWithCommasInCells()
 {
     $table = new DataTable();
     $table->addRowsFromSimpleArray(array(array("col,1" => "val\"1", "col,2" => "val\",2")));
     return $table;
 }
开发者ID:igorclark,项目名称:piwik,代码行数:6,代码来源:CSVTest.php

示例6: loadLastVisitorDetailsFromDatabase

 private function loadLastVisitorDetailsFromDatabase($idSite, $period, $date, $segment = false, $countVisitorsToFetch = 100, $visitorId = false, $minTimestamp = false, $filterSortOrder = false)
 {
     $where = $whereBind = array();
     list($whereClause, $idSites) = $this->getIdSitesWhereClause($idSite);
     $where[] = $whereClause;
     $whereBind = $idSites;
     if (strtolower($filterSortOrder) !== 'asc') {
         $filterSortOrder = 'DESC';
     }
     $orderBy = "idsite, visit_last_action_time " . $filterSortOrder;
     $orderByParent = "sub.visit_last_action_time " . $filterSortOrder;
     if (!empty($visitorId)) {
         $where[] = "log_visit.idvisitor = ? ";
         $whereBind[] = @Common::hex2bin($visitorId);
     }
     if (!empty($minTimestamp)) {
         $where[] = "log_visit.visit_last_action_time > ? ";
         $whereBind[] = date("Y-m-d H:i:s", $minTimestamp);
     }
     // If no other filter, only look at the last 24 hours of stats
     if (empty($visitorId) && empty($countVisitorsToFetch) && empty($period) && empty($date)) {
         $period = 'day';
         $date = 'yesterdaySameTime';
     }
     // SQL Filter with provided period
     if (!empty($period) && !empty($date)) {
         $currentSite = new Site($idSite);
         $currentTimezone = $currentSite->getTimezone();
         $dateString = $date;
         if ($period == 'range') {
             $processedPeriod = new Range('range', $date);
             if ($parsedDate = Range::parseDateRange($date)) {
                 $dateString = $parsedDate[2];
             }
         } else {
             $processedDate = Date::factory($date);
             if ($date == 'today' || $date == 'now' || $processedDate->toString() == Date::factory('now', $currentTimezone)->toString()) {
                 $processedDate = $processedDate->subDay(1);
             }
             $processedPeriod = Period\Factory::build($period, $processedDate);
         }
         $dateStart = $processedPeriod->getDateStart()->setTimezone($currentTimezone);
         $where[] = "log_visit.visit_last_action_time >= ?";
         $whereBind[] = $dateStart->toString('Y-m-d H:i:s');
         if (!in_array($date, array('now', 'today', 'yesterdaySameTime')) && strpos($date, 'last') === false && strpos($date, 'previous') === false && Date::factory($dateString)->toString('Y-m-d') != Date::factory('now', $currentTimezone)->toString()) {
             $dateEnd = $processedPeriod->getDateEnd()->setTimezone($currentTimezone);
             $where[] = " log_visit.visit_last_action_time <= ?";
             $dateEndString = $dateEnd->addDay(1)->toString('Y-m-d H:i:s');
             $whereBind[] = $dateEndString;
         }
     }
     if (count($where) > 0) {
         $where = join("\n\t\t\t\tAND ", $where);
     } else {
         $where = false;
     }
     $segment = new Segment($segment, $idSite);
     // Subquery to use the indexes for ORDER BY
     $select = "log_visit.*";
     $from = "log_visit";
     $subQuery = $segment->getSelectQuery($select, $from, $where, $whereBind, $orderBy);
     $sqlLimit = $countVisitorsToFetch >= 1 ? " LIMIT 0, " . (int) $countVisitorsToFetch : "";
     // Group by idvisit so that a visitor converting 2 goals only appears once
     $sql = "\n\t\t\tSELECT sub.* FROM (\n\t\t\t\t" . $subQuery['sql'] . "\n\t\t\t\t{$sqlLimit}\n\t\t\t) AS sub\n\t\t\tGROUP BY sub.idvisit\n\t\t\tORDER BY {$orderByParent}\n\t\t";
     try {
         $data = Db::fetchAll($sql, $subQuery['bind']);
     } catch (Exception $e) {
         echo $e->getMessage();
         exit;
     }
     $dataTable = new DataTable();
     $dataTable->addRowsFromSimpleArray($data);
     // $dataTable->disableFilter('Truncate');
     if (!empty($data[0])) {
         $columnsToNotAggregate = array_map(function () {
             return 'skip';
         }, $data[0]);
         $dataTable->setMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME, $columnsToNotAggregate);
     }
     return $dataTable;
 }
开发者ID:TensorWrenchOSS,项目名称:piwik,代码行数:81,代码来源:API.php

示例7: _getDataTableWithInvalidChars

 private function _getDataTableWithInvalidChars()
 {
     $table = new DataTable();
     $table->addRowsFromSimpleArray(array("\$%@(%" => 1, "avbs\$" => 2, "b/" => 2));
     return $table;
 }
开发者ID:FluentDevelopment,项目名称:piwik,代码行数:6,代码来源:XMLTest.php

示例8: setSitesTable

 private function setSitesTable($numSites)
 {
     $sites = new DataTable();
     $sites->addRowsFromSimpleArray($this->buildSitesArray(range(1, $numSites)));
     $sites->setMetadata('last_period_date', Period\Factory::build('day', '2012-12-12'));
     $this->dashboard->setSitesTable($sites);
     return $sites;
 }
开发者ID:normimuc,项目名称:piwik,代码行数:8,代码来源:DashboardTest.php


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