This repository was archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackuplib.php
More file actions
261 lines (235 loc) · 9.73 KB
/
backuplib.php
File metadata and controls
261 lines (235 loc) · 9.73 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<?php //$Id: backuplib.php,v 1.2.10.4 2011/03/15 21:46:17 diml Exp $
/**
* This php script contains all the stuff to backup/restore
* scheduler mods
*
* @package mod-scheduler
* @category mod
* @author Gustav delius < 1.8
* @author Valery Fremaux (valery.fremaux@club-internet.fr)
*
*/
//This is the "graphical" structure of the scheduler mod:
//
// scheduler
// (CL, pk->id)
// |
// |
// |
// scheduler_slots
// (UL, pk->id, fk->scheduler)
//
// Meaning: pk->primary key field of the table
// fk->foreign key to link with parent
// nt->nested field (recursive data)
// CL->course level info
// UL->user level info
// files->table may have files
//
//-----------------------------------------------------------
/**
* Includes and requires
*/
include_once $CFG->dirroot."/mod/scheduler/locallib.php";
/**
*
*/
function scheduler_backup_mods($bf, $preferences) {
//Iterate over scheduler table
$schedulers = get_records ('scheduler', 'course', $preferences->backup_course, 'id');
if ($schedulers) {
foreach ($schedulers as $scheduler) {
scheduler_backup_one_mod($bf, $preferences, $scheduler);
}
}
}
/**
*
*/
function scheduler_backup_one_mod($bf, $preferences, $scheduler) {
global $CFG;
if (is_numeric($scheduler)) {
$scheduler = get_record('scheduler', 'id', $scheduler);
}
$status = true;
//Start mod
$status = $status && fwrite ($bf, start_tag('MOD', 3, true));
//Print scheduler data
fwrite ($bf, full_tag('ID', 4, false, $scheduler->id));
fwrite ($bf, full_tag('MODTYPE', 4, false, 'scheduler'));
fwrite ($bf, full_tag('NAME', 4, false, $scheduler->name));
fwrite ($bf, full_tag('DESCRIPTION', 4, false, $scheduler->description));
fwrite ($bf, full_tag('TEACHER', 4, false, $scheduler->teacher));
fwrite ($bf, full_tag('SCALE', 4, false, $scheduler->scale));
fwrite ($bf, full_tag('STAFFROLENAME', 4, false, $scheduler->staffrolename));
fwrite ($bf, full_tag('SCHEDULERMODE', 4, false, $scheduler->schedulermode));
fwrite ($bf, full_tag('REUSEGUARDTIME', 4, false, $scheduler->reuseguardtime));
fwrite ($bf, full_tag('DEFAULTSLOTDURATION', 4, false, $scheduler->defaultslotduration));
fwrite ($bf, full_tag('MULTICOURSEAPPOITMENT', 4, false, $scheduler->allowmulticourseappointment));
fwrite ($bf, full_tag('ALLOWNOTIFICATIONS', 4, false, $scheduler->allownotifications));
fwrite ($bf, full_tag('TIMEMODIFIED', 4, false, $scheduler->timemodified));
//if we've selected to backup users info, then execute backup_scheduler_slots and appointments
if ($preferences->mods['scheduler']->userinfo) {
$scheduler_slots = get_records('scheduler_slots', 'schedulerid', $scheduler->id, 'id');
$status = $status && backup_scheduler_slots($bf, $preferences, $scheduler->id, $scheduler_slots);
$status = $status && backup_scheduler_appointments($bf, $preferences, $scheduler_slots);
}
//End mod
$status = $status && fwrite($bf, end_tag('MOD', 3, true));
return $status;
}
/**
* Backup scheduler_slots contents (executed from scheduler_backup_mods)
*/
function backup_scheduler_slots ($bf, $preferences, $schedulerid, $slots) {
global $CFG;
$status = true;
//If there is slots
if ($slots) {
//Write start tag
$status = $status && fwrite ($bf, start_tag('SLOTS', 4, true));
//Iterate over each slot
foreach ($slots as $slot) {
//Start slot
$status = $status && fwrite ($bf, start_tag('SLOT', 5, true));
//Print scheduler_slots contents
fwrite ($bf, full_tag('ID', 6, false, $slot->id));
fwrite ($bf, full_tag('SCHEDULERID', 6, false, $schedulerid));
fwrite ($bf, full_tag('STARTTIME', 6, false, $slot->starttime));
fwrite ($bf, full_tag('DURATION', 6, false, $slot->duration));
fwrite ($bf, full_tag('TEACHERID', 6, false, $slot->teacherid));
fwrite ($bf, full_tag('APPOINTMENTLOCATION', 6, false, $slot->appointmentlocation));
fwrite ($bf, full_tag('REUSE', 6, false, $slot->reuse));
fwrite ($bf, full_tag('TIMEMODIFIED', 6, false, $slot->timemodified));
fwrite ($bf, full_tag('NOTES', 6, false, $slot->notes));
fwrite ($bf, full_tag('EXCLUSIVITY', 6, false, $slot->exclusivity));
fwrite ($bf, full_tag('APPOINTMENTNOTE', 6, false, $slot->appointmentnote));
fwrite ($bf, full_tag('EMAILDATE', 6, false, $slot->emaildate));
fwrite ($bf, full_tag('HIDEUNTIL', 6, false, $slot->hideuntil));
//End slot
$status = $status && fwrite ($bf, end_tag('SLOT', 5, true));
}
//Write end tag
$status = $status && fwrite($bf, end_tag('SLOTS', 4, true));
}
return $status;
}
/**
* Backup scheduler_slots appointments (executed from scheduler_backup_mods)
*/
function backup_scheduler_appointments($bf, $preferences, $slots) {
global $CFG;
$status = true;
//Write start tag
$status = $status && fwrite ($bf, start_tag('APPOINTMENTS', 4, true));
foreach($slots as $slot){
$appointments = scheduler_get_appointments($slot->id);
//If there is slots
if ($appointments) {
//Iterate over each slots
foreach ($appointments as $appointment) {
//Start slot
$status = $status && fwrite ($bf, start_tag('APPOINTMENT', 5, true));
//Print appointment data
fwrite ($bf, full_tag('ID', 6, false, $appointment->id));
fwrite ($bf, full_tag('SCHEDULERID', 6, false, $appointment->schedulerid));
fwrite ($bf, full_tag('SLOTID', 6, false, $appointment->slotid));
fwrite ($bf, full_tag('STUDENTID', 6, false, $appointment->studentid));
fwrite ($bf, full_tag('ATTENDED', 6, false, $appointment->attended));
fwrite ($bf, full_tag('GRADE', 6, false, $appointment->grade));
fwrite ($bf, full_tag('APPOINTMENTNOTE', 6, false, $appointment->appointmentnote));
fwrite ($bf, full_tag('TIMECREATED', 6, false, $appointment->timecreated));
fwrite ($bf, full_tag('TIMEMODIFIED', 6, false, $appointment->timemodified));
//End appointment
$status = $status && fwrite ($bf, end_tag('APPOINTMENT', 5, true));
}
}
}
//Write end tag
$status = $status && fwrite($bf, end_tag('APPOINTMENTS', 4, true));
return $status;
}
/**
* Return an array of info (name, value)
*/
function scheduler_check_backup_mods($course, $user_data=false, $backup_unique_code) {
//First the course data
$info[0][0] = get_string('modulenameplural', 'scheduler');
if ($ids = scheduler_ids ($course)) {
$info[0][1] = count($ids);
} else {
$info[0][1] = 0;
}
//Now, if requested, the user_data
if ($user_data) {
$info[1][0] = get_string('slots', 'scheduler');
if ($ids = scheduler_slot_ids_by_course ($course)) {
$info[1][1] = count($ids);
} else {
$info[1][1] = 0;
}
$info[2][0] = get_string('appointments', 'scheduler');
if ($ids = scheduler_appointments_ids_by_course($course)) {
$info[2][1] = count($ids);
} else {
$info[2][1] = 0;
}
}
return $info;
}
// INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE
/**
* Returns an array of schedulers id
*/
function scheduler_ids ($course) {
global $CFG;
$sql = "
SELECT
s.id,
s.course
FROM
{$CFG->prefix}scheduler AS s
WHERE
s.course = '{$course}'
";
return get_records_sql ($sql);
}
/**
* Returns an array of scheduler slots id
*/
function scheduler_slot_ids_by_course ($course) {
global $CFG;
$sql = "
SELECT
sl.id ,
sl.schedulerid
FROM
{$CFG->prefix}scheduler_slots AS sl,
{$CFG->prefix}scheduler AS s
WHERE
s.course = '{$course}' AND
sl.schedulerid = s.id
";
return get_records_sql($sql);
}
/**
* Returns an array of scheduler appointments id
*/
function scheduler_appointments_ids_by_course ($course) {
global $CFG;
$sql = "
SELECT
a.id,
sl.schedulerid
FROM
{$CFG->prefix}scheduler_appointment AS a,
{$CFG->prefix}scheduler_slots AS sl,
{$CFG->prefix}scheduler AS s
WHERE
s.course = '{$course}' AND
sl.schedulerid = s.id AND
sl.id = a.slotid
";
return get_records_sql($sql);
}
?>