@@ -29,6 +29,8 @@ class Slack extends Plugin
2929
3030 private static $ availableParameters = array (
3131 self ::SLACK_CHANNEL_ID_PARAMETER => true ,
32+ ScheduledReports::EVOLUTION_GRAPH_PARAMETER => false ,
33+ ScheduledReports::DISPLAY_FORMAT_PARAMETER => true ,
3234 );
3335
3436 private static $ managedReportTypes = array (
@@ -74,13 +76,33 @@ public function getClientSideTranslationKeys(&$translationKeys)
7476
7577 public function validateReportParameters (&$ parameters , $ reportType )
7678 {
77- if (self ::isSlackEvent ($ reportType )) {
78- $ settings = StaticContainer::get (SystemSettings::class);
79- if (empty ($ settings ->slackOauthToken ->getValue ())) {
80- throw new \Exception (Piwik::translate ('Slack_OauthTokenRequiredErrorMessage ' ));
81- } elseif (empty ($ parameters [self ::SLACK_CHANNEL_ID_PARAMETER ])) {
82- throw new \Exception (Piwik::translate ('Slack_SlackChannelIdRequiredErrorMessage ' ));
83- }
79+ if (!self ::isSlackEvent ($ reportType )) {
80+ return ;
81+ }
82+
83+ $ reportFormat = $ parameters [ScheduledReports::DISPLAY_FORMAT_PARAMETER ];
84+ $ availableDisplayFormats = array_keys (ScheduledReports::getDisplayFormats ());
85+ if (!in_array ($ reportFormat , $ availableDisplayFormats )) {
86+ throw new \Exception (
87+ Piwik::translate (
88+ 'General_ExceptionInvalidAggregateReportsFormat ' ,
89+ array ($ reportFormat , implode (', ' , $ availableDisplayFormats ))
90+ )
91+ );
92+ }
93+
94+ // evolutionGraph is an optional parameter
95+ if (!isset ($ parameters [ScheduledReports::EVOLUTION_GRAPH_PARAMETER ])) {
96+ $ parameters [ScheduledReports::EVOLUTION_GRAPH_PARAMETER ] = ScheduledReports::EVOLUTION_GRAPH_PARAMETER_DEFAULT_VALUE ;
97+ } else {
98+ $ parameters [ScheduledReports::EVOLUTION_GRAPH_PARAMETER ] = self ::valueIsTrue ($ parameters [ScheduledReports::EVOLUTION_GRAPH_PARAMETER ]);
99+ }
100+
101+ $ settings = StaticContainer::get (SystemSettings::class);
102+ if (empty ($ settings ->slackOauthToken ->getValue ())) {
103+ throw new \Exception (Piwik::translate ('Slack_OauthTokenRequiredErrorMessage ' ));
104+ } elseif (empty ($ parameters [self ::SLACK_CHANNEL_ID_PARAMETER ])) {
105+ throw new \Exception (Piwik::translate ('Slack_SlackChannelIdRequiredErrorMessage ' ));
84106 }
85107 }
86108
@@ -220,6 +242,9 @@ public function templateReportParametersScheduledReports(&$out, $context = '')
220242
221243 $ settings = StaticContainer::get (SystemSettings::class);
222244 $ view ->isSlackOauthTokenAdded = !empty ($ settings ->slackOauthToken ->getValue ());
245+ $ view ->defaultDisplayFormat = ScheduledReports::DEFAULT_DISPLAY_FORMAT ;
246+ $ view ->defaultFormat = ReportRenderer::PDF_FORMAT ;
247+ $ view ->defaultEvolutionGraph = ScheduledReports::EVOLUTION_GRAPH_PARAMETER_DEFAULT_VALUE ;
223248 $ out .= $ view ->render ();
224249 }
225250
@@ -258,4 +283,9 @@ private function reportAlreadySent($report, Period $period)
258283
259284 return $ previousDate === $ period ->getRangeString ();
260285 }
286+
287+ private static function valueIsTrue ($ value )
288+ {
289+ return $ value == 'true ' || $ value == 1 || $ value == '1 ' || $ value === true ;
290+ }
261291}
0 commit comments