mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 00:42:54 +02:00
MDL-48803 mod/lesson: add group support
This commit is contained in:
parent
88cd577ef3
commit
fdc790fc94
@ -47,6 +47,8 @@ if ($mode !== 'display') {
|
||||
}
|
||||
$PAGE->set_url($url);
|
||||
|
||||
$currentgroup = groups_get_activity_group($cm, true);
|
||||
|
||||
$attempt = new stdClass();
|
||||
$user = new stdClass();
|
||||
$attemptid = optional_param('attemptid', 0, PARAM_INT);
|
||||
@ -178,7 +180,12 @@ switch ($mode) {
|
||||
}
|
||||
} else {
|
||||
$queryadd = '';
|
||||
$params = array ("lessonid" => $lesson->id);
|
||||
|
||||
// If group selected, only send to group members.
|
||||
list($esql, $params) = get_enrolled_sql($context, '', $currentgroup, true);
|
||||
list($sort, $sortparams) = users_order_by_sql('u');
|
||||
$params['lessonid'] = $lesson->id;
|
||||
|
||||
// Need to use inner view to avoid distinct + text
|
||||
if (!$users = $DB->get_records_sql("
|
||||
SELECT u.*
|
||||
@ -187,7 +194,9 @@ switch ($mode) {
|
||||
SELECT DISTINCT userid
|
||||
FROM {lesson_attempts}
|
||||
WHERE lessonid = :lessonid
|
||||
) ui ON u.id = ui.userid", $params)) {
|
||||
) ui ON u.id = ui.userid
|
||||
JOIN ($esql) ue ON ue.id = u.id
|
||||
ORDER BY $sort", $params)) {
|
||||
print_error('cannotfinduser', 'lesson');
|
||||
}
|
||||
}
|
||||
@ -284,27 +293,45 @@ switch ($mode) {
|
||||
}
|
||||
}
|
||||
if (count($pages) > 0) {
|
||||
$params = array ("lessonid" => $lesson->id, "qtype" => LESSON_PAGE_ESSAY);
|
||||
// Get only the attempts that are in response to essay questions
|
||||
list($usql, $parameters) = $DB->get_in_or_equal(array_keys($pages));
|
||||
if ($essayattempts = $DB->get_records_select('lesson_attempts', 'pageid '.$usql, $parameters)) {
|
||||
// Get all the users who have taken this lesson, order by their last name
|
||||
list($usql, $parameters) = $DB->get_in_or_equal(array_keys($pages), SQL_PARAMS_NAMED);
|
||||
// If group selected, only get group members attempts.
|
||||
list($esql, $params) = get_enrolled_sql($context, '', $currentgroup, true);
|
||||
$parameters = array_merge($params, $parameters);
|
||||
|
||||
$sql = "SELECT a.*
|
||||
FROM {lesson_attempts} a
|
||||
JOIN ($esql) ue ON a.userid = ue.id
|
||||
WHERE pageid $usql";
|
||||
if ($essayattempts = $DB->get_records_sql($sql, $parameters)) {
|
||||
$ufields = user_picture::fields('u');
|
||||
// Get all the users who have taken this lesson.
|
||||
list($sort, $sortparams) = users_order_by_sql('u');
|
||||
$params = array_merge($params, $sortparams);
|
||||
|
||||
$params['lessonid'] = $lesson->id;
|
||||
$sql = "SELECT DISTINCT $ufields
|
||||
FROM {user} u,
|
||||
{lesson_attempts} a
|
||||
WHERE a.lessonid = :lessonid and
|
||||
u.id = a.userid
|
||||
FROM {user} u
|
||||
JOIN {lesson_attempts} a ON u.id = a.userid
|
||||
JOIN ($esql) ue ON ue.id = a.userid
|
||||
WHERE a.lessonid = :lessonid
|
||||
ORDER BY $sort";
|
||||
if (!$users = $DB->get_records_sql($sql, $params)) {
|
||||
$mode = 'none'; // not displaying anything
|
||||
$lesson->add_message(get_string('noonehasanswered', 'lesson'));
|
||||
if (!empty($currentgroup)) {
|
||||
$groupname = groups_get_group_name($currentgroup);
|
||||
$lesson->add_message(get_string('noonehasansweredgroup', 'lesson', $groupname));
|
||||
} else {
|
||||
$lesson->add_message(get_string('noonehasanswered', 'lesson'));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$mode = 'none'; // not displaying anything
|
||||
$lesson->add_message(get_string('noonehasanswered', 'lesson'));
|
||||
if (!empty($currentgroup)) {
|
||||
$groupname = groups_get_group_name($currentgroup);
|
||||
$lesson->add_message(get_string('noonehasansweredgroup', 'lesson', $groupname));
|
||||
} else {
|
||||
$lesson->add_message(get_string('noonehasanswered', 'lesson'));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$mode = 'none'; // not displaying anything
|
||||
@ -318,6 +345,7 @@ echo $lessonoutput->header($lesson, $cm, 'essay', false, null, get_string('manua
|
||||
|
||||
switch ($mode) {
|
||||
case 'display':
|
||||
groups_print_activity_menu($cm, $url);
|
||||
// Expects $user, $essayattempts and $pages to be set already
|
||||
|
||||
// Group all the essays by userid
|
||||
@ -428,6 +456,9 @@ switch ($mode) {
|
||||
|
||||
$mform->display();
|
||||
break;
|
||||
default:
|
||||
groups_print_activity_menu($cm, $url);
|
||||
break;
|
||||
}
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
@ -307,10 +307,12 @@ $string['nodeadline'] = 'No deadline';
|
||||
$string['noessayquestionsfound'] = 'No essay questions found in this lesson.';
|
||||
$string['nohighscores'] = 'No high scores';
|
||||
$string['nolessonattempts'] = 'No attempts have been made on this lesson.';
|
||||
$string['nolessonattemptsgroup'] = 'No attempts have been made by {$a} group members on this lesson.';
|
||||
$string['nooneansweredcorrectly'] = 'No one answered correctly.';
|
||||
$string['nooneansweredthisquestion'] = 'No one answered this question.';
|
||||
$string['nooneenteredthis'] = 'No one entered this.';
|
||||
$string['noonehasanswered'] = 'No one has answered an essay question yet.';
|
||||
$string['noonehasansweredgroup'] = 'No one in {$a} has answered an essay question yet.';
|
||||
$string['noonecheckedthis'] = 'No one checked this.';
|
||||
$string['noretake'] = 'You are not allowed to retake this lesson.';
|
||||
$string['normal'] = 'Normal - follow lesson path';
|
||||
|
@ -740,9 +740,9 @@ function lesson_get_extra_capabilities() {
|
||||
function lesson_supports($feature) {
|
||||
switch($feature) {
|
||||
case FEATURE_GROUPS:
|
||||
return false;
|
||||
return true;
|
||||
case FEATURE_GROUPINGS:
|
||||
return false;
|
||||
return true;
|
||||
case FEATURE_MOD_INTRO:
|
||||
return true;
|
||||
case FEATURE_COMPLETION_TRACKS_VIEWS:
|
||||
|
@ -37,35 +37,30 @@ $lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*'
|
||||
|
||||
require_login($course, false, $cm);
|
||||
|
||||
$currentgroup = groups_get_activity_group($cm, true);
|
||||
|
||||
$context = context_module::instance($cm->id);
|
||||
require_capability('mod/lesson:viewreports', $context);
|
||||
|
||||
$ufields = user_picture::fields('u'); // These fields are enough
|
||||
$params = array("lessonid" => $lesson->id);
|
||||
list($sort, $sortparams) = users_order_by_sql('u');
|
||||
$params = array_merge($params, $sortparams);
|
||||
// TODO: Improve this. Fetching all students always is crazy!
|
||||
if (!empty($cm->groupingid)) {
|
||||
$params["groupingid"] = $cm->groupingid;
|
||||
$sql = "SELECT DISTINCT $ufields
|
||||
FROM {lesson_attempts} a
|
||||
INNER JOIN {user} u ON u.id = a.userid
|
||||
INNER JOIN {groups_members} gm ON gm.userid = u.id
|
||||
INNER JOIN {groupings_groups} gg ON gm.groupid = gg.groupid
|
||||
WHERE a.lessonid = :lessonid AND
|
||||
gg.groupingid = :groupingid
|
||||
ORDER BY $sort";
|
||||
} else {
|
||||
$sql = "SELECT DISTINCT $ufields
|
||||
FROM {user} u,
|
||||
{lesson_attempts} a
|
||||
WHERE a.lessonid = :lessonid and
|
||||
u.id = a.userid
|
||||
ORDER BY $sort";
|
||||
}
|
||||
// Only load students if there attempts for this lesson.
|
||||
if ($attempts = $DB->record_exists('lesson_attempts', array('lessonid' => $lesson->id))) {
|
||||
list($esql, $params) = get_enrolled_sql($context, '', $currentgroup, true);
|
||||
list($sort, $sortparams) = users_order_by_sql('u');
|
||||
|
||||
$students = $DB->get_recordset_sql($sql, $params);
|
||||
if (!$students->valid()) {
|
||||
$params['lessonid'] = $lesson->id;
|
||||
$ufields = user_picture::fields('u');
|
||||
$sql = "SELECT DISTINCT $ufields
|
||||
FROM {user} u
|
||||
JOIN {lesson_attempts} a ON u.id = a.userid
|
||||
JOIN ($esql) ue ON ue.id = a.userid
|
||||
WHERE a.lessonid = :lessonid
|
||||
ORDER BY $sort";
|
||||
|
||||
$students = $DB->get_recordset_sql($sql, $params);
|
||||
if (!$students->valid()) {
|
||||
$nothingtodisplay = true;
|
||||
}
|
||||
} else {
|
||||
$nothingtodisplay = true;
|
||||
}
|
||||
|
||||
@ -97,7 +92,13 @@ if (! $times = $DB->get_records('lesson_timer', array('lessonid' => $lesson->id)
|
||||
|
||||
if ($nothingtodisplay) {
|
||||
echo $lessonoutput->header($lesson, $cm, $action, false, null, get_string('nolessonattempts', 'lesson'));
|
||||
echo $OUTPUT->notification(get_string('nolessonattempts', 'lesson'));
|
||||
if (!empty($currentgroup)) {
|
||||
$groupname = groups_get_group_name($currentgroup);
|
||||
echo $OUTPUT->notification(get_string('nolessonattemptsgroup', 'lesson', $groupname));
|
||||
} else {
|
||||
echo $OUTPUT->notification(get_string('nolessonattempts', 'lesson'));
|
||||
}
|
||||
groups_print_activity_menu($cm, $url);
|
||||
echo $OUTPUT->footer();
|
||||
exit();
|
||||
}
|
||||
@ -163,6 +164,7 @@ if ($action === 'delete') {
|
||||
this action is for default view and overview view
|
||||
**************************************************************************/
|
||||
echo $lessonoutput->header($lesson, $cm, $action, false, null, get_string('overview', 'lesson'));
|
||||
groups_print_activity_menu($cm, $url);
|
||||
|
||||
$course_context = context_course::instance($course->id);
|
||||
if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) {
|
||||
@ -392,6 +394,7 @@ if ($action === 'delete') {
|
||||
|
||||
**************************************************************************/
|
||||
echo $lessonoutput->header($lesson, $cm, $action, false, null, get_string('detailedstats', 'lesson'));
|
||||
groups_print_activity_menu($cm, $url);
|
||||
|
||||
$course_context = context_course::instance($course->id);
|
||||
if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) {
|
||||
|
@ -10,6 +10,8 @@ Feature: In a lesson activity, a non editing teacher can grade essay questions
|
||||
| teacher1 | Teacher | 1 | teacher1@asd.com |
|
||||
| teacher2 | Teacher | 2 | teacher2@asd.com |
|
||||
| student1 | Student | 1 | student1@asd.com |
|
||||
| student2 | Student | 2 | student2@asd.com |
|
||||
| student3 | Student | 3 | student3@asd.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
@ -18,6 +20,20 @@ Feature: In a lesson activity, a non editing teacher can grade essay questions
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| teacher2 | C1 | teacher |
|
||||
| student1 | C1 | student |
|
||||
| student2 | C1 | student |
|
||||
| student3 | C1 | student |
|
||||
And the following "groups" exist:
|
||||
| name | course | idnumber |
|
||||
| Group A | C1 | G1 |
|
||||
| Group B | C1 | G2 |
|
||||
| Group C | C1 | G3 |
|
||||
And the following "group members" exist:
|
||||
| user | group |
|
||||
| teacher1 | G1 |
|
||||
| teacher2 | G2 |
|
||||
| student1 | G1 |
|
||||
| student2 | G2 |
|
||||
| student3 | G3 |
|
||||
And I log in as "teacher1"
|
||||
And I am on homepage
|
||||
And I follow "Course 1"
|
||||
@ -25,6 +41,7 @@ Feature: In a lesson activity, a non editing teacher can grade essay questions
|
||||
And I add a "Lesson" to section "1" and I fill the form with:
|
||||
| Name | Test lesson name |
|
||||
| Description | Test lesson description |
|
||||
| Group mode | Separate groups |
|
||||
And I follow "Test lesson name"
|
||||
And I follow "Add a question page"
|
||||
And I set the field "Select a question type" to "Essay"
|
||||
@ -40,12 +57,19 @@ Feature: In a lesson activity, a non editing teacher can grade essay questions
|
||||
And I set the field "Your answer" to "<p>Once upon a time there was a little green frog."
|
||||
And I press "Submit"
|
||||
And I log out
|
||||
And I log in as "student2"
|
||||
And I follow "Course 1"
|
||||
And I follow "Test lesson name"
|
||||
And I set the field "Your answer" to "<p>Once upon a time there were two little green frogs."
|
||||
And I press "Submit"
|
||||
And I log out
|
||||
When I log in as "teacher2"
|
||||
And I follow "Course 1"
|
||||
And I follow "Test lesson name"
|
||||
Then I should see "Grade essays"
|
||||
And I follow "Grade essays"
|
||||
And I should see "Student 1"
|
||||
And I should see "Student 2"
|
||||
And I should see "Essay question"
|
||||
And I follow "Essay question"
|
||||
And I should see "Student 1's response"
|
||||
@ -55,3 +79,11 @@ Feature: In a lesson activity, a non editing teacher can grade essay questions
|
||||
| Essay score | 1 |
|
||||
And I press "Save changes"
|
||||
And I should see "Changes saved"
|
||||
And I set the field "Separate groups" to "Group A"
|
||||
And I should see "Student 1"
|
||||
And I should not see "Student 2"
|
||||
And I set the field "Separate groups" to "Group B"
|
||||
And I should see "Student 2"
|
||||
And I should not see "Student 1"
|
||||
And I set the field "Separate groups" to "Group C"
|
||||
And I should see "No one in Group C has answered an essay question yet."
|
@ -12,6 +12,8 @@ This files describes API changes in the lesson code.
|
||||
located as part of the lesson_add_page_form_base class. If specified with a value of 'LESSON_ANSWER_HTML'
|
||||
then a rich html editor is generated. Otherwise an editor is created with Moodle Auto Format
|
||||
* removedoublecr() and importmodifiedaikenstyle() are now deprecated.
|
||||
* Added support for groups and groupings. If enabled, this allows the Report and
|
||||
Grade Essay view to be filtered by a group
|
||||
|
||||
=== Earlier changes ===
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user