diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-05-20 07:44:07 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-05-20 07:44:07 +0400 |
commit | 45ae10e999baf0dfa066e5daae00bca824a68191 (patch) | |
tree | b94f42ee5d66e4e1354be5389865af0b0dc507c9 /plugins/ScheduledReports/Menu.php | |
parent | b2cb622bf1ea754a73ce06e165a083e3305aa807 (diff) |
refs #5192 introducing a user menu
Diffstat (limited to 'plugins/ScheduledReports/Menu.php')
-rw-r--r-- | plugins/ScheduledReports/Menu.php | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/plugins/ScheduledReports/Menu.php b/plugins/ScheduledReports/Menu.php new file mode 100644 index 0000000000..7d9f180062 --- /dev/null +++ b/plugins/ScheduledReports/Menu.php @@ -0,0 +1,76 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Plugins\ScheduledReports; + +use Piwik\Menu\MenuUser; +use Piwik\Piwik; +use Piwik\Plugins\MobileMessaging\MobileMessaging; +use Piwik\Plugins\MobileMessaging\API as APIMobileMessaging; + +class Menu extends \Piwik\Plugin\Menu +{ + public function configureUserMenu(MenuUser $menu) + { + $tooltip = Piwik::translate( + \Piwik\Plugin\Manager::getInstance()->isPluginActivated('MobileMessaging') + ? 'MobileMessaging_TopLinkTooltip' : 'ScheduledReports_TopLinkTooltip'); + + $menu->add( + 'CoreAdminHome_MenuManage', + $this->getTopMenuTranslationKey(), + array('module' => 'ScheduledReports', 'action' => 'index', 'segment' => false), + true, + 13, + $tooltip + ); + } + + function getTopMenuTranslationKey() + { + // if MobileMessaging is not activated, display 'Email reports' + if (!\Piwik\Plugin\Manager::getInstance()->isPluginActivated('MobileMessaging')) + return ScheduledReports::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY; + + if (Piwik::isUserIsAnonymous()) { + return ScheduledReports::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY; + } + + try { + $reports = API::getInstance()->getReports(); + $reportCount = count($reports); + + // if there are no reports and the mobile account is + // - not configured: display 'Email reports' + // - configured: display 'Email & SMS reports' + if ($reportCount == 0) { + return APIMobileMessaging::getInstance()->areSMSAPICredentialProvided() ? + ScheduledReports::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY : ScheduledReports::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY; + } + } catch(\Exception $e) { + return ScheduledReports::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY; + } + + + $anyMobileReport = false; + foreach ($reports as $report) { + if ($report['type'] == MobileMessaging::MOBILE_TYPE) { + $anyMobileReport = true; + break; + } + } + + // if there is at least one sms report, display 'Email & SMS reports' + if ($anyMobileReport) { + return ScheduledReports::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY; + } + + return ScheduledReports::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY; + } + +} |