-
Notifications
You must be signed in to change notification settings - Fork 0
/
backuplib.php
executable file
·149 lines (126 loc) · 5.32 KB
/
backuplib.php
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
<?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/>.
//
// Copyright © 2011 The Regents of the University of California.
// All Rights Reserved.
/**
* backuplib.php
*
* @copyright © 2011 The Regents of the University of California
* @author [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package mod_resourcelist
*/
//This php script contains all the stuff to backup/restore
//resourcelist mods
//This is the "graphical" structure of the resourcelist mod:
//
// resourcelist
// (CL,pk->id,files)
//
// 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)
//
//-----------------------------------------------------------
//This function executes all the backup procedure about this mod
function resourcelist_backup_mods($bf,$preferences) {
global $CFG;
$status = true;
////Iterate over resourcelist table
$resourcelists = get_records ("resourcelist","course",$preferences->backup_course,"id");
if ($resourcelists) {
foreach ($resourcelists as $resourcelist) {
if (backup_mod_selected($preferences,'resourcelist',$resourcelist->id)) {
$status = resourcelist_backup_one_mod($bf,$preferences,$resourcelist);
}
}
}
return $status;
}
function resourcelist_backup_one_mod($bf,$preferences,$resourcelist) {
global $CFG;
if (is_numeric($resourcelist)) {
$resourcelist = get_record('resourcelist','id',$resourcelist);
}
$status = true;
//Start mod
fwrite ($bf,start_tag("MOD",3,true));
//Print assignment data
fwrite ($bf,full_tag("ID",4,false,$resourcelist->id));
fwrite ($bf,full_tag("MODTYPE",4,false,"resourcelist"));
fwrite ($bf,full_tag("NAME",4,false,$resourcelist->name));
fwrite ($bf,full_tag("SUMMARY",4,false,$resourcelist->summary));
fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$resourcelist->timemodified));
//Now backup resourcelist_items
$status = backup_resourcelist_items($bf,$preferences,$resourcelist->id);
//End mod
$status = fwrite ($bf,end_tag("MOD",3,true));
return $status;
}
// backup resourcelist items (executed from choice_backup_mods)
function backup_resourcelist_items($bf,$preferences,$resourcelist) {
global $CFG;
$status = true;
$resourcelist_items = get_records('resourcelist_items','resourcelistid',$resourcelist,'id');
if ($resourcelist_items) {
//Write start tag
$status = fwrite($bf,start_tag("LISTITEMS",4,true));
foreach($resourcelist_items as $listitem) {
//Start listitem
$status = fwrite($bf,start_tag("LISTITEM",5,true));
//Print listitem contents
fwrite($bf,full_tag("ID",6,false,$listitem->id));
fwrite($bf,full_tag("RESOURCELISTID",6,false,$listitem->resourcelistid));
fwrite($bf,full_tag("RESOURCEID",6,false,$listitem->resourceid));
//End listitem
$status = fwrite($bf,end_tag("LISTITEM",5,true));
}
//Write end tag
$status = fwrite($bf,end_tag("LISTITEMS",4,true));
}
return $status;
}
// generates an array of course and user data information used to select which instances to
// backup (and whether to include user data or not). This includes details at [0][0] and [0][1]
// about the course module name and number of instances for the course and at [1][0] and [1][1]
// with the module name and count of user information.
function resourcelist_check_backup_mods($course,$user_data=false,$backup_unique_code,$instances=null) {
if (!empty($instances) && is_array($instances) && count($instances)) {
$info = array();
foreach ($instances as $id => $instance) {
$info += resourcelist_check_backup_mods_instances($instance,$backup_unique_code);
}
return $info;
}
//First the course data
$info[0][0] = get_string("modulenameplural","resourcelist");
$info[0][1] = count_records("resourcelist", "course", "$course");
return $info;
}
function resourcelist_check_backup_mods_instances($instance,$backup_unique_code) {
//First the course data
$info[$instance->id.'0'][0] = '<b>'.$instance->name.'</b>';
$info[$instance->id.'0'][1] = '';
return $info;
}
// Recode links to ensure they work when re-imported.
/* function resourcelist_encode_content_links($content,$preferences) { */
/* } */
?>