Piwik\Columns\Dimension::getAllDimensions PHP Метод

getAllDimensions() публичный статический Метод

Gets an instance of all available visit, action and conversion dimension.
public static getAllDimensions ( ) : Dimension[]
Результат Dimension[]
    public static function getAllDimensions()
    {
        $cacheId = CacheId::pluginAware('AllDimensions');
        $cache = PiwikCache::getTransientCache();
        if (!$cache->contains($cacheId)) {
            $plugins = PluginManager::getInstance()->getPluginsLoadedAndActivated();
            $instances = array();
            /**
             * Triggered to add new dimensions that cannot be picked up automatically by the platform.
             * This is useful if the plugin allows a user to create reports / dimensions dynamically. For example
             * CustomDimensions or CustomVariables. There are a variable number of dimensions in this case and it
             * wouldn't be really possible to create a report file for one of these dimensions as it is not known
             * how many Custom Dimensions will exist.
             *
             * **Example**
             *
             *     public function addDimension(&$dimensions)
             *     {
             *         $dimensions[] = new MyCustomDimension();
             *     }
             *
             * @param Dimension[] $reports An array of dimensions
             */
            Piwik::postEvent('Dimension.addDimensions', array(&$instances));
            foreach ($plugins as $plugin) {
                foreach (self::getDimensions($plugin) as $instance) {
                    $instances[] = $instance;
                }
            }
            /**
             * Triggered to filter / restrict dimensions.
             *
             * **Example**
             *
             *     public function filterDimensions(&$dimensions)
             *     {
             *         foreach ($dimensions as $index => $dimension) {
             *              if ($dimension->getName() === 'Page URL') {}
             *                  unset($dimensions[$index]); // remove this dimension
             *              }
             *         }
             *     }
             *
             * @param Dimension[] $dimensions An array of dimensions
             */
            Piwik::postEvent('Dimension.filterDimensions', array(&$instances));
            $cache->save($cacheId, $instances);
        }
        return $cache->fetch($cacheId);
    }

Usage Example

Пример #1
0
 public function getSegmentsMetadata($idSites = array(), $_hideImplementationData = true, $isAuthenticatedWithViewAccess)
 {
     $segments = array();
     /**
      * Triggered to add custom segment definitions.
      *
      * **Example**
      *
      *     public function addSegments(&$segments)
      *     {
      *         $segment = new Segment();
      *         $segment->setSegment('my_segment_name');
      *         $segment->setType(Segment::TYPE_DIMENSION);
      *         $segment->setName('My Segment Name');
      *         $segment->setSqlSegment('log_table.my_segment_name');
      *         $segments[] = $segment;
      *     }
      *
      * @param array &$segments An array containing a list of segment entries.
      */
     Piwik::postEvent('Segment.addSegments', array(&$segments));
     foreach (Dimension::getAllDimensions() as $dimension) {
         foreach ($dimension->getSegments() as $segment) {
             $segments[] = $segment;
         }
     }
     /** @var Segment[] $dimensionSegments */
     $dimensionSegments = $segments;
     $segments = array();
     foreach ($dimensionSegments as $segment) {
         if ($segment->isRequiresAtLeastViewAccess()) {
             $segment->setPermission($isAuthenticatedWithViewAccess);
         }
         $segments[] = $segment->toArray();
     }
     foreach ($segments as &$segment) {
         $segment['name'] = Piwik::translate($segment['name']);
         $segment['category'] = Piwik::translate($segment['category']);
         if ($_hideImplementationData) {
             unset($segment['sqlFilter']);
             unset($segment['sqlFilterValue']);
             unset($segment['sqlSegment']);
             if (isset($segment['suggestedValuesCallback']) && !is_string($segment['suggestedValuesCallback'])) {
                 unset($segment['suggestedValuesCallback']);
             }
         }
     }
     usort($segments, array($this, 'sortSegments'));
     return $segments;
 }
All Usage Examples Of Piwik\Columns\Dimension::getAllDimensions