Feature: Prevent students from sharing device while self-marking.
[moodle-mod_attendance.git] / backup / moodle2 / backup_attendance_stepslib.php
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 * Defines all the backup steps that will be used by {@link backup_attendance_activity_task}
19 *
20 * @package mod_attendance
21 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25 defined('MOODLE_INTERNAL') || die();
26
27 /**
28 * Defines the complete attendance structure for backup, with file and id annotations
29 *
30 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32 */
33 class backup_attendance_activity_structure_step extends backup_activity_structure_step {
34
35 /**
36 * Define the structure of the backup workflow.
37 *
38 * @return restore_path_element $structure
39 */
40 protected function define_structure() {
41
42 // Are we including userinfo?
43 $userinfo = $this->get_setting_value('userinfo');
44
45 // XML nodes declaration - non-user data.
46 $attendance = new backup_nested_element('attendance', array('id'), array(
47 'name', 'intro', 'introformat', 'grade', 'showextrauserdetails', 'showsessiondetails', 'sessiondetailspos', 'subnet'));
48
49 $statuses = new backup_nested_element('statuses');
50 $status = new backup_nested_element('status', array('id'), array(
51 'acronym', 'description', 'grade', 'studentavailability', 'setunmarked', 'visible', 'deleted', 'setnumber'));
52
53 $warnings = new backup_nested_element('warnings');
54 $warning = new backup_nested_element('warning', array('id'), array('warningpercent', 'warnafter',
55 'maxwarn', 'emailuser', 'emailsubject', 'emailcontent', 'emailcontentformat', 'thirdpartyemails'));
56
57 $sessions = new backup_nested_element('sessions');
58 $session = new backup_nested_element('session', array('id'), array(
59 'groupid', 'sessdate', 'duration', 'lasttaken', 'lasttakenby', 'timemodified',
60 'description', 'descriptionformat', 'studentscanmark', 'studentpassword', 'autoassignstatus',
61 'subnet', 'automark', 'automarkcompleted', 'statusset', 'absenteereport', 'preventsharedip',
62 'preventsharediptime', 'caleventid'));
63
64 // XML nodes declaration - user data.
65 $logs = new backup_nested_element('logs');
66 $log = new backup_nested_element('log', array('id'), array(
67 'sessionid', 'studentid', 'statusid', 'statusset', 'timetaken', 'takenby', 'remarks'));
68
69 // Build the tree in the order needed for restore.
70 $attendance->add_child($statuses);
71 $statuses->add_child($status);
72
73 $attendance->add_child($warnings);
74 $warnings->add_child($warning);
75
76 $attendance->add_child($sessions);
77 $sessions->add_child($session);
78
79 $session->add_child($logs);
80 $logs->add_child($log);
81
82 // Data sources - non-user data.
83
84 $attendance->set_source_table('attendance', array('id' => backup::VAR_ACTIVITYID));
85
86 $status->set_source_table('attendance_statuses', array('attendanceid' => backup::VAR_PARENTID));
87
88 $warning->set_source_table('attendance_warning',
89 array('idnumber' => backup::VAR_PARENTID));
90
91 $session->set_source_table('attendance_sessions', array('attendanceid' => backup::VAR_PARENTID));
92
93 // Data sources - user related data.
94 if ($userinfo) {
95 $log->set_source_table('attendance_log', array('sessionid' => backup::VAR_PARENTID));
96 }
97
98 // Id annotations.
99 $session->annotate_ids('user', 'lasttakenby');
100 $session->annotate_ids('group', 'groupid');
101 $log->annotate_ids('user', 'studentid');
102 $log->annotate_ids('user', 'takenby');
103
104 // File annotations.
105 $session->annotate_files('mod_attendance', 'session', 'id');
106
107 // Return the root element (workshop), wrapped into standard activity structure.
108 return $this->prepare_activity_structure($attendance);
109 }
110 }