From 1c6ed50500ba3bef3d53f969f74c6db2643a4ceb Mon Sep 17 00:00:00 2001 From: sam marshall Date: Mon, 10 Jan 2011 15:20:24 +0000 Subject: [PATCH 1/3] completion MDL-25929 Remove progresstrackedroles option --- admin/settings/subsystems.php | 4 ---- course/report/completion/mod.php | 2 +- course/report/progress/index.php | 28 ++++++++++++++-------------- course/user.php | 10 ++++++++-- lang/en/completion.php | 2 -- lib/completion/cron.php | 4 ++-- lib/completionlib.php | 6 +++--- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/admin/settings/subsystems.php b/admin/settings/subsystems.php index ceccfe54692..c7735e6ec7f 100644 --- a/admin/settings/subsystems.php +++ b/admin/settings/subsystems.php @@ -37,10 +37,6 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page $optionalsubsystems->add(new admin_setting_configcheckbox('enablecompletion', get_string('enablecompletion','completion'), get_string('configenablecompletion','completion'), 0)); - $optionalsubsystems->add(new admin_setting_pickroles('progresstrackedroles', - get_string('progresstrackedroles','completion'), - get_string('configprogresstrackedroles', 'completion'), - array('student'))); $optionalsubsystems->add(new admin_setting_configcheckbox('enableavailability', get_string('enableavailability','condition'), get_string('configenableavailability','condition'), 0)); diff --git a/course/report/completion/mod.php b/course/report/completion/mod.php index 38a1cfae001..44cca9a2b5a 100644 --- a/course/report/completion/mod.php +++ b/course/report/completion/mod.php @@ -10,7 +10,7 @@ $completion = new completion_info($course); if ($completion->is_enabled() && $completion->has_criteria()) { echo '

'; - echo ''.get_string('coursecompletion').''; + echo ''.get_string('coursecompletion').''; echo '

'; } } diff --git a/course/report/progress/index.php b/course/report/progress/index.php index c68c5718b24..d246139874c 100644 --- a/course/report/progress/index.php +++ b/course/report/progress/index.php @@ -72,9 +72,6 @@ if($group===0 && $course->groupmode==SEPARATEGROUPS) { $reportsurl=$CFG->wwwroot.'/course/report.php?id='.$course->id; $completion=new completion_info($course); $activities=$completion->get_activities(); -if(count($activities)==0) { - print_error('err_noactivities','completion',$reportsurl); -} // Generate where clause $where = array(); @@ -96,16 +93,6 @@ $total = $completion->get_num_tracked_users(implode(' AND ', $where), $where_par // Total user count $grandtotal = $completion->get_num_tracked_users('', array(), $group); -// If no users in this course what-so-ever -if (!$grandtotal) { - echo $OUTPUT->box_start('errorbox errorboxcontent boxaligncenter boxwidthnormal'); - echo '

'.get_string('err_nousers','completion').'

'; - echo '

'.get_string('continue').'

'; - echo $OUTPUT->box_end(); - echo $OUTPUT->footer(); - exit; -} - // Get user data $progress = array(); @@ -120,7 +107,7 @@ if ($total) { ); } -if($csv) { +if($csv && $grandtotal && count($activities)>0) { // Only show CSV if there are some users/actvs header('Content-Disposition: attachment; filename=progress.'. preg_replace('/[^a-z0-9-]/','_',strtolower($course->shortname)).'.csv'); // Unicode byte-order mark for Excel @@ -155,6 +142,19 @@ if($csv) { groups_print_course_menu($course,$CFG->wwwroot.'/course/report/progress/?course='.$course->id); } +if(count($activities)==0) { + echo $OUTPUT->container(get_string('err_noactivities', 'completion'), 'errorbox errorboxcontent'); + echo $OUTPUT->footer(); + exit; +} + +// If no users in this course what-so-ever +if (!$grandtotal) { + echo $OUTPUT->container(get_string('err_nousers', 'completion'), 'errorbox errorboxcontent'); + echo $OUTPUT->footer(); + exit; +} + // Build link for paging $link = $CFG->wwwroot.'/course/report/progress/?course='.$course->id; if (strlen($sort)) { diff --git a/course/user.php b/course/user.php index 15acd537080..d6ba6e0b1be 100644 --- a/course/user.php +++ b/course/user.php @@ -366,14 +366,20 @@ switch ($mode) { INNER JOIN {context} con ON con.instanceid = c.id + INNER JOIN + {enrol} e + ON c.id = e.courseid + INNER JOIN + {user_enrolments} ue + ON e.id = ue.enrolid INNER JOIN {role_assignments} ra - ON ra.contextid = con.id + ON ra.contextid = con.id AND ra.userid=ue.userid AND ra.userid = {$user->id} "; // Get roles that are tracked by course completion - if ($roles = $CFG->progresstrackedroles) { + if ($roles = $CFG->gradebookroles) { $sql .= ' AND ra.roleid IN ('.$roles.') '; diff --git a/lang/en/completion.php b/lang/en/completion.php index 0d8867562e7..00b6a9dc0a1 100644 --- a/lang/en/completion.php +++ b/lang/en/completion.php @@ -62,7 +62,6 @@ $string['completionusegrade_desc'] = 'Student must receive a grade to complete t $string['completionview'] = 'Require view'; $string['completionview_desc'] = 'Student must view this activity to complete it'; $string['configenablecompletion'] = 'When enabled, this lets you turn on completion tracking (progress) features at course level.'; -$string['configprogresstrackedroles'] = 'Roles that are displayed in the progress-tracking screen. (Usually includes just students and equivalent roles.)'; $string['csvdownload'] = 'Download in spreadsheet format (UTF-8 .csv)'; $string['deletecoursecompletiondata'] = 'Delete course completion data'; $string['enablecompletion'] = 'Enable completion tracking'; @@ -130,7 +129,6 @@ $string['pending']='Pending'; $string['periodpostenrolment']='Period post enrolment'; $string['prerequisites']='Prerequisites'; $string['prerequisitescompleted']='Prerequisites completed'; -$string['progresstrackedroles']='Progress-tracked roles'; $string['recognitionofpriorlearning']='Recognition of prior learning'; $string['remainingenroledfortime']='Remaining enrolled for a specified period of time'; $string['remainingenroleduntildate']='Remaining enrolled until a specified date'; diff --git a/lib/completion/cron.php b/lib/completion/cron.php index 0a5ee7fbb70..1c30809f220 100644 --- a/lib/completion/cron.php +++ b/lib/completion/cron.php @@ -57,8 +57,8 @@ function completion_cron_mark_started() { mtrace('Marking users as started'); } - if (!empty($CFG->progresstrackedroles)) { - $roles = ' AND ra.roleid IN ('.$CFG->progresstrackedroles.')'; + if (!empty($CFG->gradebookroles)) { + $roles = ' AND ra.roleid IN ('.$CFG->gradebookroles.')'; } else { // This causes it to default to everyone (if there is no student role) $roles = ''; diff --git a/lib/completionlib.php b/lib/completionlib.php index f0482dbac4c..50e50bb866f 100644 --- a/lib/completionlib.php +++ b/lib/completionlib.php @@ -1073,8 +1073,8 @@ class completion_info { $return->sql = ''; $return->data = array(); - if (!empty($CFG->progresstrackedroles)) { - $roles = ' AND ra.roleid IN ('.$CFG->progresstrackedroles.')'; + if (!empty($CFG->gradebookroles)) { + $roles = ' AND ra.roleid IN ('.$CFG->gradebookroles.')'; } else { // This causes it to default to everyone (if there is no student role) $roles = ''; @@ -1142,7 +1142,7 @@ class completion_info { * for all users in a specific group. Intended for use when displaying progress. * * This includes only users who, in course context, have one of the roles for - * which progress is tracked (the progresstrackedroles admin option). + * which progress is tracked (the gradebookroles admin option) and are enrolled in course. * * Users are included (in the first array) even if they do not have * completion progress for any course-module. From b64a827c4de980bba34e38c9478ef6dfa4f8d22d Mon Sep 17 00:00:00 2001 From: sam marshall Date: Mon, 10 Jan 2011 15:35:46 +0000 Subject: [PATCH 2/3] completion MDL-25929 Reordered SQL to make it clearer (after tim's review) --- course/user.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/course/user.php b/course/user.php index d6ba6e0b1be..c50dc40031b 100644 --- a/course/user.php +++ b/course/user.php @@ -366,15 +366,15 @@ switch ($mode) { INNER JOIN {context} con ON con.instanceid = c.id + INNER JOIN + {role_assignments} ra + ON ra.contextid = con.id INNER JOIN {enrol} e ON c.id = e.courseid INNER JOIN {user_enrolments} ue - ON e.id = ue.enrolid - INNER JOIN - {role_assignments} ra - ON ra.contextid = con.id AND ra.userid=ue.userid + ON e.id = ue.enrolid AND ra.userid = ue.userid AND ra.userid = {$user->id} "; From 89b4ffe61708e2466d07668c1c2e2e0898d566f4 Mon Sep 17 00:00:00 2001 From: sam marshall Date: Tue, 18 Jan 2011 12:55:58 +0000 Subject: [PATCH 3/3] completion MDL-25929 Added upgrade change to remove unused setting --- lib/db/upgrade.php | 8 ++++++++ version.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 9bd96844a39..ffd0023396c 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -5512,6 +5512,14 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); upgrade_main_savepoint(true, 2010121401); } + if ($oldversion < 2011011800) { + + // Clean up the old progress tracked roles setting, no longer used (replaced by enrolment) + unset_config('progresstrackedroles'); + + upgrade_main_savepoint(true, 2011011800); + } + return true; } diff --git a/version.php b/version.php index ccea6cfb650..a8e0388a8d1 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2010122900; // YYYYMMDD = date of the last version bump +$version = 2011011800; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0.1+ (Build: 20110105)'; // Human-friendly version name