* @return null
*/
public function generate($samplecontexts, $predictions) {
+ global $OUTPUT;
$analyserclass = $this->target->get_analyser_class();
$insighturl = $this->target->get_insight_context_url($this->modelid, $context);
$fullmessage = get_string('insightinfomessage', 'analytics', $insighturl->out(false));
- $fullmessagehtml = get_string('insightinfomessagehtml', 'analytics', $insighturl->out());
+
+ $fullmessagehtml = $OUTPUT->render_from_template('core_analytics/insight_info_message', ['url' => $insighturl->out(false)]);
$this->notifications($context, $insighturl, $fullmessage, $fullmessagehtml);
}
}
* @return array Three items array with formats [\moodle_url, string, string]
*/
private function prediction_info(\core_analytics\prediction $prediction) {
+ global $OUTPUT;
$predictionactions = $this->target->prediction_actions($prediction, true, true);
- $messageactions = '';
- $messageactionshtml = '';
+ // For FORMAT_PLAIN.
+ $fullmessageplaintext = '';
+
+ // For FORMAT_HTML.
+ $messageactions = [];
$insighturl = null;
foreach ($predictionactions as $action) {
$actionurl = $action->get_url();
$actionurl->param('forwardurl', $actiondoneurl->out(false));
}
- $btnstyle = 'btn-default';
if (empty($insighturl)) {
// We use the primary action url as insight url so we log that the user followed the provided link.
$insighturl = $action->get_url();
- $btnstyle = 'btn-primary';
}
- $messageactions .= $action->get_text() . ': ' . $action->get_url()->out(false) . PHP_EOL;
- $messageactionshtml .= '<a href="' . $action->get_url()->out() . '" class="btn ' . $btnstyle . ' m-r-1 m-b-1">' .
- $action->get_text() . '</a>';
+ $actiondata = (object)['url' => $action->get_url()->out(false), 'text' => $action->get_text()];
+ $fullmessageplaintext .= get_string('insightinfomessageaction', 'analytics', $actiondata) . PHP_EOL;
+ $messageactions[] = $actiondata;
}
- $fullmessage = get_string('insightinfomessageprediction', 'analytics', $messageactions);
- $fullmessagehtml = get_string('insightinfomessagepredictionhtml', 'analytics', $messageactionshtml);
-
- return [$insighturl, $fullmessage, $fullmessagehtml];
+ $fullmessagehtml = $OUTPUT->render_from_template('core_analytics/insight_info_message_prediction', ['actions' => $messageactions]);
+ return [$insighturl, $fullmessageplaintext, $fullmessagehtml];
}
}
/**
* The insight notification subject.
*
+ * This is just a default message, you should overwrite it for a custom insight message.
+ *
* @param int $modelid
* @param \context $context
* @return string
--- /dev/null
+{{!
+ This file is part of Moodle - http://moodle.org/
+
+ Moodle is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Moodle is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+}}
+{{!
+ @template core_analytics/insight_info_message
+
+ HTML message for insights
+
+ Classes required for JS:
+ * none
+
+ Data attributes required for JS:
+ * none
+
+ Example context (json):
+ {
+ "url": "https://moodle.org"
+ }
+}}
+<style>
+
+{{! Default btn-default styles. These styles are not applied to Moodle's web UI as there is a body:not(.dir-ltr):not(.dir-rtl)}}
+
+body:not(.dir-ltr):not(.dir-rtl) .btn-insight {
+ margin-bottom: 1rem!important;
+ margin-right: 1rem!important;
+ color: #212529;
+ background-color: #e9ecef;
+ border-color: #e9ecef
+ display: inline-block;
+ font-weight: 400;
+ text-align: center;
+ white-space: nowrap;
+ vertical-align: middle;
+ user-select: none;
+ border: 1px solid transparent;
+ padding: .375rem .75rem;
+ font-size: .9375rem;
+ line-height: 1.5;
+ border-radius: .25rem;
+ text-decoration: none;
+}
+</style>
+
+{{#str}} insightinfomessagehtml, analytics {{/str}}
+<br/><br/>
+<a class="btn btn-default btn-insight" href="{{url}}">{{#str}} viewinsight, analytics {{/str}}</a>
\ No newline at end of file
--- /dev/null
+{{!
+ This file is part of Moodle - http://moodle.org/
+
+ Moodle is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Moodle is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+}}
+{{!
+ @template core_analytics/insight_info_message_prediction
+
+ HTML message for insights with one single prediction
+
+ Classes required for JS:
+ * none
+
+ Data attributes required for JS:
+ * none
+
+ Example context (json):
+ {
+ "actions": [
+ {
+ "url": "https://moodle.org",
+ "text": "Moodle"
+ }, {
+ "url": "https://en.wikipedia.org/wiki/Noodle",
+ "text": "Noodle"
+ }
+ ]
+ }
+}}
+
+{{! Default btn-default styles. These styles are not applied to Moodle's web UI as there is a body:not(.dir-ltr):not(.dir-rtl)}}
+
+<style>
+body:not(.dir-ltr):not(.dir-rtl) .btn-insight {
+ margin-bottom: 1rem!important;
+ margin-right: 1rem!important;
+ color: #212529;
+ background-color: #e9ecef;
+ border-color: #e9ecef
+ display: inline-block;
+ font-weight: 400;
+ text-align: center;
+ white-space: nowrap;
+ vertical-align: middle;
+ user-select: none;
+ border: 1px solid transparent;
+ padding: .375rem .75rem;
+ font-size: .9375rem;
+ line-height: 1.5;
+ border-radius: .25rem;
+ text-decoration: none;
+}
+</style>
+
+<br/>
+{{#actions}}
+ <a class="btn btn-default m-r-1 m-b-1 btn-insight" href="{{url}}">{{text}}</a>
+{{/actions}}
$string['eventpredictionactionstarted'] = 'Prediction process started';
$string['eventinsightsviewed'] = 'Insights viewed';
$string['fixedack'] = 'Acknowledged';
-$string['insightmessagesubject'] = 'New insight for "{$a->contextname}": {$a->insightname}';
+$string['insightmessagesubject'] = 'New insight for "{$a}"';
$string['insightinfomessage'] = 'The system generated an insight for you: {$a}';
-$string['insightinfomessagehtml'] = 'The system generated an insight for you.<br/><br/><a class="btn btn-primary" href="{$a}">View insight</a>';
-$string['insightinfomessageprediction'] = 'Some suggested actions you could perform:
-
-{$a}';
-$string['insightinfomessagepredictionhtml'] = 'Some suggested actions you could perform:<br/><br/>{$a}';
+$string['insightinfomessagehtml'] = 'The system generated an insight for you.';
+$string['insightinfomessageaction'] = '{$a->text}: {$a->url}';
$string['invalidtimesplitting'] = 'Model with ID {$a} needs a time-splitting method before it can be used to train.';
$string['invalidanalysablefortimesplitting'] = 'It cannot be analysed using {$a} time-splitting method.';
$string['nocourses'] = 'No courses to analyse';