The structure of the course completion backup

@return backup_nested_element
354418
protected function define_structure() {

        $cc = new backup_nested_element('course_completion_defaults');

        $defaults = new backup_nested_element('course_completion_default', array('id'), array(
            'modulename', 'completion', 'completionview', 'completionusegrade', 'completionexpected', 'customrules'
        ));

        // Use module name instead of module id so we can insert into another site later.
        $sourcesql = "SELECT d.id, m.name as modulename, d.completion, d.completionview, d.completionusegrade,
                  d.completionexpected, d.customrules
                FROM {course_completion_defaults} d join {modules} m on d.module = m.id
                WHERE d.course = ?";
        $defaults->set_source_sql($sourcesql, array(backup::VAR_COURSEID));

        $cc->add_child($defaults);
        return $cc;

    }
499342
public function define_course_plugin_structure() {
        global $DB;

        // Since this method is executed before the restore we can do some pre-checks here.
        // In case of merging backup into existing course find the current number of sections.
        $target = $this->step->get_task()->get_target();
        if (($target == backup::TARGET_CURRENT_ADDING || $target == backup::TARGET_EXISTING_ADDING) &&
                $this->is_pre_33_backup()) {
            $maxsection = $DB->get_field_sql(
                'SELECT max(section) FROM {course_sections} WHERE course = ?',
                [$this->step->get_task()->get_courseid()]);
            $this->originalnumsections = (int)$maxsection;
        }

        // Dummy path element is needed in order for after_restore_course() to be called.
        return [new restore_path_element('dummy_course', $this->get_pathfor('/dummycourse'))];
    }
1173700
public function getOrganizationElement()
    {
        $element = $this->getElement($this->organizationFieldName);
        $orgId   = $this->getCurrentOrganizationId();
        $orgs    = $this->getLoginOrganizations();
        $hidden  = $this->_organizationFromUrl || (count($orgs) < 2);

        if ($hidden) {
            if (! $element instanceof \Zend_Form_Element_Hidden) {
                $element = new \Zend_Form_Element_Hidden($this->organizationFieldName);
                $this->addElement($element);
            }

            if (! $this->_organizationFromUrl) {
                $orgIds = array_keys($orgs);
                $orgId  = reset($orgIds);
            }

            $element->setValue($orgId);

        } elseif (! $element instanceof \Zend_Form_Element_Select) {
            $element = $this->createElement('select', $this->organizationFieldName);
            $element->setLabel($this->translate->_('Organization'));
            $element->setRegisterInArrayValidator(true);
            $element->setRequired(true);
            $element->setMultiOptions($orgs);

            if ($this->organizationMaxLines > 1) {
                $element->setAttrib('size', min(count($orgs) + 1, $this->organizationMaxLines));
            }
            $this->addElement($element);

            $element->setValue($orgId);
        }

        return $element;
    }
311202
public function description() {
        list($missingparent, $loops) = $this->find_problems();

        $description = '<p>The course categories should be arranged into tree ' .
                ' structures by the course_categories.parent field. Sometimes ' .
                ' this tree structure gets messed up.</p>';

        $description .= tool_health_category_list_missing_parents($missingparent);
        $description .= tool_health_category_list_loops($loops);

        return $description;
    }
507738
protected function define_question_plugin_structure() {
        $qtype = self::qtype_name();
        $plugin = $this->get_plugin_element(null, '../../qtype', $qtype);

        $pluginwrapper = new backup_nested_element($this->get_recommended_name());

        $plugin->add_child($pluginwrapper);

        $dds = new backup_nested_element($qtype, array('id'), array(
            'shuffleanswers', 'correctfeedback', 'correctfeedbackformat',
            'partiallycorrectfeedback', 'partiallycorrectfeedbackformat',
            'incorrectfeedback', 'incorrectfeedbackformat', 'shownumcorrect'));

        $pluginwrapper->add_child($dds);
        $drags = new backup_nested_element('drags');

        $drag = new backup_nested_element('drag', array('id'),
                                                array('no', 'draggroup', 'infinite', 'label'));
        $drops = new backup_nested_element('drops');

        $drop = new backup_nested_element('drop', array('id'),
                                                array('no', 'xleft', 'ytop', 'choice', 'label'));

        $dds->set_source_table("qtype_{$qtype}",
                                                array('questionid' => backup::VAR_PARENTID));

        $pluginwrapper->add_child($drags);
        $drags->add_child($drag);
        $pluginwrapper->add_child($drops);
        $drops->add_child($drop);

        $drag->set_source_table("qtype_{$qtype}_drags",
                                                    array('questionid' => backup::VAR_PARENTID));

        $drop->set_source_table("qtype_{$qtype}_drops",
                                                    array('questionid' => backup::VAR_PARENTID));

        return $plugin;
    }
