[system] / trunk / wwmoodle / wwassignment4 / moodle / mod / wwassignment / restorelib.php Repository:
ViewVC logotype

View of /trunk/wwmoodle/wwassignment4/moodle/mod/wwassignment/restorelib.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5883 - (download) (as text) (annotate)
Sun Aug 24 03:03:32 2008 UTC (11 years, 5 months ago) by gage
File size: 7087 byte(s)
Modified file to use the internal configuration of the wwlink block rather than
the data from wwassignment_bridge

The instance behavior needs more detailed warning message when no webwork course is connected
or when it does not have the desired course.

    1 <?php //$Id: restorelib.php,v 1.3 2008-08-24 03:03:32 gage Exp $
    2     //This php script contains all the stuff to backup/restore
    3     //assignment mods
    4 
    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     //-----------------------------------------------------------
   23 
   24     //This function executes all the restore procedure about this mod
   25     function wwassignment_restore_mods($mod,$restore) {
   26 
   27         global $CFG;
   28 
   29         $status = true;
   30         //error_log("mod id ".$mod->id);
   31 //         if ($mod->id == "66666") {
   32 //          $wwlinkdata  = backup_getid($restore->backup_unique_code,"wwassignment_bridge","wwassignment_bridge");
   33 //             error_log("wwlink data ".print_r($wwlinkdata, true ));
   34 //             return $status;
   35 //          }
   36 
   37         //Get record from backup_ids
   38 
   39         $data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id);
   40 
   41         if ($data) {
   42             //Now get completed xmlized object
   43             $info = $data->info;
   44             //if necessary, write to restorelog and adjust date/time fields
   45             if ($restore->course_startdateoffset) {
   46                 //restore_log_date_changes('Wwassignment', $restore, $info['MOD']['#'], array('TIMEDUE', 'TIMEAVAILABLE'));
   47             }
   48             //traverse_xmlize($info);                                                                     //Debug
   49             //print_object ($GLOBALS['traverse_array']);                                                  //Debug
   50             //$GLOBALS['traverse_array']="";                                                              //Debug
   51 
   52             //Now, build the ASSIGNMENT record structure
   53             $wwassignment->course = $restore->course_id;
   54             $wwassignment->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
   55             $wwassignment->description = backup_todb($info['MOD']['#']['DESCRIPTION']['0']['#']);
   56             $wwassignment->webwork_set = backup_todb($info['MOD']['#']['WEBWORK_SET']['0']['#']);
   57             $wwassignment->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
   58 
   59 
   60 
   61             //The structure is equal to the db, so insert the assignment
   62             $newid = insert_record ("wwassignment",$wwassignment);
   63 
   64             //Do some output
   65             if (!defined('RESTORE_SILENTLY')) {
   66                 echo "<li>".get_string("modulename","wwassignment")." \"".format_string(stripslashes($wwassignment->name),true)."\"</li>";
   67             }
   68             backup_flush(300);
   69 
   70             if ($newid) {
   71                 //We have the newid, update backup_ids
   72                 backup_putid($restore->backup_unique_code,$mod->modtype,
   73                              $mod->id, $newid);
   74 
   75             } else {
   76                 $status = false;
   77             }
   78         } else {
   79             $status = false;
   80         }
   81          //error_log("mod id is ".print_r($mod,true));
   82         return $status;
   83     }
   84 
   85 
   86 
   87     //This function returns a log record with all the necessay transformations
   88     //done. It's used by restore_log_module() to restore modules log.
   89     function wwassignment_restore_logs($restore,$log) {
   90 
   91         $status = false;
   92 
   93         //Depending of the action, we recode different things
   94         switch ($log->action) {
   95         case "add":
   96             if ($log->cmid) {
   97                 //Get the new_id of the module (to recode the info field)
   98                 $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
   99                 if ($mod) {
  100                     $log->url = "view.php?id=".$log->cmid;
  101                     $log->info = $mod->new_id;
  102                     $status = true;
  103                 }
  104             }
  105             break;
  106         case "update":
  107             if ($log->cmid) {
  108                 //Get the new_id of the module (to recode the info field)
  109                 $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  110                 if ($mod) {
  111                     $log->url = "view.php?id=".$log->cmid;
  112                     $log->info = $mod->new_id;
  113                     $status = true;
  114                 }
  115             }
  116             break;
  117         case "view":
  118             if ($log->cmid) {
  119                 //Get the new_id of the module (to recode the info field)
  120                 $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  121                 if ($mod) {
  122                     $log->url = "view.php?id=".$log->cmid;
  123                     $log->info = $mod->new_id;
  124                     $status = true;
  125                 }
  126             }
  127             break;
  128         case "view all":
  129             $log->url = "index.php?id=".$log->course;
  130             $status = true;
  131             break;
  132         case "upload":
  133             if ($log->cmid) {
  134                 //Get the new_id of the module (to recode the info field)
  135                 $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  136                 if ($mod) {
  137                     $log->url = "view.php?a=".$mod->new_id;
  138                     $log->info = $mod->new_id;
  139                     $status = true;
  140                 }
  141             }
  142             break;
  143         case "view submission":
  144             if ($log->cmid) {
  145                 //Get the new_id of the module (to recode the info field)
  146                 $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  147                 if ($mod) {
  148                     $log->url = "submissions.php?id=".$mod->new_id;
  149                     $log->info = $mod->new_id;
  150                     $status = true;
  151                 }
  152             }
  153             break;
  154         case "update grades":
  155             if ($log->cmid) {
  156                 //Extract the assignment id from the url field
  157                 $assid = substr(strrchr($log->url,"="),1);
  158                 //Get the new_id of the module (to recode the info field)
  159                 $mod = backup_getid($restore->backup_unique_code,$log->module,$assid);
  160                 if ($mod) {
  161                     $log->url = "submissions.php?id=".$mod->new_id;
  162                     $status = true;
  163                 }
  164             }
  165             break;
  166         default:
  167             if (!defined('RESTORE_SILENTLY')) {
  168                 echo "action (".$log->module."-".$log->action.") unknown. Not restored<br />";                 //Debug
  169             }
  170             break;
  171         }
  172 
  173         if ($status) {
  174             $status = $log;
  175         }
  176         return $status;
  177     }
  178 ?>

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9