本文整理汇总了PHP中quiz类的典型用法代码示例。如果您正苦于以下问题:PHP quiz类的具体用法?PHP quiz怎么用?PHP quiz使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了quiz类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_quiz_report_overview_report_forcesubmit_specific_attempt
public function test_quiz_report_overview_report_forcesubmit_specific_attempt()
{
global $DB;
$this->resetAfterTest();
$generator = $this->getDataGenerator();
$quizgenerator = $generator->get_plugin_generator('mod_quiz');
$questiongenerator = $generator->get_plugin_generator('core_question');
// Make a user to do the quiz.
$user1 = $generator->create_user();
$user2 = $generator->create_user();
$user3 = $generator->create_user();
// Create our course.
$course = $generator->create_course(array('visible' => true));
// Create the quiz.
$quiz = $quizgenerator->create_instance(array('course' => $course->id, 'visible' => true, 'questionsperpage' => 0, 'grade' => 100.0, 'sumgrades' => 2));
// Create two questions.
$cat = $questiongenerator->create_question_category();
$saq = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id));
$numq = $questiongenerator->create_question('numerical', null, array('category' => $cat->id));
// Add the questions to the quiz.
quiz_add_quiz_question($saq->id, $quiz);
quiz_add_quiz_question($numq->id, $quiz);
// Get a quiz object with user access overrides.
$quizobj = quiz::create($quiz->id, $user1->id);
$quizobj2 = quiz::create($quiz->id, $user2->id);
$quizobj3 = quiz::create($quiz->id, $user3->id);
// Start the attempt.
$quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
$quba2 = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj2->get_context());
$quba2->set_preferred_behaviour($quizobj2->get_quiz()->preferredbehaviour);
$quba3 = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj3->get_context());
$quba3->set_preferred_behaviour($quizobj3->get_quiz()->preferredbehaviour);
// Create a quiz attempt.
$timenow = time();
$attempt = quiz_create_attempt($quizobj, 1, false, $timenow, false, $user1->id);
$attempt2 = quiz_create_attempt($quizobj2, 1, false, $timenow, false, $user2->id);
$attempt3 = quiz_create_attempt($quizobj3, 1, false, $timenow, false, $user3->id);
// Start the attempt.
quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow);
quiz_attempt_save_started($quizobj, $quba, $attempt);
quiz_start_new_attempt($quizobj2, $quba2, $attempt2, 1, $timenow);
quiz_attempt_save_started($quizobj2, $quba2, $attempt2);
quiz_start_new_attempt($quizobj3, $quba3, $attempt3, 1, $timenow);
quiz_attempt_save_started($quizobj3, $quba3, $attempt3);
// Answer first question and set it overdue.
$tosubmit = array(1 => array('answer' => 'frog'));
$tosubmit2 = array(1 => array('answer' => 'tiger'));
$tosubmit3 = array(1 => array('answer' => 'tiger'));
$attemptobj = quiz_attempt::create($attempt->id);
$attemptobj->process_submitted_actions($timenow, true, $tosubmit);
$attemptobj2 = quiz_attempt::create($attempt2->id);
$attemptobj2->process_submitted_actions($timenow, true, $tosubmit2);
$attemptobj3 = quiz_attempt::create($attempt3->id);
$attemptobj3->process_submitted_actions($timenow, true, $tosubmit3);
// Finish the attempt.
$attemptobj = quiz_attempt::create($attempt->id);
$this->assertTrue($attemptobj->has_response_to_at_least_one_graded_question());
$attemptobj->process_abandon($timenow, false);
// Re-load quiz attempt2 data.
$attemptobj = quiz_attempt::create($attempt->id);
$attemptobj2 = quiz_attempt::create($attempt2->id);
$attemptobj3 = quiz_attempt::create($attempt3->id);
// Check that the state of the attempt is as expected.
$this->assertEquals(1, $attemptobj->get_attempt_number());
$this->assertEquals(quiz_attempt::ABANDONED, $attemptobj->get_state());
$this->assertEquals($user1->id, $attemptobj->get_userid());
$this->assertTrue($attemptobj->has_response_to_at_least_one_graded_question());
// Check that the state of the attempt2 is as expected.
$this->assertEquals(1, $attemptobj2->get_attempt_number());
$this->assertEquals(quiz_attempt::OVERDUE, $attemptobj2->get_state());
$this->assertEquals($user2->id, $attemptobj2->get_userid());
$this->assertTrue($attemptobj2->has_response_to_at_least_one_graded_question());
// Check that the state of the attempt3 is as expected.
$this->assertEquals(1, $attemptobj3->get_attempt_number());
$this->assertEquals(quiz_attempt::OVERDUE, $attemptobj3->get_state());
$this->assertEquals($user3->id, $attemptobj3->get_userid());
$this->assertTrue($attemptobj3->has_response_to_at_least_one_graded_question());
// Force submit the attempts.
$overviewreport = new quiz_overview_report_testable();
$overviewreport->forcesubmit_attempts($quiz, false, array(), array($attempt->id, $attempt3->id));
// Check that it is now finished.
$attemptobj = quiz_attempt::create($attempt->id);
$this->assertEquals(quiz_attempt::FINISHED, $attemptobj->get_state());
$attemptobj2 = quiz_attempt::create($attempt2->id);
$this->assertEquals(quiz_attempt::OVERDUE, $attemptobj2->get_state());
$attemptobj3 = quiz_attempt::create($attempt3->id);
$this->assertEquals(quiz_attempt::FINISHED, $attemptobj3->get_state());
}
示例2: make
public static function make(quiz $quizobj, $timenow, $canignoretimelimits)
{
if (empty($quizobj->get_quiz()->honestycheckrequired)) {
return null;
}
return new self($quizobj, $timenow);
}
示例3: create_for_quiz
/**
* Create an instance of this class representing the structure of a given quiz.
* @param \quiz $quizobj the quiz.
* @return structure
*/
public static function create_for_quiz($quizobj)
{
$structure = self::create();
$structure->quizobj = $quizobj;
$structure->populate_structure($quizobj->get_quiz());
return $structure;
}
示例4: make
public static function make(quiz $quizobj, $timenow, $canignoretimelimits)
{
if (empty($quizobj->get_quiz()->timelimit) || $canignoretimelimits) {
return null;
}
return new self($quizobj, $timenow);
}
示例5: make
public static function make(quiz $quizobj, $timenow, $canignoretimelimits)
{
if (empty($quizobj->get_quiz()->offlinemode_enabled) || !self::is_compatible_behaviour($quizobj->get_quiz()->preferredbehaviour)) {
return null;
}
return new self($quizobj, $timenow);
}
示例6: edit_page
/**
* Render the edit page
*
* @param \quiz $quizobj object containing all the quiz settings information.
* @param structure $structure object containing the structure of the quiz.
* @param \question_edit_contexts $contexts the relevant question bank contexts.
* @param \moodle_url $pageurl the canonical URL of this page.
* @param array $pagevars the variables from {@link question_edit_setup()}.
* @return string HTML to output.
*/
public function edit_page(\quiz $quizobj, structure $structure,
\question_edit_contexts $contexts, \moodle_url $pageurl, array $pagevars) {
$output = '';
// Page title.
$output .= $this->heading_with_help(get_string('editingquizx', 'quiz',
format_string($quizobj->get_quiz_name())), 'editingquiz', 'quiz', '',
get_string('basicideasofquiz', 'quiz'), 2);
// Information at the top.
$output .= $this->quiz_state_warnings($structure);
$output .= $this->quiz_information($structure);
$output .= $this->maximum_grade_input($structure, $pageurl);
$output .= $this->repaginate_button($structure, $pageurl);
$output .= $this->total_marks($quizobj->get_quiz());
// Show the questions organised into sections and pages.
$output .= $this->start_section_list($structure);
foreach ($structure->get_sections() as $section) {
$output .= $this->start_section($structure, $section);
$output .= $this->questions_in_section($structure, $section, $contexts, $pagevars, $pageurl);
if ($structure->is_last_section($section)) {
$output .= \html_writer::start_div('last-add-menu');
$output .= html_writer::tag('span', $this->add_menu_actions($structure, 0,
$pageurl, $contexts, $pagevars), array('class' => 'add-menu-outer'));
$output .= \html_writer::end_div();
}
$output .= $this->end_section();
}
$output .= $this->end_section_list();
// Initialise the JavaScript.
$this->initialise_editing_javascript($structure, $contexts, $pagevars, $pageurl);
// Include the contents of any other popups required.
if ($structure->can_be_edited()) {
$popups = '';
$popups .= $this->question_bank_loading();
$this->page->requires->yui_module('moodle-mod_quiz-quizquestionbank',
'M.mod_quiz.quizquestionbank.init',
array('class' => 'questionbank', 'cmid' => $structure->get_cmid()));
$popups .= $this->random_question_form($pageurl, $contexts, $pagevars);
$this->page->requires->yui_module('moodle-mod_quiz-randomquestion',
'M.mod_quiz.randomquestion.init');
$output .= html_writer::div($popups, 'mod_quiz_edit_forms');
// Include the question chooser.
$output .= $this->question_chooser();
$this->page->requires->yui_module('moodle-mod_quiz-questionchooser', 'M.mod_quiz.init_questionchooser');
}
return $output;
}
示例7: make
public static function make(quiz $quizobj, $timenow, $canignoretimelimits)
{
if ($quizobj->get_quiz()->browsersecurity !== 'safebrowser') {
return null;
}
return new self($quizobj, $timenow);
}
示例8: test_cannot_review_message
public function test_cannot_review_message() {
$quiz = new stdClass();
$quiz->reviewattempt = 0x10010;
$quiz->timeclose = 0;
$quiz->attempts = 0;
$quiz->questions = '1,2,0,3,4,0';
$cm = new stdClass();
$cm->id = 123;
$quizobj = new quiz($quiz, $cm, new stdClass(), false);
$this->assertEqual('',
$quizobj->cannot_review_message(mod_quiz_display_options::DURING));
$this->assertEqual('',
$quizobj->cannot_review_message(mod_quiz_display_options::IMMEDIATELY_AFTER));
$this->assertEqual(get_string('noreview', 'quiz'),
$quizobj->cannot_review_message(mod_quiz_display_options::LATER_WHILE_OPEN));
$this->assertEqual(get_string('noreview', 'quiz'),
$quizobj->cannot_review_message(mod_quiz_display_options::AFTER_CLOSE));
$closetime = time() + 10000;
$quiz->timeclose = $closetime;
$quizobj = new quiz($quiz, $cm, new stdClass(), false);
$this->assertEqual(get_string('noreviewuntil', 'quiz', userdate($closetime)),
$quizobj->cannot_review_message(mod_quiz_display_options::LATER_WHILE_OPEN));
}
示例9: make
public static function make(quiz $quizobj, $timenow, $canignoretimelimits)
{
global $THEME;
if (empty($quizobj->get_quiz()->gradebycategory)) {
return null;
}
return new self($quizobj, $timenow);
}
示例10: make
public static function make(quiz $quizobj, $timenow, $canignoretimelimits)
{
global $CFG;
// If mobile services are off, the user won't be able to use any external app.
if (empty($CFG->enablemobilewebservice) or empty($quizobj->get_quiz()->allowofflineattempts)) {
return null;
}
return new self($quizobj, $timenow);
}
示例11: test_empty_quiz
public function test_empty_quiz()
{
$quiz = new stdClass();
$quiz->reviewattempt = 0x10010;
$quiz->timeclose = 0;
$quiz->attempts = 0;
$quiz->questions = '0';
$cm = new stdClass();
$cm->id = 123;
$quizobj = new quiz($quiz, $cm, new stdClass(), false);
$this->assertFalse($quizobj->has_questions());
}
示例12: 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 $quizobj the quiz object 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 $quizobj, $attemptnumber, $lastattempt, $timenow, $ispreview = false) {
global $USER;
$quiz = $quizobj->get_quiz();
if ($quiz->sumgrades < 0.000005 && $quiz->grade > 0.000005) {
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;
}
$timeclose = $quizobj->get_access_manager($timenow)->get_end_time($attempt);
if ($timeclose === false || $ispreview) {
$attempt->timecheckstate = null;
} else {
$attempt->timecheckstate = $timeclose;
}
return $attempt;
}
示例13: prepare_quiz_data
protected function prepare_quiz_data()
{
$this->resetAfterTest(true);
// Create a course
$course = $this->getDataGenerator()->create_course();
// Make a quiz.
$quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
$quiz = $quizgenerator->create_instance(array('course' => $course->id, 'questionsperpage' => 0, 'grade' => 100.0, 'sumgrades' => 2));
$cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id);
// Create a couple of questions.
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $questiongenerator->create_question_category();
$saq = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id));
$numq = $questiongenerator->create_question('numerical', null, array('category' => $cat->id));
// Add them to the quiz.
quiz_add_quiz_question($saq->id, $quiz);
quiz_add_quiz_question($numq->id, $quiz);
// Make a user to do the quiz.
$user1 = $this->getDataGenerator()->create_user();
$this->setUser($user1);
$quizobj = quiz::create($quiz->id, $user1->id);
// Start the attempt.
$quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
$timenow = time();
$attempt = quiz_create_attempt($quizobj, 1, false, $timenow);
quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow);
quiz_attempt_save_started($quizobj, $quba, $attempt);
return array($quizobj, $quba, $attempt);
}
示例14: round
public function round($id)
{
$utoken = session('user_id');
$maxround = leaderboard::where('user_id', $utoken)->select('round_id')->first();
$maxround = $maxround['round_id'];
$cc = leaderboard::where('round_id', '>', $id)->count();
$quesquery = solved::where(['user_token' => $utoken, 'round_id' => $id])->select('question_no')->get();
$totalques = quiz::where('round', $id)->select('question_id', 'position')->get();
$rquery = roundans::where('round_id', $id)->select('question', 'round_name')->first();
$rq = $rquery['question'];
$rname = $rquery['round_name'];
$qdone = array();
$i = 0;
foreach ($quesquery as $ques) {
$qdone[$i] = $ques['question_no'];
$i++;
}
$i = 0;
$i2 = 0;
$parray = array();
$tques = array();
$totpos = array();
$location = array();
foreach ($totalques as $t) {
$tques[$i2] = $t['question_id'];
$totpos[$i2] = $t['position'];
if (in_array($tques[$i2], $qdone)) {
$parray[$i] = explode(",", $t['position']);
$location[$i] = $t['position'];
$i++;
}
$i2++;
}
if ($id > $maxround || $id < 1) {
return redirect(url('/round/' . $maxround));
} else {
if ($id > $this->mxround) {
return view('quiz/winner')->with('id', $id);
} else {
return view('quiz/round')->with(['id' => $id, 'qdone' => $qdone, 'pos' => $location, 'totalques' => $tques, 'totalpos' => $totpos, 'rq' => $rq, 'rname' => $rname, 'c' => $cc, 'locations' => $parray]);
}
}
}
示例15: INT
<?php
/*$handle=new mysqli('localhost','sygmaapp','sygelvshi15','sygma2015');
$handle->query("CREATE TABLE IF NOT EXISTS `contestants` (p_id INT(5) PRIMARY KEY AUTO_INCREMENT, q_id INT(5), team_code VARCHAR(50), score INT(10))");
$s = $_POST['s'];
$user = $_POST['user'];
$id = $_POST['id'];
$q="SELECT * FROM contestants WHERE team_code ='".$user."' AND q_id =".$id." ";
$result= $handle->query($q);
if($result->num_rows)
{
echo "recieved";
while($row = $result->fetch_assoc())
{
$s = $row['score'] + $_POST['s'];
$q="UPDATE contestants SET score = ". $s ." WHERE team_code = '".$user."'AND q_id =".$id." " ;
$handle->query($q);
}
}
else
{
echo "idle";
}*/
require "class.quiz.php";
$q = new quiz();
$q->updateScore($_POST);