Gitlab CSE Unil

restore_assignfeedback_editpdfplus_subplugin.class.php 3.46 KB
Newer Older
M. Chardon's avatar
init  
M. Chardon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * This file contains the restore code for the feedback_editpdfplus plugin.
 *
 * @package   assignfeedback_editpdfplus
 * @copyright 2013 Damyon Wiese
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
defined('MOODLE_INTERNAL') || die();

/**
 * Restore subplugin class.
 *
 * Provides the necessary information needed
 * to restore one assign_feedback subplugin.
 *
 * @package   assignfeedback_editpdfplus
 * @copyright 2013 Damyon Wiese
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class restore_assignfeedback_editpdfplus_subplugin extends restore_subplugin {

    /**
     * Returns the paths to be handled by the subplugin at assignment level
     * @return array
     */
    protected function define_grade_subplugin_structure() {

        $paths = array();

        // We used get_recommended_name() so this works.
        // The files node is a placeholder just containing gradeid so we can restore files once per grade.
        $elename = $this->get_namefor('files');
        $elepath = $this->get_pathfor('/feedback_editpdfplus_files');
        $paths[] = new restore_path_element($elename, $elepath);

        // Now we have the list of comments and annotations per grade.
M. Chardon's avatar
M. Chardon committed
53
        $elename = $this->get_namefor('feedback_editpdfplus_annotation');
54
          $elepath = $this->get_pathfor('/feedback_editpdfplus_annotations/feedback_editpdfplus_annotation');
M. Chardon's avatar
init  
M. Chardon committed
55
56
57
58
59
60
61
62
63
64
65
66
        $paths[] = new restore_path_element($elename, $elepath);

        return $paths;
    }

    /**
     * Processes one feedback_editpdfplus_files element
     * @param mixed $data
     */
    public function process_assignfeedback_editpdfplus_files($data) {
        $data = (object)$data;

67
68
69
70
71
          // In this case the id is the old gradeid which will be mapped.
          $this->add_related_files('assignfeedback_editpdfplus',
          \assignfeedback_editpdfplus\document_services::FINAL_PDF_FILEAREA, 'grade', null, $data->gradeid);
          $this->add_related_files('assignfeedback_editpdfplus',
          \assignfeedback_editpdfplus\document_services::PAGE_IMAGE_READONLY_FILEAREA, 'grade', null, $data->gradeid);
M. Chardon's avatar
init  
M. Chardon committed
72
73
74
75
76
77
78
        $this->add_related_files('assignfeedback_editpdfplus', 'stamps', 'grade', null, $data->gradeid);
    }

    /**
     * Processes one feedback_editpdfplus_annotations/annotation element
     * @param mixed $data
     */
M. Chardon's avatar
M. Chardon committed
79
    public function process_assignfeedback_editpdfplus_feedback_editpdfplus_annotation($data) {
M. Chardon's avatar
init  
M. Chardon committed
80
81
        global $DB;

82
83
84
85
86
          $data = (object)$data;
          $oldgradeid = $data->gradeid;
          // The mapping is set in the restore for the core assign activity
          // when a grade node is processed.
          $data->gradeid = $this->get_mappingid('grade', $data->gradeid);
M. Chardon's avatar
init  
M. Chardon committed
87

88
          $DB->insert_record('assignfeedback_editpp_annot', $data);
M. Chardon's avatar
init  
M. Chardon committed
89
90
91
92

    }

}