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; }
private function setManageVariables(View $view) { $view->isSuperUser = Piwik::hasUserSuperUserAccess(); $mobileMessagingAPI = API::getInstance(); $view->delegatedManagement = $mobileMessagingAPI->getDelegatedManagement(); $view->credentialSupplied = $mobileMessagingAPI->areSMSAPICredentialProvided(); $view->accountManagedByCurrentUser = $view->isSuperUser || $view->delegatedManagement; $view->strHelpAddPhone = $this->translator->translate('MobileMessaging_Settings_PhoneNumbers_HelpAdd', array($this->translator->translate('General_Settings'), $this->translator->translate('MobileMessaging_SettingsMenu'))); $view->creditLeft = 0; $view->provider = ''; if ($view->credentialSupplied && $view->accountManagedByCurrentUser) { $view->provider = $mobileMessagingAPI->getSMSProvider(); $view->creditLeft = $mobileMessagingAPI->getCreditLeft(); } $providers = array(); foreach (SMSProvider::findAvailableSmsProviders() as $provider) { $providers[$provider->getId()] = $provider->getDescription(); } $view->smsProviders = $providers; // construct the list of countries from the lang files $countries = array(); foreach ($this->regionDataProvider->getCountryList() as $countryCode => $continentCode) { if (isset(CountryCallingCodes::$countryCallingCodes[$countryCode])) { $countries[$countryCode] = array('countryName' => \Piwik\Plugins\UserCountry\countryTranslate($countryCode), 'countryCallingCode' => CountryCallingCodes::$countryCallingCodes[$countryCode]); } } $view->countries = $countries; $view->defaultCountry = Common::getCountry(LanguagesManager::getLanguageCodeForCurrentUser(), true, IP::getIpFromHeader()); $view->phoneNumbers = $mobileMessagingAPI->getPhoneNumbers(); $this->setBasicVariablesView($view); }
public function index() { Piwik::checkUserIsNotAnonymous(); $view = new View('@MobileMessaging/index'); $view->isSuperUser = Piwik::hasUserSuperUserAccess(); $mobileMessagingAPI = API::getInstance(); $view->delegatedManagement = $mobileMessagingAPI->getDelegatedManagement(); $view->credentialSupplied = $mobileMessagingAPI->areSMSAPICredentialProvided(); $view->accountManagedByCurrentUser = $view->isSuperUser || $view->delegatedManagement; $view->strHelpAddPhone = Piwik::translate('MobileMessaging_Settings_PhoneNumbers_HelpAdd', array(Piwik::translate('General_Settings'), Piwik::translate('MobileMessaging_SettingsMenu'))); if ($view->credentialSupplied && $view->accountManagedByCurrentUser) { $view->provider = $mobileMessagingAPI->getSMSProvider(); $view->creditLeft = $mobileMessagingAPI->getCreditLeft(); } $view->smsProviders = SMSProvider::$availableSMSProviders; // construct the list of countries from the lang files $countries = array(); foreach (Common::getCountriesList() as $countryCode => $continentCode) { if (isset(CountryCallingCodes::$countryCallingCodes[$countryCode])) { $countries[$countryCode] = array('countryName' => \Piwik\Plugins\UserCountry\countryTranslate($countryCode), 'countryCallingCode' => CountryCallingCodes::$countryCallingCodes[$countryCode]); } } $view->countries = $countries; $view->defaultCountry = Common::getCountry(LanguagesManager::getLanguageCodeForCurrentUser(), true, IP::getIpFromHeader()); $view->phoneNumbers = $mobileMessagingAPI->getPhoneNumbers(); $this->setBasicVariablesView($view); return $view->render(); }
public function filterPhoneNumbers($phoneNumbers) { $availablePhoneNumbers = APIMobileMessaging::getInstance()->getActivatedPhoneNumbers(); foreach ($phoneNumbers as $key => &$phoneNumber) { $phoneNumber = trim($phoneNumber); if (!in_array($phoneNumber, $availablePhoneNumbers)) { unset($phoneNumbers[$key]); } } return array_values($phoneNumbers); }
/** * @group Plugins * * @dataProvider getSendReportTestCases */ public function testSendReport($expectedReportContent, $expectedPhoneNumber, $expectedFrom, $reportContent, $phoneNumber, $reportSubject) { $report = array('parameters' => array(MobileMessaging::PHONE_NUMBERS_PARAMETER => array($phoneNumber))); $stubbedAPIMobileMessaging = $this->getMock('\\Piwik\\Plugins\\MobileMessaging\\API', array('sendSMS', 'getInstance'), $arguments = array(), $mockClassName = '', $callOriginalConstructor = false); $stubbedAPIMobileMessaging->expects($this->once())->method('sendSMS')->with($this->equalTo($expectedReportContent, 0), $this->equalTo($expectedPhoneNumber, 1), $this->equalTo($expectedFrom, 2)); \Piwik\Plugins\MobileMessaging\API::setSingletonInstance($stubbedAPIMobileMessaging); $mobileMessaging = new MobileMessaging(); $mobileMessaging->sendReport(MobileMessaging::MOBILE_TYPE, $report, $reportContent, null, null, $reportSubject, null, null); \Piwik\Plugins\MobileMessaging\API::unsetInstance(); }
public static function template_reportParametersScheduledReports(&$out) { if (Piwik::isUserIsAnonymous()) { return; } $view = new View('@MobileMessaging/reportParametersScheduledReports'); $view->reportType = self::MOBILE_TYPE; $view->phoneNumbers = APIMobileMessaging::getInstance()->getActivatedPhoneNumbers(); $out .= $view->render(); }
/** * top menu should display 'Email reports' if there are no SMS reports and at least one email report * whatever the status of the mobile provider account * * @group Plugins */ public function testGetTopMenuTranslationKeyNoSMSReportAccountOK() { // set mobile provider account self::setSuperUser(); APIMobileMessaging::getInstance()->setSMSAPICredential('StubbedProvider', ''); self::addReport(self::getMonthlyEmailReportData($this->idSite)); $pdfReportPlugin = new Menu(); $this->assertEquals(Menu::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY, $pdfReportPlugin->getTopMenuTranslationKey()); }
public static function template_reportParametersScheduledReports(&$out, $context = '') { if (Piwik::isUserIsAnonymous()) { return; } $view = new View('@MobileMessaging/reportParametersScheduledReports'); $view->reportType = self::MOBILE_TYPE; $view->context = $context; $numbers = APIMobileMessaging::getInstance()->getActivatedPhoneNumbers(); $phoneNumbers = array(); if (!empty($numbers)) { foreach ($numbers as $number) { $phoneNumbers[$number] = $number; } } $view->phoneNumbers = $phoneNumbers; $out .= $view->render(); }
/** * @param array $alerts * @param APIMobileMessaging $mobileMessagingAPI * @param string $phoneNumber */ protected function sendAlertsPerSmsToRecipient($alerts, $mobileMessagingAPI, $phoneNumber) { if (empty($phoneNumber) || empty($alerts)) { return; } if (!PluginManager::getInstance()->isPluginActivated('MobileMessaging')) { return; } $controller = new Controller(); $content = $controller->formatAlerts($alerts, 'sms'); $subject = Piwik::translate('CustomAlerts_SmsAlertFromName'); $mobileMessagingAPI->sendSMS($content, $phoneNumber, $subject); }