/** * @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; }
protected function getExistingCategories() { $categories = array(); foreach (Widgets::getAllWidgets() as $widget) { if ($widget->getCategory()) { $categories[] = Piwik::translate($widget->getCategory()); } } $categories = array_values(array_unique($categories)); return $categories; }
private static function addWidgets() { if (!self::$hookCalled) { self::$hookCalled = true; /** * @ignore * @deprecated */ Piwik::postEvent('WidgetsList.addWidgets'); $widgetsList = self::getInstance(); foreach (Report::getAllReports() as $report) { if ($report->isEnabled()) { $report->configureWidget($widgetsList); } } $widgetContainers = Widgets::getAllWidgets(); foreach ($widgetContainers as $widgetContainer) { $widgets = $widgetContainer->getWidgets(); foreach ($widgets as $widget) { $widgetsList->add($widget['category'], $widget['name'], $widget['module'], $widget['method'], $widget['params']); } } foreach ($widgetContainers as $widgetContainer) { $widgetContainer->configureWidgetsList($widgetsList); } } }