Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/workshop/form/comments/db/upgradelib.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00033 function workshopform_comments_upgrade_legacy() {
00034     global $CFG, $DB, $OUTPUT;
00035     require_once($CFG->dirroot . '/mod/workshop/db/upgradelib.php');
00036 
00037     if (!workshopform_comments_upgrade_legacy_needed()) {
00038         return;
00039     }
00040 
00041     // get the list of all legacy workshops using this grading strategy
00042     if ($legacyworkshops = $DB->get_records('workshop_old', array('gradingstrategy' => 0), 'course,id', 'id')) {
00043         echo $OUTPUT->notification('Copying assessment forms elements', 'notifysuccess');
00044         $legacyworkshops = array_keys($legacyworkshops);
00045         // get the list of all form elements
00046         list($workshopids, $params) = $DB->get_in_or_equal($legacyworkshops, SQL_PARAMS_NAMED);
00047         $sql = "SELECT *
00048                   FROM {workshop_elements_old}
00049                  WHERE workshopid $workshopids
00050                        AND newid IS NULL";
00051         $rs = $DB->get_recordset_sql($sql, $params);
00052         foreach ($rs as $old) {
00053             $new = workshopform_comments_upgrade_element($old, $old->workshopid);
00054             $newid = $DB->insert_record('workshopform_comments', $new);
00055             $DB->set_field('workshop_elements_old', 'newplugin', 'comments', array('id' => $old->id));
00056             $DB->set_field('workshop_elements_old', 'newid', $newid, array('id' => $old->id));
00057         }
00058         $rs->close();
00059 
00060         // now we need to reload the legacy element ids
00061         $newelementids = workshop_upgrade_element_id_mappings('comments');
00062 
00063         // migrate all comments for these elements (i.e. the values that reviewers put into forms)
00064         echo $OUTPUT->notification('Copying assessment form comments', 'notifysuccess');
00065         $sql = "SELECT *
00066                   FROM {workshop_grades_old}
00067                  WHERE workshopid $workshopids
00068                        AND newid IS NULL";
00069         $rs = $DB->get_recordset_sql($sql, $params);
00070         $newassessmentids = workshop_upgrade_assessment_id_mappings();
00071         foreach ($rs as $old) {
00072             if (!isset($newassessmentids[$old->assessmentid])) {
00073                 // orphaned comment - the assessment was removed but the grade remained
00074                 continue;
00075             }
00076             if (!isset($newelementids[$old->workshopid]) or !isset($newelementids[$old->workshopid][$old->elementno])) {
00077                 // orphaned comment - the assessment form element has been removed after the grade was recorded
00078                 continue;
00079             }
00080             $new = workshopform_comments_upgrade_grade($old, $newassessmentids[$old->assessmentid],
00081                                                          $newelementids[$old->workshopid][$old->elementno]);
00082             $newid = $DB->insert_record('workshop_grades', $new);
00083             $DB->set_field('workshop_grades_old', 'newplugin', 'comments', array('id' => $old->id));
00084             $DB->set_field('workshop_grades_old', 'newid', $newid, array('id' => $old->id));
00085         }
00086         $rs->close();
00087     }
00088 }
00089 
00097 function workshopform_comments_upgrade_element(stdclass $old, $newworkshopid) {
00098     $new                    = new stdclass();
00099     $new->workshopid        = $newworkshopid;
00100     $new->sort              = $old->elementno;
00101     $new->description       = $old->description;
00102     $new->descriptionformat = FORMAT_HTML;
00103     return $new;
00104 }
00105 
00114 function workshopform_comments_upgrade_grade(stdclass $old, $newassessmentid, stdclass $newdimensioninfo) {
00115     $new                    = new stdclass();
00116     $new->assessmentid      = $newassessmentid;
00117     $new->strategy          = 'comments';
00118     $new->dimensionid       = $newdimensioninfo->newid;
00119     $new->grade             = 100.00000;
00120     $new->peercomment       = $old->feedback;
00121     $new->peercommentformat = FORMAT_HTML;
00122     return $new;
00123 }
00124 
00130 function workshopform_comments_upgrade_legacy_needed() {
00131     global $CFG, $DB;
00132 
00133     $dbman = $DB->get_manager();
00134     if (!($dbman->table_exists('workshop_elements_old') and $dbman->table_exists('workshop_grades_old'))) {
00135         return false;
00136     }
00137     return true;
00138 }
 All Data Structures Namespaces Files Functions Variables Enumerations