Пример #1
0
 /**
  * Returns a list of all available reports. Even not enabled reports will be returned. They will be already sorted
  * depending on the order and category of the report.
  * @return \Piwik\Plugin\Report[]
  * @api
  */
 public function getAllReports()
 {
     $reports = $this->getAllReportClasses();
     $cacheId = CacheId::languageAware('Reports' . md5(implode('', $reports)));
     $cache = PiwikCache::getTransientCache();
     if (!$cache->contains($cacheId)) {
         $instances = array();
         /**
          * Triggered to add new reports 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 addReport(&$reports)
          *     {
          *         $reports[] = new MyCustomReport();
          *     }
          *
          * @param Report[] $reports An array of reports
          */
         Piwik::postEvent('Report.addReports', array(&$instances));
         foreach ($reports as $report) {
             $instances[] = new $report();
         }
         /**
          * Triggered to filter / restrict reports.
          *
          * **Example**
          *
          *     public function filterReports(&$reports)
          *     {
          *         foreach ($reports as $index => $report) {
          *              if ($report->getCategory() === 'Actions') {}
          *                  unset($reports[$index]); // remove all reports having this action
          *              }
          *         }
          *     }
          *
          * @param Report[] $reports An array of reports
          */
         Piwik::postEvent('Report.filterReports', array(&$instances));
         usort($instances, array($this, 'sort'));
         $cache->save($cacheId, $instances);
     }
     return $cache->fetch($cacheId);
 }
Пример #2
0
 public static function getDefaultProcessedMetrics()
 {
     $cacheId = CacheId::languageAware('DefaultProcessedMetrics');
     $cache = PiwikCache::getTransientCache();
     if ($cache->contains($cacheId)) {
         return $cache->fetch($cacheId);
     }
     $translations = array('nb_actions_per_visit' => 'General_ColumnActionsPerVisit', 'avg_time_on_site' => 'General_ColumnAvgTimeOnSite', 'bounce_rate' => 'General_ColumnBounceRate', 'conversion_rate' => 'General_ColumnConversionRate');
     $translations = array_map(array('\\Piwik\\Piwik', 'translate'), $translations);
     $cache->save($cacheId, $translations);
     return $translations;
 }
Пример #3
0
 /**
  * Returns all available user settings. A plugin has to specify a file named `UserSettings.php` containing a class
  * named `UserSettings` that extends `Piwik\Settings\Plugin\UserSettings` in order to be considered as a plugin
  * setting. Otherwise the settings for a plugin won't be available.
  *
  * @return UserSettings[]   An array containing array([pluginName] => [setting instance]).
  */
 public function getAllUserSettings()
 {
     $cacheId = CacheId::languageAware('AllUserSettings');
     $cache = PiwikCache::getTransientCache();
     if (!$cache->contains($cacheId)) {
         $pluginNames = $this->pluginManager->getActivatedPlugins();
         $byPluginName = array();
         foreach ($pluginNames as $plugin) {
             $component = $this->getUserSettings($plugin);
             if (!empty($component)) {
                 $byPluginName[$plugin] = $component;
             }
         }
         $cache->save($cacheId, $byPluginName);
     }
     return $cache->fetch($cacheId);
 }
Пример #4
0
 /**
  * Returns a list of all available reports. Even not enabled reports will be returned. They will be already sorted
  * depending on the order and category of the report.
  * @return \Piwik\Plugin\Report[]
  * @api
  */
 public static function getAllReports()
 {
     $reports = self::getAllReportClasses();
     $cacheId = CacheId::languageAware('Reports' . md5(implode('', $reports)));
     $cache = PiwikCache::getTransientCache();
     if (!$cache->contains($cacheId)) {
         $instances = array();
         foreach ($reports as $report) {
             $instances[] = new $report();
         }
         usort($instances, array('self', 'sort'));
         $cache->save($cacheId, $instances);
     }
     return $cache->fetch($cacheId);
 }
Пример #5
0
 public function test_languageAware_shouldAppendTheLoadedLanguage()
 {
     $result = CacheId::languageAware('myrandomkey');
     $this->assertEquals('myrandomkey-en', $result);
 }