Ejemplo n.º 1
0
$canaddquestion = (bool) $contexts->having_add_and_use();
$quizhasattempts = quiz_has_attempts($quiz->id);
$PAGE->set_url($thispageurl);
// Get the course object and related bits.
$course = $DB->get_record('course', array('id' => $quiz->course));
if (!$course) {
    print_error('invalidcourseid', 'error');
}
$questionbank = new quiz_question_bank_view($contexts, $thispageurl, $course, $cm, $quiz);
$questionbank->set_quiz_has_attempts($quizhasattempts);
// Log this visit.
add_to_log($cm->course, 'quiz', 'editquestions', "view.php?id={$cm->id}", "{$quiz->id}", $cm->id);
// You need mod/quiz:manage in addition to question capabilities to access this page.
require_capability('mod/quiz:manage', $contexts->lowest());
if (empty($quiz->grades)) {
    $quiz->grades = quiz_get_all_question_grades($quiz);
}
// Process commands ============================================================
if ($quiz->shufflequestions) {
    // Strip page breaks before processing actions, so that re-ordering works
    // as expected when shuffle questions is on.
    $quiz->questions = quiz_repaginate($quiz->questions, 0);
}
// Get the list of question ids had their check-boxes ticked.
$selectedquestionids = array();
$params = (array) data_submitted();
foreach ($params as $key => $value) {
    if (preg_match('!^s([0-9]+)$!', $key, $matches)) {
        $selectedquestionids[] = $matches[1];
    }
}
Ejemplo n.º 2
0
function RWSAAQRand()
{
    global $CFG;
    global $DB;
    global $RWSUID;
    RWSCMAuth();
    RWSCRAuth();
    RWSCMUSvc();
    RWSCMMaint();
    $r_pm = RWSGSOpt("quizid", PARAM_ALPHANUM);
    if ($r_pm === false || strlen($r_pm) == 0) {
        RWSSErr("2067");
    }
    $r_qzmi = intval($r_pm);
    $r_cmod = RWSCMUQuiz($r_qzmi);
    $r_cid = $r_cmod->course;
    RWSCMUCourse($r_cid, true);
    $r_mr = $DB->get_record("modules", array("id" => $r_cmod->module));
    if ($r_mr === false) {
        RWSSErr("2043");
    }
    $r_qiz = $DB->get_record($r_mr->name, array("id" => $r_cmod->instance));
    if ($r_qiz === false) {
        RWSSErr("2044");
    }
    $r_pm = RWSGSOpt("qcatid", PARAM_ALPHANUM);
    if ($r_pm === false || strlen($r_pm) == 0) {
        RWSSErr("2064");
    }
    $r_qci = intval($r_pm);
    $r_qca = $DB->get_record("question_categories", array("id" => $r_qci));
    if ($r_qca === false) {
        RWSSErr("2065");
    }
    if (respondusws_floatcompare($CFG->version, 2013111800, 2) >= 0) {
        $r_ctx = context::instance_by_id($r_qca->contextid);
    } else {
        $r_ctx = get_context_instance_by_id($r_qca->contextid);
    }
    $r_qcci = RWSGCFCat($r_ctx);
    if ($r_qcci != $r_cid) {
        if (is_siteadmin($RWSUID)) {
            if ($r_qcci != SITEID) {
                RWSSErr("2109");
            }
        } else {
            RWSSErr("2084");
        }
    }
    $r_pm = RWSGSOpt("qcount", PARAM_ALPHANUM);
    if ($r_pm === false || strlen($r_pm) == 0) {
        RWSSErr("2085");
    }
    $r_qct = intval($r_pm);
    if ($r_qct <= 0) {
        RWSSErr("2085");
    }
    $r_pm = RWSGSOpt("qgrade", PARAM_NOTAGS);
    if ($r_pm === false || strlen($r_pm) == 0) {
        RWSSErr("2086");
    }
    $r_qg = round(floatval($r_pm));
    if ($r_qg <= 0) {
        RWSSErr("2086");
    }
    $r_mr = $DB->get_record("modules", array("id" => $r_cmod->module));
    if ($r_mr === false) {
        RWSSErr("2043");
    }
    $r_qiz = $DB->get_record($r_mr->name, array("id" => $r_cmod->instance));
    if ($r_qiz === false) {
        RWSSErr("2044");
    }
    if (!isset($r_qiz->instance)) {
        $r_qiz->instance = $r_qiz->id;
    }
    $r_aerr = 0;
    for ($r_i = 0; $r_i < $r_qct; $r_i++) {
        $r_qst = new stdClass();
        $r_qst->qtype = RWSRND;
        $r_qst->parent = 0;
        $r_qst->hidden = 0;
        $r_qst->length = 1;
        $r_qst->questiontext = 1;
        if (respondusws_floatcompare($CFG->version, 2011070100, 2) >= 0) {
            $r_rqt = question_bank::get_qtype("random");
            $r_qst->name = $r_rqt->question_name($r_qca, !empty($r_qst->questiontext));
        } else {
            $r_qst->name = random_qtype::question_name($r_qca, !empty($r_qst->questiontext));
        }
        $r_qst->questiontextformat = FORMAT_HTML;
        $r_qst->penalty = 0;
        if (respondusws_floatcompare($CFG->version, 2011070100, 2) >= 0) {
            $r_qst->defaultmark = $r_qg;
        } else {
            $r_qst->defaultgrade = $r_qg;
        }
        $r_qst->generalfeedback = "";
        $r_qst->generalfeedbackformat = FORMAT_HTML;
        $r_qst->category = $r_qca->id;
        $r_qst->stamp = make_unique_id_code();
        $r_qst->createdby = $RWSUID;
        $r_qst->modifiedby = $RWSUID;
        $r_qst->timecreated = time();
        $r_qst->timemodified = time();
        $r_qst->id = $DB->insert_record("question", $r_qst);
        $DB->set_field("question", "parent", $r_qst->id, array("id" => $r_qst->id));
        $r_h = question_hash($r_qst);
        $DB->set_field("question", "version", $r_h, array("id" => $r_qst->id));
        if (respondusws_floatcompare($CFG->version, 2011070100, 2) >= 0) {
            quiz_add_quiz_question($r_qst->id, $r_qiz);
        } else {
            $r_ok = quiz_add_quiz_question($r_qst->id, $r_qiz);
            if (!$r_ok) {
                $DB->delete_records("question", array("id" => $r_qst->id));
                $r_aerr++;
            }
        }
    }
    if ($r_aerr > 0) {
        RWSSErr("2087,{$r_aerr}");
    }
    if ($r_aerr < $r_qct) {
        quiz_delete_previews($r_qiz);
    }
    if (respondusws_floatcompare($CFG->version, 2014051200, 2) >= 0) {
        quiz_update_sumgrades($r_qiz);
    } else {
        $r_qiz->grades = quiz_get_all_question_grades($r_qiz);
        $r_sumg = array_sum($r_qiz->grades);
        $DB->set_field("quiz", "sumgrades", $r_sumg, array("id" => $r_qiz->id));
    }
    RWSSStat("1006");
}
Ejemplo n.º 3
0
/**
 * Update the sumgrades field of the quiz. This needs to be called whenever
 * the grading structure of the quiz is changed. For example if a question is
 * added or removed, or a question weight is changed.
 *
 * @param object $quiz a quiz.
 */
