|
| 1 | +<?php |
| 2 | +// This file is part of Moodle - http://moodle.org/ |
| 3 | +// |
| 4 | +// Moodle is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// Moodle is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +/** |
| 18 | + * This file contains the backup structure code for mod_observation |
| 19 | + * |
| 20 | + * @package mod_observation |
| 21 | + * @copyright Catalyst IT Australia |
| 22 | + * @author Matthew Hilton |
| 23 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 24 | + */ |
| 25 | + |
| 26 | +/** |
| 27 | + * Structure step to backup one observation activity |
| 28 | + */ |
| 29 | +class backup_observation_activity_structure_step extends backup_activity_structure_step { |
| 30 | + |
| 31 | + /** |
| 32 | + * Define structure of backup |
| 33 | + */ |
| 34 | + protected function define_structure() { |
| 35 | + $userinfo = $this->get_setting_value('userinfo'); |
| 36 | + |
| 37 | + $observation = new backup_nested_element('observation', ['id'], [ |
| 38 | + 'name', |
| 39 | + 'intro', |
| 40 | + 'timemodified', |
| 41 | + 'observer_ins', |
| 42 | + 'observer_ins_f', |
| 43 | + 'observee_ins', |
| 44 | + 'observee_ins_f', |
| 45 | + 'students_self_unregister', |
| 46 | + 'marking_type' |
| 47 | + ]); |
| 48 | + |
| 49 | + $notifications = new backup_nested_element('notifications'); |
| 50 | + |
| 51 | + $notification = new backup_nested_element('notification', ['id'], [ |
| 52 | + 'timeslot_id', |
| 53 | + 'time_before' |
| 54 | + ]); |
| 55 | + |
| 56 | + $points = new backup_nested_element('points'); |
| 57 | + |
| 58 | + $point = new backup_nested_element('point', ['id'], [ |
| 59 | + 'obs_id', |
| 60 | + 'title', |
| 61 | + 'list_order', |
| 62 | + 'ins', |
| 63 | + 'ins_f', |
| 64 | + 'max_grade', |
| 65 | + 'res_type', |
| 66 | + 'file_size' |
| 67 | + ]); |
| 68 | + |
| 69 | + $responses = new backup_nested_element('responses'); |
| 70 | + |
| 71 | + $response = new backup_nested_element('response', ['id'], [ |
| 72 | + 'obs_pt_id', |
| 73 | + 'obs_ses_id', |
| 74 | + 'grade_given', |
| 75 | + 'response', |
| 76 | + 'ex_comment', |
| 77 | + 'timecreated', |
| 78 | + 'timemodified' |
| 79 | + ]); |
| 80 | + |
| 81 | + $sessions = new backup_nested_element('sessions'); |
| 82 | + |
| 83 | + $session = new backup_nested_element('session', ['id'], [ |
| 84 | + 'obs_id', |
| 85 | + 'observee_id', |
| 86 | + 'observer_id', |
| 87 | + 'state', |
| 88 | + 'start_time', |
| 89 | + 'finish_time', |
| 90 | + 'ex_comment' |
| 91 | + ]); |
| 92 | + |
| 93 | + $timeslots = new backup_nested_element('timeslots'); |
| 94 | + |
| 95 | + $timeslot = new backup_nested_element('timeslot', ['id'], [ |
| 96 | + 'obs_id', |
| 97 | + 'start_time', |
| 98 | + 'duration', |
| 99 | + 'observer_id', |
| 100 | + 'observee_id', |
| 101 | + 'observer_event_id', |
| 102 | + 'observee_event_id' |
| 103 | + ]); |
| 104 | + |
| 105 | + // Timeslots tree. |
| 106 | + $observation->add_child($timeslots); |
| 107 | + $timeslots->add_child($timeslot); |
| 108 | + $timeslot->add_child($notifications); |
| 109 | + $notifications->add_child($notification); |
| 110 | + |
| 111 | + // Points tree. |
| 112 | + $observation->add_child($points); |
| 113 | + $points->add_child($point); |
| 114 | + |
| 115 | + // Sessions tree. |
| 116 | + $observation->add_child($sessions); |
| 117 | + $sessions->add_child($session); |
| 118 | + |
| 119 | + // Responses tree. |
| 120 | + $session->add_child($responses); |
| 121 | + $responses->add_child($response); |
| 122 | + |
| 123 | + // Set table sources. |
| 124 | + $observation->set_source_table('observation', ['id' => backup::VAR_ACTIVITYID]); |
| 125 | + $point->set_source_table('observation_points', ['obs_id' => backup::VAR_PARENTID]); |
| 126 | + |
| 127 | + // These are only possible if user info is included. |
| 128 | + if ($userinfo || PHPUNIT_TEST) { |
| 129 | + $response->set_source_table('observation_point_responses', ['obs_ses_id' => backup::VAR_PARENTID]); |
| 130 | + $timeslot->set_source_table('observation_timeslots', ['obs_id' => backup::VAR_PARENTID]); |
| 131 | + $notification->set_source_table('observation_notifications', ['timeslot_id' => backup::VAR_PARENTID]); |
| 132 | + $session->set_source_table('observation_sessions', ['obs_id' => backup::VAR_PARENTID]); |
| 133 | + } |
| 134 | + |
| 135 | + // User ID annotations. |
| 136 | + $timeslot->annotate_ids('user', 'observee_id'); |
| 137 | + $timeslot->annotate_ids('user', 'observer_id'); |
| 138 | + |
| 139 | + $session->annotate_ids('user', 'observee_id'); |
| 140 | + $session->annotate_ids('user', 'observer_id'); |
| 141 | + |
| 142 | + // Annotate files. |
| 143 | + $response->annotate_files('mod_observation', 'response', 'id'); |
| 144 | + |
| 145 | + return $this->prepare_activity_structure($observation); |
| 146 | + } |
| 147 | +} |
0 commit comments