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 { ...@@ -119,6 +119,9 @@ class models_list implements \renderable, \templatable {
debugging("The time splitting method '{$modeldata->timesplitting}' should include a '{$identifier}_help' debugging("The time splitting method '{$modeldata->timesplitting}' should include a '{$identifier}_help'
string to describe its purpose.", DEBUG_DEVELOPER); 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?. // Has this model generated predictions?.
...@@ -207,19 +210,22 @@ class models_list implements \renderable, \templatable { ...@@ -207,19 +210,22 @@ class models_list implements \renderable, \templatable {
} }
// Enable / disable. // Enable / disable.
if ($model->is_enabled()) { if ($model->is_enabled() || !empty($modeldata->timesplitting)) {
$action = 'disable'; // If there is no timesplitting method set, the model can not be enabled.
$text = get_string('disable'); if ($model->is_enabled()) {
$icontype = 't/block'; $action = 'disable';
} else { $text = get_string('disable');
$action = 'enable'; $icontype = 't/block';
$text = get_string('enable'); } else {
$icontype = 'i/checked'; $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. // Export training data.
if (!$model->is_static() && $model->is_trained()) { if (!$model->is_static() && $model->is_trained()) {
......
...@@ -85,6 +85,8 @@ $string['previouspage'] = 'Previous page'; ...@@ -85,6 +85,8 @@ $string['previouspage'] = 'Previous page';
$string['samestartdate'] = 'Current start date is good'; $string['samestartdate'] = 'Current start date is good';
$string['sameenddate'] = 'Current end date is good'; $string['sameenddate'] = 'Current end date is good';
$string['target'] = 'Target'; $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['trainandpredictmodel'] = 'Training model and calculating predictions';
$string['trainingprocessfinished'] = 'Training process finished'; $string['trainingprocessfinished'] = 'Training process finished';
$string['trainingresults'] = 'Training results'; $string['trainingresults'] = 'Training results';
......
...@@ -160,6 +160,9 @@ ...@@ -160,6 +160,9 @@
{{/timesplitting}} {{/timesplitting}}
{{^timesplitting}} {{^timesplitting}}
{{#str}}notdefined, tool_analytics{{/str}} {{#str}}notdefined, tool_analytics{{/str}}
{{#timesplittinghelp}}
{{>core/help_icon}}
{{/timesplittinghelp}}
{{/timesplitting}} {{/timesplitting}}
</td> </td>
<td> <td>
......
...@@ -1013,6 +1013,10 @@ class model { ...@@ -1013,6 +1013,10 @@ class model {
if (!$this->is_static()) { if (!$this->is_static()) {
$this->model->trained = 0; $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. // Purge pages with insights as this may change things.
......
...@@ -226,7 +226,7 @@ class analytics_model_testcase extends advanced_testcase { ...@@ -226,7 +226,7 @@ class analytics_model_testcase extends advanced_testcase {
$this->model->mark_as_trained(); $this->model->mark_as_trained();
$this->assertEquals($originaluniqueid, $this->model->get_unique_id()); $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()); $this->assertEquals($originaluniqueid, $this->model->get_unique_id());
// Wait 1 sec so the timestamp changes. // Wait 1 sec so the timestamp changes.
......
Supports Markdown
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