コード例 #1
0
ファイル: MultiSites.php プロジェクト: neolf/PIWIK4MOBILE
 public function getReportMetadata($notification)
 {
     $isGoalPluginEnabled = Piwik_Common::isGoalPluginEnabled();
     $metrics = array('nb_visits', 'nb_actions');
     if ($isGoalPluginEnabled) {
         $metrics['revenue'] = Piwik_Translate('Goals_ColumnRevenue');
     }
     $reports =& $notification->getNotificationObject();
     $reports[] = array('category' => Piwik_Translate('General_MultiSitesSummary'), 'name' => Piwik_Translate('General_AllWebsitesDashboard'), 'module' => 'MultiSites', 'action' => 'getAll', 'dimension' => Piwik_Translate('General_Website'), 'metrics' => $metrics, 'processedMetrics' => false, 'constantRowsCount' => false, 'order' => 5);
 }
コード例 #2
0
ファイル: API.php プロジェクト: neolf/PIWIK4MOBILE
 /**
  * Returns a report displaying the total visits, actions and revenue, as
  * well as the evolution of these values, of all existing sites over a
  * specified period of time.
  * 
  * If the specified period is not a 'range', this function will calculcate
  * evolution metrics. Evolution metrics are metrics that display the
  * percent increase/decrease of another metric since the last period.
  * 
  * This function will merge the result of the archive query so each
  * row in the result DataTable will correspond to the metrics of a single
  * site. If a date range is specified, the result will be a
  * DataTable_Array, but it will still be merged.
  * 
  * @param string $period The period type to get data for.
  * @param string $date The date(s) to get data for.
  * @param string $segment The segments to get data for.
  */
 public function getAll($period, $date, $segment = false)
 {
     Piwik::checkUserHasSomeViewAccess();
     $isGoalPluginEnabled = Piwik_Common::isGoalPluginEnabled();
     // get site data for every viewable site and cache them
     if (Piwik::isUserIsSuperUser()) {
         $sites = Piwik_SitesManager_API::getInstance()->getAllSites();
         Piwik_Site::setSites($sites);
     } else {
         $sites = Piwik_SitesManager_API::getInstance()->getSitesWithAtLeastViewAccess();
         Piwik_Site::setSitesFromArray($sites);
     }
     // build the archive type used to query archive data
     $archive = Piwik_Archive::build('all', $period, $date, $segment);
     // determine what data will be displayed
     $fieldsToGet = array('nb_visits', 'nb_actions');
     if ($isGoalPluginEnabled) {
         $revenueMetric = Piwik_Goals::getRecordName('revenue');
         $fieldsToGet[] = $revenueMetric;
     }
     // get the data
     $dataTable = $archive->getDataTableFromNumeric($fieldsToGet);
     // get rid of the DataTable_Array that is created by the IndexedBySite archive type
     $dataTable = $dataTable->mergeChildren();
     // if the period isn't a range & a lastN/previousN date isn't used, we get the same
     // data for the last period to show the evolution of visits/actions/revenue
     if ($period != 'range' && !preg_match('/(last|previous)([0-9]*)/', $date, $regs)) {
         if (strpos($date, ',')) {
             $rangePeriod = new Piwik_Period_Range($period, $date);
             $lastStartDate = Piwik_Period_Range::removePeriod($period, $rangePeriod->getDateStart(), $n = 1);
             $lastEndDate = Piwik_Period_Range::removePeriod($period, $rangePeriod->getDateEnd(), $n = 1);
             $strLastDate = "{$lastStartDate},{$lastEndDate}";
         } else {
             $strLastDate = Piwik_Period_Range::removePeriod($period, Piwik_Date::factory($date), $n = 1)->toString();
         }
         $pastArchive = Piwik_Archive::build('all', $period, $strLastDate, $segment);
         $pastData = $pastArchive->getDataTableFromNumeric($fieldsToGet);
         $pastData = $pastData->mergeChildren();
         // use past data to calculate evolution percentages
         $this->calculateEvolutionPercentages($dataTable, $pastData, $fieldsToGet);
     }
     // move the site id to a metadata column
     $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'idsite'));
     // set the label of each row to the site name
     $getNameFor = array('Piwik_Site', 'getNameFor');
     $dataTable->filter('ColumnCallbackReplace', array('label', $getNameFor));
     // rename the revenue column from the metric name to 'revenue'
     if ($isGoalPluginEnabled) {
         $mapping = array($revenueMetric => 'revenue');
         $dataTable->filter('ReplaceColumnNames', array($mapping));
     }
     // Ensures data set sorted, for Metadata output
     $dataTable->filter('Sort', array('nb_visits', 'desc', $naturalSort = false));
     return $dataTable;
 }