608247
public function getCompleteChar(): string
    {
        if (null === $this->completeChar) {
            return $this->maxSteps ? '=' : $this->completeChar;
        }

        return $this->completeChar;
    }
242494
public function build() {

        // If we have decided not to backup blocks, prevent anything to be built
        if (!$this->get_setting_value('blocks')) {
            $this->built = true;
            return;
        }

        // If "child" of activity task and it has been excluded, nothing to do
        $parent = basename(dirname(dirname($this->taskbasepath)));
        if ($parent != 'course') {
            $includedsetting = $parent . '_included';
            if (!$this->get_setting_value($includedsetting)) {
                $this->built = true;
                return;
            }
        }

        // Process the block.xml common file (instance + positions)
        $this->add_step(new restore_block_instance_structure_step('block_commons', 'block.xml'));

        // Here we add all the common steps for any block and, in the point of interest
        // we call to define_my_steps() in order to get the particular ones inserted in place.
        $this->define_my_steps();

        // Restore block role assignments and overrides (internally will observe the role_assignments setting)
        $this->add_step(new restore_ras_and_caps_structure_step('block_ras_and_caps', 'roles.xml'));

        // Restore block comments (conditionally)
        if ($this->get_setting_value('comments')) {
            $this->add_step(new restore_comments_structure_step('block_comments', 'comments.xml'));
        }

        // Search reindexing (if enabled).
        if (\core_search\manager::is_indexing_enabled()) {
            $wholecourse = $this->get_target() == backup::TARGET_NEW_COURSE;
            $wholecourse = $wholecourse || $this->setting_exists('overwrite_conf') && $this->get_setting_value('overwrite_conf');
            if (!$wholecourse) {
                $this->add_step(new restore_block_search_index('block_search_index'));
            }
        }

        // At the end, mark it as built
        $this->built = true;
    }
619091
public function backupStructure(): string
	{
		// Fairly easy for SQLite...just query the master table
		$sql = 'SELECT "sql" FROM "sqlite_master"';
		$res = $this->getDriver()->query($sql);
		$result = $res->fetchAll(PDO::FETCH_ASSOC);

		$sqlArray = [];

		foreach($result as $r)
		{
			$sqlArray[] = $r['sql'];
		}

		return implode(";\n", $sqlArray) . ";";
	}
823495
protected function get_restore_content_dir() {
        $backupfile = null;
        $shortname = null;

        if (!empty($this->options['backupfile'])) {
            $backupfile = $this->options['backupfile'];
        } else if (!empty($this->options['templatecourse']) || is_numeric($this->options['templatecourse'])) {
            $shortname = $this->options['templatecourse'];
        }

        $errors = array();
        $dir = tool_uploadcourse_helper::get_restore_content_dir($backupfile, $shortname, $errors);
        if (!empty($errors)) {
            foreach ($errors as $key => $message) {
                $this->error($key, $message);
            }
            return false;
        } else if ($dir === false) {
            // We want to return null when nothing was wrong, but nothing was found.
            $dir = null;
        }

        if (empty($dir) && !empty($this->importoptions['restoredir'])) {
            $dir = $this->importoptions['restoredir'];
        }

        return $dir;
    }
659403
public function copyEmpty()
    {
        $class_name = get_class($this);
        $wrapper = new $class_name();

        $wrapper->row_wrapper_class = $this->row_wrapper_class;
        $wrapper->index_field = $this->index_field;
        $wrapper->options = $this->options;

        return $wrapper;
    }
