Commit a576da55 authored by Damyon Wiese's avatar Damyon Wiese
Browse files

Merge branch 'MDL-60861-master' of git://github.com/ankitagarwal/moodle

parents 233c91e7 8d6b7f0c
......@@ -119,6 +119,9 @@ class models_list implements \renderable, \templatable {
debugging("The time splitting method '{$modeldata->timesplitting}' should include a '{$identifier}_help'
string to describe its purpose.", DEBUG_DEVELOPER);
}
} else {
$helpicon = new \help_icon('timesplittingnotdefined', 'tool_analytics');
$modeldata->timesplittinghelp = $helpicon->export_for_template($output);
}
// Has this model generated predictions?.
......@@ -207,19 +210,22 @@ class models_list implements \renderable, \templatable {
}
// 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';
if ($model->is_enabled() || !empty($modeldata->timesplitting)) {
// If there is no timesplitting method set, the model can not be enabled.
if ($model->is_enabled()) {
$action = 'disable';
$text = get_string('disable');
$icontype = 't/block';
} else {
$action = 'enable';
$text = get_string('enable');
$icontype = 'i/checked';
}
$urlparams['action'] = $action;
$url = new \moodle_url('model.php', $urlparams);
$icon = new \action_menu_link_secondary($url, new \pix_icon($icontype, $text), $text);
$actionsmenu->add($icon);
}
$urlparams['action'] = $action;
$url = new \moodle_url('model.php', $urlparams);
$icon = new \action_menu_link_secondary($url, new \pix_icon($icontype, $text), $text);
$actionsmenu->add($icon);
// Export training data.
if (!$model->is_static() && $model->is_trained()) {
......
......@@ -85,6 +85,8 @@ $string['previouspage'] = 'Previous page';
$string['samestartdate'] = 'Current start date is good';
$string['sameenddate'] = 'Current end date is good';
$string['target'] = 'Target';
$string['timesplittingnotdefined'] = 'Time splitting is not defined.';
$string['timesplittingnotdefined_help'] = 'You need to select a time-splitting method before enabling the model.';
$string['trainandpredictmodel'] = 'Training model and calculating predictions';
$string['trainingprocessfinished'] = 'Training process finished';
$string['trainingresults'] = 'Training results';
......
......@@ -160,6 +160,9 @@
{{/timesplitting}}
{{^timesplitting}}
{{#str}}notdefined, tool_analytics{{/str}}
{{#timesplittinghelp}}
{{>core/help_icon}}
{{/timesplittinghelp}}
{{/timesplitting}}
</td>
<td>
......
......@@ -1013,6 +1013,10 @@ class model {
if (!$this->is_static()) {
$this->model->trained = 0;
}
} else if (empty($this->model->timesplitting)) {
// A valid timesplitting method needs to be supplied before a model can be enabled.
throw new \moodle_exception('invalidtimesplitting', 'analytics', '', $this->model->id);
}
// Purge pages with insights as this may change things.
......
......@@ -226,7 +226,7 @@ class analytics_model_testcase extends advanced_testcase {
$this->model->mark_as_trained();
$this->assertEquals($originaluniqueid, $this->model->get_unique_id());
$this->model->enable();
$this->model->enable('\core\analytics\time_splitting\deciles');
$this->assertEquals($originaluniqueid, $this->model->get_unique_id());
// Wait 1 sec so the timestamp changes.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment