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; }
public function doUpdate(Updater $updater) { $model = new ScheduledReportsModel(); $allReports = ScheduledReportsAPI::getInstance()->getReports(); foreach ($allReports as $report) { $update = array('hour' => $this->adjustTimezoneBySite($report['hour'], $report['idsite'])); $model->updateReport($report['idreport'], $update); } }
public function index() { $view = new View('@ScheduledReports/index'); $this->setGeneralVariablesView($view); $view->countWebsites = count(APISitesManager::getInstance()->getSitesIdWithAtLeastViewAccess()); // get report types $reportTypes = API::getReportTypes(); $view->reportTypes = $reportTypes; $view->defaultReportType = self::DEFAULT_REPORT_TYPE; $view->defaultReportFormat = ScheduledReports::DEFAULT_REPORT_FORMAT; $view->displayFormats = ScheduledReports::getDisplayFormats(); $reportsByCategoryByType = array(); $reportFormatsByReportType = array(); $allowMultipleReportsByReportType = array(); foreach ($reportTypes as $reportType => $reportTypeIcon) { // get report formats $reportFormatsByReportType[$reportType] = API::getReportFormats($reportType); $allowMultipleReportsByReportType[$reportType] = API::allowMultipleReports($reportType); // get report metadata $reportsByCategory = array(); $availableReportMetadata = API::getReportMetadata($this->idSite, $reportType); foreach ($availableReportMetadata as $reportMetadata) { $reportsByCategory[$reportMetadata['category']][] = $reportMetadata; } $reportsByCategoryByType[$reportType] = $reportsByCategory; } $view->reportsByCategoryByReportType = $reportsByCategoryByType; $view->reportFormatsByReportType = $reportFormatsByReportType; $view->allowMultipleReportsByReportType = $allowMultipleReportsByReportType; $reports = array(); $reportsById = array(); if (!Piwik::isUserIsAnonymous()) { $reports = API::getInstance()->getReports($this->idSite, $period = false, $idReport = false, $ifSuperUserReturnOnlySuperUserReports = true); foreach ($reports as &$report) { $report['recipients'] = API::getReportRecipients($report); $reportsById[$report['idreport']] = $report; } } $view->reports = $reports; $view->reportsJSON = Common::json_encode($reportsById); $view->downloadOutputType = API::OUTPUT_INLINE; $view->periods = ScheduledReports::getPeriodToFrequency(); $view->defaultPeriod = ScheduledReports::DEFAULT_PERIOD; $view->defaultHour = ScheduledReports::DEFAULT_HOUR; $view->language = LanguagesManager::getLanguageCodeForCurrentUser(); $view->segmentEditorActivated = false; if (API::isSegmentEditorActivated()) { $savedSegmentsById = array(); foreach (APISegmentEditor::getInstance()->getAll($this->idSite) as $savedSegment) { $savedSegmentsById[$savedSegment['idsegment']] = $savedSegment['name']; } $view->savedSegmentsById = $savedSegmentsById; $view->segmentEditorActivated = true; } return $view->render(); }
public function schedule() { foreach (API::getInstance()->getReports() as $report) { if (!$report['deleted'] && $report['period'] != Schedule::PERIOD_NEVER) { $schedule = Schedule::getScheduledTimeForPeriod($report['period']); $schedule->setHour($report['hour']); $schedule->setTimezone('UTC'); // saved hour is UTC always $this->custom(API::getInstance(), 'sendReport', $report['idreport'], $schedule); } } }
/** * When the MultiSites plugin is not activated, the SMS content should invite the user to activate it back * * @group Plugins */ public function testWarnUserViaSMSMultiSitesDeactivated() { // safety net \Piwik\Plugin\Manager::getInstance()->loadPlugins(array('ScheduledReports', 'MobileMessaging')); $this->assertFalse(\Piwik\Plugin\Manager::getInstance()->isPluginActivated('MultiSites')); $APIScheduledReports = APIScheduledReports::getInstance(); $reportId = $APIScheduledReports->addReport($this->idSiteAccess, 'description', 'month', 0, 'mobile', 'sms', array(), array("phoneNumbers" => array('33698896656'))); list($outputFilename, $prettyDate, $websiteName, $additionalFiles) = $APIScheduledReports->generateReport($reportId, '01-01-2010', 'en', 2); $handle = fopen($outputFilename, "r"); $contents = fread($handle, filesize($outputFilename)); fclose($handle); $this->assertEquals(\Piwik\Piwik::translate('MobileMessaging_MultiSites_Must_Be_Activated'), $contents); }
public function segmentDeactivation($idSegment) { $reportsUsingSegment = API::getInstance()->getReports(false, false, false, false, $idSegment); if (empty($reportsUsingSegment)) { return; } $this->throwExceptionReportsAreUsingSegment($reportsUsingSegment); }
private function addReport($login, $idSite) { $this->setIdentity($login); $reportType = 'email'; $reportFormat = 'pdf'; $reports = array(); $parameters = array(ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_TABLES_ONLY); $reportId = API::getInstance()->addReport($idSite, 'description', 'day', 3, $reportType, $reportFormat, $reports, $parameters); $this->reportIds[$login . '_' . $idSite] = $reportId; }
/** * Create three MAIL and two MOBILE scheduled reports * * Reports sent by mail can contain PNG graphs when the user specifies it. * Depending on the system under test, generated images differ slightly. * Because of this discrepancy, PNG graphs are only tested if the system under test * has the characteristics described in 'canImagesBeIncludedInScheduledReports'. * See tests/README.md for more detail. * * @see canImagesBeIncludedInScheduledReports * @param int $idSite id of website created */ public static function setUpScheduledReports($idSite) { // fake access is needed so API methods can call Piwik::getCurrentUserLogin(), e.g: 'ScheduledReports.addReport' $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; Access::setSingletonInstance($pseudoMockAccess); // retrieve available reports $availableReportMetadata = APIScheduledReports::getReportMetadata($idSite, ScheduledReports::EMAIL_TYPE); $availableReportIds = array(); foreach ($availableReportMetadata as $reportMetadata) { $availableReportIds[] = $reportMetadata['uniqueId']; } //@review should we also test evolution graphs? // set-up mail report APIScheduledReports::getInstance()->addReport($idSite, 'Mail Test report', 'day', 0, ScheduledReports::EMAIL_TYPE, ReportRenderer::HTML_FORMAT, $availableReportIds, array(ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_TABLES_ONLY)); // set-up sms report for one website APIScheduledReports::getInstance()->addReport($idSite, 'SMS Test report, one website', 'day', 0, MobileMessaging::MOBILE_TYPE, MobileMessaging::SMS_FORMAT, array("MultiSites_getOne"), array("phoneNumbers" => array())); // set-up sms report for all websites APIScheduledReports::getInstance()->addReport($idSite, 'SMS Test report, all websites', 'day', 0, MobileMessaging::MOBILE_TYPE, MobileMessaging::SMS_FORMAT, array("MultiSites_getAll"), array("phoneNumbers" => array())); if (self::canImagesBeIncludedInScheduledReports()) { // set-up mail report with images APIScheduledReports::getInstance()->addReport($idSite, 'Mail Test report', 'day', 0, ScheduledReports::EMAIL_TYPE, ReportRenderer::HTML_FORMAT, $availableReportIds, array(ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_TABLES_AND_GRAPHS)); // set-up mail report with one row evolution based png graph APIScheduledReports::getInstance()->addReport($idSite, 'Mail Test report', 'day', 0, ScheduledReports::EMAIL_TYPE, ReportRenderer::HTML_FORMAT, array('Actions_getPageTitles'), array(ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_GRAPHS_ONLY, ScheduledReports::EVOLUTION_GRAPH_PARAMETER => 'true')); } }
function deactivate() { // delete all mobile reports $APIScheduledReports = APIScheduledReports::getInstance(); $reports = $APIScheduledReports->getReports(); foreach ($reports as $report) { if ($report['type'] == MobileMessaging::MOBILE_TYPE) { $APIScheduledReports->deleteReport($report['idreport']); } } }
private static function updateReport($idReport, $data) { APIScheduledReports::getInstance()->updateReport($idReport, $data['idsite'], $data['description'], $data['period'], $data['hour'], $data['type'], $data['format'], $data['reports'], $data['parameters']); return $idReport; }