作者:KiwiJuice
项目:handball-dacha
public static function getArchiveIdAndVisits(Site $site, Period $period, Segment $segment, $minDatetimeArchiveProcessedUTC, $requestedPlugin)
{
$dateStart = $period->getDateStart();
$bindSQL = array($site->getId(), $dateStart->toString('Y-m-d'), $period->getDateEnd()->toString('Y-m-d'), $period->getId());
$timeStampWhere = '';
if ($minDatetimeArchiveProcessedUTC) {
$timeStampWhere = " AND ts_archived >= ? ";
$bindSQL[] = Date::factory($minDatetimeArchiveProcessedUTC)->getDatetime();
}
$pluginOrVisitsSummary = array("VisitsSummary", $requestedPlugin);
$pluginOrVisitsSummary = array_unique($pluginOrVisitsSummary);
$sqlWhereArchiveName = self::getNameCondition($pluginOrVisitsSummary, $segment);
$sqlQuery = "\tSELECT idarchive, value, name, date1 as startDate\n\t\t\t\t\t\tFROM " . ArchiveTableCreator::getNumericTable($dateStart) . "``\n\t\t\t\t\t\tWHERE idsite = ?\n\t\t\t\t\t\t\tAND date1 = ?\n\t\t\t\t\t\t\tAND date2 = ?\n\t\t\t\t\t\t\tAND period = ?\n\t\t\t\t\t\t\tAND ( ({$sqlWhereArchiveName})\n\t\t\t\t\t\t\t\t OR name = '" . self::NB_VISITS_RECORD_LOOKED_UP . "'\n\t\t\t\t\t\t\t\t OR name = '" . self::NB_VISITS_CONVERTED_RECORD_LOOKED_UP . "')\n\t\t\t\t\t\t\t{$timeStampWhere}\n\t\t\t\t\t\tORDER BY idarchive DESC";
$results = Db::fetchAll($sqlQuery, $bindSQL);
if (empty($results)) {
return false;
}
$idArchive = self::getMostRecentIdArchiveFromResults($segment, $requestedPlugin, $results);
$idArchiveVisitsSummary = self::getMostRecentIdArchiveFromResults($segment, "VisitsSummary", $results);
list($visits, $visitsConverted) = self::getVisitsMetricsFromResults($idArchive, $idArchiveVisitsSummary, $results);
if ($visits === false && $idArchive === false) {
return false;
}
return array($idArchive, $visits, $visitsConverted);
}
作者:brienomatt
项目:elmsl
/**
* Returns true if it is likely that the data for this report has been purged and if the
* user should be told about that.
*
* In order for this function to return true, the following must also be true:
* - The data table for this report must either be empty or not have been fetched.
* - The period of this report is not a multiple period.
* - The date of this report must be older than the delete_reports_older_than config option.
* @param DataTableInterface $dataTable
* @return bool
*/
public static function hasReportBeenPurged($dataTable)
{
$strPeriod = Common::getRequestVar('period', false);
$strDate = Common::getRequestVar('date', false);
if (false !== $strPeriod && false !== $strDate && (is_null($dataTable) || !empty($dataTable) && $dataTable->getRowsCount() == 0)) {
// if range, only look at the first date
if ($strPeriod == 'range') {
$idSite = Common::getRequestVar('idSite', '');
if (intval($idSite) != 0) {
$site = new Site($idSite);
$timezone = $site->getTimezone();
} else {
$timezone = 'UTC';
}
$period = new Range('range', $strDate, $timezone);
$reportDate = $period->getDateStart();
} elseif (Period::isMultiplePeriod($strDate, $strPeriod)) {
// if a multiple period, this function is irrelevant
return false;
} else {
// otherwise, use the date as given
$reportDate = Date::factory($strDate);
}
$reportYear = $reportDate->toString('Y');
$reportMonth = $reportDate->toString('m');
if (static::shouldReportBePurged($reportYear, $reportMonth)) {
return true;
}
}
return false;
}
作者:KiwiJuice
项目:handball-dacha
public function getRowEvolution($idSite, $period, $date, $apiModule, $apiAction, $label = false, $segment = false, $column = false, $language = false, $idGoal = false, $legendAppendMetric = true, $labelUseAbsoluteUrl = true)
{
// validation of requested $period & $date
if ($period == 'range') {
// load days in the range
$period = 'day';
}
if (!Period::isMultiplePeriod($date, $period)) {
throw new Exception("Row evolutions can not be processed with this combination of \\'date\\' and \\'period\\' parameters.");
}
$label = ResponseBuilder::unsanitizeLabelParameter($label);
$labels = Piwik::getArrayFromApiParameter($label);
$metadata = $this->getRowEvolutionMetaData($idSite, $period, $date, $apiModule, $apiAction, $language, $idGoal);
$dataTable = $this->loadRowEvolutionDataFromAPI($metadata, $idSite, $period, $date, $apiModule, $apiAction, $labels, $segment, $idGoal);
if (empty($labels)) {
$labels = $this->getLabelsFromDataTable($dataTable, $labels);
$dataTable = $this->enrichRowAddMetadataLabelIndex($labels, $dataTable);
}
if (count($labels) != 1) {
$data = $this->getMultiRowEvolution($dataTable, $metadata, $apiModule, $apiAction, $labels, $column, $legendAppendMetric, $labelUseAbsoluteUrl);
} else {
$data = $this->getSingleRowEvolution($idSite, $dataTable, $metadata, $apiModule, $apiAction, $labels[0], $labelUseAbsoluteUrl);
}
return $data;
}
作者:jniebuh
项目:piwi
/**
* Generates the subperiods (one for each day in the month)
*/
protected function generate()
{
if ($this->subperiodsProcessed) {
return;
}
parent::generate();
$date = $this->date;
$startMonth = $date->setDay(1)->setTime('00:00:00');
$endMonth = $startMonth->addPeriod(1, 'month')->setDay(1)->subDay(1);
$this->processOptimalSubperiods($startMonth, $endMonth);
}
作者:KiwiJuice
项目:handball-dacha
/**
* General method to get transitions for an action
*
* @param $actionName
* @param $actionType "url"|"title"
* @param $idSite
* @param $period
* @param $date
* @param bool $segment
* @param bool $limitBeforeGrouping
* @param string $parts
* @return array
* @throws Exception
*/
public function getTransitionsForAction($actionName, $actionType, $idSite, $period, $date, $segment = false, $limitBeforeGrouping = false, $parts = 'all')
{
Piwik::checkUserHasViewAccess($idSite);
// get idaction of the requested action
$idaction = $this->deriveIdAction($actionName, $actionType);
if ($idaction < 0) {
throw new Exception('NoDataForAction');
}
// prepare log aggregator
$segment = new Segment($segment, $idSite);
$site = new Site($idSite);
$period = Period::factory($period, $date);
$params = new ArchiveProcessor\Parameters($site, $period, $segment);
$logAggregator = new LogAggregator($params);
// prepare the report
$report = array('date' => Period::factory($period->getLabel(), $date)->getLocalizedShortString());
$partsArray = explode(',', $parts);
if ($parts == 'all' || in_array('internalReferrers', $partsArray)) {
$this->addInternalReferrers($logAggregator, $report, $idaction, $actionType, $limitBeforeGrouping);
}
if ($parts == 'all' || in_array('followingActions', $partsArray)) {
$includeLoops = $parts != 'all' && !in_array('internalReferrers', $partsArray);
$this->addFollowingActions($logAggregator, $report, $idaction, $actionType, $limitBeforeGrouping, $includeLoops);
}
if ($parts == 'all' || in_array('externalReferrers', $partsArray)) {
$this->addExternalReferrers($logAggregator, $report, $idaction, $actionType, $limitBeforeGrouping);
}
// derive the number of exits from the other metrics
if ($parts == 'all') {
$report['pageMetrics']['exits'] = $report['pageMetrics']['pageviews'] - $this->getTotalTransitionsToFollowingActions() - $report['pageMetrics']['loops'];
}
// replace column names in the data tables
$reportNames = array('previousPages' => true, 'previousSiteSearches' => false, 'followingPages' => true, 'followingSiteSearches' => false, 'outlinks' => true, 'downloads' => true);
foreach ($reportNames as $reportName => $replaceLabel) {
if (isset($report[$reportName])) {
$columnNames = array(Metrics::INDEX_NB_ACTIONS => 'referrals');
if ($replaceLabel) {
$columnNames[Metrics::INDEX_NB_ACTIONS] = 'referrals';
}
$report[$reportName]->filter('ReplaceColumnNames', array($columnNames));
}
}
return $report;
}
作者:carriercom
项目:piwi
/**
* 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;
}
作者:brienomatt
项目:elmsl
/**
* Creates a new Period instance with a period ID and {@link Date} instance.
*
* _Note: This method cannot create {@link Period\Range} periods._
*
* @param string $period `"day"`, `"week"`, `"month"`, `"year"`, `"range"`.
* @param Date|string $date A date within the period or the range of dates.
* @param Date|string $timezone Optional timezone that will be used only when $period is 'range' or $date is 'last|previous'
* @throws Exception If `$strPeriod` is invalid.
* @return \Piwik\Period
*/
public static function build($period, $date, $timezone = 'UTC')
{
self::checkPeriodIsEnabled($period);
if (is_string($date)) {
if (Period::isMultiplePeriod($date, $period) || $period == 'range') {
return new Range($period, $date, $timezone);
}
$date = Date::factory($date);
}
switch ($period) {
case 'day':
return new Day($date);
break;
case 'week':
return new Week($date);
break;
case 'month':
return new Month($date);
break;
case 'year':
return new Year($date);
break;
}
}
作者:KiwiJuice
项目:handball-dacha
/**
* Adds new subperiods
*
* @param Date $startDate
* @param Date $endDate
* @param string $period
*/
protected function fillArraySubPeriods($startDate, $endDate, $period)
{
$arrayPeriods = array();
$endSubperiod = Period::factory($period, $endDate);
$arrayPeriods[] = $endSubperiod;
// set end date to start of end period since we're comparing against start date.
$endDate = $endSubperiod->getDateStart();
while ($endDate->isLater($startDate)) {
$endDate = $endDate->addPeriod(-1, $period);
$subPeriod = Period::factory($period, $endDate);
$arrayPeriods[] = $subPeriod;
}
$arrayPeriods = array_reverse($arrayPeriods);
foreach ($arrayPeriods as $period) {
$this->addSubperiod($period);
}
}
作者:hichni
项目:piwi
/**
* Returns `true` if this instance will request a single DataTable, `false` if requesting
* more than one.
*
* @return bool
*/
public function isRequestingSingleDataTable()
{
$requestArray = $this->request->getRequestArray() + $_GET + $_POST;
$date = Common::getRequestVar('date', null, 'string', $requestArray);
$period = Common::getRequestVar('period', null, 'string', $requestArray);
$idSite = Common::getRequestVar('idSite', null, 'string', $requestArray);
if (Period::isMultiplePeriod($date, $period) || strpos($idSite, ',') !== false || $idSite == 'all') {
return false;
}
return true;
}
作者:qiua
项目:piwi
/**
* @expectedException \Exception
* @expectedExceptionMessage General_ExceptionInvalidDateFormat
* @dataProvider getInvalidDateFormats
*/
public function testValidate_InvalidDates($invalidDateFormat)
{
Period::checkDateFormat($invalidDateFormat);
}
作者:carriercom
项目:piwi
/**
* @param $archiveGroups
* @param $site
* @param $period
*/
private function prepareArchive(array $archiveGroups, Site $site, Period $period)
{
$parameters = new ArchiveProcessor\Parameters($site, $period, $this->params->getSegment(), $this->params->isSkipAggregationOfSubTables());
$archiveLoader = new ArchiveProcessor\Loader($parameters);
$periodString = $period->getRangeString();
// process for each plugin as well
foreach ($archiveGroups as $plugin) {
$doneFlag = $this->getDoneStringForPlugin($plugin);
$this->initializeArchiveIdCache($doneFlag);
$idArchive = $archiveLoader->prepareArchive($plugin);
if ($idArchive) {
$this->idarchives[$doneFlag][$periodString][] = $idArchive;
}
}
}
作者:CaptainShar
项目:SSAD_Projec
private function makeSureToWorkOnFirstLevelDataTable($table)
{
if (!array_key_exists('idSubtable', $this->request)) {
return $table;
}
$firstLevelReport = $this->findFirstLevelReport();
if (empty($firstLevelReport)) {
// it is not a subtable report
$module = $this->apiModule;
$action = $this->apiMethod;
} else {
$module = $firstLevelReport->getModule();
$action = $firstLevelReport->getAction();
}
$request = $this->request;
/** @var \Piwik\Period $period */
$period = $table->getMetadata('period');
if (!empty($period)) {
// we want a dataTable, not a dataTable\map
if (Period::isMultiplePeriod($request['date'], $request['period']) || 'range' == $period->getLabel()) {
$request['date'] = $period->getRangeString();
$request['period'] = 'range';
} else {
$request['date'] = $period->getDateStart()->toString();
$request['period'] = $period->getLabel();
}
}
$table = $this->callApiAndReturnDataTable($module, $action, $request);
if ($table instanceof DataTable\Map) {
$table = $table->mergeChildren();
}
return $table;
}
作者:KiwiJuice
项目:handball-dacha
/**
* Returns start & end dates for the range described by a period and optional lastN
* argument.
*
* @param string|bool $date The start date of the period (or the date range of a range
* period).
* @param string $period The period type ('day', 'week', 'month', 'year' or 'range').
* @param bool|int $lastN Whether to include the last N periods in the range or not.
* Ignored if period == range.
*
* @return Date[] array of Date objects or array(false, false)
* @ignore
*/
public static function getDateRangeForPeriod($date, $period, $lastN = false)
{
if ($date === false) {
return array(false, false);
}
// if the range is just a normal period (or the period is a range in which case lastN is ignored)
if ($lastN === false || $period == 'range') {
if ($period == 'range') {
$oPeriod = new Range('day', $date);
} else {
$oPeriod = Period::factory($period, Date::factory($date));
}
$startDate = $oPeriod->getDateStart();
$endDate = $oPeriod->getDateEnd();
} else {
list($date, $lastN) = EvolutionViz::getDateRangeAndLastN($period, $date, $lastN);
list($startDate, $endDate) = explode(',', $date);
$startDate = Date::factory($startDate);
$endDate = Date::factory($endDate);
}
return array($startDate, $endDate);
}
作者:piwi
项目:piwi
/**
* Returns a prettified date string for use in period selector widget.
*
* @param Period $period The period to return a pretty string for.
* @return string
* @api
*/
public static function getCalendarPrettyDate($period)
{
if ($period instanceof Month) {
// show month name when period is for a month
return $period->getLocalizedLongString();
} else {
return $period->getPrettyString();
}
}
作者:KiwiJuice
项目:handball-dacha
public function getProcessedReport($idSite, $period, $date, $apiModule, $apiAction, $segment = false, $apiParameters = false, $idGoal = false, $language = false, $showTimer = true, $hideMetricsDoc = false, $idSubtable = false, $showRawMetrics = false)
{
$timer = new Timer();
if (empty($apiParameters)) {
$apiParameters = array();
}
if (!empty($idGoal) && empty($apiParameters['idGoal'])) {
$apiParameters['idGoal'] = $idGoal;
}
// Is this report found in the Metadata available reports?
$reportMetadata = $this->getMetadata($idSite, $apiModule, $apiAction, $apiParameters, $language, $period, $date, $hideMetricsDoc, $showSubtableReports = true);
if (empty($reportMetadata)) {
throw new Exception("Requested report {$apiModule}.{$apiAction} for Website id={$idSite} not found in the list of available reports. \n");
}
$reportMetadata = reset($reportMetadata);
// Generate Api call URL passing custom parameters
$parameters = array_merge($apiParameters, array('method' => $apiModule . '.' . $apiAction, 'idSite' => $idSite, 'period' => $period, 'date' => $date, 'format' => 'original', 'serialize' => '0', 'language' => $language, 'idSubtable' => $idSubtable));
if (!empty($segment)) {
$parameters['segment'] = $segment;
}
$url = Url::getQueryStringFromParameters($parameters);
$request = new Request($url);
try {
/** @var DataTable */
$dataTable = $request->process();
} catch (Exception $e) {
throw new Exception("API returned an error: " . $e->getMessage() . " at " . basename($e->getFile()) . ":" . $e->getLine() . "\n");
}
list($newReport, $columns, $rowsMetadata, $totals) = $this->handleTableReport($idSite, $dataTable, $reportMetadata, $showRawMetrics);
foreach ($columns as $columnId => &$name) {
$name = ucfirst($name);
}
$website = new Site($idSite);
$period = Period::factory($period, $date);
$period = $period->getLocalizedLongString();
$return = array('website' => $website->getName(), 'prettyDate' => $period, 'metadata' => $reportMetadata, 'columns' => $columns, 'reportData' => $newReport, 'reportMetadata' => $rowsMetadata, 'reportTotal' => $totals);
if ($showTimer) {
$return['timerMillis'] = $timer->getTimeMs(0);
}
return $return;
}
作者:KiwiJuice
项目:handball-dacha
/**
* Sends the http headers for csv file
*/
protected function renderHeader()
{
$fileName = 'Piwik ' . Piwik::translate('General_Export');
$period = Common::getRequestVar('period', false);
$date = Common::getRequestVar('date', false);
if ($period || $date) {
if ($period == 'range') {
$period = new Range($period, $date);
} else {
if (strpos($date, ',') !== false) {
$period = new Range('range', $date);
} else {
$period = Period::factory($period, Date::factory($date));
}
}
$prettyDate = $period->getLocalizedLongString();
$meta = $this->getApiMetaData();
$fileName .= ' _ ' . $meta['name'] . ' _ ' . $prettyDate . '.csv';
}
// silent fail otherwise unit tests fail
@header('Content-Type: application/vnd.ms-excel');
@header('Content-Disposition: attachment; filename="' . $fileName . '"');
ProxyHttp::overrideCacheControlHeaders();
}
作者:carriercom
项目:piwi
/**
* @param array $reports
* @param array $info
* @return mixed
*/
public function getReportMetadata(&$reports, $info)
{
$idSites = $info['idSites'];
// If only one website is selected, we add the Graph URL
if (count($idSites) != 1) {
return;
}
$idSite = reset($idSites);
// in case API.getReportMetadata was not called with date/period we use sane defaults
if (empty($info['period'])) {
$info['period'] = 'day';
}
if (empty($info['date'])) {
$info['date'] = 'today';
}
// need two sets of period & date, one for single period graphs, one for multiple periods graphs
if (Period::isMultiplePeriod($info['date'], $info['period'])) {
$periodForMultiplePeriodGraph = $info['period'];
$dateForMultiplePeriodGraph = $info['date'];
$periodForSinglePeriodGraph = 'range';
$dateForSinglePeriodGraph = $info['date'];
} else {
$periodForSinglePeriodGraph = $info['period'];
$dateForSinglePeriodGraph = $info['date'];
$piwikSite = new Site($idSite);
if ($periodForSinglePeriodGraph == 'range') {
$periodForMultiplePeriodGraph = Config::getInstance()->General['graphs_default_period_to_plot_when_period_range'];
$dateForMultiplePeriodGraph = $dateForSinglePeriodGraph;
} else {
$periodForMultiplePeriodGraph = $periodForSinglePeriodGraph;
$dateForMultiplePeriodGraph = Range::getRelativeToEndDate($periodForSinglePeriodGraph, 'last' . self::GRAPH_EVOLUTION_LAST_PERIODS, $dateForSinglePeriodGraph, $piwikSite);
}
}
$token_auth = Common::getRequestVar('token_auth', false);
$urlPrefix = "index.php?";
foreach ($reports as &$report) {
$reportModule = $report['module'];
$reportAction = $report['action'];
$reportUniqueId = $reportModule . '_' . $reportAction;
$parameters = array();
$parameters['module'] = 'API';
$parameters['method'] = 'ImageGraph.get';
$parameters['idSite'] = $idSite;
$parameters['apiModule'] = $reportModule;
$parameters['apiAction'] = $reportAction;
if (!empty($token_auth)) {
$parameters['token_auth'] = $token_auth;
}
// Forward custom Report parameters to the graph URL
if (!empty($report['parameters'])) {
$parameters = array_merge($parameters, $report['parameters']);
}
if (empty($report['dimension'])) {
$parameters['period'] = $periodForMultiplePeriodGraph;
$parameters['date'] = $dateForMultiplePeriodGraph;
} else {
$parameters['period'] = $periodForSinglePeriodGraph;
$parameters['date'] = $dateForSinglePeriodGraph;
}
// add the idSubtable if it exists
$idSubtable = Common::getRequestVar('idSubtable', false);
if ($idSubtable !== false) {
$parameters['idSubtable'] = $idSubtable;
}
if (!empty($_GET['_restrictSitesToLogin']) && TaskScheduler::isTaskBeingExecuted()) {
$parameters['_restrictSitesToLogin'] = $_GET['_restrictSitesToLogin'];
}
$report['imageGraphUrl'] = $urlPrefix . Url::getQueryStringFromParameters($parameters);
// thanks to API.getRowEvolution, reports with dimensions can now be plotted using an evolution graph
// however, most reports with a fixed set of dimension values are excluded
// this is done so Piwik Mobile and Scheduled Reports do not display them
$reportWithDimensionsSupportsEvolution = empty($report['constantRowsCount']) || in_array($reportUniqueId, self::$CONSTANT_ROW_COUNT_REPORT_EXCEPTIONS);
$reportSupportsEvolution = !in_array($reportUniqueId, self::$REPORTS_DISABLED_EVOLUTION_GRAPH);
if ($reportSupportsEvolution && $reportWithDimensionsSupportsEvolution) {
$parameters['period'] = $periodForMultiplePeriodGraph;
$parameters['date'] = $dateForMultiplePeriodGraph;
$report['imageGraphEvolutionUrl'] = $urlPrefix . Url::getQueryStringFromParameters($parameters);
}
}
}
作者:KiwiJuice
项目:handball-dacha
public function get($idSite, $period, $date, $apiModule, $apiAction, $graphType = false, $outputType = API::GRAPH_OUTPUT_INLINE, $columns = false, $labels = false, $showLegend = true, $width = false, $height = false, $fontSize = API::DEFAULT_FONT_SIZE, $legendFontSize = false, $aliasedGraph = true, $idGoal = false, $colors = false, $textColor = API::DEFAULT_TEXT_COLOR, $backgroundColor = API::DEFAULT_BACKGROUND_COLOR, $gridColor = API::DEFAULT_GRID_COLOR, $idSubtable = false, $legendAppendMetric = true, $segment = false)
{
Piwik::checkUserHasViewAccess($idSite);
// Health check - should we also test for GD2 only?
if (!SettingsServer::isGdExtensionEnabled()) {
throw new Exception('Error: To create graphs in Piwik, please enable GD php extension (with Freetype support) in php.ini,
and restart your web server.');
}
$useUnicodeFont = array('am', 'ar', 'el', 'fa', 'fi', 'he', 'ja', 'ka', 'ko', 'te', 'th', 'zh-cn', 'zh-tw');
$languageLoaded = Translate::getLanguageLoaded();
$font = self::getFontPath(self::DEFAULT_FONT);
if (in_array($languageLoaded, $useUnicodeFont)) {
$unicodeFontPath = self::getFontPath(self::UNICODE_FONT);
$font = file_exists($unicodeFontPath) ? $unicodeFontPath : $font;
}
// save original GET to reset after processing. Important for API-in-API-call
$savedGET = $_GET;
try {
$apiParameters = array();
if (!empty($idGoal)) {
$apiParameters = array('idGoal' => $idGoal);
}
// Fetch the metadata for given api-action
$metadata = APIMetadata::getInstance()->getMetadata($idSite, $apiModule, $apiAction, $apiParameters, $languageLoaded, $period, $date, $hideMetricsDoc = false, $showSubtableReports = true);
if (!$metadata) {
throw new Exception('Invalid API Module and/or API Action');
}
$metadata = $metadata[0];
$reportHasDimension = !empty($metadata['dimension']);
$constantRowsCount = !empty($metadata['constantRowsCount']);
$isMultiplePeriod = Period::isMultiplePeriod($date, $period);
if (!$reportHasDimension && !$isMultiplePeriod) {
throw new Exception('The graph cannot be drawn for this combination of \'date\' and \'period\' parameters.');
}
if (empty($legendFontSize)) {
$legendFontSize = (int) $fontSize + self::DEFAULT_LEGEND_FONT_SIZE_OFFSET;
}
if (empty($graphType)) {
if ($isMultiplePeriod) {
$graphType = StaticGraph::GRAPH_TYPE_BASIC_LINE;
} else {
if ($constantRowsCount) {
$graphType = StaticGraph::GRAPH_TYPE_VERTICAL_BAR;
} else {
$graphType = StaticGraph::GRAPH_TYPE_HORIZONTAL_BAR;
}
}
$reportUniqueId = $metadata['uniqueId'];
if (isset(self::$DEFAULT_GRAPH_TYPE_OVERRIDE[$reportUniqueId][$isMultiplePeriod])) {
$graphType = self::$DEFAULT_GRAPH_TYPE_OVERRIDE[$reportUniqueId][$isMultiplePeriod];
}
} else {
$availableGraphTypes = StaticGraph::getAvailableStaticGraphTypes();
if (!in_array($graphType, $availableGraphTypes)) {
throw new Exception(Piwik::translate('General_ExceptionInvalidStaticGraphType', array($graphType, implode(', ', $availableGraphTypes))));
}
}
$width = (int) $width;
$height = (int) $height;
if (empty($width)) {
$width = self::$DEFAULT_PARAMETERS[$graphType][self::WIDTH_KEY];
}
if (empty($height)) {
$height = self::$DEFAULT_PARAMETERS[$graphType][self::HEIGHT_KEY];
}
// Cap width and height to a safe amount
$width = min($width, self::MAX_WIDTH);
$height = min($height, self::MAX_HEIGHT);
$reportColumns = array_merge(!empty($metadata['metrics']) ? $metadata['metrics'] : array(), !empty($metadata['processedMetrics']) ? $metadata['processedMetrics'] : array(), !empty($metadata['metricsGoal']) ? $metadata['metricsGoal'] : array(), !empty($metadata['processedMetricsGoal']) ? $metadata['processedMetricsGoal'] : array());
$ordinateColumns = array();
if (empty($columns)) {
$ordinateColumns[] = empty($reportColumns[self::DEFAULT_ORDINATE_METRIC]) ? key($metadata['metrics']) : self::DEFAULT_ORDINATE_METRIC;
} else {
$ordinateColumns = explode(',', $columns);
foreach ($ordinateColumns as $column) {
if (empty($reportColumns[$column])) {
throw new Exception(Piwik::translate('ImageGraph_ColumnOrdinateMissing', array($column, implode(',', array_keys($reportColumns)))));
}
}
}
$ordinateLabels = array();
foreach ($ordinateColumns as $column) {
$ordinateLabels[$column] = $reportColumns[$column];
}
// sort and truncate filters
$defaultFilterTruncate = self::$DEFAULT_PARAMETERS[$graphType][self::TRUNCATE_KEY];
switch ($graphType) {
case StaticGraph::GRAPH_TYPE_3D_PIE:
case StaticGraph::GRAPH_TYPE_BASIC_PIE:
if (count($ordinateColumns) > 1) {
// pChart doesn't support multiple series on pie charts
throw new Exception("Pie charts do not currently support multiple series");
}
$_GET['filter_sort_column'] = reset($ordinateColumns);
$this->setFilterTruncate($defaultFilterTruncate);
break;
case StaticGraph::GRAPH_TYPE_VERTICAL_BAR:
case StaticGraph::GRAPH_TYPE_BASIC_LINE:
if (!$isMultiplePeriod && !$constantRowsCount) {
$this->setFilterTruncate($defaultFilterTruncate);
//.........这里部分代码省略.........
作者:KiwiJuice
项目:handball-dacha
public function getSitesInfo($isWidgetized = false)
{
Piwik::checkUserHasSomeViewAccess();
$displayRevenueColumn = Common::isGoalPluginEnabled();
$date = Common::getRequestVar('date', 'today');
$period = Common::getRequestVar('period', 'day');
$siteIds = APISitesManager::getInstance()->getSitesIdWithAtLeastViewAccess();
list($minDate, $maxDate) = Site::getMinMaxDateAcrossWebsites($siteIds);
// overwrites the default Date set in the parent controller
// Instead of the default current website's local date,
// we set "today" or "yesterday" based on the default Piwik timezone
$piwikDefaultTimezone = APISitesManager::getInstance()->getDefaultTimezone();
if ($period != 'range') {
$date = $this->getDateParameterInTimezone($date, $piwikDefaultTimezone);
$this->setDate($date);
$date = $date->toString();
}
$dataTable = APIMultiSites::getInstance()->getAll($period, $date, $segment = false);
// put data into a form the template will understand better
$digestableData = array();
foreach ($siteIds as $idSite) {
$isEcommerceEnabled = Site::isEcommerceEnabledFor($idSite);
$digestableData[$idSite] = array('idsite' => $idSite, 'main_url' => Site::getMainUrlFor($idSite), 'name' => Site::getNameFor($idSite), 'visits' => 0, 'pageviews' => 0);
if ($period != 'range') {
$digestableData[$idSite]['visits_evolution'] = 0;
$digestableData[$idSite]['pageviews_evolution'] = 0;
}
if ($displayRevenueColumn) {
$revenueDefault = $isEcommerceEnabled ? 0 : "'-'";
if ($period != 'range') {
$digestableData[$idSite]['revenue_evolution'] = $revenueDefault;
}
}
}
foreach ($dataTable->getRows() as $row) {
$idsite = (int) $row->getMetadata('idsite');
$site =& $digestableData[$idsite];
$site['visits'] = (int) $row->getColumn('nb_visits');
$site['pageviews'] = (int) $row->getColumn('nb_pageviews');
if ($displayRevenueColumn) {
if ($row->getColumn('revenue') !== false) {
$site['revenue'] = $row->getColumn('revenue');
}
}
if ($period != 'range') {
$site['visits_evolution'] = $row->getColumn('visits_evolution');
$site['pageviews_evolution'] = $row->getColumn('pageviews_evolution');
if ($displayRevenueColumn) {
$site['revenue_evolution'] = $row->getColumn('revenue_evolution');
}
}
}
$this->applyPrettyMoney($digestableData);
$view = new View("@MultiSites/getSitesInfo");
$view->isWidgetized = $isWidgetized;
$view->sitesData = array_values($digestableData);
$view->evolutionBy = $this->evolutionBy;
$view->period = $period;
$view->page = $this->page;
$view->limit = $this->limit;
$view->orderBy = $this->orderBy;
$view->order = $this->order;
$view->totalVisits = $dataTable->getMetadata('total_nb_visits');
$view->totalRevenue = $dataTable->getMetadata('total_revenue');
$view->displayRevenueColumn = $displayRevenueColumn;
$view->totalPageviews = $dataTable->getMetadata('total_nb_pageviews');
$view->pastTotalVisits = $dataTable->getMetadata('last_period_total_nb_visits');
$view->totalVisitsEvolution = $dataTable->getMetadata('total_visits_evolution');
if ($view->totalVisitsEvolution > 0) {
$view->totalVisitsEvolution = '+' . $view->totalVisitsEvolution;
}
if ($period != 'range') {
$lastPeriod = Period::factory($period, $dataTable->getMetadata('last_period_date'));
$view->pastPeriodPretty = self::getCalendarPrettyDate($lastPeriod);
}
$params = $this->getGraphParamsModified();
$view->dateSparkline = $period == 'range' ? $date : $params['date'];
$view->autoRefreshTodayReport = false;
// if the current date is today, or yesterday,
// in case the website is set to UTC-12), or today in UTC+14, we refresh the page every 5min
if (in_array($date, array('today', date('Y-m-d'), 'yesterday', Date::factory('yesterday')->toString('Y-m-d'), Date::factory('now', 'UTC+14')->toString('Y-m-d')))) {
$view->autoRefreshTodayReport = Config::getInstance()->General['multisites_refresh_after_seconds'];
}
$this->setGeneralVariablesView($view);
$this->setMinDateView($minDate, $view);
$this->setMaxDateView($maxDate, $view);
$view->show_sparklines = Config::getInstance()->General['show_multisites_sparklines'];
return $view->render();
}
作者:dorelljame
项目:piwi
private function markReportAsSent($report, Period $period)
{
$key = self::OPTION_KEY_LAST_SENT_DATERANGE . $report['idreport'];
Option::set($key, $period->getRangeString());
}