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

View of /trunk/wwmoodle/wwassignment4/moodle/mod/wwassignment/backuplib.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: 6564 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: backuplib.php,v 1.3 2008-08-24 03:03:32 gage Exp $
    2     //This php script contains all the stuff to backup
    3     //wwassignment 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 backup procedure about this mod
   25 
   26 
   27     function wwassignment_backup_mods($bf,$preferences) {
   28         //error_log("wwassignment_backup_mods");
   29         ////error_log("preferences ".print_r($preferences,true));
   30         global $CFG;
   31 
   32         $status = true;
   33 
   34         //Iterate over assignment table
   35         $wwassignments = get_records ("wwassignment","course",$preferences->backup_course);
   36         if ($wwassignments) {
   37             foreach ($wwassignments as $wwassignment) {
   38                 ////error_log("backing up wwassignment ".$wwassignment->id);
   39                 if (backup_mod_selected($preferences,'wwassignment',$wwassignment->id)) {
   40                     $status = wwassignment_backup_one_mod($bf,$preferences,$wwassignment);
   41                     // backup files happens in backup_one_mod now too.
   42                 }
   43             }
   44         }
   45 
   46 
   47 
   48          //error_log("end wwassignment_backup_mods");
   49          return $status;
   50     }
   51 
   52     function wwassignment_backup_one_mod($bf,$preferences,$wwassignment) {
   53         //error_log("wwassignment_backup_one_mod");
   54         ////error_log("preferences ".print_r($preferences,true));
   55         global $CFG;
   56 
   57         if (is_numeric($wwassignment)) {
   58             $wwassignment = get_record('wwassignment','id',$wwassignment);
   59         }
   60 
   61         $status = true;
   62 //             function full_tag($tag,$level=0,$endline=true,$content,$attributes=null) {
   63 //         //Start mod
   64         fwrite ($bf,start_tag("MOD",3,true));
   65         //Print wwassignment data
   66         fwrite ($bf,full_tag("ID",4,false,$wwassignment->id));
   67         fwrite ($bf,full_tag("MODTYPE",4,false,"wwassignment"));
   68         fwrite ($bf,full_tag("NAME",4,false,$wwassignment->name));
   69         fwrite ($bf,full_tag("DESCRIPTION",4,false,$wwassignment->description));
   70         fwrite ($bf,full_tag("WEBWORK_SET",4,false,$wwassignment->webwork_set));
   71         fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$wwassignment->timemodified));
   72         //if we've selected to backup users info, then execute backup_assignment_submisions and
   73         //backup_assignment_files_instance
   74 
   75          //End mod
   76         $status =fwrite ($bf,end_tag("MOD",3,true));
   77 
   78 
   79         //error_log("end wwassignment_one_backup_mod");
   80         //error_log("preferences ".print_r($preferences,true));
   81 
   82 
   83 
   84            return $status;
   85      }
   86 
   87 
   88     //Return an array of info (name,value)
   89     function wwassignment_check_backup_mods($course,$user_data=false,$backup_unique_code,$instances=null) {
   90            ////error_log("wwassignment_check_backup_mods ");
   91            ////error_log("user_data ".print_r($user_data,true) );
   92            ////error_log("backup code ".print_r($backup_unique_code,true));
   93            ////error_log("instance ".print_r($instance,true));
   94         $info=array();
   95         if (!empty($instances) && is_array($instances) && count($instances)) {
   96             foreach ($instances as $id => $instance) {
   97                 $info += wwassignment_check_backup_mods_instances($instance,$backup_unique_code);
   98             }
   99             return $info;
  100         }
  101         //First the course data
  102         $info[0][0] = get_string("modulenameplural","wwassignment");
  103         if ($ids = wwassignment_ids ($course)) {
  104             $info[0][1] = count($ids);
  105         } else {
  106             $info[0][1] = 0;
  107         }
  108 
  109          ////error_log("end wwassignment_check_backup_mods");
  110 
  111          return $info;
  112     }
  113 
  114     //Return an array of info (name,value)
  115     function wwassignment_check_backup_mods_instances($instance,$backup_unique_code) {
  116         ////error_log("wwassignment_check_backup_mods_instances ");
  117         ////error_log("content ".print_r($content,true));
  118         ////error_log("preferences ".print_r($preferences,true));
  119 
  120         $info[$instance->id.'0'][0] = '<b>'.$instance->name.'</b>';
  121         $info[$instance->id.'0'][1] = '';
  122 //         if (!empty($instance->userdata)) {
  123 //             $info[$instance->id.'1'][0] = get_string("submissions","assignment");
  124 //             if ($ids = assignment_submission_ids_by_instance ($instance->id)) {
  125 //                 $info[$instance->id.'1'][1] = count($ids);
  126 //             } else {
  127 //                 $info[$instance->id.'1'][1] = 0;
  128 //             }
  129 //         }
  130          ////error_log("end wwassignment_check_backup_mods_instances");
  131 
  132          return $info;
  133      }
  134 //
  135 //     //Return a content encoded to support interactivities linking. Every module
  136 //     //should have its own. They are called automatically from the backup procedure.
  137 //     function assignment_encode_content_links ($content,$preferences) {
  138 //
  139 //         global $CFG;
  140 //
  141 //         $base = preg_quote($CFG->wwwroot,"/");
  142 //
  143 //         //Link to the list of assignments
  144 //         $buscar="/(".$base."\/mod\/assignment\/index.php\?id\=)([0-9]+)/";
  145 //         $result= preg_replace($buscar,'$@ASSIGNMENTINDEX*$2@$',$content);
  146 //
  147 //         //Link to assignment view by moduleid
  148 //         $buscar="/(".$base."\/mod\/assignment\/view.php\?id\=)([0-9]+)/";
  149 //         $result= preg_replace($buscar,'$@ASSIGNMENTVIEWBYID*$2@$',$result);
  150 //
  151 //         return $result;
  152 //     }
  153 
  154       // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE
  155 
  156     //Returns an array of assignments id
  157     function wwassignment_ids ($course) {
  158         ////error_log("wwassignment_ids ");
  159         ////error_log("course ".print_r($course,true));
  160 
  161         global $CFG;
  162 
  163 
  164         ////error_log("end wwassignment_ids");
  165 
  166         return get_records_sql ("SELECT a.id, a.course
  167                                  FROM {$CFG->prefix}wwassignment a
  168                                  WHERE a.course = '$course'");
  169     }
  170 
  171 
  172 ?>

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9