Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Commit

Permalink
Merge branch 'MDL-41540-master-v2' of git://github.com/jamiepratt/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed Sep 17, 2013
2 parents 81ece3f + 7078252 commit 23eed08
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
9 changes: 7 additions & 2 deletions mod/quiz/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,17 @@
* 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.
* @param int $userid the id of the user attempting this quiz.
*
* @return object the newly created attempt object.
*/
function quiz_create_attempt(quiz $quizobj, $attemptnumber, $lastattempt, $timenow, $ispreview = false) {
function quiz_create_attempt(quiz $quizobj, $attemptnumber, $lastattempt, $timenow, $ispreview = false, $userid = null) {
global $USER;

if ($userid === null) {
$userid = $USER->id;
}

$quiz = $quizobj->get_quiz();
if ($quiz->sumgrades < 0.000005 && $quiz->grade > 0.000005) {
throw new moodle_exception('cannotstartgradesmismatch', 'quiz',
Expand All @@ -103,7 +108,7 @@ function quiz_create_attempt(quiz $quizobj, $attemptnumber, $lastattempt, $timen
// We are not building on last attempt so create a new attempt.
$attempt = new stdClass();
$attempt->quiz = $quiz->id;
$attempt->userid = $USER->id;
$attempt->userid = $userid;
$attempt->preview = 0;
$attempt->layout = quiz_clean_layout($quiz->questions, true);
if ($quiz->shufflequestions) {
Expand Down
3 changes: 1 addition & 2 deletions mod/quiz/tests/attempt_walkthrough_from_csv_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,13 @@ protected function walkthrough_attempts($steps) {
if (!$user = $DB->get_record('user', $username)) {
$user = $this->getDataGenerator()->create_user($username);
}
$this->setUser($user);
// Start the attempt.
$quizobj = quiz::create($this->quiz->id, $user->id);
$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);
$attempt = quiz_create_attempt($quizobj, 1, false, $timenow, false, $user->id);
// Select variant and / or random sub question.
if (!isset($step['variants'])) {
$step['variants'] = array();
Expand Down
3 changes: 1 addition & 2 deletions mod/quiz/tests/attempt_walkthrough_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public function test_quiz_attempt_walkthrough() {

// Make a user to do the quiz.
$user1 = $this->getDataGenerator()->create_user();
$this->setUser($user1);

$quizobj = quiz::create($quiz->id, $user1->id);

Expand All @@ -77,7 +76,7 @@ public function test_quiz_attempt_walkthrough() {
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);

$timenow = time();
$attempt = quiz_create_attempt($quizobj, 1, false, $timenow);
$attempt = quiz_create_attempt($quizobj, 1, false, $timenow, false, $user1->id);

quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow);

Expand Down

0 comments on commit 23eed08

Please sign in to comment.