Piwik\Plugins\ScheduledReports\API::getReportRecipients PHP Method

getReportRecipients() public static method

public static getReportRecipients ( $report )
    public static function getReportRecipients($report)
    {
        $recipients = array();
        /**
         * Triggered when getting the list of recipients of a scheduled report.
         *
         * Plugins that provide their own scheduled report transport medium should use this event
         * to extract the list of recipients their backend's specific scheduled report
         * format.
         *
         * @param array &$recipients An array of strings describing each of the scheduled
         *                           reports recipients. Can be, for example, a list of email
         *                           addresses or phone numbers or whatever else your plugin
         *                           uses.
         * @param string $reportType A string ID describing how the report is sent, eg,
         *                           `'sms'` or `'email'`.
         * @param array $report An array describing the scheduled report that is being
         *                      generated.
         */
        Piwik::postEvent(self::GET_REPORT_RECIPIENTS_EVENT, array(&$recipients, $report['type'], $report));
        return $recipients;
    }

Usage Example

Example #1
0
 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();
 }