コード例 #3
0
ファイル: Sms.php プロジェクト: nnnnathann/piwik
    public function renderReport($processedReport)
    {
        $isGoalPluginEnabled = Piwik_Common::isGoalPluginEnabled();
        $prettyDate = $processedReport['prettyDate'];
        $reportData = $processedReport['reportData'];
        $evolutionMetrics = array();
        $multiSitesAPIMetrics = Piwik_MultiSites_API::getApiMetrics($enhanced = true);
        foreach ($multiSitesAPIMetrics as $metricSettings) {
            $evolutionMetrics[] = $metricSettings[Piwik_MultiSites_API::METRIC_EVOLUTION_COL_NAME_KEY];
        }
        // no decimal for all metrics to shorten SMS content (keeps the monetary sign for revenue metrics)
        $reportData->filter('ColumnCallbackReplace', array(array_merge(array_keys($multiSitesAPIMetrics), $evolutionMetrics), create_function('$value', '
					return preg_replace_callback (
						FLOAT_REGEXP,
						create_function (
							\'$matches\',
							\'return round($matches[0]);\'
						),
						$value
					);
					')));
        // evolution metrics formatting :
        //  - remove monetary, percentage and white spaces to shorten SMS content
        //    (this is also needed to be able to test $value != 0 and see if there is an evolution at all in SMSReport.tpl)
        //  - adds a plus sign
        $reportData->filter('ColumnCallbackReplace', array($evolutionMetrics, create_function('$value', '
					$matched = preg_match(FLOAT_REGEXP, $value, $matches);
					return $matched ? sprintf("%+d",$matches[0]) : $value;
					')));
        $dataRows = $reportData->getRows();
        $reportMetadata = $processedReport['reportMetadata'];
        $reportRowsMetadata = $reportMetadata->getRows();
        $siteHasECommerce = array();
        foreach ($reportRowsMetadata as $rowMetadata) {
            $idSite = $rowMetadata->getColumn('idsite');
            $siteHasECommerce[$idSite] = Piwik_Site::isEcommerceEnabledFor($idSite);
        }
        $smarty = new Piwik_Smarty();
        $smarty->assign("isGoalPluginEnabled", $isGoalPluginEnabled);
        $smarty->assign("reportRows", $dataRows);
        $smarty->assign("reportRowsMetadata", $reportRowsMetadata);
        $smarty->assign("prettyDate", $prettyDate);
        $smarty->assign("siteHasECommerce", $siteHasECommerce);
        $smarty->assign("displaySiteName", $processedReport['metadata']['action'] == 'getAll');
        $this->rendering .= $smarty->fetch(PIWIK_USER_PATH . '/plugins/MobileMessaging/templates/SMSReport.tpl');
    }
コード例 #4
0
ファイル: GoalManager.php プロジェクト: nomoto-ubicast/piwik
 function detectGoalId($idSite)
 {
     if (!Piwik_Common::isGoalPluginEnabled()) {
         return false;
     }
     $goals = $this->getGoalDefinitions($idSite);
     if (!isset($goals[$this->idGoal])) {
         return false;
     }
     $goal = $goals[$this->idGoal];
     $url = Piwik_Common::getRequestVar('url', '', 'string', $this->request);
     $goal['url'] = Piwik_Tracker_Action::excludeQueryParametersFromUrl($url, $idSite);
     $goal['revenue'] = $this->getRevenue(Piwik_Common::getRequestVar('revenue', $goal['revenue'], 'float', $this->request));
     $this->convertedGoals[] = $goal;
     return true;
 }
コード例 #5
0
ファイル: Controller.php プロジェクト: nnnnathann/piwik
 public function getSitesInfo($view)
 {
     Piwik::checkUserHasSomeViewAccess();
     $displayRevenueColumn = Piwik_Common::isGoalPluginEnabled();
     // 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 = Piwik_SitesManager_API::getInstance()->getDefaultTimezone();
     $dateRequest = Piwik_Common::getRequestVar('date', 'today');
     $period = Piwik_Common::getRequestVar('period', 'day');
     $date = $dateRequest;
     if ($period != 'range') {
         $date = $this->getDateParameterInTimezone($dateRequest, $piwikDefaultTimezone);
         $date = $date->toString();
     }
     $siteIds = Piwik_SitesManager_API::getInstance()->getSitesIdWithAtLeastViewAccess();
     $dataTable = Piwik_MultiSites_API::getInstance()->getAll($period, $date, $segment = false);
     list($minDate, $maxDate) = $this->getMinMaxDateAcrossWebsites($siteIds);
     $totalVisits = $totalActions = $totalRevenue = 0;
     // put data into a form the template will understand better
     $digestableData = array();
     foreach ($siteIds as $idSite) {
         $isEcommerceEnabled = Piwik_Site::isEcommerceEnabledFor($idSite);
         $digestableData[$idSite] = array('idsite' => $idSite, 'main_url' => Piwik_Site::getMainUrlFor($idSite), 'name' => Piwik_Site::getNameFor($idSite), 'visits' => 0, 'actions' => 0);
         if ($period != 'range') {
             $digestableData[$idSite]['visits_evolution'] = 0;
             $digestableData[$idSite]['actions_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');
         $totalVisits += $site['visits'];
         $site['actions'] = (int) $row->getColumn('nb_actions');
         $totalActions += $site['actions'];
         if ($displayRevenueColumn) {
             if ($row->getColumn('revenue') !== false) {
                 $site['revenue'] = $row->getColumn('revenue');
                 $totalRevenue += $site['revenue'];
             }
         }
         if ($period != 'range') {
             $site['visits_evolution'] = $row->getColumn('visits_evolution');
             $site['actions_evolution'] = $row->getColumn('actions_evolution');
             if ($displayRevenueColumn) {
                 $site['revenue_evolution'] = $row->getColumn('revenue_evolution');
             }
         }
     }
     $this->applyPrettyMoney($digestableData);
     $view->sitesData = array_values($digestableData);
     $view->evolutionBy = $this->evolutionBy;
     $view->period = $period;
     $view->dateRequest = $dateRequest;
     $view->page = $this->page;
     $view->limit = $this->limit;
     $view->orderBy = $this->orderBy;
     $view->order = $this->order;
     $view->totalVisits = $totalVisits;
     $view->totalRevenue = $totalRevenue;
     $view->displayRevenueColumn = $displayRevenueColumn;
     $view->totalActions = $totalActions;
     $params = $this->getGraphParamsModified();
     $view->dateSparkline = $period == 'range' ? $dateRequest : $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', Piwik_Date::factory('yesterday')->toString('Y-m-d'), Piwik_Date::factory('now', 'UTC+14')->toString('Y-m-d')))) {
         $view->autoRefreshTodayReport = Piwik_Config::getInstance()->General['multisites_refresh_after_seconds'];
     }
     $this->setGeneralVariablesView($view);
     $this->setMinDateView($minDate, $view);
     $this->setMaxDateView($maxDate, $view);
     $view->show_sparklines = Piwik_Config::getInstance()->General['show_multisites_sparklines'];
     echo $view->render();
 }
コード例 #6
0
ファイル: API.php プロジェクト: nnnnathann/piwik
 /**
  * @ignore
  */
 public static function getApiMetrics($enhanced)
 {
     $metrics = self::$baseMetrics;
     if (Piwik_Common::isGoalPluginEnabled()) {
         // goal revenue metric
         $metrics[self::GOAL_REVENUE_METRIC] = array(self::METRIC_TRANSLATION_KEY => 'Goals_ColumnRevenue', self::METRIC_EVOLUTION_COL_NAME_KEY => self::GOAL_REVENUE_METRIC . '_evolution', self::METRIC_RECORD_NAME_KEY => Piwik_Goals::getRecordName(self::GOAL_REVENUE_METRIC), self::METRIC_IS_ECOMMERCE_KEY => false);
         if ($enhanced) {
             // number of goal conversions metric
             $metrics[self::GOAL_CONVERSION_METRIC] = array(self::METRIC_TRANSLATION_KEY => 'Goals_ColumnConversions', self::METRIC_EVOLUTION_COL_NAME_KEY => self::GOAL_CONVERSION_METRIC . '_evolution', self::METRIC_RECORD_NAME_KEY => Piwik_Goals::getRecordName(self::GOAL_CONVERSION_METRIC), self::METRIC_IS_ECOMMERCE_KEY => false);
             // number of orders
             $metrics[self::ECOMMERCE_ORDERS_METRIC] = array(self::METRIC_TRANSLATION_KEY => 'General_EcommerceOrders', self::METRIC_EVOLUTION_COL_NAME_KEY => self::ECOMMERCE_ORDERS_METRIC . '_evolution', self::METRIC_RECORD_NAME_KEY => Piwik_Goals::getRecordName(self::GOAL_CONVERSION_METRIC, 0), self::METRIC_IS_ECOMMERCE_KEY => true);
             // eCommerce revenue
             $metrics[self::ECOMMERCE_REVENUE_METRIC] = array(self::METRIC_TRANSLATION_KEY => 'General_ProductRevenue', self::METRIC_EVOLUTION_COL_NAME_KEY => self::ECOMMERCE_REVENUE_METRIC . '_evolution', self::METRIC_RECORD_NAME_KEY => Piwik_Goals::getRecordName(self::GOAL_REVENUE_METRIC, 0), self::METRIC_IS_ECOMMERCE_KEY => true);
         }
     }
     return $metrics;
 }
コード例 #7
0
ファイル: PrivacyManager.php プロジェクト: nnnnathann/piwik
 /**
  * Returns the names of metrics that should be kept when purging as they appear in
  * archive tables.
  */
 public static function getAllMetricsToKeep()
 {
     $metricsToKeep = self::getMetricsToKeep();
     // convert goal metric names to correct archive names
     if (Piwik_Common::isGoalPluginEnabled()) {
         $goalMetricsToKeep = self::getGoalMetricsToKeep();
         $maxGoalId = self::getMaxGoalId();
         // for each goal metric, there's a different name for each goal, including the overview,
         // the order report & cart report
         foreach ($goalMetricsToKeep as $metric) {
             for ($i = 1; $i <= $maxGoalId; ++$i) {
                 $metricsToKeep[] = Piwik_Goals::getRecordName($metric, $i);
             }
             $metricsToKeep[] = Piwik_Goals::getRecordName($metric);
             $metricsToKeep[] = Piwik_Goals::getRecordName($metric, Piwik_Tracker_GoalManager::IDGOAL_ORDER);
             $metricsToKeep[] = Piwik_Goals::getRecordName($metric, Piwik_Tracker_GoalManager::IDGOAL_CART);
         }
     }
     return $metricsToKeep;
 }
コード例 #8
0
	public function getSitesInfo()
	{
		Piwik::checkUserHasSomeViewAccess();
		$displayRevenueColumn = Piwik_Common::isGoalPluginEnabled();
		
		// 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 = Piwik_SitesManager_API::getInstance()->getDefaultTimezone();
		$dateRequest = Piwik_Common::getRequestVar('date', 'today');
		$period = Piwik_Common::getRequestVar('period', 'day');	
		$date = $dateRequest;
		if($period != 'range')
		{
			$date = $this->getDateParameterInTimezone($dateRequest, $piwikDefaultTimezone);
			$date = $date->toString();
		}
		
		$mySites = Piwik_SitesManager_API::getInstance()->getSitesWithAtLeastViewAccess();
		
		$ids = 'all';
		
		// Current date - select metrics
		$dataTableArray = Piwik_VisitsSummary_API::getInstance()->get($ids, $period, $date, $segment = false, $columns = array('nb_visits', 'nb_actions'));
		$currentVisits = $this->getArrayFromAPI($dataTableArray, 'nb_visits');
		$currentActions = $this->getArrayFromAPI($dataTableArray, 'nb_actions');
		if($displayRevenueColumn)
		{
		    $dataTableArray = Piwik_Goals_API::getInstance()->get($ids, $period, $date, $segment = false, $idGoal = false, $columns = array('revenue'));
		    $currentRevenue = $this->getArrayFromAPI($dataTableArray, 'revenue');
		}
		// Previous date
		$lastVisits = $lastActions = $lastRevenue = array();
		if($period != 'range')
		{
			$lastDate = Piwik_Period_Range::removePeriod($period, Piwik_Date::factory($date), $n = 1 );
			$dataTableArray = Piwik_VisitsSummary_API::getInstance()->get($ids, $period, $lastDate, $segment = false, $columns = array('nb_visits', 'nb_actions'));
			$lastVisits =  $this->getArrayFromAPI($dataTableArray, 'nb_visits');
			$lastActions =  $this->getArrayFromAPI($dataTableArray, 'nb_actions');
			if($displayRevenueColumn)
			{
			    $dataTableArray = Piwik_Goals_API::getInstance()->get($ids, $period, $lastDate, $segment = false, $idGoal = false, $columns = array('revenue'));
			    $lastRevenue = $this->getArrayFromAPI($dataTableArray, 'revenue');
			}
		}
		
		$visitsSummary = $this->getChangeCurrentVsLast($currentVisits, $lastVisits);
		$actionsSummary = $this->getChangeCurrentVsLast($currentActions, $lastActions);
		if($displayRevenueColumn)
		{
		    $revenueSummary = $this->getChangeCurrentVsLast($currentRevenue, $lastRevenue);
		}
		$totalVisits = $totalActions = $totalRevenue = 0;
		
		foreach($mySites as &$site)
		{
			$idSite = $site['idsite'];
			if($period != 'range')
			{
				$site['lastVisits'] = $lastVisits[$idSite];
				$site['lastActions'] = $lastActions[$idSite];
				if($displayRevenueColumn)
				{
				    $site['lastRevenue'] = $lastRevenue[$idSite];
				}
			}
			
			$site['visits'] = $currentVisits[$idSite];
			$site['actions'] = $currentActions[$idSite];
			$totalVisits += $site['visits'];
			$totalActions += $site['actions'];
			$site['visitsSummaryValue'] = $visitsSummary[$idSite];
			$site['actionsSummaryValue'] = $actionsSummary[$idSite];
			$site['revenue'] = $site['revenueSummaryValue'] = 0;
			if($displayRevenueColumn)
			{
    			$site['revenue'] = $currentRevenue[$idSite];
    			$totalRevenue += $site['revenue'];
    			$site['revenueSummaryValue'] = $revenueSummary[$idSite];
			}
		}
		$mySites = $this->applyPrettyMoney($mySites);
		
		$view = new Piwik_View("MultiSites/templates/index.tpl");
		$view->mySites = $mySites;
		$view->evolutionBy = $this->evolutionBy;
		$view->period = $period;
		$view->dateRequest = $dateRequest;
		$view->page = $this->page;
		$view->limit = $this->limit;
		$view->orderBy = $this->orderBy;
		$view->order = $this->order;
		$view->totalVisits = $totalVisits;
		$view->totalRevenue = $totalRevenue;
		$view->displayRevenueColumn = $displayRevenueColumn;
		$view->totalActions = $totalActions;
	
		$params = $this->getGraphParamsModified();
		$view->dateSparkline = $period == 'range' ? $dateRequest : $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', Piwik_Date::factory('yesterday')->toString('Y-m-d'),
											Piwik_Date::factory('now', 'UTC+14')->toString('Y-m-d'))))
		{
			
			$view->autoRefreshTodayReport = Zend_Registry::get('config')->General->multisites_refresh_after_seconds;
		}
		$this->setGeneralVariablesView($view);
		$this->setMinMaxDateAcrossWebsites($mySites, $view);
		$view->show_sparklines = Zend_Registry::get('config')->General->show_multisites_sparklines;

		echo $view->render();
	}