"generateReport" will generate the requested report (for a specific date range, website and in the requested language). "sendEmailReport" will send the report by email to the recipients specified for this report. You can also get the list of all existing reports via "getReports", create new reports via "addReport", or manage existing reports with "updateReport" and "deleteReport". See also the documentation about Scheduled Email reports in Piwik.
Inheritance: extends Piwik\Plugin\API
コード例 #1
0
ファイル: Menu.php プロジェクト: brienomatty/elmsln
 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;
 }
コード例 #2
0
ファイル: 2.16.5.php プロジェクト: piwik/piwik
 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);
     }
 }
コード例 #3
0
ファイル: Controller.php プロジェクト: carriercomm/piwik
 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();
 }
コード例 #4
0
ファイル: Tasks.php プロジェクト: piwik/piwik
 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);
         }
     }
 }
コード例 #5
0
 /**
  * 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);
 }
コード例 #6
0
 public function segmentDeactivation($idSegment)
 {
     $reportsUsingSegment = API::getInstance()->getReports(false, false, false, false, $idSegment);
     if (empty($reportsUsingSegment)) {
         return;
     }
     $this->throwExceptionReportsAreUsingSegment($reportsUsingSegment);
 }
コード例 #7
0
 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;
 }
コード例 #8
0
ファイル: Fixture.php プロジェクト: igorclark/piwik
 /**
  * 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'));
     }
 }
コード例 #9
0
 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']);
         }
     }
 }
コード例 #10
0
ファイル: ApiTest.php プロジェクト: JoeHorn/piwik
 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;
 }
コード例 #11
0
ファイル: Html.php プロジェクト: FluentDevelopment/piwik
 protected function getAttachment($report, $processedReport, $prettyDate)
 {
     $additionalFile = array();
     $segment = \Piwik\Plugins\ScheduledReports\API::getSegment($report['idsegment']);
     $segmentName = $segment != null ? sprintf(' (%s)', $segment['name']) : '';
     $processedReportMetadata = $processedReport['metadata'];
     $additionalFile['filename'] = sprintf('%s - %s - %d - %s %d%s.png', $processedReportMetadata['name'], $prettyDate, $report['idsite'], Piwik::translate('General_Report'), $report['idreport'], $segmentName);
     $additionalFile['cid'] = $processedReportMetadata['uniqueId'];
     $additionalFile['content'] = ReportRenderer::getStaticGraph($processedReportMetadata, Html::IMAGE_GRAPH_WIDTH, Html::IMAGE_GRAPH_HEIGHT, $processedReport['evolutionGraph'], $segment);
     $additionalFile['mimeType'] = 'image/png';
     $additionalFile['encoding'] = \Zend_Mime::ENCODING_BASE64;
     return $additionalFile;
 }