$actionsmenu->add($icon);
}
+ // Enable / disable.
+ if ($model->is_enabled()) {
+ $action = 'disable';
+ $text = get_string('disable');
+ $icontype = 't/block';
+ } else {
+ $action = 'enable';
+ $text = get_string('enable');
+ $icontype = 'i/checked';
+ }
+ $url = new \moodle_url('model.php', array('action' => $action, 'id' => $model->get_id()));
+ $icon = new \action_menu_link_secondary($url, new \pix_icon($icontype, $text), $text);
+ $actionsmenu->add($icon);
+
// Evaluate machine-learning-based models.
if ($model->get_indicators() && !$model->is_static()) {
$url = new \moodle_url('model.php', array('action' => 'evaluate', 'id' => $model->get_id()));
case 'log':
$title = get_string('viewlog', 'tool_analytics');
break;
+ case 'enable':
+ $title = get_string('enable');
+ break;
+ case 'disable':
+ $title = get_string('disable');
+ break;
+
default:
throw new moodle_exception('errorunknownaction', 'analytics');
}
switch ($action) {
+ case 'enable':
+ $model->enable();
+ redirect(new \moodle_url('/admin/tool/analytics/index.php'));
+
+ case 'disable':
+ $model->update(0, false, false);
+ redirect(new \moodle_url('/admin/tool/analytics/index.php'));
+
case 'edit':
if ($model->is_static()) {
* Updates the model.
*
* @param int|bool $enabled
- * @param \core_analytics\local\indicator\base[] $indicators
- * @param string $timesplittingid
+ * @param \core_analytics\local\indicator\base[]|false $indicators False to respect current indicators
+ * @param string|false $timesplittingid False to respect current time splitting method
* @return void
*/
- public function update($enabled, $indicators, $timesplittingid = '') {
+ public function update($enabled, $indicators = false, $timesplittingid = '') {
global $USER, $DB;
\core_analytics\manager::check_can_manage_models();
$now = time();
- $indicatorclasses = self::indicator_classes($indicators);
+ if ($indicators !== false) {
+ $indicatorclasses = self::indicator_classes($indicators);
+ $indicatorsstr = json_encode($indicatorclasses);
+ } else {
+ // Respect current value.
+ $indicatorsstr = $this->model->indicators;
+ }
+
+ if ($timesplittingid === false) {
+ // Respect current value.
+ $timesplittingid = $this->model->timesplitting;
+ }
- $indicatorsstr = json_encode($indicatorclasses);
if ($this->model->timesplitting !== $timesplittingid ||
$this->model->indicators !== $indicatorsstr) {
// We update the version of the model so different time splittings are not mixed up.
/**
* Enabled the model using the provided time splitting method.
*
- * @param string $timesplittingid
+ * @param string|false $timesplittingid False to respect the current time splitting method.
* @return void
*/
public function enable($timesplittingid = false) {