470427
public function definition() {
        global $USER, $CFG, $DB;

        $courseconfig = get_config('moodlecourse');
        $mform = $this->_form;
        $course = $this->_customdata['course'];
        $completion = new completion_info($course);

        $params = array(
            'course'  => $course->id
        );

        // Check if there are existing criteria completions.
        if ($completion->is_course_locked()) {
            $mform->addElement('header', 'completionsettingslocked', get_string('completionsettingslocked', 'completion'));
            $mform->addElement('static', '', '', get_string('err_settingslocked', 'completion'));
            $mform->addElement('submit', 'settingsunlock', get_string('unlockcompletiondelete', 'completion'));
        }

        // Get array of all available aggregation methods.
        $aggregation_methods = $completion->get_aggregation_methods();

        // Overall criteria aggregation.
        $mform->addElement('header', 'overallcriteria', get_string('general', 'core_form'));
        // Map aggregation methods to context-sensitive human readable dropdown menu.
        $overallaggregationmenu = array();
        foreach ($aggregation_methods as $methodcode => $methodname) {
            if ($methodcode === COMPLETION_AGGREGATION_ALL) {
                $overallaggregationmenu[COMPLETION_AGGREGATION_ALL] = get_string('overallaggregation_all', 'core_completion');
            } else if ($methodcode === COMPLETION_AGGREGATION_ANY) {
                $overallaggregationmenu[COMPLETION_AGGREGATION_ANY] = get_string('overallaggregation_any', 'core_completion');
            } else {
                $overallaggregationmenu[$methodcode] = $methodname;
            }
        }
        $mform->addElement('select', 'overall_aggregation', get_string('overallaggregation', 'core_completion'), $overallaggregationmenu);
        $mform->setDefault('overall_aggregation', $completion->get_aggregation_method());

        // Activity completion criteria
        $label = get_string('coursecompletioncondition', 'core_completion', get_string('activitiescompleted', 'core_completion'));
        $mform->addElement('header', 'activitiescompleted', $label);
        // Get the list of currently specified conditions and expand the section if some are found.
        $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_ACTIVITY);
        if (!empty($current)) {
            $mform->setExpanded('activitiescompleted');
        }

        $activities = $completion->get_activities();
        if (!empty($activities)) {

            if (!$completion->is_course_locked()) {
                $this->add_checkbox_controller(1, null, null, 0);
            }
            foreach ($activities as $activity) {
                $params_a = array('moduleinstance' => $activity->id);
                $criteria = new completion_criteria_activity(array_merge($params, $params_a));
                $criteria->config_form_display($mform, $activity);
            }
            $mform->addElement('static', 'criteria_role_note', '', get_string('activitiescompletednote', 'core_completion'));

            if (count($activities) > 1) {
                // Map aggregation methods to context-sensitive human readable dropdown menu.
                $activityaggregationmenu = array();
                foreach ($aggregation_methods as $methodcode => $methodname) {
                    if ($methodcode === COMPLETION_AGGREGATION_ALL) {
                        $activityaggregationmenu[COMPLETION_AGGREGATION_ALL] = get_string('activityaggregation_all', 'core_completion');
                    } else if ($methodcode === COMPLETION_AGGREGATION_ANY) {
                        $activityaggregationmenu[COMPLETION_AGGREGATION_ANY] = get_string('activityaggregation_any', 'core_completion');
                    } else {
                        $activityaggregationmenu[$methodcode] = $methodname;
                    }
                }
                $mform->addElement('select', 'activity_aggregation', get_string('activityaggregation', 'core_completion'), $activityaggregationmenu);
                $mform->setDefault('activity_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_ACTIVITY));
            }

        } else {
            $mform->addElement('static', 'noactivities', '', get_string('err_noactivities', 'completion'));
        }

        // Course prerequisite completion criteria.
        $label = get_string('coursecompletioncondition', 'core_completion', get_string('dependenciescompleted', 'core_completion'));
        $mform->addElement('header', 'courseprerequisites', $label);
        // Get the list of currently specified conditions and expand the section if some are found.
        $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_COURSE);
        if (!empty($current)) {
            $mform->setExpanded('courseprerequisites');
        }

        // Get applicable courses (prerequisites).
        $selectedcourses = $DB->get_fieldset_sql("SELECT cc.courseinstance
                  FROM {course_completion_criteria} cc WHERE cc.course = ?", [$course->id]);
        $hasselectablecourses = core_course_category::search_courses(['onlywithcompletion' => true], ['limit' => 2]);
        unset($hasselectablecourses[$course->id]);
        if ($hasselectablecourses) {
            // Show multiselect box.
            $mform->addElement('course', 'criteria_course', get_string('coursesavailable', 'completion'),
                array('multiple' => 'multiple', 'onlywithcompletion' => true, 'exclude' => $course->id));
            $mform->setDefault('criteria_course', $selectedcourses);

            // Map aggregation methods to context-sensitive human readable dropdown menu.
            $courseaggregationmenu = array();
            foreach ($aggregation_methods as $methodcode => $methodname) {
                if ($methodcode === COMPLETION_AGGREGATION_ALL) {
                    $courseaggregationmenu[COMPLETION_AGGREGATION_ALL] = get_string('courseaggregation_all', 'core_completion');
                } else if ($methodcode === COMPLETION_AGGREGATION_ANY) {
                    $courseaggregationmenu[COMPLETION_AGGREGATION_ANY] = get_string('courseaggregation_any', 'core_completion');
                } else {
                    $courseaggregationmenu[$methodcode] = $methodname;
                }
            }
            $mform->addElement('select', 'course_aggregation', get_string('courseaggregation', 'core_completion'), $courseaggregationmenu);
            $mform->setDefault('course_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_COURSE));
        } else {
            $mform->addElement('static', 'nocourses', '', get_string('err_nocourses', 'completion'));
        }

        // Completion on date
        $label = get_string('coursecompletioncondition', 'core_completion', get_string('completionondate', 'core_completion'));
        $mform->addElement('header', 'date', $label);
        // Expand the condition section if it is currently enabled.
        $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_DATE);
        if (!empty($current)) {
            $mform->setExpanded('date');
        }
        $criteria = new completion_criteria_date($params);
        $criteria->config_form_display($mform);

        // Completion after enrolment duration
        $label = get_string('coursecompletioncondition', 'core_completion', get_string('enrolmentduration', 'core_completion'));
        $mform->addElement('header', 'duration', $label);
        // Expand the condition section if it is currently enabled.
        $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_DURATION);
        if (!empty($current)) {
            $mform->setExpanded('duration');
        }
        $criteria = new completion_criteria_duration($params);
        $criteria->config_form_display($mform);

        // Completion on unenrolment
        $label = get_string('coursecompletioncondition', 'core_completion', get_string('unenrolment', 'core_completion'));
        $mform->addElement('header', 'unenrolment', $label);
        // Expand the condition section if it is currently enabled.
        $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_UNENROL);
        if (!empty($current)) {
            $mform->setExpanded('unenrolment');
        }
        $criteria = new completion_criteria_unenrol($params);
        $criteria->config_form_display($mform);

        // Completion on course grade
        $label = get_string('coursecompletioncondition', 'core_completion', get_string('coursegrade', 'core_completion'));
        $mform->addElement('header', 'grade', $label);
        // Expand the condition section if it is currently enabled.
        $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_GRADE);
        if (!empty($current)) {
            $mform->setExpanded('grade');
        }
        $course_grade = $DB->get_field('grade_items', 'gradepass', array('courseid' => $course->id, 'itemtype' => 'course'));
        if (!$course_grade) {
            $course_grade = '0.00000';
        }
        $criteria = new completion_criteria_grade($params);
        $criteria->config_form_display($mform, $course_grade);

        // Manual self completion
        $label = get_string('coursecompletioncondition', 'core_completion', get_string('manualselfcompletion', 'core_completion'));
        $mform->addElement('header', 'manualselfcompletion', $label);
        // Expand the condition section if it is currently enabled.
        $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_SELF);
        if (!empty($current)) {
            $mform->setExpanded('manualselfcompletion');
        }
        $criteria = new completion_criteria_self($params);
        $criteria->config_form_display($mform);
        $mform->addElement('static', 'criteria_self_note', '', get_string('manualselfcompletionnote', 'core_completion'));

        // Role completion criteria
        $label = get_string('coursecompletioncondition', 'core_completion', get_string('manualcompletionby', 'core_completion'));
        $mform->addElement('header', 'roles', $label);
        // Expand the condition section if it is currently enabled.
        $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_ROLE);
        if (!empty($current)) {
            $mform->setExpanded('roles');
        }
        $roles = get_roles_with_capability('moodle/course:markcomplete', CAP_ALLOW, context_course::instance($course->id, IGNORE_MISSING));

        if (!empty($roles)) {
            foreach ($roles as $role) {
                $params_a = array('role' => $role->id);
                $criteria = new completion_criteria_role(array_merge($params, $params_a));
                $criteria->config_form_display($mform, $role);
            }
            $mform->addElement('static', 'criteria_role_note', '', get_string('manualcompletionbynote', 'core_completion'));
            // Map aggregation methods to context-sensitive human readable dropdown menu.
            $roleaggregationmenu = array();
            foreach ($aggregation_methods as $methodcode => $methodname) {
                if ($methodcode === COMPLETION_AGGREGATION_ALL) {
                    $roleaggregationmenu[COMPLETION_AGGREGATION_ALL] = get_string('roleaggregation_all', 'core_completion');
                } else if ($methodcode === COMPLETION_AGGREGATION_ANY) {
                    $roleaggregationmenu[COMPLETION_AGGREGATION_ANY] = get_string('roleaggregation_any', 'core_completion');
                } else {
                    $roleaggregationmenu[$methodcode] = $methodname;
                }
            }
            $mform->addElement('select', 'role_aggregation', get_string('roleaggregation', 'core_completion'), $roleaggregationmenu);
            $mform->setDefault('role_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_ROLE));

        } else {
            $mform->addElement('static', 'noroles', '', get_string('err_noroles', 'completion'));
        }

        // Add common action buttons.
        $this->add_action_buttons();

        // Add hidden fields.
        $mform->addElement('hidden', 'id', $course->id);
        $mform->setType('id', PARAM_INT);

        // If the criteria are locked, freeze values and submit button.
        if ($completion->is_course_locked()) {
            $except = array('settingsunlock');
            $mform->hardFreezeAllVisibleExcept($except);
            $mform->addElement('cancel');
        }
    }
