Piwik\SettingsPiwik::getKnownSegmentsToArchiveForSite PHP Method

getKnownSegmentsToArchiveForSite() public static method

Returns the list of stored segments to pre-process for an individual site when executing cron archiving.
public static getKnownSegmentsToArchiveForSite ( integer $idSite ) : string[]
$idSite integer The ID of the site to get stored segments for.
return string[] The list of stored segments that apply to the requested site.
    public static function getKnownSegmentsToArchiveForSite($idSite)
    {
        $cacheId = 'KnownSegmentsToArchiveForSite' . $idSite;
        $cache = PiwikCache::getTransientCache();
        if ($cache->contains($cacheId)) {
            return $cache->fetch($cacheId);
        }
        $segments = array();
        /**
         * Triggered during the cron archiving process to collect segments that
         * should be pre-processed for one specific site. The archiving process will be launched
         * for each of these segments when archiving data for that one site.
         *
         * This event can be used to add segments to be pre-processed for one site.
         *
         * _Note: If you just want to add a segment that is managed by the user, you should use the
         * SegmentEditor API._
         *
         * **Example**
         *
         *     Piwik::addAction('Segments.getKnownSegmentsToArchiveForSite', function (&$segments, $idSite) {
         *         $segments[] = 'country=jp;city=Tokyo';
         *     });
         *
         * @param array &$segmentsToProcess List of segment definitions, eg,
         *
         *                                      array(
         *                                          'browserCode=ff;resolution=800x600',
         *                                          'country=JP;city=Tokyo'
         *                                      )
         *
         *                                  Add segments to this array in your event handler.
         * @param int $idSite The ID of the site to get segments for.
         */
        Piwik::postEvent('Segments.getKnownSegmentsToArchiveForSite', array(&$segments, $idSite));
        $segments = array_unique($segments);
        $cache->save($cacheId, $segments);
        return $segments;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @param $idSites
  * @return array
  */
 private static function getSegmentsToProcess($idSites)
 {
     $knownSegmentsToArchiveAllSites = SettingsPiwik::getKnownSegmentsToArchive();
     $segmentsToProcess = $knownSegmentsToArchiveAllSites;
     foreach ($idSites as $idSite) {
         $segmentForThisWebsite = SettingsPiwik::getKnownSegmentsToArchiveForSite($idSite);
         $segmentsToProcess = array_merge($segmentsToProcess, $segmentForThisWebsite);
     }
     $segmentsToProcess = array_unique($segmentsToProcess);
     return $segmentsToProcess;
 }
All Usage Examples Of Piwik\SettingsPiwik::getKnownSegmentsToArchiveForSite