Skip to content

Commit

Permalink
Merge branch 'MDL-50916_m31v2' of https://github.com/sbourget/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Jan 5, 2016
2 parents 4323a97 + 21ee092 commit 6393e3d
Show file tree
Hide file tree
Showing 3 changed files with 277 additions and 11 deletions.
1 change: 1 addition & 0 deletions mod/lesson/lang/en/lesson.php
Expand Up @@ -473,6 +473,7 @@
$string['timespenterror'] = 'Spend at least {$a} minutes in the lesson';
$string['timespentminutes'] = 'Time spent (minutes)';
$string['timetaken'] = 'Time taken';
$string['totalpagesviewedheader'] = 'Number of pages viewed';
$string['true'] = 'True';
$string['truefalse'] = 'True/false';
$string['unabledtosavefile'] = 'The file you uploaded could not be saved';
Expand Down
74 changes: 63 additions & 11 deletions mod/lesson/lib.php
Expand Up @@ -343,41 +343,80 @@ function lesson_user_complete($course, $user, $mod, $lesson) {
require_once("$CFG->libdir/gradelib.php");

$grades = grade_get_grades($course->id, 'mod', 'lesson', $lesson->id, $user->id);
if (!empty($grades->items[0]->grades)) {

// Display the grade and feedback.
if (empty($grades->items[0]->grades)) {
echo $OUTPUT->container(get_string("nolessonattempts", "lesson"));
} else {
$grade = reset($grades->items[0]->grades);
echo $OUTPUT->container(get_string('grade').': '.$grade->str_long_grade);
if (empty($grade->grade)) {
// Check to see if it an ungraded / incomplete attempt.
$sql = "SELECT *
FROM {lesson_timer}
WHERE lessonid = :lessonid
AND userid = :userid
ORDER by starttime desc";
$params = array('lessonid' => $lesson->id, 'userid' => $user->id);

if ($attempt = $DB->get_record_sql($sql, $params, IGNORE_MULTIPLE)) {
if ($attempt->completed) {
$status = get_string("completed", "lesson");
} else {
$status = get_string("notyetcompleted", "lesson");
}
} else {
$status = get_string("nolessonattempts", "lesson");
}
} else {
$status = get_string("grade") . ': ' . $grade->str_long_grade;
}

// Display the grade or lesson status if there isn't one.
echo $OUTPUT->container($status);

if ($grade->str_feedback) {
echo $OUTPUT->container(get_string('feedback').': '.$grade->str_feedback);
}
}

// Display the lesson progress.
// Attempt, pages viewed, questions answered, correct answers, time.
$params = array ("lessonid" => $lesson->id, "userid" => $user->id);
if ($attempts = $DB->get_records_select("lesson_attempts", "lessonid = :lessonid AND userid = :userid", $params,
"retry, timeseen")) {
$attempts = $DB->get_records_select("lesson_attempts", "lessonid = :lessonid AND userid = :userid", $params, "retry, timeseen");
$branches = $DB->get_records_select("lesson_branch", "lessonid = :lessonid AND userid = :userid", $params, "retry, timeseen");
if (!empty($attempts) or !empty($branches)) {
echo $OUTPUT->box_start();
$table = new html_table();
$table->head = array (get_string("attemptheader", "lesson"), get_string("numberofpagesviewedheader", "lesson"),
get_string("numberofcorrectanswersheader", "lesson"), get_string("time"));
// Table Headings.
$table->head = array (get_string("attemptheader", "lesson"),
get_string("totalpagesviewedheader", "lesson"),
get_string("numberofpagesviewedheader", "lesson"),
get_string("numberofcorrectanswersheader", "lesson"),
get_string("time"));
$table->width = "100%";
$table->align = array ("center", "center", "center", "center");
$table->size = array ("*", "*", "*", "*");
$table->align = array ("center", "center", "center", "center", "center");
$table->size = array ("*", "*", "*", "*", "*");
$table->cellpadding = 2;
$table->cellspacing = 0;

$retry = 0;
$nquestions = 0;
$npages = 0;
$ncorrect = 0;

// Filter question pages (from lesson_attempts).
foreach ($attempts as $attempt) {
if ($attempt->retry == $retry) {
$npages++;
$nquestions++;
if ($attempt->correct) {
$ncorrect++;
}
$timeseen = $attempt->timeseen;
} else {
$table->data[] = array($retry + 1, $npages, $ncorrect, userdate($timeseen));
$table->data[] = array($retry + 1, $npages, $nquestions, $ncorrect, userdate($timeseen));
$retry++;
$nquestions = 1;
$npages = 1;
if ($attempt->correct) {
$ncorrect = 1;
Expand All @@ -386,8 +425,21 @@ function lesson_user_complete($course, $user, $mod, $lesson) {
}
}
}
if ($npages) {
$table->data[] = array($retry + 1, $npages, $ncorrect, userdate($timeseen));

// Filter content pages (from lesson_branch).
foreach ($branches as $branch) {
if ($branch->retry == $retry) {
$npages++;

$timeseen = $branch->timeseen;
} else {
$table->data[] = array($retry + 1, $npages, $nquestions, $ncorrect, userdate($timeseen));
$retry++;
$npages = 1;
}
}
if ($npages > 0) {
$table->data[] = array($retry + 1, $npages, $nquestions, $ncorrect, userdate($timeseen));
}
echo html_writer::table($table);
echo $OUTPUT->box_end();
Expand Down
213 changes: 213 additions & 0 deletions mod/lesson/tests/behat/lesson_complete_report.feature
@@ -0,0 +1,213 @@
@mod @mod_lesson
Feature: Teachers can review student progress on all lessons in a course by viewing the complete report
As a Teacher
I need to view the complete report for one of my students.

Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
And I add a "Lesson" to section "1"
And I set the following fields to these values:
| Name | Test lesson name |
| Description | Test lesson description |
| Re-takes allowed | Yes |
And I press "Save and return to course"
And I follow "Test lesson name"

@javascript
Scenario: View student progress for lesson that was never attempted
Given I follow "Add a content page"
And I set the following fields to these values:
| Page title | First page name |
| Page contents | First page contents |
| id_answer_editor_0 | Next page |
| id_jumpto_0 | Next page |
And I press "Save page"
And I set the field "qtype" to "Question"
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 | Paper is made from trees. |
| id_answer_editor_0 | True |
| id_response_editor_0 | Correct |
| id_jumpto_0 | Next page |
| id_answer_editor_1 | False |
| id_response_editor_1 | Wrong |
| id_jumpto_1 | This page |
And I press "Save page"
When I follow "Course 1"
And I follow "Participants"
And I follow "Student 1"
And I follow "Complete report"
Then I should see "No attempts have been made on this lesson"

@javascript
Scenario: View student progress for an incomplete lesson containing both content and question pages
Given I follow "Add a content page"
And I set the following fields to these values:
| Page title | First page name |
| Page contents | First page contents |
| id_answer_editor_0 | Next page |
| id_jumpto_0 | Next page |
And I press "Save page"
And I set the field "qtype" to "Question"
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 | Paper is made from trees. |
| id_answer_editor_0 | True |
| id_response_editor_0 | Correct |
| id_jumpto_0 | Next page |
| id_answer_editor_1 | False |
| id_response_editor_1 | Wrong |
| id_jumpto_1 | This page |
And I press "Save page"
And I set the field "qtype" to "Add a content page"
And I set the following fields to these values:
| Page title | Second page name |
| Page contents | Second page contents |
| id_answer_editor_0 | Previous page |
| id_jumpto_0 | Previous page |
| id_answer_editor_1 | Next page |
| id_jumpto_1 | Next page |
And I press "Save page"
And I log out
When I log in as "student1"
And I follow "Course 1"
And I follow "Test lesson name"
And I should see "First page contents"
And I press "Next page"
And I log out
Then I log in as "teacher1"
And I follow "Course 1"
And I follow "Participants"
And I follow "Student 1"
And I follow "Complete report"
And I should see "Lesson has been started, but not yet completed"
And I should see "1" in the ".cell.c1" "css_element"
And I should see "0" in the ".cell.c2" "css_element"

@javascript
Scenario: View student progress for a lesson containing both content and question pages
Given I follow "Add a content page"
And I set the following fields to these values:
| Page title | First page name |
| Page contents | First page contents |
| id_answer_editor_0 | Next page |
| id_jumpto_0 | Next page |
And I press "Save page"
And I set the field "qtype" to "Question"
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 | The sky is Pink. |
| id_answer_editor_0 | False |
| id_response_editor_0 | Correct |
| id_jumpto_0 | Next page |
| id_answer_editor_1 | True |
| id_response_editor_1 | Wrong |
| id_jumpto_1 | This page |
And I press "Save page"
And I set the field "qtype" to "Question"
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 | Paper is made from trees. |
| id_answer_editor_0 | True |
| id_response_editor_0 | Correct |
| id_jumpto_0 | Next page |
| id_answer_editor_1 | False |
| id_response_editor_1 | Wrong |
| id_jumpto_1 | This page |
And I press "Save page"
And I set the field "qtype" to "Add a content page"
And I set the following fields to these values:
| Page title | Second page name |
| Page contents | Second page contents |
| id_answer_editor_0 | Previous page |
| id_jumpto_0 | Previous page |
| id_answer_editor_1 | Next page |
| id_jumpto_1 | Next page |
And I press "Save page"
And I log out
When I log in as "student1"
And I follow "Course 1"
And I follow "Test lesson name"
And I should see "First page contents"
And I press "Next page"
And I should see "Second page contents"
And I press "Next page"
And I should see "Paper is made from trees."
And I set the following fields to these values:
| True | 1 |
And I press "Submit"
And I press "Continue"
And I should see "The sky is Pink."
And I set the following fields to these values:
| True | 1 |
And I press "Submit"
And I press "Continue"
And I should see "Congratulations - end of lesson reached"
And I log out
Then I log in as "teacher1"
And I follow "Course 1"
And I follow "Participants"
And I follow "Student 1"
And I follow "Complete report"
And I should see "Grade: 50.00 / 100.00"
And I should see "4" in the ".cell.c1" "css_element"
And I should see "2" in the ".cell.c2" "css_element"
And I should see "1" in the ".cell.c3" "css_element"

@javascript
Scenario: View student attempts in a lesson containing only content pages
Given I follow "Add a content page"
And I set the following fields to these values:
| Page title | First page name |
| Page contents | First page contents |
| id_answer_editor_0 | Next page |
| id_jumpto_0 | Next page |
And I press "Save page"
And I set the field "qtype" to "Add a content page"
And I set the following fields to these values:
| Page title | Second page name |
| Page contents | Second page contents |
| id_answer_editor_0 | Previous page |
| id_jumpto_0 | Previous page |
| id_answer_editor_1 | End of lesson |
| id_jumpto_1 | End of lesson |
And I press "Save page"
And I log out
When I log in as "student1"
And I follow "Course 1"
And I follow "Test lesson name"
And I should see "First page contents"
And I press "Next page"
And I should see "Second page contents"
And I press "End of lesson"
And I log out
Then I log in as "teacher1"
And I follow "Course 1"
And I follow "Participants"
And I follow "Student 1"
And I follow "Complete report"
And I should see "Completed"
And I should see "2" in the ".cell.c1" "css_element"
And I should see "0" in the ".cell.c2" "css_element"
And I should see "0" in the ".cell.c3" "css_element"

0 comments on commit 6393e3d

Please sign in to comment.