isEcommerceEnabledFor() 공개 정적인 메소드

Returns whether the site with the specified ID is ecommerce enabled or not.
public static isEcommerceEnabledFor ( integer $idsite ) : string
$idsite integer The site ID.
리턴 string
예제 #1
0
파일: Sms.php 프로젝트: dorelljames/piwik
 public function renderReport($processedReport)
 {
     $isGoalPluginEnabled = Common::isGoalPluginEnabled();
     $prettyDate = $processedReport['prettyDate'];
     $reportData = $processedReport['reportData'];
     $evolutionMetrics = array();
     $multiSitesAPIMetrics = API::getApiMetrics($enhanced = true);
     foreach ($multiSitesAPIMetrics as $metricSettings) {
         $evolutionMetrics[] = $metricSettings[API::METRIC_EVOLUTION_COL_NAME_KEY];
     }
     $floatRegex = self::FLOAT_REGEXP;
     // 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), function ($value) use($floatRegex) {
         return preg_replace_callback($floatRegex, 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.twig)
     //  - adds a plus sign
     $reportData->filter('ColumnCallbackReplace', array($evolutionMetrics, function ($value) use($floatRegex) {
         $matched = preg_match($floatRegex, $value, $matches);
         $formatted = $matched ? sprintf("%+d", $matches[0]) : $value;
         return \Piwik\NumberFormatter::getInstance()->formatPercentEvolution($formatted);
     }));
     $dataRows = $reportData->getRows();
     $reportMetadata = $processedReport['reportMetadata'];
     $reportRowsMetadata = $reportMetadata->getRows();
     $siteHasECommerce = array();
     foreach ($reportRowsMetadata as $rowMetadata) {
         $idSite = $rowMetadata->getColumn('idsite');
         $siteHasECommerce[$idSite] = Site::isEcommerceEnabledFor($idSite);
     }
     $view = new View('@MobileMessaging/SMSReport');
     $view->assign("isGoalPluginEnabled", $isGoalPluginEnabled);
     $view->assign("reportRows", $dataRows);
     $view->assign("reportRowsMetadata", $reportRowsMetadata);
     $view->assign("prettyDate", $prettyDate);
     $view->assign("siteHasECommerce", $siteHasECommerce);
     $view->assign("displaySiteName", $processedReport['metadata']['action'] == 'getAll');
     // segment
     $segment = $processedReport['segment'];
     $displaySegment = $segment != null;
     $view->assign("displaySegment", $displaySegment);
     if ($displaySegment) {
         $view->assign("segmentName", $segment['name']);
     }
     $this->rendering .= $view->render();
 }
 public function compute(Row $row)
 {
     $columnName = $this->getWrappedName();
     $currentValue = $this->getMetric($row, $columnName);
     // if the site this is for doesn't support ecommerce & this is for the revenue_evolution column,
     // we don't add the new column
     if ($currentValue === false || !$this->isRevenueEvolution) {
         $idSite = $row->getMetadata('idsite');
         if (!$idSite || !Site::isEcommerceEnabledFor($idSite)) {
             $row->deleteColumn($columnName);
             return false;
         }
     }
     return parent::compute($row);
 }
 /**
  * Returns the difference between the column in the specific row and its
  * sister column in the past DataTable.
  *
  * @param Row $row
  * @return int|float
  */
 protected function getDividend($row)
 {
     $currentValue = $row->getColumn($this->columnValueToRead);
     // if the site this is for doesn't support ecommerce & this is for the revenue_evolution column,
     // we don't add the new column
     if ($currentValue === false && $this->isRevenueEvolution && !Site::isEcommerceEnabledFor($row->getColumn('label'))) {
         return false;
     }
     $pastRow = $this->getPastRowFromCurrent($row);
     if ($pastRow) {
         $pastValue = $pastRow->getColumn($this->columnValueToRead);
     } else {
         $pastValue = 0;
     }
     return $currentValue - $pastValue;
 }
