コード例 #1
0
ファイル: upgradelib.php プロジェクト: nuckey/moodle
/**
 * Upgrades legacy workshops using rubric grading strategy
 */
function workshopform_rubric_upgrade_legacy_rubric() {
    global $CFG, $DB, $OUTPUT;
    require_once($CFG->dirroot . '/mod/workshop/db/upgradelib.php');

    // get the list of all legacy workshops using this grading strategy
    if ($legacyworkshops = $DB->get_records('workshop_old', array('gradingstrategy' => 4), 'course,id', 'id')) {
        echo $OUTPUT->notification('Copying rubric assessment form elements', 'notifysuccess');
        $legacyworkshops = array_keys($legacyworkshops);
        // get the list of all form elements and rubrics
        list($workshopids, $params) = $DB->get_in_or_equal($legacyworkshops, SQL_PARAMS_NAMED);
        $sql = "SELECT e.id AS eid, e.workshopid AS workshopid, e.elementno AS esort, e.description AS edesc, e.weight AS eweight,
                       r.id AS rid, r.rubricno AS rgrade, r.description AS rdesc
                  FROM {workshop_elements_old} e
             LEFT JOIN {workshop_rubrics_old} r ON (r.elementno = e.elementno AND r.workshopid = e.workshopid)
                 WHERE e.workshopid $workshopids
                       AND e.newid IS NULL
                       AND r.newid IS NULL
              ORDER BY e.workshopid, e.elementno, r.rubricno";
        $rs = $DB->get_recordset_sql($sql, $params);
        $newdimensionids    = array();  // (int)workshopid => (int)elementno => (int)dimensionid
        $newlevelids        = array();  // (int)oldrubricid => (int)newlevelid
        $prevelement        = null;
        foreach ($rs as $old) {
            // create rubric criterion and the configuration if necessary
            if (!isset($newdimensionids[$old->workshopid]) or !isset($newdimensionids[$old->workshopid][$old->esort])) {
                if (!$DB->record_exists('workshopform_rubric', array('workshopid' => $old->workshopid, 'sort' => $old->esort))) {
                    $newdimension = new stdclass();
                    $newdimension->workshopid = $old->workshopid;
                    $newdimension->sort = $old->esort;
                    $newdimension->description = $old->edesc;
                    $newdimension->descriptionformat = FORMAT_HTML;
                    $newdimensionids[$old->workshopid][$old->esort] = $DB->insert_record('workshopform_rubric', $newdimension);
                } else {
                    $newdimensionids[$old->workshopid][$old->esort] = $DB->get_field('workshopform_rubric', 'id',
                                                                    array('workshopid' => $old->workshopid, 'sort' => $old->esort));
                }
                if (!$DB->record_exists('workshopform_rubric_config', array('workshopid' => $old->workshopid))) {
                    $newconfig = new stdclass();
                    $newconfig->workshopid = $old->workshopid;
                    $newconfig->layout = 'grid';
                    $DB->insert_record('workshopform_rubric_config', $newconfig);
                }
            }
            // process the information about the criterion levels
            if (trim($old->rdesc)) {
                $new = workshopform_rubric_upgrade_rubric_level($old, $newdimensionids[$old->workshopid][$old->esort]);
                $newid = $DB->insert_record('workshopform_rubric_levels', $new);
                $DB->set_field('workshop_rubrics_old', 'newplugin', 'rubric_levels', array('id' => $old->rid));
                $DB->set_field('workshop_rubrics_old', 'newid', $newid, array('id' => $old->rid));
            }
            // mark the whole element as processed if the last level was processed
            if ($old->rgrade == 4) {
                $DB->set_field('workshop_elements_old', 'newplugin', 'rubric', array('id' => $old->eid));
                $DB->set_field('workshop_elements_old', 'newid', $newdimensionids[$old->workshopid][$old->esort], array('id' => $old->eid));
            }
        }
        $rs->close();

        // reload the mappings - this must be reloaded so that we can run this during recovery
        $newelementids = workshop_upgrade_element_id_mappings('rubric');

        // load the legacy element weights and multiply the new max grade by it
        echo $OUTPUT->notification('Recalculating rubric assessment form element weights', 'notifysuccess');
        $oldweights = $DB->get_records('workshop_elements_old', array('newplugin' => 'rubric'), '', 'id,workshopid,elementno,weight');
        $newweights = array();
        foreach ($oldweights as $eid => $element) {
            $newweights[$newelementids[$element->workshopid][$element->elementno]->newid] = workshopform_rubric_upgrade_weight($element->weight);
        }
        unset($oldweights);
        unset($element);

        // migrate all grades for these elements (it est the values that reviewers put into forms)
        echo $OUTPUT->notification('Copying rubric assessment form grades', 'notifysuccess');
        $sql = "SELECT *
                  FROM {workshop_grades_old}
                 WHERE workshopid $workshopids
                       AND newid IS NULL";
        $rs = $DB->get_recordset_sql($sql, $params);
        $newassessmentids = workshop_upgrade_assessment_id_mappings();
        foreach ($rs as $old) {
            if (!isset($newelementids[$old->workshopid]) or !isset($newelementids[$old->workshopid][$old->elementno])) {
                // orphaned grade - the assessment form element has been removed after the grade was recorded
                continue;
            }
            $new                    = new stdclass();
            $new->assessmentid      = $newassessmentids[$old->assessmentid];
            $new->strategy          = 'rubric';
            $new->dimensionid       = $newelementids[$old->workshopid][$old->elementno]->newid;
            $new->grade             = $old->grade * $newweights[$new->dimensionid];
            $new->peercomment       = $old->feedback;
            $new->peercommentformat = FORMAT_HTML;
            $newid = $DB->insert_record('workshop_grades', $new);
            $DB->set_field('workshop_grades_old', 'newplugin', 'rubric', array('id' => $old->id));
            $DB->set_field('workshop_grades_old', 'newid', $newid, array('id' => $old->id));
        }
        $rs->close();
    }
}
コード例 #2
0
ファイル: lib.php プロジェクト: pzhu2004/moodle
 /**
  * Processes gathered elements coming from the legacy rubric strategy
  */
 protected function convert_legacy_rubric_elements()
 {
     $this->write_xml('workshopform_rubric_config', array('layout' => 'grid'));
     foreach ($this->elements as $element) {
         $this->xmlwriter->begin_tag('workshopform_rubric_dimension', array('id' => $element['id']));
         $this->xmlwriter->full_tag('sort', $element['elementno']);
         $this->xmlwriter->full_tag('description', $element['description']);
         $this->xmlwriter->full_tag('descriptionformat', FORMAT_HTML);
         foreach ($this->rubrics[$element['id']] as $rubric) {
             $fakerecord = new stdClass();
             $fakerecord->rgrade = $rubric['rubricno'];
             $fakerecord->eweight = $element['weight'];
             $fakerecord->rdesc = $rubric['description'];
             $level = (array) workshopform_rubric_upgrade_rubric_level($fakerecord, $element['id']);
             unset($level['dimensionid']);
             $level['id'] = $this->converter->get_nextid();
             $this->write_xml('workshopform_rubric_level', $level, array('/workshopform_rubric_level/id'));
         }
         $this->xmlwriter->end_tag('workshopform_rubric_dimension');
     }
 }