369856
public function add_completion_rules() {
        $mform = $this->_form;

        $mform->addElement('checkbox', 'completionendreached', get_string('completionendreached', 'lesson'),
                get_string('completionendreached_desc', 'lesson'));
        // Enable this completion rule by default.
        $mform->setDefault('completionendreached', 1);

        $group = array();
        $group[] =& $mform->createElement('checkbox', 'completiontimespentenabled', '',
                get_string('completiontimespent', 'lesson'));
        $group[] =& $mform->createElement('duration', 'completiontimespent', '', array('optional' => false));
        $mform->addGroup($group, 'completiontimespentgroup', get_string('completiontimespentgroup', 'lesson'), array(' '), false);
        $mform->disabledIf('completiontimespent[number]', 'completiontimespentenabled', 'notchecked');
        $mform->disabledIf('completiontimespent[timeunit]', 'completiontimespentenabled', 'notchecked');

        return array('completionendreached', 'completiontimespentgroup');
    }
1026884
public function process_course_completion_criteria($data) {
        global $DB;

        $data = (object)$data;
        $data->course = $this->get_courseid();

        // Apply the date offset to the time end field
        $data->timeend = $this->apply_date_offset($data->timeend);

        // Map the role from the criteria
        if (isset($data->role) && $data->role != '') {
            // Newer backups should include roleshortname, which makes this much easier.
            if (!empty($data->roleshortname)) {
                $roleinstanceid = $DB->get_field('role', 'id', array('shortname' => $data->roleshortname));
                if (!$roleinstanceid) {
                    $this->log(
                        'Could not match the role shortname in course_completion_criteria, so skipping',
                        backup::LOG_DEBUG
                    );
                    return;
                }
                $data->role = $roleinstanceid;
            } else {
                $data->role = $this->get_mappingid('role', $data->role);
            }

            // Check we have an id, otherwise it causes all sorts of bugs.
            if (!$data->role) {
                $this->log(
                    'Could not match role in course_completion_criteria, so skipping',
                    backup::LOG_DEBUG
                );
                return;
            }
        }

        // If the completion criteria is for a module we need to map the module instance
        // to the new module id.
        if (!empty($data->moduleinstance) && !empty($data->module)) {
            $data->moduleinstance = $this->get_mappingid('course_module', $data->moduleinstance);
            if (empty($data->moduleinstance)) {
                $this->log(
                    'Could not match the module instance in course_completion_criteria, so skipping',
                    backup::LOG_DEBUG
                );
                return;
            }
        } else {
            $data->module = null;
            $data->moduleinstance = null;
        }

        // We backup the course shortname rather than the ID so that we can match back to the course
        if (!empty($data->courseinstanceshortname)) {
            $courseinstanceid = $DB->get_field('course', 'id', array('shortname'=>$data->courseinstanceshortname));
            if (!$courseinstanceid) {
                $this->log(
                    'Could not match the course instance in course_completion_criteria, so skipping',
                    backup::LOG_DEBUG
                );
                return;
            }
        } else {
            $courseinstanceid = null;
        }
        $data->courseinstance = $courseinstanceid;

        $params = array(
            'course'         => $data->course,
            'criteriatype'   => $data->criteriatype,
            'enrolperiod'    => $data->enrolperiod,
            'courseinstance' => $data->courseinstance,
            'module'         => $data->module,
            'moduleinstance' => $data->moduleinstance,
            'timeend'        => $data->timeend,
            'gradepass'      => $data->gradepass,
            'role'           => $data->role
        );
        $newid = $DB->insert_record('course_completion_criteria', $params);
        $this->set_mapping('course_completion_criteria', $data->id, $newid);
    }