예제 #4
0
 public function testSetDefaultTimezoneAndCurrencyAndExcludedQueryParametersAndExcludedIps()
 {
     // test that they return default values
     $defaultTimezone = API::getInstance()->getDefaultTimezone();
     $this->assertEquals('UTC', $defaultTimezone);
     $defaultCurrency = API::getInstance()->getDefaultCurrency();
     $this->assertEquals('USD', $defaultCurrency);
     $excludedIps = API::getInstance()->getExcludedIpsGlobal();
     $this->assertEquals('', $excludedIps);
     $excludedQueryParameters = API::getInstance()->getExcludedQueryParametersGlobal();
     $this->assertEquals('', $excludedQueryParameters);
     // test that when not specified, defaults are set as expected
     $idsite = API::getInstance()->addSite("site1", array('http://example.org'));
     $site = new Site($idsite);
     $this->assertEquals('UTC', $site->getTimezone());
     $this->assertEquals('USD', $site->getCurrency());
     $this->assertEquals('', $site->getExcludedQueryParameters());
     $this->assertEquals('', $site->getExcludedIps());
     $this->assertEquals(false, $site->isEcommerceEnabled());
     // set the global timezone and get it
     $newDefaultTimezone = 'UTC+5.5';
     API::getInstance()->setDefaultTimezone($newDefaultTimezone);
     $defaultTimezone = API::getInstance()->getDefaultTimezone();
     $this->assertEquals($newDefaultTimezone, $defaultTimezone);
     // set the default currency and get it
     $newDefaultCurrency = 'EUR';
     API::getInstance()->setDefaultCurrency($newDefaultCurrency);
     $defaultCurrency = API::getInstance()->getDefaultCurrency();
     $this->assertEquals($newDefaultCurrency, $defaultCurrency);
     // set the global IPs to exclude and get it
     $newGlobalExcludedIps = '1.1.1.*,1.1.*.*,150.1.1.1';
     API::getInstance()->setGlobalExcludedIps($newGlobalExcludedIps);
     $globalExcludedIps = API::getInstance()->getExcludedIpsGlobal();
     $this->assertEquals($newGlobalExcludedIps, $globalExcludedIps);
     // set the global URL query params to exclude and get it
     $newGlobalExcludedQueryParameters = 'PHPSESSID,blabla, TesT';
     // removed the space
     $expectedGlobalExcludedQueryParameters = 'PHPSESSID,blabla,TesT';
     API::getInstance()->setGlobalExcludedQueryParameters($newGlobalExcludedQueryParameters);
     $globalExcludedQueryParameters = API::getInstance()->getExcludedQueryParametersGlobal();
     $this->assertEquals($expectedGlobalExcludedQueryParameters, $globalExcludedQueryParameters);
     // create a website and check that default currency and default timezone are set
     // however, excluded IPs and excluded query Params are not returned
     $idsite = API::getInstance()->addSite("site1", array('http://example.org'), $ecommerce = 0, $siteSearch = 0, $searchKeywordParameters = 'test1,test2', $searchCategoryParameters = 'test2,test1', '', '', $newDefaultTimezone);
     $site = new Site($idsite);
     $this->assertEquals($newDefaultTimezone, $site->getTimezone());
     $this->assertEquals(date('Y-m-d'), $site->getCreationDate()->toString());
     $this->assertEquals($newDefaultCurrency, $site->getCurrency());
     $this->assertEquals('', $site->getExcludedIps());
     $this->assertEquals('', $site->getExcludedQueryParameters());
     $this->assertEquals('test1,test2', $site->getSearchKeywordParameters());
     $this->assertEquals('test2,test1', $site->getSearchCategoryParameters());
     $this->assertFalse($site->isSiteSearchEnabled());
     $this->assertFalse(Site::isSiteSearchEnabledFor($idsite));
     $this->assertFalse($site->isEcommerceEnabled());
     $this->assertFalse(Site::isEcommerceEnabledFor($idsite));
 }
