blob: ea02b98b60520121c1e42d28aafd548ae3bbdf25 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @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
{
const MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY = 'MobileMessaging_TopMenu';
const PDF_REPORTS_TOP_MENU_TRANSLATION_KEY = 'ScheduledReports_EmailReports';
public function configureUserMenu(MenuUser $menu)
{
$tooltip = Piwik::translate(
\Piwik\Plugin\Manager::getInstance()->isPluginActivated('MobileMessaging')
? 'MobileMessaging_TopLinkTooltip' : 'ScheduledReports_TopLinkTooltip');
$menu->addPersonalItem(
$this->getTopMenuTranslationKey(),
$this->urlForAction('index', array('segment' => false)),
7,
$tooltip
);
}
function getTopMenuTranslationKey()
{
// if MobileMessaging is not activated, display 'Email reports'
if (!\Piwik\Plugin\Manager::getInstance()->isPluginActivated('MobileMessaging'))
return self::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY;
if (Piwik::isUserIsAnonymous()) {
return self::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() ?
self::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY : self::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY;
}
} catch(\Exception $e) {
return self::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 self::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY;
}
return self::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY;
}
}
|