Skip to content

Commit

Permalink
Merge branch 'MDL-60861-master' of git://github.com/ankitagarwal/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
Damyon Wiese committed Dec 12, 2017
2 parents 233c91e + 8d6b7f0 commit a576da5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
30 changes: 18 additions & 12 deletions admin/tool/analytics/classes/output/models_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public function export_for_template(\renderer_base $output) {
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?.
Expand Down Expand Up @@ -207,19 +210,22 @@ public function export_for_template(\renderer_base $output) {
}

// 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()) {
Expand Down
2 changes: 2 additions & 0 deletions admin/tool/analytics/lang/en/tool_analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
$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';
Expand Down
3 changes: 3 additions & 0 deletions admin/tool/analytics/templates/models_list.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@
{{/timesplitting}}
{{^timesplitting}}
{{#str}}notdefined, tool_analytics{{/str}}
{{#timesplittinghelp}}
{{>core/help_icon}}
{{/timesplittinghelp}}
{{/timesplitting}}
</td>
<td>
Expand Down
4 changes: 4 additions & 0 deletions analytics/classes/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,10 @@ public function enable($timesplittingid = false) {
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.
Expand Down
2 changes: 1 addition & 1 deletion analytics/tests/model_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function test_unique_id() {
$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.
Expand Down

0 comments on commit a576da5

Please sign in to comment.