c90d8079107e31dc7ee665c4fa43bf0b55798b7e
[moodle.git] / mod / assignment / restorelib.php
1 <?php
2     //This php script contains all the stuff to backup/restore
3     //assignment mods
5     //This is the "graphical" structure of the assignment mod:
6     //
7     //                     assignment
8     //                    (CL,pk->id)
9     //                        |
10     //                        |
11     //                        |
12     //                 assignment_submisions
13     //           (UL,pk->id, fk->assignment,files)
14     //
15     // Meaning: pk->primary key field of the table
16     //          fk->foreign key to link with parent
17     //          nt->nested field (recursive data)
18     //          CL->course level info
19     //          UL->user level info
20     //          files->table may have files)
21     //
22     //-----------------------------------------------------------
25     //This function returns a log record with all the necessay transformations
26     //done. It's used by restore_log_module() to restore modules log.
27     function assignment_restore_logs($restore,$log) {
29         $status = false;
31         //Depending of the action, we recode different things
32         switch ($log->action) {
33         case "add":
34             if ($log->cmid) {
35                 //Get the new_id of the module (to recode the info field)
36                 $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
37                 if ($mod) {
38                     $log->url = "view.php?id=".$log->cmid;
39                     $log->info = $mod->new_id;
40                     $status = true;
41                 }
42             }
43             break;
44         case "update":
45             if ($log->cmid) {
46                 //Get the new_id of the module (to recode the info field)
47                 $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
48                 if ($mod) {
49                     $log->url = "view.php?id=".$log->cmid;
50                     $log->info = $mod->new_id;
51                     $status = true;
52                 }
53             }
54             break;
55         case "view":
56             if ($log->cmid) {
57                 //Get the new_id of the module (to recode the info field)
58                 $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
59                 if ($mod) {
60                     $log->url = "view.php?id=".$log->cmid;
61                     $log->info = $mod->new_id;
62                     $status = true;
63                 }
64             }
65             break;
66         case "view all":
67             $log->url = "index.php?id=".$log->course;
68             $status = true;
69             break;
70         case "upload":
71             if ($log->cmid) {
72                 //Get the new_id of the module (to recode the info field)
73                 $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
74                 if ($mod) {
75                     $log->url = "view.php?a=".$mod->new_id;
76                     $log->info = $mod->new_id;
77                     $status = true;
78                 }
79             }
80             break;
81         case "view submission":
82             if ($log->cmid) {
83                 //Get the new_id of the module (to recode the info field)
84                 $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
85                 if ($mod) {
86                     $log->url = "submissions.php?id=".$mod->new_id;
87                     $log->info = $mod->new_id;
88                     $status = true;
89                 }
90             }
91             break;
92         case "update grades":
93             if ($log->cmid) {
94                 //Extract the assignment id from the url field
95                 $assid = substr(strrchr($log->url,"="),1);
96                 //Get the new_id of the module (to recode the info field)
97                 $mod = backup_getid($restore->backup_unique_code,$log->module,$assid);
98                 if ($mod) {
99                     $log->url = "submissions.php?id=".$mod->new_id;
100                     $status = true;
101                 }
102             }
103             break;
104         default:
105             if (!defined('RESTORE_SILENTLY')) {
106                 echo "action (".$log->module."-".$log->action.") unknown. Not restored<br />";                 //Debug
107             }
108             break;
109         }
111         if ($status) {
112             $status = $log;
113         }
114         return $status;
115     }