本文整理汇总了PHP中quiz_set_grade函数的典型用法代码示例。如果您正苦于以下问题:PHP quiz_set_grade函数的具体用法?PHP quiz_set_grade怎么用?PHP quiz_set_grade使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quiz_set_grade函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: quiz_update_sumgrades
/**
* 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.
*
* You should call {@link quiz_delete_previews()} before you call this function.
*
* @param object $quiz a quiz.
*/
function quiz_update_sumgrades($quiz) {
global $DB;
$sql = 'UPDATE {quiz}
SET sumgrades = COALESCE((
SELECT SUM(grade)
FROM {quiz_question_instances}
WHERE quiz = {quiz}.id
), 0)
WHERE id = ?';
$DB->execute($sql, array($quiz->id));
$quiz->sumgrades = $DB->get_field('quiz', 'sumgrades', array('id' => $quiz->id));
if ($quiz->sumgrades < 0.000005 && quiz_has_attempts($quiz->id)) {
// If the quiz has been attempted, and the sumgrades has been
// set to 0, then we must also set the maximum possible grade to 0, or
// we will get a divide by zero error.
quiz_set_grade(0, $quiz);
}
}
示例2: count
for ($i = $moveselectedonpage; $i > $numpages; $i--) {
$questions[] = 0;
$pagebreakpositions[] = count($questions) - 1;
}
$moveselectedpos = $pagebreakpositions[$moveselectedonpage - 1];
// Do the move.
array_splice($questions, $moveselectedpos, 0, $selectedquestionids);
$quiz->questions = implode(',', $questions);
// Update the database.
$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
$deletepreviews = true;
}
// If rescaling is required save the new maximum.
$maxgrade = unformat_float(optional_param('maxgrade', -1, PARAM_RAW));
if ($maxgrade >= 0) {
quiz_set_grade($maxgrade, $quiz);
}
if ($deletepreviews) {
quiz_delete_previews($quiz);
}
if ($recomputesummarks) {
quiz_update_sumgrades($quiz);
quiz_update_all_attempt_sumgrades($quiz);
quiz_update_all_final_grades($quiz);
quiz_update_grades($quiz, 0, true);
}
redirect($afteractionurl);
}
$questionbank->process_actions($thispageurl, $cm);
// End of process commands =====================================================
$PAGE->requires->yui2_lib('container');
示例3: quiz_update_sumgrades
/**
* 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;
$sql = 'UPDATE {quiz}
SET sumgrades = COALESCE((
SELECT SUM(grade)
FROM {quiz_question_instances}
WHERE quiz = {quiz}.id
), 0)
WHERE id = ?';
$DB->execute($sql, array($quiz->id));
$quiz->sumgrades = $DB->get_field('quiz', 'sumgrades', array('id' => $quiz->id));
if ($quiz->sumgrades < 0.000005 && quiz_clean_layout($quiz->questions, true)) {
// If there is at least one question in the quiz, and the sumgrades has been
// set to 0, then also set the maximum possible grade to 0.
quiz_set_grade(0, $quiz);
}
}
示例4: implode
}
$quiz->questions = implode(",", $questions);
// Always have a page break at the end
$quiz->questions = $quiz->questions . ',0';
// Avoid duplicate page breaks
while (strpos($quiz->questions, ',0,0')) {
$quiz->questions = str_replace(',0,0', ',0', $quiz->questions);
}
if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->instance)) {
error('Could not save question list');
}
}
// If rescaling is required save the new maximum
$maxgrade = optional_param('maxgrade', -1, PARAM_INTEGER);
if ($maxgrade >= 0) {
if (!quiz_set_grade($maxgrade, $quiz)) {
error('Could not set a new maximum grade for the quiz');
}
}
$significantchangemade = true;
}
/// Delete any teacher preview attempts if the quiz has been modified
if ($significantchangemade) {
$previewattempts = get_records_select('quiz_attempts', 'quiz = ' . $quiz->id . ' AND preview = 1');
if ($previewattempts) {
foreach ($previewattempts as $attempt) {
quiz_delete_attempt($attempt, $quiz);
}
}
}
question_showbank_actions($thispageurl, $cm);
示例5: ksort
if ($questions) {
ksort($questions);
$quiz->questions = implode(",", $questions);
// Always have a page break at the end
$quiz->questions = $quiz->questions . ',0';
// Avoid duplicate page breaks
while (strpos($quiz->questions, ',0,0')) {
$quiz->questions = str_replace(',0,0', ',0', $quiz->questions);
}
if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->instance)) {
error('Could not save question list');
}
}
// If rescaling is required save the new maximum
if (isset($_REQUEST['maxgrade'])) {
if (!quiz_set_grade(optional_param('maxgrade', 0), $quiz)) {
error('Could not set a new maximum grade for the quiz');
}
}
}
/// Delete any teacher preview attempts if the quiz has been modified
if (isset($_REQUEST['savechanges']) or isset($_REQUEST['delete']) or isset($_REQUEST['repaginate']) or isset($_REQUEST['addrandom']) or isset($_REQUEST['addquestion']) or isset($_REQUEST['up']) or isset($_REQUEST['down']) or isset($_REQUEST['add'])) {
delete_records('quiz_attempts', 'preview', '1', 'quiz', $quiz->id);
}
question_showbank_actions($thispageurl, $cm);
/// all commands have been dealt with, now print the page
// Print basic page layout.
if (isset($quiz->instance) and record_exists_select('quiz_attempts', "quiz = '{$quiz->instance}' AND preview = '0'")) {
// one column layout with table of questions used in this quiz
$strupdatemodule = has_capability('moodle/course:manageactivities', $contexts->lowest()) ? update_module_button($cm->id, $course->id, get_string('modulename', 'quiz')) : "";
$navlinks = array();
示例6: ksort
if ($questions) {
ksort($questions);
$modform->questions = implode(",", $questions);
// Always have a page break at the end
$modform->questions = $modform->questions . ',0';
// Avoid duplicate page breaks
while (strpos($modform->questions, ',0,0')) {
$modform->questions = str_replace(',0,0', ',0', $modform->questions);
}
if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->instance)) {
error('Could not save question list');
}
}
// If rescaling is required save the new maximum
if (isset($_REQUEST['maxgrade'])) {
if (!quiz_set_grade(optional_param('maxgrade', 0), $modform)) {
error('Could not set a new maximum grade for the quiz');
}
}
}
if (isset($_REQUEST['showbreaks'])) {
$SESSION->quiz_showbreaks = optional_param('showbreaks', 0, PARAM_BOOL);
$SESSION->quiz_reordertool = optional_param('reordertool', 0, PARAM_BOOL);
}
/// Delete any teacher preview attempts if the quiz has been modified
if (isset($_REQUEST['savechanges']) or isset($_REQUEST['delete']) or isset($_REQUEST['repaginate']) or isset($_REQUEST['addrandom']) or isset($_REQUEST['addquestion']) or isset($_REQUEST['up']) or isset($_REQUEST['down']) or isset($_REQUEST['add'])) {
delete_records('quiz_attempts', 'preview', '1', 'quiz', $modform->id);
}
/// all commands have been dealt with, now print the page
if (empty($modform->category) or !record_exists('question_categories', 'id', $modform->category)) {
$category = get_default_question_category($course->id);
示例7: quiz_update_sumgrades
/**
* 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;
$sql = 'UPDATE {quiz}
SET sumgrades = COALESCE((
SELECT SUM(grade)
FROM {quiz_question_instances}
WHERE quiz = {quiz}.id
), 0)
WHERE id = ?';
$DB->execute($sql, array($quiz->id));
$quiz->sumgrades = $DB->get_field('quiz', 'sumgrades', array('id' => $quiz->id));
if ($quiz->sumgrades < 5.0E-6) {
quiz_set_grade(0, $quiz);
}
}