function quiz_update_sumgrades($quiz)
{
    global $DB;
    $grades = quiz_get_all_question_grades($quiz);
    $sumgrades = 0;
    foreach ($grades as $grade) {
        $sumgrades += $grade;
    }
    if (!isset($quiz->sumgrades) || $quiz->sumgrades != $sumgrades) {
        $DB->set_field('quiz', 'sumgrades', $sumgrades, array('id' => $quiz->id));
        $quiz->sumgrades = $sumgrades;
    }
}
Ejemplo n.º 4
0
}
// Get the course object and related bits.
if (!($course = get_record("course", "id", $modform->course))) {
    error("This course doesn't exist");
}
$coursecontext = get_context_instance(CONTEXT_COURSE, $modform->course);
require_login($course->id, false);
// Get the module and related bits.
$cm = get_coursemodule_from_instance('quiz', $modform->instance);
$modform->cmid = $cm->id;
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// Log this visit.
add_to_log($cm->course, 'quiz', 'editquestions', "view.php?id={$cm->id}", "{$quizid}", $cm->id);
require_capability('mod/quiz:manage', $context);
if (isset($modform->instance) && empty($modform->grades)) {
    $modform->grades = quiz_get_all_question_grades($modform);
}
$SESSION->returnurl = $FULLME;
/// Now, check for commands on this page and modify variables as necessary
if (isset($_REQUEST['up']) and confirm_sesskey()) {
    /// Move the given question up a slot
    $up = optional_param('up', 0, PARAM_INT);
    $questions = explode(",", $modform->questions);
    if ($up > 0 and isset($questions[$up])) {
        $prevkey = $questions[$up - 1] == 0 ? $up - 2 : $up - 1;
        $swap = $questions[$prevkey];
        $questions[$prevkey] = $questions[$up];
        $questions[$up] = $swap;
        $modform->questions = implode(",", $questions);
        // Always have a page break at the end
        $modform->questions = $modform->questions . ',0';