diff --git a/admin/tool/analytics/classes/output/models_list.php b/admin/tool/analytics/classes/output/models_list.php index 181b48dc48f..36f1febbcae 100644 --- a/admin/tool/analytics/classes/output/models_list.php +++ b/admin/tool/analytics/classes/output/models_list.php @@ -117,6 +117,20 @@ class models_list implements \renderable, \templatable { $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())); diff --git a/admin/tool/analytics/model.php b/admin/tool/analytics/model.php index 2c641791262..9ef3c3d49d9 100644 --- a/admin/tool/analytics/model.php +++ b/admin/tool/analytics/model.php @@ -51,6 +51,13 @@ switch ($action) { 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'); } @@ -63,6 +70,14 @@ $PAGE->set_heading($title); 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()) { diff --git a/analytics/classes/model.php b/analytics/classes/model.php index 79352cb2c27..985d6551c85 100644 --- a/analytics/classes/model.php +++ b/analytics/classes/model.php @@ -395,20 +395,30 @@ class model { * 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. @@ -900,7 +910,7 @@ class model { /** * 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) {