MDL-11515:
[moodle-linuxchix.git] / mod / label / backuplib.php
blob5918b7ea40f4f1f46ce6830134479e83fc67fdf9
1 <?php //$Id$
2 //This php script contains all the stuff to backup/restore
3 //label mods
5 //This is the "graphical" structure of the label mod:
6 //
7 // label
8 // (CL,pk->id)
9 //
10 // Meaning: pk->primary key field of the table
11 // fk->foreign key to link with parent
12 // nt->nested field (recursive data)
13 // CL->course level info
14 // UL->user level info
15 // files->table may have files)
17 //-----------------------------------------------------------
19 //This function executes all the backup procedure about this mod
20 function label_backup_mods($bf,$preferences) {
21 global $CFG;
23 $status = true;
25 ////Iterate over label table
26 if ($labels = get_records ("label","course", $preferences->backup_course,"id")) {
27 foreach ($labels as $label) {
28 if (backup_mod_selected($preferences,'label',$label->id)) {
29 $status = label_backup_one_mod($bf,$preferences,$label);
33 return $status;
36 function label_backup_one_mod($bf,$preferences,$label) {
38 global $CFG;
40 if (is_numeric($label)) {
41 $label = get_record('label','id',$label);
44 $status = true;
46 //Start mod
47 fwrite ($bf,start_tag("MOD",3,true));
48 //Print assignment data
49 fwrite ($bf,full_tag("ID",4,false,$label->id));
50 fwrite ($bf,full_tag("MODTYPE",4,false,"label"));
51 fwrite ($bf,full_tag("NAME",4,false,$label->name));
52 fwrite ($bf,full_tag("CONTENT",4,false,$label->content));
53 fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$label->timemodified));
54 //End mod
55 $status = fwrite ($bf,end_tag("MOD",3,true));
57 return $status;
60 ////Return an array of info (name,value)
61 function label_check_backup_mods($course,$user_data=false,$backup_unique_code,$instances=null) {
62 if (!empty($instances) && is_array($instances) && count($instances)) {
63 $info = array();
64 foreach ($instances as $id => $instance) {
65 $info += label_check_backup_mods_instances($instance,$backup_unique_code);
67 return $info;
70 //First the course data
71 $info[0][0] = get_string("modulenameplural","label");
72 $info[0][1] = count_records("label", "course", "$course");
73 return $info;
76 ////Return an array of info (name,value)
77 function label_check_backup_mods_instances($instance,$backup_unique_code) {
78 //First the course data
79 $info[$instance->id.'0'][0] = '<b>'.$instance->name.'</b>';
80 $info[$instance->id.'0'][1] = '';
81 return $info;