@@ -58,7 +58,7 @@ public function registerEvents()
5858 'ScheduledReports.sendReport ' => 'sendReport ' ,
5959 'Template.reportParametersScheduledReports ' => 'templateReportParametersScheduledReports ' ,
6060 'Translate.getClientSideTranslationKeys ' => 'getClientSideTranslationKeys ' ,
61- 'CustomAlerts.validateReportParameters ' => 'validateCustomAlertReportParameters ' ,
61+ 'CustomAlerts.validateReportParameters ' => 'validateCustomAlertReportParameters ' ,
6262 'CustomAlerts.sendNewAlerts ' => 'sendNewAlerts ' ,
6363 ];
6464 }
@@ -76,6 +76,16 @@ public function getClientSideTranslationKeys(&$translationKeys)
7676 $ translationKeys [] = 'Slack_SlackEnterYourSlackChannelIdHelpText ' ;
7777 }
7878
79+ /**
80+ *
81+ * Validates the Schedule Report for Slack reportType
82+ *
83+ * @param $parameters
84+ * @param $reportType
85+ * @return void
86+ * @throws \Piwik\Exception\DI\DependencyException
87+ * @throws \Piwik\Exception\DI\NotFoundException
88+ */
7989 public function validateReportParameters (&$ parameters , $ reportType )
8090 {
8191 if (!self ::isSlackEvent ($ reportType )) {
@@ -108,6 +118,15 @@ public function validateReportParameters(&$parameters, $reportType)
108118 }
109119 }
110120
121+ /**
122+ *
123+ * Get report metadata for Slack scheduled report
124+ *
125+ * @param $availableReportMetadata
126+ * @param $reportType
127+ * @param $idSite
128+ * @return void
129+ */
111130 public function getReportMetadata (&$ availableReportMetadata , $ reportType , $ idSite )
112131 {
113132 if (!self ::isSlackEvent ($ reportType )) {
@@ -121,25 +140,58 @@ public function getReportMetadata(&$availableReportMetadata, $reportType, $idSit
121140 );
122141 }
123142
143+ /**
144+ *
145+ * Adds Slack as a reportType in Schedule Reports
146+ *
147+ * @param $reportTypes
148+ * @return void
149+ */
124150 public function getReportTypes (&$ reportTypes )
125151 {
126152 $ reportTypes = array_merge ($ reportTypes , self ::$ managedReportTypes );
127153 }
128154
155+ /**
156+ *
157+ * Adds allowed reportTypes for Slack, e.g. PDF, CSV and TSV
158+ *
159+ * @param $reportFormats
160+ * @param $reportType
161+ * @return void
162+ */
129163 public function getReportFormats (&$ reportFormats , $ reportType )
130164 {
131165 if (self ::isSlackEvent ($ reportType )) {
132166 $ reportFormats = array_merge ($ reportFormats , self ::$ managedReportFormats );
133167 }
134168 }
135169
170+ /**
171+ *
172+ * Adds report parameter for Slack, e.g. SlackChannelID
173+ *
174+ * @param $availableParameters
175+ * @param $reportType
176+ * @return void
177+ */
136178 public function getReportParameters (&$ availableParameters , $ reportType )
137179 {
138180 if (self ::isSlackEvent ($ reportType )) {
139181 $ availableParameters = self ::$ availableParameters ;
140182 }
141183 }
142184
185+ /**
186+ *
187+ * Process the Schedule report for reportType Slack
188+ *
189+ * @param $processedReports
190+ * @param $reportType
191+ * @param $outputType
192+ * @param $report
193+ * @return void
194+ */
143195 public function processReports (&$ processedReports , $ reportType , $ outputType , $ report )
144196 {
145197 if (!self ::isSlackEvent ($ reportType )) {
@@ -153,6 +205,17 @@ public function processReports(&$processedReports, $reportType, $outputType, $re
153205 );
154206 }
155207
208+ /**
209+ *
210+ * Sets the rendered instance based on reportFormat for Slack
211+ *
212+ * @param $reportRenderer
213+ * @param $reportType
214+ * @param $outputType
215+ * @param $report
216+ * @return void
217+ * @throws \Exception
218+ */
156219 public function getRendererInstance (&$ reportRenderer , $ reportType , $ outputType , $ report )
157220 {
158221 if (!self ::isSlackEvent ($ reportType )) {
@@ -164,13 +227,30 @@ public function getRendererInstance(&$reportRenderer, $reportType, $outputType,
164227 $ reportRenderer = ReportRenderer::factory ($ reportFormat );
165228 }
166229
230+ /**
231+ *
232+ * To allow multiple reports in a single file
233+ *
234+ * @param $allowMultipleReports
235+ * @param $reportType
236+ * @return void
237+ */
167238 public function allowMultipleReports (&$ allowMultipleReports , $ reportType )
168239 {
169240 if (self ::isSlackEvent ($ reportType )) {
170241 $ allowMultipleReports = true ;
171242 }
172243 }
173244
245+ /**
246+ *
247+ * Displays the recipients in the list of Schedule Reports
248+ *
249+ * @param $recipients
250+ * @param $reportType
251+ * @param $report
252+ * @return void
253+ */
174254 public function getReportRecipients (&$ recipients , $ reportType , $ report )
175255 {
176256 if (!self ::isSlackEvent ($ reportType ) || empty ($ report ['parameters ' ][self ::SLACK_CHANNEL_ID_PARAMETER ])) {
@@ -181,6 +261,9 @@ public function getReportRecipients(&$recipients, $reportType, $report)
181261 }
182262
183263 /**
264+ *
265+ * Code to send a Schedule Report via Slack
266+ *
184267 * @param $reportType
185268 * @param $report
186269 * @param $contents
@@ -189,8 +272,11 @@ public function getReportRecipients(&$recipients, $reportType, $report)
189272 * @param $reportSubject
190273 * @param $reportTitle
191274 * @param $additionalFiles
192- * @param Period|null $period
275+ * @param $period
193276 * @param $force
277+ * @return void
278+ * @throws \Piwik\Exception\DI\DependencyException
279+ * @throws \Piwik\Exception\DI\NotFoundException
194280 */
195281 public function sendReport (
196282 $ reportType ,
@@ -203,7 +289,8 @@ public function sendReport(
203289 $ additionalFiles ,
204290 $ period ,
205291 $ force
206- ) {
292+ )
293+ {
207294 if (!self ::isSlackEvent ($ reportType )) {
208295 return ;
209296 }
@@ -232,6 +319,16 @@ public function sendReport(
232319 $ scheduleReportSlack ->send ();
233320 }
234321
322+ /**
323+ *
324+ * Add the view template for Slack report parameters
325+ *
326+ * @param $out
327+ * @param $context
328+ * @return void
329+ * @throws \Piwik\Exception\DI\DependencyException
330+ * @throws \Piwik\Exception\DI\NotFoundException
331+ */
235332 public function templateReportParametersScheduledReports (&$ out , $ context = '' )
236333 {
237334 if (Piwik::isUserIsAnonymous ()) {
@@ -277,17 +374,35 @@ public function uninstall()
277374 return ;
278375 }
279376
377+ /**
378+ *
379+ * Validation check for CustomAlert report parameters
380+ *
381+ * @param $parameters
382+ * @param $alertMedium
383+ * @return void
384+ * @throws \Exception
385+ */
280386 public function validateCustomAlertReportParameters ($ parameters , $ alertMedium )
281387 {
282388 if ($ alertMedium === self ::SLACK_TYPE && empty ($ parameters [self ::SLACK_CHANNEL_ID_PARAMETER ])) {
283389 throw new \Exception (Piwik::translate ('Slack_SlackChannelIdRequiredErrorMessage ' ));
284390 }
285391 }
286392
393+ /**
394+ *
395+ * Code to send CustomAlerts via Slack
396+ *
397+ * @param $triggeredAlerts
398+ * @return void
399+ * @throws \Piwik\Exception\DI\DependencyException
400+ * @throws \Piwik\Exception\DI\NotFoundException
401+ */
287402 public function sendNewAlerts ($ triggeredAlerts ): void
288403 {
289404 if (!empty ($ triggeredAlerts )) {
290- $ enrichTriggerAlerts = new EnrichTriggeredAlerts ( );
405+ $ enrichTriggerAlerts = StaticContainer:: get (EnrichTriggeredAlerts::class );
291406 $ triggeredAlerts = $ enrichTriggerAlerts ->enrichTriggeredAlerts ($ triggeredAlerts );
292407 $ settings = StaticContainer::get (SystemSettings::class);
293408 $ token = $ settings ->slackOauthToken ->getValue ();
@@ -305,6 +420,13 @@ public function sendNewAlerts($triggeredAlerts): void
305420 }
306421 }
307422
423+ /**
424+ *
425+ * Group alerts by slackChannelID to reduce number of network calls for multiple alerts
426+ *
427+ * @param array $alerts
428+ * @return array
429+ */
308430 private function groupAlertsByChannelId (array $ alerts ): array
309431 {
310432 $ groupedAlerts = [];
@@ -321,11 +443,27 @@ private function groupAlertsByChannelId(array $alerts): array
321443 return $ groupedAlerts ;
322444 }
323445
446+ /**
447+ *
448+ * Returns the alert message to send via Slack
449+ *
450+ * @param array $alert
451+ * @param string $metric
452+ * @param string $reportName
453+ * @return string
454+ */
324455 public function getAlertMessage (array $ alert , string $ metric , string $ reportName ): string
325456 {
326457 return Piwik::translate ('Slack_SlackAlertContent ' , [$ alert ['name ' ], $ alert ['siteName ' ], $ metric , $ reportName , $ this ->transformAlertCondition ($ alert )]);
327458 }
328459
460+ /**
461+ *
462+ * Transform the alert condition to text
463+ *
464+ * @param array $alert
465+ * @return string
466+ */
329467 private function transformAlertCondition (array $ alert ): string
330468 {
331469 switch ($ alert ['metric_condition ' ]) {
0 commit comments