예제 #5
0
 private function getGoals($idSite)
 {
     // get all goals to display info for
     $allGoals = array();
     // add the ecommerce goal if ecommerce is enabled for the site
     if (Site::isEcommerceEnabledFor($idSite)) {
         $ecommerceGoal = array('idgoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER, 'name' => Piwik::translate('Goals_EcommerceOrder'), 'quoted_name' => false);
         $allGoals[$ecommerceGoal['idgoal']] = $ecommerceGoal;
     }
     // add the site's goals (and escape all goal names)
     $siteGoals = APIGoals::getInstance()->getGoals($idSite);
     foreach ($siteGoals as &$goal) {
         $goal['name'] = Common::sanitizeInputValue($goal['name']);
         $goal['quoted_name'] = '"' . $goal['name'] . '"';
         $allGoals[$goal['idgoal']] = $goal;
     }
     return $allGoals;
 }
예제 #6
0
 private function removeEcommerceRelatedMetricsOnNonEcommercePiwikSites($dataTable, $apiECommerceMetrics)
 {
     // $dataTableRows instanceOf Row[]
     $dataTableRows = $dataTable->getRows();
     foreach ($dataTableRows as $dataTableRow) {
         $siteId = $dataTableRow->getColumn('label');
         if (!Site::isEcommerceEnabledFor($siteId)) {
             foreach ($apiECommerceMetrics as $metricSettings) {
                 $dataTableRow->deleteColumn($metricSettings[self::METRIC_RECORD_NAME_KEY]);
                 $dataTableRow->deleteColumn($metricSettings[self::METRIC_EVOLUTION_COL_NAME_KEY]);
             }
         }
     }
 }
예제 #7
0
 /**
  * Returns an array describing a visitor using her last visits (uses a maximum of 100).
  *
  * @param int $idSite Site ID
  * @param bool|false|string $visitorId The ID of the visitor whose profile to retrieve.
  * @param bool|false|string $segment
  * @param bool $checkForLatLong If true, hasLatLong will appear in the output and be true if
  *                              one of the first 100 visits has a latitude/longitude.
  * @return array
  */
 public function getVisitorProfile($idSite, $visitorId = false, $segment = false, $checkForLatLong = false)
 {
     Piwik::checkUserHasViewAccess($idSite);
     if ($visitorId === false) {
         $visitorId = $this->getMostRecentVisitorId($idSite, $segment);
     }
     $newSegment = ($segment === false ? '' : $segment . ';') . 'visitorId==' . $visitorId;
     $visits = $this->loadLastVisitorDetailsFromDatabase($idSite, $period = false, $date = false, $newSegment, $numVisitorsToFetch = self::VISITOR_PROFILE_MAX_VISITS_TO_AGGREGATE, $overrideVisitorId = false, $minTimestamp = false);
     $this->addFilterToCleanVisitors($visits, $idSite, $flat = false, $doNotFetchActions = false, $filterNow = true);
     if ($visits->getRowsCount() == 0) {
         return array();
     }
     $isEcommerceEnabled = Site::isEcommerceEnabledFor($idSite);
     $result = array();
     $result['totalVisits'] = 0;
     $result['totalVisitDuration'] = 0;
     $result['totalActions'] = 0;
     $result['totalSearches'] = 0;
     $result['totalPageViews'] = 0;
     $result['totalGoalConversions'] = 0;
     $result['totalConversionsByGoal'] = array();
     if ($isEcommerceEnabled) {
         $result['totalEcommerceConversions'] = 0;
         $result['totalEcommerceRevenue'] = 0;
         $result['totalEcommerceItems'] = 0;
         $result['totalAbandonedCarts'] = 0;
         $result['totalAbandonedCartsRevenue'] = 0;
         $result['totalAbandonedCartsItems'] = 0;
     }
     $countries = array();
     $continents = array();
     $cities = array();
     $siteSearchKeywords = array();
     $pageGenerationTimeTotal = 0;
     // aggregate all requested visits info for total_* info
     foreach ($visits->getRows() as $visit) {
         ++$result['totalVisits'];
         $result['totalVisitDuration'] += $visit->getColumn('visitDuration');
         $result['totalActions'] += $visit->getColumn('actions');
         $result['totalGoalConversions'] += $visit->getColumn('goalConversions');
         // individual goal conversions are stored in action details
         foreach ($visit->getColumn('actionDetails') as $action) {
             if ($action['type'] == 'goal') {
                 // handle goal conversion
                 $idGoal = $action['goalId'];
                 $idGoalKey = 'idgoal=' . $idGoal;
                 if (!isset($result['totalConversionsByGoal'][$idGoalKey])) {
                     $result['totalConversionsByGoal'][$idGoalKey] = 0;
                 }
                 ++$result['totalConversionsByGoal'][$idGoalKey];
                 if (!empty($action['revenue'])) {
                     if (!isset($result['totalRevenueByGoal'][$idGoalKey])) {
                         $result['totalRevenueByGoal'][$idGoalKey] = 0;
                     }
                     $result['totalRevenueByGoal'][$idGoalKey] += $action['revenue'];
                 }
             } else {
                 if ($action['type'] == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER && $isEcommerceEnabled) {
                     ++$result['totalEcommerceConversions'];
                     $result['totalEcommerceRevenue'] += $action['revenue'];
                     $result['totalEcommerceItems'] += $action['items'];
                 } else {
                     if ($action['type'] == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART && $isEcommerceEnabled) {
                         ++$result['totalAbandonedCarts'];
                         $result['totalAbandonedCartsRevenue'] += $action['revenue'];
                         $result['totalAbandonedCartsItems'] += $action['items'];
                     }
                 }
             }
             if (isset($action['siteSearchKeyword'])) {
                 $keyword = $action['siteSearchKeyword'];
                 if (!isset($siteSearchKeywords[$keyword])) {
                     $siteSearchKeywords[$keyword] = 0;
                     ++$result['totalSearches'];
                 }
                 ++$siteSearchKeywords[$keyword];
             }
             if (isset($action['generationTime'])) {
                 $pageGenerationTimeTotal += $action['generationTime'];
                 ++$result['totalPageViews'];
             }
         }
         $countryCode = $visit->getColumn('countryCode');
         if (!isset($countries[$countryCode])) {
             $countries[$countryCode] = 0;
         }
         ++$countries[$countryCode];
         $continentCode = $visit->getColumn('continentCode');
         if (!isset($continents[$continentCode])) {
             $continents[$continentCode] = 0;
         }
         ++$continents[$continentCode];
         if ($countryCode && !array_key_exists($countryCode, $cities)) {
             $cities[$countryCode] = array();
         }
         $city = $visit->getColumn('city');
         if (!empty($city)) {
             $cities[$countryCode][] = $city;
         }
     }
     // sort countries/continents/search keywords by visit/action
     asort($countries);
     asort($continents);
     arsort($siteSearchKeywords);
     // transform country/continents/search keywords into something that will look good in XML
     $result['countries'] = $result['continents'] = $result['searches'] = array();
     foreach ($countries as $countryCode => $nbVisits) {
         $countryInfo = array('country' => $countryCode, 'nb_visits' => $nbVisits, 'flag' => \Piwik\Plugins\UserCountry\getFlagFromCode($countryCode), 'prettyName' => \Piwik\Plugins\UserCountry\countryTranslate($countryCode));
         if (!empty($cities[$countryCode])) {
             $countryInfo['cities'] = array_unique($cities[$countryCode]);
         }
         $result['countries'][] = $countryInfo;
     }
     foreach ($continents as $continentCode => $nbVisits) {
         $result['continents'][] = array('continent' => $continentCode, 'nb_visits' => $nbVisits, 'prettyName' => \Piwik\Plugins\UserCountry\continentTranslate($continentCode));
     }
     foreach ($siteSearchKeywords as $keyword => $searchCount) {
         $result['searches'][] = array('keyword' => $keyword, 'searches' => $searchCount);
     }
     if ($result['totalPageViews']) {
         $result['averagePageGenerationTime'] = round($pageGenerationTimeTotal / $result['totalPageViews'], $precision = 2);
     }
     $result['totalVisitDurationPretty'] = MetricsFormatter::getPrettyTimeFromSeconds($result['totalVisitDuration']);
     // use requested visits for first/last visit info
     $rows = $visits->getRows();
     $result['firstVisit'] = $this->getVisitorProfileVisitSummary(end($rows));
     $result['lastVisit'] = $this->getVisitorProfileVisitSummary(reset($rows));
     // check if requested visits have lat/long
     if ($checkForLatLong) {
         $result['hasLatLong'] = false;
         foreach ($rows as $visit) {
             if ($visit->getColumn('latitude') !== false) {
                 // realtime map only checks for latitude
                 $result['hasLatLong'] = true;
                 break;
             }
         }
     }
     // save count of visits we queries
     $result['visitsAggregated'] = count($rows);
     // use N most recent visits for last_visits
     $visits->deleteRowsOffset(self::VISITOR_PROFILE_MAX_VISITS_TO_SHOW);
     $result['lastVisits'] = $visits;
     // use the right date format for the pretty server date
     $timezone = Site::getTimezoneFor($idSite);
     foreach ($result['lastVisits']->getRows() as $visit) {
         $dateTimeVisitFirstAction = Date::factory($visit->getColumn('firstActionTimestamp'), $timezone);
         $datePretty = $dateTimeVisitFirstAction->getLocalized(self::VISITOR_PROFILE_DATE_FORMAT);
         $visit->setColumn('serverDatePrettyFirstAction', $datePretty);
         $dateTimePretty = $datePretty . ' ' . $visit->getColumn('serverTimePrettyFirstAction');
         $visit->setColumn('serverDateTimePrettyFirstAction', $dateTimePretty);
     }
     $result['userId'] = $visit->getColumn('userId');
     // get visitor IDs that are adjacent to this one in log_visit
     // TODO: make sure order of visitor ids is not changed if a returning visitor visits while the user is
     //       looking at the popup.
     $latestVisitTime = reset($rows)->getColumn('lastActionDateTime');
     $result['nextVisitorId'] = $this->getAdjacentVisitorId($idSite, $visitorId, $latestVisitTime, $segment, $getNext = true);
     $result['previousVisitorId'] = $this->getAdjacentVisitorId($idSite, $visitorId, $latestVisitTime, $segment, $getNext = false);
     /**
      * Triggered in the Live.getVisitorProfile API method. Plugins can use this event
      * to discover and add extra data to visitor profiles.
      *
      * For example, if an email address is found in a custom variable, a plugin could load the
      * gravatar for the email and add it to the visitor profile, causing it to display in the
      * visitor profile popup.
      *
      * The following visitor profile elements can be set to augment the visitor profile popup:
      *
      * - **visitorAvatar**: A URL to an image to display in the top left corner of the popup.
      * - **visitorDescription**: Text to be used as the tooltip of the avatar image.
      *
      * @param array &$visitorProfile The unaugmented visitor profile info.
      */
     Piwik::postEvent('Live.getExtraVisitorDetails', array(&$result));
     return $result;
 }
예제 #8
0
 public function __construct($idSite)
 {
     $this->idSite = $idSite;
     $this->isEcommerceEnabled = Site::isEcommerceEnabledFor($this->idSite);
 }
예제 #9
0
 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();
 }