Merge branch 'MDL-59307_master' of git://github.com/dmonllao/moodle

This commit is contained in:
Andrew Nicols 2017-07-31 10:12:02 +08:00
commit d267d66fdf
3 changed files with 45 additions and 6 deletions

View file

@ -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()));

View file

@ -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()) {

View file

@ -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();
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;
}
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) {