mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-53716 competency: Backup and restore course competency user data
This commit is contained in:
parent
6bd3ab0717
commit
e9114a9ed4
@ -1541,6 +1541,8 @@ class backup_activity_logstores_structure_step extends backup_course_logstores_s
|
||||
class backup_course_competencies_structure_step extends backup_structure_step {
|
||||
|
||||
protected function define_structure() {
|
||||
$userinfo = $this->get_setting_value('users');
|
||||
|
||||
$wrapper = new backup_nested_element('course_competencies');
|
||||
|
||||
$settings = new backup_nested_element('settings', array('id'), array('pushratingstouserplans'));
|
||||
@ -1554,11 +1556,11 @@ class backup_course_competencies_structure_step extends backup_structure_step {
|
||||
$competencies = new backup_nested_element('competencies');
|
||||
$wrapper->add_child($competencies);
|
||||
|
||||
$competency = new backup_nested_element('competency', null, array('idnumber', 'ruleoutcome',
|
||||
'sortorder', 'frameworkidnumber'));
|
||||
$competency = new backup_nested_element('competency', null, array('id', 'idnumber', 'ruleoutcome',
|
||||
'sortorder', 'frameworkid', 'frameworkidnumber'));
|
||||
$competencies->add_child($competency);
|
||||
|
||||
$sql = 'SELECT c.idnumber, cc.ruleoutcome, cc.sortorder, f.idnumber AS frameworkidnumber
|
||||
$sql = 'SELECT c.id, c.idnumber, cc.ruleoutcome, cc.sortorder, f.id AS frameworkid, f.idnumber AS frameworkidnumber
|
||||
FROM {' . \core_competency\course_competency::TABLE . '} cc
|
||||
JOIN {' . \core_competency\competency::TABLE . '} c ON c.id = cc.competencyid
|
||||
JOIN {' . \core_competency\competency_framework::TABLE . '} f ON f.id = c.competencyframeworkid
|
||||
@ -1566,6 +1568,21 @@ class backup_course_competencies_structure_step extends backup_structure_step {
|
||||
ORDER BY cc.sortorder';
|
||||
$competency->set_source_sql($sql, array('courseid' => backup::VAR_COURSEID));
|
||||
|
||||
$usercomps = new backup_nested_element('user_competencies');
|
||||
$wrapper->add_child($usercomps);
|
||||
if ($userinfo) {
|
||||
$usercomp = new backup_nested_element('user_competency', null, array('userid', 'competencyid',
|
||||
'proficiency', 'grade'));
|
||||
$usercomps->add_child($usercomp);
|
||||
|
||||
$sql = 'SELECT ucc.userid, ucc.competencyid, ucc.proficiency, ucc.grade
|
||||
FROM {' . \core_competency\user_competency_course::TABLE . '} ucc
|
||||
WHERE ucc.courseid = :courseid
|
||||
AND ucc.grade IS NOT NULL';
|
||||
$usercomp->set_source_sql($sql, array('courseid' => backup::VAR_COURSEID));
|
||||
$usercomp->annotate_ids('user', 'userid');
|
||||
}
|
||||
|
||||
return $wrapper;
|
||||
}
|
||||
}
|
||||
|
@ -3066,10 +3066,15 @@ class restore_course_competencies_structure_step extends restore_structure_step
|
||||
* @return array
|
||||
*/
|
||||
protected function define_structure() {
|
||||
$userinfo = $this->get_setting_value('users');
|
||||
$paths = array(
|
||||
new restore_path_element('course_competency', '/course_competencies/competencies/competency'),
|
||||
new restore_path_element('course_competency_settings', '/course_competencies/settings')
|
||||
new restore_path_element('course_competency_settings', '/course_competencies/settings'),
|
||||
);
|
||||
if ($userinfo) {
|
||||
$paths[] = new restore_path_element('user_competency_course',
|
||||
'/course_competencies/user_competencies/user_competency');
|
||||
}
|
||||
return $paths;
|
||||
}
|
||||
|
||||
@ -3080,22 +3085,27 @@ class restore_course_competencies_structure_step extends restore_structure_step
|
||||
*/
|
||||
public function process_course_competency_settings($data) {
|
||||
global $DB;
|
||||
|
||||
$data = (object) $data;
|
||||
$courseid = $this->task->get_courseid();
|
||||
$exists = \core_competency\course_competency_settings::get_record(array('courseid' => $courseid));
|
||||
|
||||
// Now update or insert.
|
||||
// We do not restore the course settings during merge.
|
||||
$target = $this->get_task()->get_target();
|
||||
if ($target == backup::TARGET_CURRENT_ADDING || $target == backup::TARGET_EXISTING_ADDING) {
|
||||
return;
|
||||
}
|
||||
|
||||
$courseid = $this->task->get_courseid();
|
||||
$exists = \core_competency\course_competency_settings::record_exists_select('courseid = :courseid',
|
||||
array('courseid' => $courseid));
|
||||
|
||||
// Strangely the course settings already exist, let's just leave them as is then.
|
||||
if ($exists) {
|
||||
$settings = $exists;
|
||||
$settings->set_pushratingstouserplans($data->pushratingstouserplans);
|
||||
return $settings->update();
|
||||
} else {
|
||||
$this->log('Course competency settings not restored, existing settings have been found.', backup::LOG_WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
$data = (object) array('courseid' => $courseid, 'pushratingstouserplans' => $data->pushratingstouserplans);
|
||||
$settings = new \core_competency\course_competency_settings(0, $data);
|
||||
$result = $settings->create();
|
||||
return !empty($result);
|
||||
}
|
||||
$settings->create();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3116,6 +3126,7 @@ class restore_course_competencies_structure_step extends restore_structure_step
|
||||
if (!$competency) {
|
||||
return;
|
||||
}
|
||||
$this->set_mapping(\core_competency\competency::TABLE, $data->id, $competency->get_id());
|
||||
|
||||
$params = array(
|
||||
'competencyid' => $competency->get_id(),
|
||||
@ -3133,6 +3144,41 @@ class restore_course_competencies_structure_step extends restore_structure_step
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the user competency course.
|
||||
*
|
||||
* @param array $data The data.
|
||||
*/
|
||||
public function process_user_competency_course($data) {
|
||||
global $USER, $DB;
|
||||
$data = (object) $data;
|
||||
|
||||
$data->competencyid = $this->get_mappingid(\core_competency\competency::TABLE, $data->competencyid);
|
||||
if (!$data->competencyid) {
|
||||
// This is strange, the competency does not belong to the course.
|
||||
return;
|
||||
} else if ($data->grade === null) {
|
||||
// We do not need to do anything when there is no grade.
|
||||
return;
|
||||
}
|
||||
|
||||
$data->userid = $this->get_mappingid('user', $data->userid);
|
||||
$shortname = $DB->get_field('course', 'shortname', array('id' => $this->task->get_courseid()), MUST_EXIST);
|
||||
|
||||
// The method add_evidence also sets the course rating.
|
||||
\core_competency\api::add_evidence($data->userid,
|
||||
$data->competencyid,
|
||||
$this->task->get_contextid(),
|
||||
\core_competency\evidence::ACTION_OVERRIDE,
|
||||
'evidence_courserestored',
|
||||
'core_competency',
|
||||
$shortname,
|
||||
false,
|
||||
null,
|
||||
$data->grade,
|
||||
$USER->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute conditions.
|
||||
*
|
||||
|
@ -95,6 +95,7 @@ $string['eventuserevidenceupdated'] = 'Evidence of prior learning updated.';
|
||||
$string['evidence_competencyrule'] = 'The rule of the competency was met.';
|
||||
$string['evidence_coursecompleted'] = 'The course \'{$a}\' was completed.';
|
||||
$string['evidence_coursemodulecompleted'] = 'The activity \'{$a}\' was completed.';
|
||||
$string['evidence_courserestored'] = 'The rating was restored along with the course \'{$a}\'.';
|
||||
$string['evidence_evidenceofpriorlearninglinked'] = 'The evidence of prior learning \'{$a}\' was linked.';
|
||||
$string['evidence_evidenceofpriorlearningunlinked'] = 'The evidence of prior learning \'{$a}\' was unlinked.';
|
||||
$string['evidence_manualoverride'] = 'The competency rating was manually set.';
|
||||
|
Loading…
x
Reference in New Issue
Block a user