本文整理匯總了PHP中quiz_repaginate函數的典型用法代碼示例。如果您正苦於以下問題:PHP quiz_repaginate函數的具體用法?PHP quiz_repaginate怎麽用?PHP quiz_repaginate使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了quiz_repaginate函數的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: quiz_create_attempt
/**
* Creates an object to represent a new attempt at a quiz
*
* Creates an attempt object to represent an attempt at the quiz by the current
* user starting at the current time. The ->id field is not set. The object is
* NOT written to the database.
*
* @param object $quiz the quiz to create an attempt for.
* @param int $attemptnumber the sequence number for the attempt.
* @param object $lastattempt the previous attempt by this user, if any. Only needed
* if $attemptnumber > 1 and $quiz->attemptonlast is true.
* @param int $timenow the time the attempt was started at.
* @param bool $ispreview whether this new attempt is a preview.
*
* @return object the newly created attempt object.
*/
function quiz_create_attempt($quiz, $attemptnumber, $lastattempt, $timenow, $ispreview = false)
{
global $USER;
if ($attemptnumber == 1 || !$quiz->attemptonlast) {
// We are not building on last attempt so create a new attempt.
$attempt = new stdClass();
$attempt->quiz = $quiz->id;
$attempt->userid = $USER->id;
$attempt->preview = 0;
$attempt->layout = quiz_clean_layout($quiz->questions, true);
if ($quiz->shufflequestions) {
$attempt->layout = quiz_repaginate($attempt->layout, $quiz->questionsperpage, true);
}
} else {
// Build on last attempt.
if (empty($lastattempt)) {
print_error('cannotfindprevattempt', 'quiz');
}
$attempt = $lastattempt;
}
$attempt->attempt = $attemptnumber;
$attempt->timestart = $timenow;
$attempt->timefinish = 0;
$attempt->timemodified = $timenow;
// If this is a preview, mark it as such.
if ($ispreview) {
$attempt->preview = 1;
}
return $attempt;
}
示例2: quiz_create_attempt
/**
* Creates an object to represent a new attempt at a quiz
*
* Creates an attempt object to represent an attempt at the quiz by the current
* user starting at the current time. The ->id field is not set. The object is
* NOT written to the database.
*
* @param object $quiz the quiz to create an attempt for.
* @param int $attemptnumber the sequence number for the attempt.
* @param object $lastattempt the previous attempt by this user, if any. Only needed
* if $attemptnumber > 1 and $quiz->attemptonlast is true.
* @param int $timenow the time the attempt was started at.
* @param bool $ispreview whether this new attempt is a preview.
*
* @return object the newly created attempt object.
*/
function quiz_create_attempt($quiz, $attemptnumber, $lastattempt, $timenow, $ispreview = false)
{
global $USER;
if ($quiz->sumgrades < 5.0E-6 && $quiz->grade > 5.0E-6) {
throw new moodle_exception('cannotstartgradesmismatch', 'quiz', new moodle_url('/mod/quiz/view.php', array('q' => $quiz->id)), array('grade' => quiz_format_grade($quiz, $quiz->grade)));
}
if ($attemptnumber == 1 || !$quiz->attemptonlast) {
// We are not building on last attempt so create a new attempt.
$attempt = new stdClass();
$attempt->quiz = $quiz->id;
$attempt->userid = $USER->id;
$attempt->preview = 0;
$attempt->layout = quiz_clean_layout($quiz->questions, true);
if ($quiz->shufflequestions) {
$attempt->layout = quiz_repaginate($attempt->layout, $quiz->questionsperpage, true);
}
} else {
// Build on last attempt.
if (empty($lastattempt)) {
print_error('cannotfindprevattempt', 'quiz');
}
$attempt = $lastattempt;
}
$attempt->attempt = $attemptnumber;
$attempt->timestart = $timenow;
$attempt->timefinish = 0;
$attempt->timemodified = $timenow;
$attempt->state = quiz_attempt::IN_PROGRESS;
// If this is a preview, mark it as such.
if ($ispreview) {
$attempt->preview = 1;
}
return $attempt;
}
示例3: quiz_create_attempt
/**
* Creates an object to represent a new attempt at a quiz
*
* Creates an attempt object to represent an attempt at the quiz by the current
* user starting at the current time. The ->id field is not set. The object is
* NOT written to the database.
* @return object The newly created attempt object.
* @param object $quiz The quiz to create an attempt for.
* @param integer $attemptnumber The sequence number for the attempt.
*/
function quiz_create_attempt($quiz, $attemptnumber)
{
global $USER, $CFG;
if (!$attemptnumber > 1 or !$quiz->attemptonlast or !($attempt = get_record('quiz_attempts', 'quiz', $quiz->id, 'userid', $USER->id, 'attempt', $attemptnumber - 1))) {
// we are not building on last attempt so create a new attempt
$attempt->quiz = $quiz->id;
$attempt->userid = $USER->id;
$attempt->preview = 0;
if ($quiz->shufflequestions) {
$attempt->layout = quiz_repaginate($quiz->questions, $quiz->questionsperpage, true);
} else {
$attempt->layout = $quiz->questions;
}
}
$timenow = time();
$attempt->attempt = $attemptnumber;
$attempt->sumgrades = 0.0;
$attempt->timestart = $timenow;
$attempt->timefinish = 0;
$attempt->timemodified = $timenow;
$attempt->uniqueid = question_new_attempt_uniqueid();
return $attempt;
}
示例4: array
<a href="' . $thispageurl->out(true, array('qbanktool' => '0')) . '" id="hidebankcmd">[' . get_string('hide') . ']</a>';
echo '</h2></div></div><div class="content">';
echo '<span id="questionbank"></span>';
echo '<div class="container">';
echo '<div id="module" class="module">';
echo '<div class="bd">';
$questionbank->display('editq', $pagevars['qpage'], $pagevars['qperpage'], $pagevars['cat'], $pagevars['recurse'], $pagevars['showhidden'], $pagevars['qbshowtext']);
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div></div>';
echo '<div class="quizcontents ' . $quizcontentsclass . '" id="quizcontentsblock">';
if ($quiz->shufflequestions) {
$repaginatingdisabledhtml = 'disabled="disabled"';
$repaginatingdisabled = true;
$quiz->questions = quiz_repaginate($quiz->questions, $quiz->questionsperpage);
} else {
$repaginatingdisabledhtml = '';
$repaginatingdisabled = false;
}
if ($quiz_reordertool) {
echo '<div class="repaginatecommand"><button id="repaginatecommand" ' . $repaginatingdisabledhtml . '>' . get_string('repaginatecommand', 'quiz') . '...</button>';
echo '</div>';
}
if ($quiz_reordertool) {
echo $OUTPUT->heading_with_help(get_string('orderingquizx', 'quiz', format_string($quiz->name)), 'orderandpaging', 'quiz');
} else {
echo $OUTPUT->heading(get_string('editingquizx', 'quiz', format_string($quiz->name)), 2);
echo $OUTPUT->help_icon('editingquiz', 'quiz', get_string('basicideasofquiz', 'quiz'));
}
quiz_print_status_bar($quiz);
示例5: quiz_upgrade
//.........這裏部分代碼省略.........
$wtm->update('quiz_questions', 'questiontext', 'questiontextformat', $sql);
}
if ($success && $oldversion < 2005041304) {
// make random questions hidden
$success = $success && modify_database('', "UPDATE prefix_quiz_questions SET hidden = '1' WHERE qtype ='" . RANDOM . "';");
}
if ($success && $oldversion < 2005042002) {
$success = $success && table_column('quiz_answers', 'answer', 'answer', 'text', '', '', '', 'not null', '');
}
if ($success && $oldversion < 2005042400) {
// Changes to quiz table
// The bits of the optionflags field will hold various option flags
$success = $success && table_column('quiz', '', 'optionflags', 'integer', '10', 'unsigned', '0', 'not null', 'timeclose');
// The penalty scheme
$success = $success && table_column('quiz', '', 'penaltyscheme', 'integer', '4', 'unsigned', '0', 'not null', 'optionflags');
// The review options are now all stored in the bits of the review field
$success = $success && table_column('quiz', 'review', 'review', 'integer', 10, 'unsigned', 0, 'not null', '');
/// Changes to quiz_attempts table
// The preview flag marks teacher previews
$success = $success && table_column('quiz_attempts', '', 'preview', 'tinyint', '2', 'unsigned', '0', 'not null', 'timemodified');
// The layout is the list of questions with inserted page breaks.
$success = $success && table_column('quiz_attempts', '', 'layout', 'text', '', '', '', 'not null', 'timemodified');
// For old quiz attempts we will set this to the repaginated question list from $quiz->questions
/// The following updates of field values require a loop through all quizzes
// This is because earlier versions of mysql don't allow joins in UPDATE
if ($quizzes = get_records('quiz')) {
// turn reporting off temporarily to avoid one line output per set_field
$olddebug = $db->debug;
$db->debug = false;
echo 'Now updating ' . count($quizzes) . ' quizzes';
foreach ($quizzes as $quiz) {
// repaginate
if ($quiz->questionsperpage) {
$quiz->questions = quiz_repaginate($quiz->questions, $quiz->questionsperpage);
$success = $success && set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->id);
}
$success = $success && set_field('quiz_attempts', 'layout', $quiz->questions, 'quiz', $quiz->id);
// set preview flag
if ($teachers = get_course_teachers($quiz->course)) {
$teacherids = implode(',', array_keys($teachers));
$success = $success && execute_sql("UPDATE {$CFG->prefix}quiz_attempts SET preview = 1 WHERE userid IN ({$teacherids})");
}
// set review flags in quiz table
$review = QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_RESPONSES + QUIZ_REVIEW_SCORES;
if ($quiz->feedback) {
$review += QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_FEEDBACK;
}
if ($quiz->correctanswers) {
$review += QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_ANSWERS;
}
if ($quiz->review & 1) {
$review += QUIZ_REVIEW_CLOSED;
}
if ($quiz->review & 2) {
$review += QUIZ_REVIEW_OPEN;
}
$success = $success && set_field('quiz', 'review', $review, 'id', $quiz->id);
}
$db->debug = $olddebug;
}
// We can now drop the fields whose data has been moved to the review field
$success = $success && execute_sql(" ALTER TABLE `{$CFG->prefix}quiz` DROP feedback");
$success = $success && execute_sql(" ALTER TABLE `{$CFG->prefix}quiz` DROP correctanswers");
/// Renaming tables
// rename the quiz_question_grades table to quiz_question_instances
$success = $success && modify_database('', 'ALTER TABLE prefix_quiz_question_grades RENAME prefix_quiz_question_instances;');
示例6: quiz_restore_pre15_mods
function quiz_restore_pre15_mods($mod, $restore)
{
global $CFG;
$status = true;
//Get record from backup_ids
$data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
if ($data) {
//Now get completed xmlized object
$info = $data->info;
//if necessary, write to restorelog and adjust date/time fields
if ($restore->course_startdateoffset) {
restore_log_date_changes('Quiz', $restore, $info['MOD']['#'], array('TIMEOPEN', 'TIMECLOSE'));
}
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now, build the QUIZ record structure
$quiz->course = $restore->course_id;
$quiz->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
$quiz->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
$quiz->timeopen = backup_todb($info['MOD']['#']['TIMEOPEN']['0']['#']);
$quiz->timeclose = backup_todb($info['MOD']['#']['TIMECLOSE']['0']['#']);
$quiz->attempts = backup_todb($info['MOD']['#']['ATTEMPTS_NUMBER']['0']['#']);
$quiz->attemptonlast = backup_todb($info['MOD']['#']['ATTEMPTONLAST']['0']['#']);
$quiz->feedback = backup_todb($info['MOD']['#']['FEEDBACK']['0']['#']);
$quiz->correctanswers = backup_todb($info['MOD']['#']['CORRECTANSWERS']['0']['#']);
$quiz->grademethod = backup_todb($info['MOD']['#']['GRADEMETHOD']['0']['#']);
if (isset($info['MOD']['#']['DECIMALPOINTS']['0']['#'])) {
//Only if it's set, to apply DB default else.
$quiz->decimalpoints = backup_todb($info['MOD']['#']['DECIMALPOINTS']['0']['#']);
}
$quiz->review = backup_todb($info['MOD']['#']['REVIEW']['0']['#']);
$quiz->questionsperpage = backup_todb($info['MOD']['#']['QUESTIONSPERPAGE']['0']['#']);
$quiz->shufflequestions = backup_todb($info['MOD']['#']['SHUFFLEQUESTIONS']['0']['#']);
$quiz->shuffleanswers = backup_todb($info['MOD']['#']['SHUFFLEANSWERS']['0']['#']);
$quiz->questions = backup_todb($info['MOD']['#']['QUESTIONS']['0']['#']);
$quiz->sumgrades = backup_todb($info['MOD']['#']['SUMGRADES']['0']['#']);
$quiz->grade = backup_todb($info['MOD']['#']['GRADE']['0']['#']);
$quiz->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']);
$quiz->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
$quiz->timelimit = backup_todb($info['MOD']['#']['TIMELIMIT']['0']['#']);
$quiz->password = backup_todb($info['MOD']['#']['PASSWORD']['0']['#']);
$quiz->subnet = backup_todb($info['MOD']['#']['SUBNET']['0']['#']);
$quiz->popup = backup_todb($info['MOD']['#']['POPUP']['0']['#']);
//We have to recode the questions field (a list of questions id)
$newquestions = array();
if ($questionsarr = explode(",", $quiz->questions)) {
foreach ($questionsarr as $key => $value) {
if ($question = backup_getid($restore->backup_unique_code, "question", $value)) {
$newquestions[] = $question->new_id;
}
}
}
$quiz->questions = implode(",", $newquestions);
//Recalculate the questions field to include page breaks if necessary
$quiz->questions = quiz_repaginate($quiz->questions, $quiz->questionsperpage);
//Calculate the new review field contents (logic extracted from upgrade)
$review = QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_RESPONSES + QUIZ_REVIEW_SCORES;
if ($quiz->feedback) {
$review += QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_FEEDBACK;
}
if ($quiz->correctanswers) {
$review += QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_ANSWERS;
}
if ($quiz->review & 1) {
$review += QUIZ_REVIEW_CLOSED;
}
if ($quiz->review & 2) {
$review += QUIZ_REVIEW_OPEN;
}
$quiz->review = $review;
//The structure is equal to the db, so insert the quiz
$newid = insert_record("quiz", $quiz);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
echo "<li>" . get_string("modulename", "quiz") . " \"" . format_string(stripslashes($quiz->name), true) . "\"</li>";
}
backup_flush(300);
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
//We have to restore the quiz_question_instances now (old quiz_question_grades, course level)
$status = quiz_question_instances_restore_pre15_mods($newid, $info, $restore);
//We have to restore the question_versions now (course level table)
$status = quiz_question_versions_restore_pre15_mods($newid, $info, $restore);
//Now check if want to restore user data and do it.
if (restore_userdata_selected($restore, 'quiz', $mod->id)) {
//Restore quiz_attempts
$status = quiz_attempts_restore_pre15_mods($newid, $info, $restore, $quiz->questions);
if ($status) {
//Restore quiz_grades
$status = quiz_grades_restore_pre15_mods($newid, $info, $restore);
}
}
} else {
$status = false;
}
} else {
$status = false;
}
//.........這裏部分代碼省略.........
示例7: quiz_update_instance
/**
* 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 $quiz the data that came from the form.
* @return mixed true on success, false or a string error message on failure.
*/
function quiz_update_instance($quiz, $mform) {
global $CFG, $DB;
// Process the options from the form.
$result = quiz_process_options($quiz);
if ($result && is_string($result)) {
return $result;
}
$oldquiz = $DB->get_record('quiz', array('id' => $quiz->instance));
// Repaginate, if asked to.
if (!$quiz->shufflequestions && !empty($quiz->repaginatenow)) {
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
$quiz->questions = quiz_repaginate(quiz_clean_layout($oldquiz->questions, true),
$quiz->questionsperpage);
}
unset($quiz->repaginatenow);
// Update the database.
$quiz->id = $quiz->instance;
$DB->update_record('quiz', $quiz);
// Do the processing required after an add or an update.
quiz_after_add_or_update($quiz);
if ($oldquiz->grademethod != $quiz->grademethod) {
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
$quiz->sumgrades = $oldquiz->sumgrades;
$quiz->grade = $oldquiz->grade;
quiz_update_all_final_grades($quiz);
quiz_update_grades($quiz);
}
// Delete any previous preview attempts.
quiz_delete_previews($quiz);
return true;
}
示例8: quiz_update_instance
/**
* 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 $quiz the data that came from the form.
* @return mixed true on success, false or a string error message on failure.
*/
function quiz_update_instance($quiz, $mform)
{
global $CFG, $DB;
require_once $CFG->dirroot . '/mod/quiz/locallib.php';
// Process the options from the form.
$result = quiz_process_options($quiz);
if ($result && is_string($result)) {
return $result;
}
// Get the current value, so we can see what changed.
$oldquiz = $DB->get_record('quiz', array('id' => $quiz->instance));
// We need two values from the existing DB record that are not in the form,
// in some of the function calls below.
$quiz->sumgrades = $oldquiz->sumgrades;
$quiz->grade = $oldquiz->grade;
// Repaginate, if asked to.
if (!$quiz->shufflequestions && !empty($quiz->repaginatenow)) {
$quiz->questions = quiz_repaginate(quiz_clean_layout($oldquiz->questions, true), $quiz->questionsperpage);
}
unset($quiz->repaginatenow);
// Update the database.
$quiz->id = $quiz->instance;
$DB->update_record('quiz', $quiz);
// Do the processing required after an add or an update.
quiz_after_add_or_update($quiz);
if ($oldquiz->grademethod != $quiz->grademethod) {
quiz_update_all_final_grades($quiz);
quiz_update_grades($quiz);
}
$quizdateschanged = $oldquiz->timelimit != $quiz->timelimit || $oldquiz->timeclose != $quiz->timeclose || $oldquiz->graceperiod != $quiz->graceperiod;
if ($quizdateschanged) {
quiz_update_open_attempts(array('quizid' => $quiz->id));
}
// Delete any previous preview attempts.
quiz_delete_previews($quiz);
return true;
}
示例9: quiz_upgrade
//.........這裏部分代碼省略.........
$sql .= "where {$CFG->prefix}quiz_category.id = {$CFG->prefix}quiz_questions.category ";
$sql .= "and {$CFG->prefix}quiz_questions.id = ";
$wtm->update('quiz_questions', 'questiontext', 'questiontextformat', $sql);
}
if ($success && $oldversion < 2005041300) {
$success = $success && modify_database('', "UPDATE prefix_quiz_questions SET hidden = '1' WHERE qtype ='" . RANDOM . "';");
}
if ($success && $oldversion < 2005042002) {
$success = $success && table_column('quiz_answers', 'answer', 'answer', 'text', '', '', '', 'not null', '');
}
if ($success && $oldversion < 2005042400) {
begin_sql();
// Changes to quiz table
// The bits of the optionflags field will hold various option flags
$success = $success && table_column('quiz', '', 'optionflags', 'integer', '10', 'unsigned', '0', 'not null', 'timeclose');
// The penalty scheme
$success = $success && table_column('quiz', '', 'penaltyscheme', 'integer', '4', 'unsigned', '0', 'not null', 'optionflags');
// The review options are now all stored in the bits of the review field
$success = $success && table_column('quiz', 'review', 'review', 'integer', 10, 'unsigned', 0, 'not null', '');
/// Changes to quiz_attempts table
// The preview flag marks teacher previews
$success = $success && table_column('quiz_attempts', '', 'preview', 'tinyint', '2', 'unsigned', '0', 'not null', 'timemodified');
// The layout is the list of questions with inserted page breaks.
$success = $success && table_column('quiz_attempts', '', 'layout', 'text', '', '', '', 'not null', 'timemodified');
// For old quiz attempts we will set this to the repaginated question list from $quiz->questions
/// The following updates of field values require a loop through all quizzes
// This is because earlier versions of mysql don't allow joins in UPDATE
if ($quizzes = get_records('quiz')) {
// turn reporting off temporarily to avoid one line output per set_field
$olddebug = $db->debug;
$db->debug = false;
foreach ($quizzes as $quiz) {
// repaginate
$quiz->questions = $quiz->questionsperpage ? quiz_repaginate($quiz->questions, $quiz->questionsperpage) : $quiz->questions;
if ($quiz->questionsperpage) {
$quiz->questions = quiz_repaginate($quiz->questions, $quiz->questionsperpage);
$success = $success && set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->id);
}
set_field('quiz_attempts', 'layout', $quiz->questions, 'quiz', $quiz->id);
// set preview flag
if ($teachers = get_course_teachers($quiz->course)) {
$teacherids = implode(',', array_keys($teachers));
$success = $success && execute_sql("UPDATE {$CFG->prefix}quiz_attempts SET preview = 1 WHERE userid IN ({$teacherids})");
}
// set review flags in quiz table
$review = QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_RESPONSES + QUIZ_REVIEW_SCORES;
if ($quiz->feedback) {
$review += QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_FEEDBACK;
}
if ($quiz->correctanswers) {
$review += QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_ANSWERS;
}
if ($quiz->review & 1) {
$review += QUIZ_REVIEW_CLOSED;
}
if ($quiz->review & 2) {
$review += QUIZ_REVIEW_OPEN;
}
$success = $success && set_field('quiz', 'review', $review, 'id', $quiz->id);
}
$db->debug = $olddebug;
}
// We can now drop the fields whose data has been moved to the review field
$success = $success && execute_sql(" ALTER TABLE {$CFG->prefix}quiz DROP COLUMN feedback");
$success = $success && execute_sql(" ALTER TABLE {$CFG->prefix}quiz DROP COLUMN correctanswers");
/// Renaming tables
示例10: test_quiz_repaginate
public function test_quiz_repaginate() {
// Test starting with 1 question per page.
$this->assertEquals(quiz_repaginate('1,0,2,0,3,0', 0), '1,2,3,0');
$this->assertEquals(quiz_repaginate('1,0,2,0,3,0', 3), '1,2,3,0');
$this->assertEquals(quiz_repaginate('1,0,2,0,3,0', 2), '1,2,0,3,0');
$this->assertEquals(quiz_repaginate('1,0,2,0,3,0', 1), '1,0,2,0,3,0');
// Test starting with all on one page page.
$this->assertEquals(quiz_repaginate('1,2,3,0', 0), '1,2,3,0');
$this->assertEquals(quiz_repaginate('1,2,3,0', 3), '1,2,3,0');
$this->assertEquals(quiz_repaginate('1,2,3,0', 2), '1,2,0,3,0');
$this->assertEquals(quiz_repaginate('1,2,3,0', 1), '1,0,2,0,3,0');
// Test single question case.
$this->assertEquals(quiz_repaginate('100,0', 0), '100,0');
$this->assertEquals(quiz_repaginate('100,0', 1), '100,0');
// No questions case.
$this->assertEquals(quiz_repaginate('0', 0), '0');
// Test empty pages are removed.
$this->assertEquals(quiz_repaginate('1,2,3,0,0,0', 0), '1,2,3,0');
$this->assertEquals(quiz_repaginate('1,0,0,0,2,3,0', 0), '1,2,3,0');
$this->assertEquals(quiz_repaginate('0,0,0,1,2,3,0', 0), '1,2,3,0');
// Test shuffle option.
$this->assertTrue(in_array(quiz_repaginate('1,2,0', 0, true),
array('1,2,0', '2,1,0')));
$this->assertTrue(in_array(quiz_repaginate('1,2,0', 1, true),
array('1,0,2,0', '2,0,1,0')));
}
示例11: error
if (!isset($question->id)) {
error('Could not insert new random question!');
}
quiz_add_quiz_question($question->id, $modform);
}
}
}
if (isset($_REQUEST['repaginate']) and confirm_sesskey()) {
/// Re-paginate the quiz
if (isset($_REQUEST['questionsperpage'])) {
$modform->questionsperpage = required_param('questionsperpage', PARAM_INT);
if (!set_field('quiz', 'questionsperpage', $modform->questionsperpage, 'id', $modform->id)) {
error('Could not save number of questions per page');
}
}
$modform->questions = quiz_repaginate($modform->questions, $modform->questionsperpage);
if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->id)) {
error('Could not save layout');
}
}
if (isset($_REQUEST['delete']) and confirm_sesskey()) {
/// Remove a question from the quiz
quiz_delete_quiz_question($_REQUEST['delete'], $modform);
}
if (isset($_REQUEST['savechanges']) and confirm_sesskey()) {
$savequizid = required_param('savequizid', PARAM_INT);
if ($modform->id != $savequizid) {
error("Error saving quiz settings, please do not change two quizes from the same browser", $CFG->wwwroot . '/mod/quiz/edit.php?quizid=' . $savequizid);
}
/// We need to save the new ordering (if given) and the new grades
$oldquestions = explode(",", $modform->questions);
示例12: blended_create_attempt
/**
* Create a new Attempt in a quiz.
*
* @param unknown_type $quiz record identifying the quiz in which the attempt will be created.
* @param unknown_type $attemptnumber
* TODO check uniqueid usage
* TODO refactor this to a middle-layer library.
*/
function blended_create_attempt($quiz, $attemptnumber)
{
global $USER, $CFG;
// we are not building on last attempt so create a new attempt
$attempt->quiz = $quiz->id;
//$attempt->userid = $USER->id;
$attempt->preview = 0;
if ($quiz->shufflequestions) {
$attempt->layout = quiz_repaginate($quiz->questions, $quiz->questionsperpage, true);
} else {
$attempt->layout = $quiz->questions;
}
$timenow = time();
$attempt->attempt = $attemptnumber;
$attempt->userid = $USER->id;
$attempt->sumgrades = 0.0;
$attempt->timestart = $timenow;
$attempt->timefinish = 0;
$attempt->timemodified = $timenow;
//$attempt->uniqueid = question_new_attempt_uniqueid('blended');
//$attempt->id = $attempt->uniqueid;
return $attempt;
}