Exemple #1
0
/**
 * Copies the settings from a source emarking activity to a destination one
 *
 * @param unknown $emarkingsrc
 * @param unknown $emarkingdst
 * @param unknown $rubricoverride
 * @param unknown $markersoverride
 */
function emarking_copy_settings($emarkingsrc, $emarkingdst, $rubricoverride, $markersoverride)
{
    global $DB, $OUTPUT;
    $transaction = $DB->start_delegated_transaction();
    $criteriaitems = emarking_match_rubrics($emarkingsrc, $emarkingdst, $rubricoverride);
    try {
        emarking_copy_predefined_comments($emarkingsrc, $emarkingdst);
        emarking_copy_pages($emarkingsrc, $emarkingdst, $criteriaitems);
        if ($markersoverride) {
            emarking_copy_markers($emarkingsrc, $emarkingdst, $criteriaitems);
        }
        emarking_copy_outcomes($emarkingsrc, $emarkingdst, $criteriaitems, $rubricoverride);
    } catch (moodle_exception $exception) {
        $DB->rollback_delegated_transaction($transaction, $exception);
        return false;
    }
    // This goes at the end as the emarking object is left unusable.
    echo $OUTPUT->box("Copying emarking settings");
    $emarkingsrc->id = $emarkingdst->id;
    $emarkingsrc->name = $emarkingdst->name;
    $emarkingsrc->intro = $emarkingdst->intro;
    $emarkingsrc->introformat = $emarkingdst->introformat;
    $emarkingsrc->timecreated = $emarkingdst->timecreated;
    $emarkingsrc->course = $emarkingdst->course;
    if (!$DB->update_record('emarking', $emarkingsrc)) {
        $DB->rollback_delegated_transaction($transaction, new moodle_exception("Could not update emarking destination"));
        return false;
    }
    $DB->commit_delegated_transaction($transaction);
    echo $OUTPUT->box("Success!");
    return true;
}
Exemple #2
0
function emarking_copy_peer_review($emarkingsrc, $emarkingdst)
{
    global $DB, $OUTPUT;
    // This goes at the end as the emarking object is left unusable.
    echo $OUTPUT->box("Copying emarking settings, submission, pages and rubric");
    $transaction = $DB->start_delegated_transaction();
    try {
        emarking_copy_exam($emarkingsrc, $emarkingdst);
        emarking_match_rubrics($emarkingsrc, $emarkingdst, true);
        emarking_copy_predefined_comments($emarkingsrc, $emarkingdst);
        emarking_copy_submissions_drafts($emarkingsrc, $emarkingdst);
        emarking_assign_peers($emarkingdst);
    } catch (moodle_exception $exception) {
        $DB->rollback_delegated_transaction($transaction, $exception);
        return false;
    }
    $emarkingdst->copiedfromparent = 1;
    if (!$DB->update_record('emarking', $emarkingdst)) {
        $DB->rollback_delegated_transaction($transaction, new moodle_exception("Could not update emarking destination"));
        return false;
    }
    $DB->commit_delegated_transaction($transaction);
    echo $OUTPUT->box("Success!");
    return true;
}