Exemplo n.º 1
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return array
  * @throws \RuntimeException
  */
 protected function getCategory(InputInterface $input, OutputInterface $output)
 {
     $validate = function ($category) {
         if (empty($category)) {
             throw new \InvalidArgumentException('Please enter the name of the category your widget should belong to');
         }
         return $category;
     };
     $category = $input->getOption('category');
     $categories = array();
     foreach (Widgets::getAllWidgets() as $widget) {
         if ($widget->getCategory()) {
             $categories[] = Piwik::translate($widget->getCategory());
         }
     }
     $categories = array_values(array_unique($categories));
     if (empty($category)) {
         $dialog = $this->getHelperSet()->get('dialog');
         $category = $dialog->askAndValidate($output, 'Enter the widget category, for instance "Visitor" (you can reuse any existing category or define a new one): ', $validate, false, null, $categories);
     } else {
         $validate($category);
     }
     $translationKey = Translate::findTranslationKeyForTranslation($category);
     if (!empty($translationKey)) {
         return $translationKey;
     }
     $category = ucfirst($category);
     return $category;
 }
Exemplo n.º 2
0
 private function getEnglishTranslationForFeatureName($featureName)
 {
     if (Translate::getLanguageLoaded() == 'en') {
         return $featureName;
     }
     $translationKeyForFeature = Translate::findTranslationKeyForTranslation($featureName);
     return Piwik::translate($translationKeyForFeature, array(), 'en');
 }
Exemplo n.º 3
0
 private function getEnglishTranslationForFeatureName($featureName)
 {
     $loadedLanguage = Translate::getLanguageLoaded();
     if ($loadedLanguage == 'en') {
         return $featureName;
     }
     $translationKeyForFeature = Translate::findTranslationKeyForTranslation($featureName);
     if (!empty($translationKeyForFeature)) {
         Translate::reloadLanguage('en');
         $featureName = Piwik::translate($translationKeyForFeature);
         Translate::reloadLanguage($loadedLanguage);
         return $featureName;
     }
     return $featureName;
 }
Exemplo n.º 4
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param string $pluginName
  * @return array
  * @throws \RuntimeException
  */
 protected function getCategory(InputInterface $input, OutputInterface $output, $pluginName)
 {
     $path = $this->getPluginPath($pluginName) . '/Reports/Base.php';
     if (file_exists($path)) {
         // category is already defined in base.php
         return '';
     }
     $validate = function ($category) {
         if (empty($category)) {
             throw new \InvalidArgumentException('Please enter the name of the category your report belongs to');
         }
         return $category;
     };
     $category = $input->getOption('category');
     $reports = new ReportsProvider();
     $categories = array();
     foreach ($reports->getAllReports() as $report) {
         if ($report->getCategoryId()) {
             $categories[] = Piwik::translate($report->getCategoryId());
         }
     }
     $categories = array_values(array_unique($categories));
     if (empty($category)) {
         $dialog = $this->getHelperSet()->get('dialog');
         $category = $dialog->askAndValidate($output, 'Enter the report category, for instance "Visitor" (you can reuse any existing category or define a new one): ', $validate, false, null, $categories);
     } else {
         $validate($category);
     }
     $translationKey = Translate::findTranslationKeyForTranslation($category);
     if (!empty($translationKey)) {
         return $translationKey;
     }
     $category = ucfirst($category);
     return $category;
 }