mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 10:26:40 +02:00
MDL-64786 analytics: Allow renaming models via inplace editable element
This commit is contained in:
parent
6482734681
commit
066a4d6493
10 changed files with 170 additions and 10 deletions
|
@ -1446,7 +1446,10 @@ class model {
|
|||
\core_analytics\manager::check_can_manage_models();
|
||||
|
||||
$data = clone $this->model;
|
||||
|
||||
$data->name = $this->inplace_editable_name()->export_for_template($output);
|
||||
$data->target = $this->get_target()->get_name();
|
||||
$data->targetclass = $this->get_target()->get_id();
|
||||
|
||||
if ($timesplitting = $this->get_time_splitting()) {
|
||||
$data->timesplitting = $timesplitting->get_name();
|
||||
|
@ -1691,6 +1694,54 @@ class model {
|
|||
$DB->update_record('analytics_models', $this->model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the model.
|
||||
*
|
||||
* By default, models use their target's name as their own name. They can have their explicit name, too. In which
|
||||
* case, the explicit name is used instead of the default one.
|
||||
*
|
||||
* @return string|lang_string
|
||||
*/
|
||||
public function get_name() {
|
||||
|
||||
if (trim($this->model->name) === '') {
|
||||
return $this->get_target()->get_name();
|
||||
|
||||
} else {
|
||||
return $this->model->name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renames the model to the given name.
|
||||
*
|
||||
* When given an empty string, the model falls back to using the associated target's name as its name.
|
||||
*
|
||||
* @param string $name The new name for the model, empty string for using the default name.
|
||||
*/
|
||||
public function rename(string $name) {
|
||||
global $DB, $USER;
|
||||
|
||||
$this->model->name = $name;
|
||||
$this->model->timemodified = time();
|
||||
$this->model->usermodified = $USER->id;
|
||||
|
||||
$DB->update_record('analytics_models', $this->model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an inplace editable element with the model's name.
|
||||
*
|
||||
* @return \core\output\inplace_editable
|
||||
*/
|
||||
public function inplace_editable_name() {
|
||||
|
||||
$displayname = format_string($this->get_name());
|
||||
|
||||
return new \core\output\inplace_editable('core_analytics', 'modelname', $this->model->id,
|
||||
has_capability('moodle/analytics:managemodels', \context_system::instance()), $displayname, $this->model->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the id from {analytics_predictions} db table to the prediction \stdClass objects.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue