Merge branch 'MDL-50145_master' of git://github.com/markn86/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2015-06-09 20:40:56 +02:00
commit db91aae8f4
2 changed files with 114 additions and 18 deletions

View File

@ -437,28 +437,48 @@ function lesson_print_overview($courses, &$htmlarray) {
}
// Get the last page viewed by the current user for every lesson in this course.
list($insql, $inparams) = $DB->get_in_or_equal($listoflessons, SQL_PARAMS_NAMED);
$dbparams = array_merge($inparams, array('userid1' => $USER->id, 'userid2' => $USER->id));
$dbparams = array_merge($inparams, array('userid' => $USER->id));
$lastattempts = $DB->get_records_sql("SELECT l.id, l.timeseen,l.lessonid, l.userid,
l.retry, l.pageid, l.nextpageid, p.qtype FROM (
SELECT lessonid, userid, pageid, timeseen, retry, id, answerid AS nextpageid
FROM {lesson_attempts}
WHERE userid = :userid1
UNION
SELECT lessonid, userid, pageid, timeseen, retry, id, nextpageid
FROM {lesson_branch}
WHERE userid = :userid2) l
JOIN {lesson_pages} p
ON l.pageid = p.id
WHERE l.lessonid $insql
ORDER BY l.lessonid asc, l.timeseen desc", $dbparams);
// Get the lesson attempts for the user that have the maximum 'timeseen' value.
$select = "SELECT l.id, l.timeseen, l.lessonid, l.userid, l.retry, l.pageid, l.answerid as nextpageid, p.qtype ";
$from = "FROM {lesson_attempts} l
JOIN (
SELECT idselect.lessonid, idselect.userid, MAX(idselect.id) AS id
FROM {lesson_attempts} idselect
JOIN (
SELECT lessonid, userid, MAX(timeseen) AS timeseen
FROM {lesson_attempts}
WHERE userid = :userid
AND lessonid $insql
GROUP BY userid, lessonid
) timeselect
ON timeselect.timeseen = idselect.timeseen
AND timeselect.userid = idselect.userid
AND timeselect.lessonid = idselect.lessonid
GROUP BY idselect.userid, idselect.lessonid
) aid
ON l.id = aid.id
JOIN {lesson_pages} p
ON l.pageid = p.id ";
$lastattempts = $DB->get_records_sql($select . $from, $dbparams);
// Now, get the lesson branches for the user that have the maximum 'timeseen' value.
$select = "SELECT l.id, l.timeseen, l.lessonid, l.userid, l.retry, l.pageid, l.nextpageid, p.qtype ";
$from = str_replace('{lesson_attempts}', '{lesson_branch}', $from);
$lastbranches = $DB->get_records_sql($select . $from, $dbparams);
$lastviewed = array();
foreach ($lastattempts as $lastattempt) {
if (!isset($lastviewed[$lastattempt->lessonid])) {
$lastviewed[$lastattempt->lessonid] = $lastattempt;
} else if ($lastviewed[$lastattempt->lessonid]->timeseen < $lastattempt->timeseen) {
$lastviewed[$lastattempt->lessonid] = $lastattempt;
$lastviewed[$lastattempt->lessonid] = $lastattempt;
}
// Go through the branch times and record the 'timeseen' value if it doesn't exist
// for the lesson, or replace it if it exceeds the current recorded time.
foreach ($lastbranches as $lastbranch) {
if (!isset($lastviewed[$lastbranch->lessonid])) {
$lastviewed[$lastbranch->lessonid] = $lastbranch;
} else if ($lastviewed[$lastbranch->lessonid]->timeseen < $lastbranch->timeseen) {
$lastviewed[$lastbranch->lessonid] = $lastbranch;
}
}

View File

@ -324,3 +324,79 @@ Feature: In Dashboard, a student can see their current status on all lessons wit
Then I should see "You have lessons that are due"
And I click on ".collapsibleregioncaption" "css_element"
And I should see "No attempts have been made on this lesson"
Scenario: Viewing the status for multiple lessons in multiple courses
Given the following "courses" exist:
| fullname | shortname | category |
| Course 2 | C2 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C2 | editingteacher |
| student1 | C2 | student |
And the following "activities" exist:
| activity | name | intro | deadline | retake | course | idnumber |
| lesson | Test lesson name 2 | Test lesson description | 1893481200 | 1 | C1 | lesson1 |
| lesson | Test lesson name 3 | Test lesson description | 1893481200 | 1 | C2 | lesson1 |
And I turn editing mode off
And I follow "Test lesson name"
And I follow "Add a question page"
And I set the field "Select a question type" to "True/false"
And I press "Add a question page"
And I set the following fields to these values:
| Page title | True/false question |
| Page contents | D035 M00d13 r0x0rz j00 b0x0rs? |
| id_answer_editor_0 | True |
| id_answer_editor_1 | False |
And I press "Save page"
And I follow "Test lesson name 2"
And I follow "Add a question page"
And I set the field "Select a question type" to "True/false"
And I press "Add a question page"
And I set the following fields to these values:
| Page title | True/false question |
| Page contents | D035 M00d13 r0x0rz j00 b0x0rs? |
| id_answer_editor_0 | True |
| id_answer_editor_1 | False |
And I press "Save page"
And I click on "Dashboard" "link" in the "Navigation" "block"
And I follow "Course 2"
And I follow "Test lesson name 3"
And I follow "Add a question page"
And I set the field "Select a question type" to "True/false"
And I press "Add a question page"
And I set the following fields to these values:
| Page title | True/false question 1 |
| Page contents | D035 M00d13 r0x0rz j00 b0x0rs? |
| id_answer_editor_0 | True |
| id_answer_editor_1 | False |
And I press "Save page"
And I select "Question" from the "qtype" singleselect
And I set the field "Select a question type" to "True/false"
And I press "Add a question page"
And I set the following fields to these values:
| Page title | True/false question 2 |
| Page contents | D035 M00d13 r0x0rz j00 b0x0rs? |
| id_answer_editor_0 | True |
| id_answer_editor_1 | False |
And I press "Save page"
And I log out
And I log in as "student1"
And I follow "Course 1"
And I follow "Test lesson name"
And I should see "D035 M00d13 r0x0rz j00 b0x0rs?"
And I set the following fields to these values:
| True | 1 |
And I press "Submit"
And I click on "Dashboard" "link" in the "Navigation" "block"
And I follow "Course 2"
And I follow "Test lesson name 3"
And I should see "D035 M00d13 r0x0rz j00 b0x0rs?"
And I set the following fields to these values:
| True | 1 |
And I press "Submit"
When I click on "Dashboard" "link" in the "Navigation" "block"
Then I should see "You have lessons that are due" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' coursebox ' ) and contains(normalize-space(.), 'Course 1')]/div[contains( normalize-space(.), 'You have lessons that are due ' )]" "xpath_element"
And I should see "You have lessons that are due" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' coursebox ' ) and contains(normalize-space(.), 'Course 2')]/div[contains( normalize-space(.), 'You have lessons that are due ' )]" "xpath_element"
And I should see "Lesson has been started, but not yet completed" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' overview ' ) and descendant-or-self::a[.='Test lesson name 3']]" "xpath_element"
And I should see "Completed, You can re-attempt this lesson" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' overview ' ) and descendant-or-self::a[.='Test lesson name']]" "xpath_element"
And I should see "No attempts have been made on this lesson" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' overview ' ) and descendant-or-self::a[.='Test lesson name 2']]" "xpath_element"