示例#1
0
文件: lib.php 项目: pspro360/emarking
/**
 * Updates an instance of the emarking in the database
 *
 * 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 object|\stdClass $emarking
 *            An object from the form in mod_form.php
 * @param mod_emarking_mod_form $mform            
 * @return boolean Success/Fail
 */
function emarking_update_instance(stdClass $emarking, mod_emarking_mod_form $mform = null)
{
    global $DB, $CFG, $COURSE;
    // If there is NO exam for the emarking activity and the user selected she
    // wouldn't use a previous exam there is something wrong
    if (!($exam = $DB->get_record("emarking_exams", array("emarking" => $emarking->instance))) && $mform->get_data()->exam == 0) {
        return false;
    }
    // If there is NO exam with the id selected by the user there is something wrong
    // (When the emarking already has an exam, the data comes in a hidden field
    if (!($exam = $DB->get_record("emarking_exams", array("id" => $mform->get_data()->exam)))) {
        return false;
    }
    // We update the exam row
    $exam->name = $emarking->name;
    $exam->emarking = $emarking->instance;
    $DB->update_record("emarking_exams", $exam);
    if (!isset($mform->get_data()->linkrubric)) {
        $emarking->linkrubric = 0;
    }
    if (!isset($mform->get_data()->collaborativefeatures)) {
        $emarking->collaborativefeatures = 0;
    }
    if (!isset($mform->get_data()->enableduedate)) {
        $emarking->markingduedate = NULL;
    }
    if (!isset($mform->get_data()->enablescan)) {
        $emarking->enablescan = 0;
    }
    if (!isset($mform->get_data()->enableosm)) {
        $emarking->enableosm = 0;
    }
    $emarking->introformat = FORMAT_HTML;
    $emarking->timemodified = time();
    $emarking->id = $emarking->instance;
    $ret = $DB->update_record('emarking', $emarking);
    emarking_grade_item_update($emarking);
    return $ret;
}
示例#2
0
/**
 * Updates an instance of the emarking in the database
 *
 * 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 object|\stdClass $emarking An object from the form in mod_form.php
 * @param mod_emarking_mod_form $mform
 * @return boolean Success/Fail
 */
function emarking_update_instance(stdClass $emarking, mod_emarking_mod_form $mform = null)
{
    global $DB, $CFG, $COURSE;
    if (!isset($mform->get_data()->linkrubric)) {
        $emarking->linkrubric = 0;
    }
    if (!isset($mform->get_data()->collaborativefeatures)) {
        $emarking->collaborativefeatures = 0;
    }
    if (!isset($mform->get_data()->experimentalgroups)) {
        $emarking->experimentalgroups = 0;
        $DB->delete_records("emarking_experimental_groups", array("emarkingid" => $emarking->instance));
    } else {
        $groups = $DB->get_records("groups", array("courseid" => $COURSE->id));
        foreach ($groups as $group) {
            if (!$DB->get_record("emarking_experimental_groups", array("emarkingid" => $emarking->instance, "groupid" => $group->id))) {
                $expGroup = new stdClass();
                $expGroup->emarkingid = $emarking->instance;
                $expGroup->groupid = $group->id;
                $expGroup->datestart = time();
                $expGroup->dateend = time() + 30 * 24 * 60 * 60;
                $DB->insert_record("emarking_experimental_groups", $expGroup);
            }
        }
    }
    if (!isset($mform->get_data()->enableduedate)) {
        $emarking->markingduedate = NULL;
    }
    $emarking->timemodified = time();
    $emarking->id = $emarking->instance;
    $ret = $DB->update_record('emarking', $emarking);
    emarking_grade_item_update($emarking);
    return $ret;
}