398527
public function backups()
    {
        //Only admins can access this controller
        if (!$this->Auth->isGroup('admin')) {
            return;
        }

        $links[] = [__d('me_cms', 'List backups'), [
            'controller' => 'Backups',
            'action' => 'index',
            'plugin' => 'MeCms',
            'prefix' => ADMIN_PREFIX,
        ]];
        $links[] = [__d('me_cms', 'Add backup'), [
            'controller' => 'Backups',
            'action' => 'add',
            'plugin' => 'MeCms',
            'prefix' => ADMIN_PREFIX,
        ]];

        return [$links, __d('me_cms', 'Backups'), ['icon' => 'database']];
    }
405243
protected function SaveElement()
    {
        $this->confirm->SetErrorUrl($this->selectorError->Save($this->confirm->GetErrorUrl()));
        $this->confirm->SetSuccessUrl($this->selectorSuccess->Save($this->confirm->GetSuccessUrl()));
        return $this->confirm;
    }
623588
public function define_enrol_plugin_structure() {
        // Get the parent we will be adding these elements to.
        $plugin = $this->get_plugin_element();

        // Define our elements.
        $tool = new backup_nested_element('tool', array('id'), array(
            'enrolid', 'contextid', 'institution', 'lang', 'timezone', 'maxenrolled', 'maildisplay', 'city',
            'country', 'gradesync', 'gradesynccompletion', 'membersync', 'membersyncmode',  'roleinstructor',
            'rolelearner', 'secret', 'timecreated', 'timemodified'));

        $users = new backup_nested_element('users');

        $user = new backup_nested_element('user', array('id'), array(
            'userid', 'toolid', 'serviceurl', 'sourceid', 'consumerkey', 'consumersecret', 'membershipurl',
            'membershipsid'));

        // Build elements hierarchy.
        $plugin->add_child($tool);
        $tool->add_child($users);
        $users->add_child($user);

        // Set sources to populate the data.
        $tool->set_source_table('enrol_lti_tools',
            array('enrolid' => backup::VAR_PARENTID));

        // Users are only added only if users included.
        if ($this->task->get_setting_value('users')) {
            $user->set_source_table('enrol_lti_users', array('toolid' => backup::VAR_PARENTID));
        }
    }
555627
protected function define_instance_plugin_structure() {

        // Append data only if the ancestor 'definition' element has 'method' set to 'guide'.
        $plugin = $this->get_plugin_element(null, '../../../../method', 'guide');

        // Create a visible container for our data.
        $pluginwrapper = new backup_nested_element($this->get_recommended_name());

        // Connect our visible container to the parent.
        $plugin->add_child($pluginwrapper);

        // Define our elements.

        $fillings = new backup_nested_element('fillings');

        $filling = new backup_nested_element('filling', array('id'), array(
            'criterionid', 'remark', 'remarkformat', 'score'));

        // Build elements hierarchy.

        $pluginwrapper->add_child($fillings);
        $fillings->add_child($filling);

        // Set sources to populate the data.

        $filling->set_source_table('gradingform_guide_fillings',
            array('instanceid' => backup::VAR_PARENTID));

        // No need to annotate ids or files yet (one day when remark field supports
        // embedded fileds, they must be annotated here).

        return $plugin;
    }