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


PHP Factory::isPeriodEnabledForAPI方法代码示例

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


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

示例1: getSuggestedValuesForSegment

 /**
  * Given a segment, will return a list of the most used values for this particular segment.
  * @param $segmentName
  * @param $idSite
  * @throws \Exception
  * @return array
  */
 public function getSuggestedValuesForSegment($segmentName, $idSite)
 {
     if (empty(Config::getInstance()->General['enable_segment_suggested_values'])) {
         return array();
     }
     Piwik::checkUserHasViewAccess($idSite);
     $maxSuggestionsToReturn = 30;
     $segment = $this->findSegment($segmentName, $idSite);
     // if segment has suggested values callback then return result from it instead
     $suggestedValuesCallbackRequiresTable = false;
     if (isset($segment['suggestedValuesCallback'])) {
         $suggestedValuesCallbackRequiresTable = $this->doesSuggestedValuesCallbackNeedData($segment['suggestedValuesCallback']);
         if (!$suggestedValuesCallbackRequiresTable) {
             return call_user_func($segment['suggestedValuesCallback'], $idSite, $maxSuggestionsToReturn);
         }
     }
     // if period=range is disabled, do not proceed
     if (!Period\Factory::isPeriodEnabledForAPI('range')) {
         return array();
     }
     if (!empty($segment['unionOfSegments'])) {
         $values = array();
         foreach ($segment['unionOfSegments'] as $unionSegmentName) {
             $unionSegment = $this->findSegment($unionSegmentName, $idSite);
             try {
                 $result = $this->getSuggestedValuesForSegmentName($idSite, $unionSegment, $maxSuggestionsToReturn);
                 if (!empty($result)) {
                     $values = array_merge($result, $values);
                 }
             } catch (\Exception $e) {
                 // we ignore if there was no data found for $unionSegmentName
             }
         }
         if (empty($values)) {
             throw new \Exception("There was no data to suggest for {$segmentName}");
         }
     } else {
         $values = $this->getSuggestedValuesForSegmentName($idSite, $segment, $maxSuggestionsToReturn);
     }
     $values = $this->getMostFrequentValues($values);
     $values = array_slice($values, 0, $maxSuggestionsToReturn);
     $values = array_map(array('Piwik\\Common', 'unsanitizeInputValue'), $values);
     return $values;
 }
开发者ID:mgou-net,项目名称:piwik,代码行数:51,代码来源:API.php

示例2: getSuggestedValuesForSegment

 /**
  * Given a segment, will return a list of the most used values for this particular segment.
  * @param $segmentName
  * @param $idSite
  * @throws \Exception
  * @return array
  */
 public function getSuggestedValuesForSegment($segmentName, $idSite)
 {
     if (empty(Config::getInstance()->General['enable_segment_suggested_values'])) {
         return array();
     }
     Piwik::checkUserHasViewAccess($idSite);
     $maxSuggestionsToReturn = 30;
     $segmentsMetadata = $this->getSegmentsMetadata($idSite, $_hideImplementationData = false);
     $segmentFound = false;
     foreach ($segmentsMetadata as $segmentMetadata) {
         if ($segmentMetadata['segment'] == $segmentName) {
             $segmentFound = $segmentMetadata;
             break;
         }
     }
     if (empty($segmentFound)) {
         throw new \Exception("Requested segment not found.");
     }
     // if segment has suggested values callback then return result from it instead
     if (isset($segmentFound['suggestedValuesCallback'])) {
         return call_user_func($segmentFound['suggestedValuesCallback'], $idSite, $maxSuggestionsToReturn);
     }
     // if period=range is disabled, do not proceed
     if (!Period\Factory::isPeriodEnabledForAPI('range')) {
         return array();
     }
     $startDate = Date::now()->subDay(60)->toString();
     $requestLastVisits = "method=Live.getLastVisitsDetails\n        &idSite={$idSite}\n        &period=range\n        &date={$startDate},today\n        &format=original\n        &serialize=0\n        &flat=1";
     // Select non empty fields only
     // Note: this optimization has only a very minor impact
     $requestLastVisits .= "&segment={$segmentName}" . urlencode('!=');
     // By default Live fetches all actions for all visitors, but we'd rather do this only when required
     if ($this->doesSegmentNeedActionsData($segmentName)) {
         $requestLastVisits .= "&filter_limit=400";
     } else {
         $requestLastVisits .= "&doNotFetchActions=1";
         $requestLastVisits .= "&filter_limit=800";
     }
     $request = new Request($requestLastVisits);
     $table = $request->process();
     if (empty($table)) {
         throw new \Exception("There was no data to suggest for {$segmentName}");
     }
     // Cleanup data to return the top suggested (non empty) labels for this segment
     $values = $table->getColumn($segmentName);
     // Select also flattened keys (custom variables "page" scope, page URLs for one visit, page titles for one visit)
     $valuesBis = $table->getColumnsStartingWith($segmentName . ColumnDelete::APPEND_TO_COLUMN_NAME_TO_KEEP);
     $values = array_merge($values, $valuesBis);
     $values = $this->getMostFrequentValues($values);
     $values = array_slice($values, 0, $maxSuggestionsToReturn);
     $values = array_map(array('Piwik\\Common', 'unsanitizeInputValue'), $values);
     return $values;
 }
开发者ID:KingNoosh,项目名称:Teknik,代码行数:60,代码来源:API.php


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