コード例 #1
0
ファイル: upgrade.php プロジェクト: Gavinthisisit/Moodle
/**
 * Performs upgrade of the database structure and data
 *
 * Teamwork supports upgrades from version 1.9.0 and higher only. During 1.9 > 2.0 upgrade,
 * there are significant database changes.
 *
 * @param int $oldversion the version we are upgrading from
 * @return bool result
 */
function xmldb_teamwork_upgrade($oldversion)
{
    global $CFG, $DB, $OUTPUT;
    $dbman = $DB->get_manager();
    // Moodle v2.2.0 release upgrade line
    if ($oldversion < 2012033100) {
        // add the field 'phaseswitchassessment' to the 'teamwork' table
        $table = new xmldb_table('teamwork');
        $field = new xmldb_field('phaseswitchassessment', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'assessmentend');
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        upgrade_mod_savepoint(true, 2012033100, 'teamwork');
    }
    /**
     * Remove all teamwork calendar events
     */
    if ($oldversion < 2012041700) {
        require_once $CFG->dirroot . '/calendar/lib.php';
        $events = $DB->get_records('event', array('modulename' => 'teamwork'));
        foreach ($events as $event) {
            $event = calendar_event::load($event);
            $event->delete();
        }
        upgrade_mod_savepoint(true, 2012041700, 'teamwork');
    }
    /**
     * Recreate all teamwork calendar events
     */
    if ($oldversion < 2012041701) {
        require_once dirname(dirname(__FILE__)) . '/lib.php';
        $sql = "SELECT w.id, w.course, w.name, w.intro, w.introformat, w.submissionstart,\n                       w.submissionend, w.assessmentstart, w.assessmentend,\n                       cm.id AS cmid\n                  FROM {teamwork} w\n                  JOIN {modules} m ON m.name = 'teamwork'\n                  JOIN {course_modules} cm ON (cm.module = m.id AND cm.course = w.course AND cm.instance = w.id)";
        $rs = $DB->get_recordset_sql($sql);
        foreach ($rs as $teamwork) {
            $cmid = $teamwork->cmid;
            unset($teamwork->cmid);
            teamwork_calendar_update($teamwork, $cmid);
        }
        $rs->close();
        upgrade_mod_savepoint(true, 2012041701, 'teamwork');
    }
    // Moodle v2.3.0 release upgrade line
    /**
     * Add new fields conclusion and conclusionformat
     */
    if ($oldversion < 2012102400) {
        $table = new xmldb_table('teamwork');
        $field = new xmldb_field('conclusion', XMLDB_TYPE_TEXT, null, null, null, null, null, 'phaseswitchassessment');
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        $field = new xmldb_field('conclusionformat', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '1', 'conclusion');
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        upgrade_mod_savepoint(true, 2012102400, 'teamwork');
    }
    // Moodle v2.4.0 release upgrade line
    // Put any upgrade step following this
    /**
     * Add overall feedback related fields into the teamwork table.
     */
    if ($oldversion < 2013032500) {
        $table = new xmldb_table('teamwork');
        $field = new xmldb_field('overallfeedbackmode', XMLDB_TYPE_INTEGER, '3', null, null, null, '1', 'conclusionformat');
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        $field = new xmldb_field('overallfeedbackfiles', XMLDB_TYPE_INTEGER, '3', null, null, null, '0', 'overallfeedbackmode');
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        $field = new xmldb_field('overallfeedbackmaxbytes', XMLDB_TYPE_INTEGER, '10', null, null, null, '100000', 'overallfeedbackfiles');
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        upgrade_mod_savepoint(true, 2013032500, 'teamwork');
    }
    /**
     * Add feedbackauthorattachment field into the teamwork_assessments table.
     */
    if ($oldversion < 2013032501) {
        $table = new xmldb_table('teamwork_assessments');
        $field = new xmldb_field('feedbackauthorattachment', XMLDB_TYPE_INTEGER, '3', null, null, null, '0', 'feedbackauthorformat');
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        upgrade_mod_savepoint(true, 2013032501, 'teamwork');
    }
    // Moodle v2.5.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.6.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.7.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.8.0 release upgrade line.
    // Put any upgrade step following this.
    return true;
}
コード例 #2
0
ファイル: lib.php プロジェクト: Gavinthisisit/Moodle
/**
 * Given an object containing all the necessary data,
 * (defined by the form in mod_form.php) this function
 * will update an existing instance with new data.
 *
 * @param stdClass $teamwork An object from the form in mod_form.php
 * @return bool success
 */
function teamwork_update_instance(stdclass $teamwork)
{
    global $CFG, $DB;
    require_once dirname(__FILE__) . '/locallib.php';
    $teamwork->timemodified = time();
    $teamwork->id = $teamwork->instance;
    $teamwork->useexamples = (int) (!empty($teamwork->useexamples));
    $teamwork->usepeerassessment = 1;
    $teamwork->useselfassessment = (int) (!empty($teamwork->useselfassessment));
    $teamwork->latesubmissions = (int) (!empty($teamwork->latesubmissions));
    $teamwork->phaseswitchassessment = (int) (!empty($teamwork->phaseswitchassessment));
    // todo - if the grading strategy is being changed, we may want to replace all aggregated peer grades with nulls
    $DB->update_record('teamwork', $teamwork);
    $context = context_module::instance($teamwork->coursemodule);
    // process the custom wysiwyg editors
    if ($draftitemid = $teamwork->instructauthorseditor['itemid']) {
        $teamwork->instructauthors = file_save_draft_area_files($draftitemid, $context->id, 'mod_teamwork', 'instructauthors', 0, teamwork::instruction_editors_options($context), $teamwork->instructauthorseditor['text']);
        $teamwork->instructauthorsformat = $teamwork->instructauthorseditor['format'];
    }
    if ($draftitemid = $teamwork->instructreviewerseditor['itemid']) {
        $teamwork->instructreviewers = file_save_draft_area_files($draftitemid, $context->id, 'mod_teamwork', 'instructreviewers', 0, teamwork::instruction_editors_options($context), $teamwork->instructreviewerseditor['text']);
        $teamwork->instructreviewersformat = $teamwork->instructreviewerseditor['format'];
    }
    if ($draftitemid = $teamwork->conclusioneditor['itemid']) {
        $teamwork->conclusion = file_save_draft_area_files($draftitemid, $context->id, 'mod_teamwork', 'conclusion', 0, teamwork::instruction_editors_options($context), $teamwork->conclusioneditor['text']);
        $teamwork->conclusionformat = $teamwork->conclusioneditor['format'];
    }
    // re-save the record with the replaced URLs in editor fields
    $DB->update_record('teamwork', $teamwork);
    // update gradebook items
    teamwork_grade_item_update($teamwork);
    teamwork_grade_item_category_update($teamwork);
    // update calendar events
    teamwork_calendar_update($teamwork, $teamwork->coursemodule);
    return true;
}