Skip to content

Commit 9fc60df

Browse files
author
David Monllao
committed
Merge branch 'MDL-62262-35' of https://github.com/lucaboesch/moodle into MOODLE_35_STABLE
2 parents c270b92 + 942d4df commit 9fc60df

File tree

3 files changed

+42
-49
lines changed

3 files changed

+42
-49
lines changed

mod/quiz/index.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,13 @@
5555
die;
5656
}
5757

58-
// Check if we need the closing date header.
59-
$showclosingheader = false;
58+
// Check if we need the feedback header.
6059
$showfeedback = false;
6160
foreach ($quizzes as $quiz) {
62-
if ($quiz->timeclose!=0) {
63-
$showclosingheader=true;
64-
}
6561
if (quiz_has_feedback($quiz)) {
6662
$showfeedback=true;
6763
}
68-
if ($showclosingheader && $showfeedback) {
64+
if ($showfeedback) {
6965
break;
7066
}
7167
}
@@ -74,10 +70,8 @@
7470
$headings = array(get_string('name'));
7571
$align = array('left');
7672

77-
if ($showclosingheader) {
78-
array_push($headings, get_string('quizcloses', 'quiz'));
79-
array_push($align, 'left');
80-
}
73+
array_push($headings, get_string('quizcloses', 'quiz'));
74+
array_push($align, 'left');
8175

8276
if (course_format_uses_sections($course->format)) {
8377
array_unshift($headings, get_string('sectionname', 'format_'.$course->format));
@@ -147,14 +141,10 @@
147141
format_string($quiz->name, true) . '</a>';
148142

149143
// Close date.
150-
if ($quiz->timeclose) {
151-
if (($timeclosedates[$quiz->id]->usertimeclose == 0) AND ($timeclosedates[$quiz->id]->usertimelimit == 0)) {
152-
$data[] = get_string('noclose', 'quiz');
153-
} else {
154-
$data[] = userdate($timeclosedates[$quiz->id]->usertimeclose);
155-
}
156-
} else if ($showclosingheader) {
157-
$data[] = '';
144+
if (($timeclosedates[$quiz->id]->usertimeclose != 0)) {
145+
$data[] = userdate($timeclosedates[$quiz->id]->usertimeclose);
146+
} else {
147+
$data[] = get_string('noclose', 'quiz');
158148
}
159149

160150
if ($showing == 'stats') {

mod/quiz/locallib.php

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,53 +1211,40 @@ function quiz_get_user_image_options() {
12111211

12121212
/**
12131213
* Return an user's timeclose for all quizzes in a course, hereby taking into account group and user overrides.
1214-
* The query used herein is very similar to the one in function quiz_get_attempt_usertime_sql, so, in case you
1215-
* would change either one of them, make sure to apply your changes to both.
12161214
*
12171215
* @param int $courseid the course id.
1218-
* @return object An object with quizids and unixdates of the most lenient close overrides, if any.
1216+
* @return object An object with of all quizids and close unixdates in this course, taking into account the most lenient
1217+
* overrides, if existing and 0 if no close date is set.
12191218
*/
12201219
function quiz_get_user_timeclose($courseid) {
12211220
global $DB, $USER;
12221221

12231222
// For teacher and manager/admins return timeclose.
12241223
if (has_capability('moodle/course:update', context_course::instance($courseid))) {
1225-
$sql = "SELECT quiz.id, quiz.timeclose AS usertimeclose, COALESCE(quiz.timelimit, 0) AS usertimelimit
1224+
$sql = "SELECT quiz.id, quiz.timeclose AS usertimeclose
12261225
FROM {quiz} quiz
12271226
WHERE quiz.course = :courseid";
12281227

12291228
$results = $DB->get_records_sql($sql, array('courseid' => $courseid));
12301229
return $results;
12311230
}
12321231

1233-
// The multiple qgo JOINS are necessary because we want timeclose/timelimit = 0 (unlimited) to supercede
1234-
// any other group override.
1235-
12361232
$sql = "SELECT q.id,
1237-
COALESCE(v.oneclose, v.twoclose, v.threeclose, q.timeclose, 0) AS usertimeclose,
1238-
COALESCE(v.onelimit, v.twolimit, v.threelimit, q.timelimit, 0) AS usertimelimit
1233+
COALESCE(v.userclose, v.groupclose, q.timeclose, 0) AS usertimeclose
12391234
FROM (
1240-
SELECT quiz.id AS quizid,
1241-
MAX(quo.timeclose) AS oneclose, MAX(qgo1.timeclose) AS twoclose, MAX(qgo2.timeclose) AS threeclose,
1242-
MAX(quo.timelimit) AS onelimit, MAX(qgo3.timelimit) AS twolimit, MAX(qgo4.timelimit) AS threelimit
1235+
SELECT quiz.id as quizid,
1236+
MAX(quo.timeclose) AS userclose, MAX(qgo.timeclose) AS groupclose
12431237
FROM {quiz} quiz
1244-
LEFT JOIN {quiz_overrides} quo ON quo.quiz = quiz.id
1245-
LEFT JOIN {groups_members} gm ON gm.userid = quo.userid
1246-
LEFT JOIN {quiz_overrides} qgo1 ON qgo1.timeclose = 0 AND qgo1.quiz = quiz.id
1247-
LEFT JOIN {quiz_overrides} qgo2 ON qgo2.timeclose > 0 AND qgo2.quiz = quiz.id
1248-
LEFT JOIN {quiz_overrides} qgo3 ON qgo3.timelimit = 0 AND qgo3.quiz = quiz.id
1249-
LEFT JOIN {quiz_overrides} qgo4 ON qgo4.timelimit > 0 AND qgo4.quiz = quiz.id
1250-
AND qgo1.groupid = gm.groupid
1251-
AND qgo2.groupid = gm.groupid
1252-
AND qgo3.groupid = gm.groupid
1253-
AND qgo4.groupid = gm.groupid
1238+
LEFT JOIN {quiz_overrides} quo on quiz.id = quo.quiz AND quo.userid = :userid
1239+
LEFT JOIN {groups_members} gm ON gm.userid = :useringroupid
1240+
LEFT JOIN {quiz_overrides} qgo on quiz.id = qgo.quiz AND qgo.groupid = gm.groupid
12541241
WHERE quiz.course = :courseid
1255-
AND ((quo.userid = :userid) OR ((gm.userid IS NULL) AND (quo.userid IS NULL)))
12561242
GROUP BY quiz.id) v
1257-
JOIN {quiz} q ON q.id = v.quizid";
1243+
JOIN {quiz} q ON q.id = v.quizid";
12581244

1259-
$results = $DB->get_records_sql($sql, array('courseid' => $courseid, 'userid' => $USER->id));
1245+
$results = $DB->get_records_sql($sql, array('userid' => $USER->id, 'useringroupid' => $USER->id, 'courseid' => $courseid));
12601246
return $results;
1247+
12611248
}
12621249

12631250
/**

mod/quiz/tests/locallib_test.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ public function test_quiz_get_user_timeclose() {
311311
// Create generator, course and quizzes.
312312
$student1 = $this->getDataGenerator()->create_user();
313313
$student2 = $this->getDataGenerator()->create_user();
314+
$student3 = $this->getDataGenerator()->create_user();
314315
$teacher = $this->getDataGenerator()->create_user();
315316
$course = $this->getDataGenerator()->create_course();
316317
$quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
@@ -323,13 +324,15 @@ public function test_quiz_get_user_timeclose() {
323324

324325
$student1id = $student1->id;
325326
$student2id = $student2->id;
327+
$student3id = $student3->id;
326328
$teacherid = $teacher->id;
327329

328330
// Users enrolments.
329331
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
330332
$teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'));
331333
$this->getDataGenerator()->enrol_user($student1id, $course->id, $studentrole->id, 'manual');
332334
$this->getDataGenerator()->enrol_user($student2id, $course->id, $studentrole->id, 'manual');
335+
$this->getDataGenerator()->enrol_user($student3id, $course->id, $studentrole->id, 'manual');
333336
$this->getDataGenerator()->enrol_user($teacherid, $course->id, $teacherrole->id, 'manual');
334337

335338
// Create groups.
@@ -357,14 +360,31 @@ public function test_quiz_get_user_timeclose() {
357360
$object = new stdClass();
358361
$object->id = $quiz1->id;
359362
$object->usertimeclose = $basetimestamp + 10800; // The overriden timeclose for quiz 1.
360-
$object->usertimelimit = 0;
361363

362364
$comparearray[$quiz1->id] = $object;
363365

364366
$object = new stdClass();
365367
$object->id = $quiz2->id;
366368
$object->usertimeclose = $basetimestamp + 7200; // The unchanged timeclose for quiz 2.
367-
$object->usertimelimit = 0;
369+
370+
$comparearray[$quiz2->id] = $object;
371+
372+
$this->assertEquals($comparearray, quiz_get_user_timeclose($course->id));
373+
374+
// Let's test quiz 1 closes in two hours (the original value) for user student 3 since member of no group.
375+
$this->setUser($student3id);
376+
$params = new stdClass();
377+
378+
$comparearray = array();
379+
$object = new stdClass();
380+
$object->id = $quiz1->id;
381+
$object->usertimeclose = $basetimestamp + 7200; // The original timeclose for quiz 1.
382+
383+
$comparearray[$quiz1->id] = $object;
384+
385+
$object = new stdClass();
386+
$object->id = $quiz2->id;
387+
$object->usertimeclose = $basetimestamp + 7200; // The original timeclose for quiz 2.
368388

369389
$comparearray[$quiz2->id] = $object;
370390

@@ -386,14 +406,12 @@ public function test_quiz_get_user_timeclose() {
386406
$object = new stdClass();
387407
$object->id = $quiz1->id;
388408
$object->usertimeclose = $basetimestamp + 14400; // The overriden timeclose for quiz 1.
389-
$object->usertimelimit = 0;
390409

391410
$comparearray[$quiz1->id] = $object;
392411

393412
$object = new stdClass();
394413
$object->id = $quiz2->id;
395414
$object->usertimeclose = $basetimestamp + 7200; // The unchanged timeclose for quiz 2.
396-
$object->usertimelimit = 0;
397415

398416
$comparearray[$quiz2->id] = $object;
399417

@@ -407,14 +425,12 @@ public function test_quiz_get_user_timeclose() {
407425
$object = new stdClass();
408426
$object->id = $quiz1->id;
409427
$object->usertimeclose = $basetimestamp + 7200; // The unchanged timeclose for quiz 1.
410-
$object->usertimelimit = 0;
411428

412429
$comparearray[$quiz1->id] = $object;
413430

414431
$object = new stdClass();
415432
$object->id = $quiz2->id;
416433
$object->usertimeclose = $basetimestamp + 7200; // The unchanged timeclose for quiz 2.
417-
$object->usertimelimit = 0;
418434

419435
$comparearray[$quiz2->id] = $object;
420436

0 commit comments

Comments
 (0)