fixing the participants report to work with roles
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php // $Id$
|
||||
|
||||
require_once('../../../config.php');
|
||||
require_once($CFG->libdir.'/statslib.php');
|
||||
|
||||
define('DEFAULT_PAGE_SIZE', 20);
|
||||
define('SHOW_ALL_PAGE_SIZE', 5000);
|
||||
@@ -8,7 +9,7 @@
|
||||
$id = required_param('id', PARAM_INT); // course id.
|
||||
$moduleid = optional_param('moduleid', 0, PARAM_INT); // module id.
|
||||
$oldmod = optional_param('oldmod', 0, PARAM_INT);
|
||||
$teachers = optional_param('teachers', 0, PARAM_BOOL); // show teachers? off = students.
|
||||
$roleid = optional_param('roleid',0,PARAM_INT); // which role to show
|
||||
$instanceid = optional_param('instanceid', 0, PARAM_INT); // instance we're looking at.
|
||||
$timefrom = optional_param('timefrom', 0, PARAM_INT); // how far back to look...
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
@@ -28,6 +29,10 @@
|
||||
print_error('invalidcourse');
|
||||
}
|
||||
|
||||
if ($roleid != 0 && !$role = get_record('role','id',$roleid)) {
|
||||
print_error('invalidrole');
|
||||
}
|
||||
|
||||
require_login($course->id);
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
|
||||
@@ -102,10 +107,12 @@
|
||||
$timeoptions[strtotime('-1 year',$now)] = get_string('lastyear');
|
||||
}
|
||||
|
||||
$useroptions = array(0 => $course->students,
|
||||
1 => $course->teachers,
|
||||
);
|
||||
|
||||
$useroptions = array();
|
||||
if ($roles = get_roles_on_exact_context(get_context_instance(CONTEXT_COURSE,$course->id))) {
|
||||
foreach ($roles as $r) {
|
||||
$useroptions[$r->id] = $r->name;
|
||||
}
|
||||
}
|
||||
$actionoptions = array('' => $strallactions,
|
||||
'view' => $strview,
|
||||
'post' => $strpost,
|
||||
@@ -126,7 +133,7 @@
|
||||
choose_from_menu($timeoptions,'timefrom',$timefrom);
|
||||
echo "</td><td>".
|
||||
get_string('showonly').' ';
|
||||
choose_from_menu($useroptions,'teachers',$teachers,'');
|
||||
choose_from_menu($useroptions,'roleid',$roleid,'');
|
||||
echo "</td><td>\n".
|
||||
get_string('showactions'),' ';
|
||||
choose_from_menu($actionoptions,'action',$action,'');
|
||||
@@ -143,8 +150,8 @@
|
||||
exit;
|
||||
}
|
||||
|
||||
$baseurl = $CFG->wwwroot.'/course/report/participation/index.php?id='.$course->id.'&teachers='
|
||||
.$teachers.'&instanceid='.$instanceid.'&timefrom='.$timefrom.'&moduleid='
|
||||
$baseurl = $CFG->wwwroot.'/course/report/participation/index.php?id='.$course->id.'&roleid='
|
||||
.$roleid.'&instanceid='.$instanceid.'&timefrom='.$timefrom.'&moduleid='
|
||||
.$moduleid.'&action='.$action.'&perpage='.$perpage;
|
||||
|
||||
|
||||
@@ -184,19 +191,20 @@
|
||||
'<input type="hidden" name="oldmod" value="'.$moduleid.'" />'."\n".
|
||||
'<input type="hidden" name="timefrom" value="'.$timefrom.'" />'."\n".
|
||||
'<input type="hidden" name="action" value="'.$action.'" />'."\n".
|
||||
'<input type="hidden" name="roleid" value="'.$roleid.'" />'."\n".
|
||||
'<input type="hidden" name="moduleid" value="'.$moduleid.'" />'."\n".
|
||||
'<table align="center"><tr><td>';
|
||||
choose_from_menu($instanceoptions,'instanceid',$instanceid);
|
||||
echo '<input type="submit" value="'.get_string('go').'" /></td></tr></table>'."\n".
|
||||
"</form>\n";
|
||||
|
||||
if (!empty($instanceid)) {
|
||||
if (!empty($instanceid) && !empty($roleid)) {
|
||||
if (!$cm = get_coursemodule_from_instance($module->name,$instanceid,$course->id)) {
|
||||
print_error('cmunknown');
|
||||
}
|
||||
|
||||
require_once($CFG->dirroot.'/lib/tablelib.php');
|
||||
$table = new flexible_table('course-participation-'.$course->id.'-'.$cm->id.'-'.$teachers);
|
||||
$table = new flexible_table('course-participation-'.$course->id.'-'.$cm->id.'-'.$roleid);
|
||||
$table->course = $course;
|
||||
|
||||
$table->define_columns(array('fullname','count',''));
|
||||
@@ -219,12 +227,11 @@
|
||||
));
|
||||
$table->setup();
|
||||
|
||||
|
||||
|
||||
$sql = 'SELECT DISTINCT e.userid, u.firstname,u.lastname,u.idnumber,count(l.action) as count FROM '
|
||||
. $CFG->prefix.'user_'.((!empty($teachers)) ? 'teachers' : 'students').' e '
|
||||
.' JOIN '.$CFG->prefix.'user u ON u.id = e.userid LEFT JOIN '.$CFG->prefix.'log l ON e.userid = l.userid '
|
||||
.' AND e.course = l.course AND l.time > '.$timefrom.' AND l.course = '.$course->id.' AND l.module = \''.$module->name.'\' '
|
||||
$primary_roles = stats_get_primary_role_subselect();
|
||||
$sql = 'SELECT DISTINCT prs.userid, u.firstname,u.lastname,u.idnumber,count(l.action) as count FROM ('.$primary_roles.') prs'
|
||||
.' JOIN '.$CFG->prefix.'user u ON u.id = prs.userid LEFT JOIN '.$CFG->prefix.'log l ON prs.userid = l.userid '
|
||||
.' AND prs.courseid = l.course AND l.time > '.$timefrom.' AND l.course = '.$course->id.' AND l.module = \''.$module->name.'\' '
|
||||
.' AND l.cmid = '.$cm->id;
|
||||
switch ($action) {
|
||||
case 'view':
|
||||
@@ -239,20 +246,21 @@
|
||||
|
||||
}
|
||||
|
||||
$sql .= ' WHERE e.course = '.$course->id;
|
||||
$sql .= ' WHERE prs.courseid = '.$course->id.' AND prs.primary_roleid = '.$roleid.' AND prs.contextlevel = '.CONTEXT_COURSE.' AND prs.courseid = '.$course->id;
|
||||
|
||||
if ($table->get_sql_where()) {
|
||||
$sql .= ' AND '.$table->get_sql_where(); //initial bar
|
||||
}
|
||||
|
||||
$sql .= ' GROUP BY e.userid,u.firstname,u.lastname,u.idnumber,l.userid';
|
||||
$sql .= ' GROUP BY prs.userid,u.firstname,u.lastname,u.idnumber,l.userid';
|
||||
|
||||
if ($table->get_sql_sort()) {
|
||||
$sql .= ' ORDER BY '.$table->get_sql_sort();
|
||||
}
|
||||
|
||||
$countsql = 'SELECT COUNT(DISTINCT(e.userid)) FROM '.$CFG->prefix.'user_'.((!empty($teachers)) ? 'teachers' : 'students').' e '
|
||||
.' JOIN '.$CFG->prefix.'user u ON u.id = e.userid WHERE e.course = '.$course->id;
|
||||
$countsql = 'SELECT COUNT(DISTINCT(prs.userid)) FROM ('.$primary_roles.') prs '
|
||||
.' JOIN '.$CFG->prefix.'user u ON u.id = prs.userid WHERE prs.courseid = '.$course->id
|
||||
.' AND prs.primary_roleid = '.$roleid.' AND prs.contextlevel = '.CONTEXT_COURSE;
|
||||
|
||||
$totalcount = count_records_sql($countsql);
|
||||
|
||||
@@ -279,7 +287,7 @@
|
||||
$data = array();
|
||||
|
||||
$a->count = $totalcount;
|
||||
$a->items = $totalcount == 1 ? ((!empty($teachers)) ? $course->teacher : $course->student) : ((!empty($teachers)) ? $course->teachers : $course->students);
|
||||
$a->items = $role->name;
|
||||
|
||||
if ($matchcount != $totalcount) {
|
||||
$a->items .= ' ('.get_string('matched').' '.$matchcount.')';
|
||||
@@ -332,7 +340,7 @@ function checknos() {
|
||||
foreach ($users as $u) {
|
||||
$data = array('<a href="'.$CFG->wwwroot.'/user/view.php?id='.$u->userid.'&course='.$course->id.'">'.fullname($u,true).'</a>',
|
||||
((!empty($u->count)) ? get_string('yes').' ('.$u->count.') ' : get_string('no')),
|
||||
'<input type="checkbox" name="'.((!empty($teachers)) ? 'teacher' : 'user').$u->userid.'" value="'.$u->count.'" />',
|
||||
'<input type="checkbox" name="user'.$u->userid.'" value="'.$u->count.'" />',
|
||||
);
|
||||
$table->add_data($data);
|
||||
}
|
||||
|
||||
@@ -59,10 +59,12 @@
|
||||
$timeoptions[strtotime('-1 year',$now)] = get_string('lastyear');
|
||||
}
|
||||
|
||||
$useroptions = array(0 => $course->students,
|
||||
1 => $course->teachers,
|
||||
);
|
||||
|
||||
$useroptions = array();
|
||||
if ($roles = get_roles_on_exact_context(get_context_instance(CONTEXT_COURSE,$course->id))) {
|
||||
foreach ($roles as $role) {
|
||||
$useroptions[$role->id] = $role->name;
|
||||
}
|
||||
}
|
||||
$actionoptions = array('' => $strallactions,
|
||||
'view' => $strview,
|
||||
'post' => $strpost,
|
||||
@@ -81,7 +83,7 @@
|
||||
choose_from_menu($timeoptions,'timefrom',0);
|
||||
echo "</td><td>".
|
||||
get_string('showonly').' ';
|
||||
choose_from_menu($useroptions,'teachers',0,'');
|
||||
choose_from_menu($useroptions,'roleid',0,'');
|
||||
echo "</td><td>\n".
|
||||
get_string('showactions'),' ';
|
||||
choose_from_menu($actionoptions,'action',0,'');
|
||||
|
||||
@@ -37,6 +37,7 @@ $string['invalidfieldname'] = '\"$a\" is not a valid field name';
|
||||
$string['invalidfiletype'] = '\"$a\" is not a valid file type';
|
||||
$string['invalidmd5'] = 'Invalid md5';
|
||||
$string['invalidxmlfile'] = '\"$a\" is not a valid XML file';
|
||||
$string['invalidrole'] = 'Invalid role';
|
||||
$string['missingfield'] = 'Field \"$a\" is missing';
|
||||
$string['missingrequiredfield'] = 'Some required field is missing';
|
||||
$string['modulerequirementsnotmet'] = 'Module \"$a->modulename\" ($a->moduleversion) could not be installed. It requires a newer version of Moodle (currently you are using $a->currentmoodle, you need $a->requiremoodle).';
|
||||
|
||||
+25
-20
@@ -138,26 +138,7 @@ function stats_cron_daily () {
|
||||
continue;
|
||||
}
|
||||
|
||||
$primary_roles = 'SELECT ra.userid,
|
||||
ra.roleid AS primary_roleid,
|
||||
ra.contextid,
|
||||
r.sortorder,
|
||||
r.name,
|
||||
r.description,
|
||||
r.shortname,
|
||||
c.instanceid AS courseid,
|
||||
c.contextlevel
|
||||
FROM '.$CFG->prefix.'role_assignments ra
|
||||
INNER JOIN '.$CFG->prefix.'role r ON ra.roleid = r.id
|
||||
INNER JOIN '.$CFG->prefix.'context c ON ra.contextid = c.id
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM '.$CFG->prefix.'role_assignments i_ra
|
||||
INNER JOIN '.$CFG->prefix.'role i_r ON i_ra.roleid = i_r.id
|
||||
WHERE ra.userid = i_ra.userid AND
|
||||
ra.contextid = i_ra.contextid AND
|
||||
i_r.sortorder < r.sortorder) ';
|
||||
|
||||
$primary_roles = stats_get_primary_role_subselect();
|
||||
foreach ($roles as $role) {
|
||||
// ENROLMENT FIRST....
|
||||
// ALL users with this role...
|
||||
@@ -1334,4 +1315,28 @@ function stats_upgrade_table_for_roles ($period) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function stats_get_primary_role_subselect() {
|
||||
global $CFG;
|
||||
return 'SELECT ra.userid,
|
||||
ra.roleid AS primary_roleid,
|
||||
ra.contextid,
|
||||
r.sortorder,
|
||||
r.name,
|
||||
r.description,
|
||||
r.shortname,
|
||||
c.instanceid AS courseid,
|
||||
c.contextlevel
|
||||
FROM '.$CFG->prefix.'role_assignments ra
|
||||
INNER JOIN '.$CFG->prefix.'role r ON ra.roleid = r.id
|
||||
INNER JOIN '.$CFG->prefix.'context c ON ra.contextid = c.id
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM '.$CFG->prefix.'role_assignments i_ra
|
||||
INNER JOIN '.$CFG->prefix.'role i_r ON i_ra.roleid = i_r.id
|
||||
WHERE ra.userid = i_ra.userid AND
|
||||
ra.contextid = i_ra.contextid AND
|
||||
i_r.sortorder < r.sortorder
|
||||
) ';
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user