return 'u.lastaccess != 0 AND u.lastaccess < '.$accesssince;
}
}
-
-function get_participants_extra ($userids, $course, $context) {
- global $CFG, $DB;
-
- if (count($userids) === 0) {
- return array();
- }
-
- $params = array();
-
- $userids = implode(',', $userids);
-
- // turn the path into a list of context ids
- $contextids = substr($context->path, 1); // kill leading slash
- $contextids = str_replace('/', ',', $contextids);;
-
- $gpjoin = "LEFT OUTER JOIN {groupings_groups} gpg
- ON gpg.groupid=g.id
- LEFT OUTER JOIN {groupings} gp
- ON (gp.courseid={$course->id} AND gp.id=gpg.groupingid)";
- $gpselect = ',gp.id AS gpid, gp.name AS gpname ';
-
- // Note: this returns strange redundant rows, perhaps
- // due to the multiple OUTER JOINs. If we can tweak the
- // JOINs to avoid it ot
- $sql = "SELECT DISTINCT ra.userid,
- ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth AS ctxdepth,
- ctx.contextlevel AS ctxlevel, ctx.instanceid AS ctxinstanceid,
- cc.name AS ccname,
- ra.roleid AS roleid,
- g.id AS gid, g.name AS gname
- $gpselect
- FROM {role_assignments} ra
- JOIN {context} ctx
- ON (ra.contextid=ctx.id)
- LEFT JOIN {course_categories} cc
- ON (ctx.contextlevel=40 AND ctx.instanceid=cc.id)
-
- /* only if groups active */
- LEFT JOIN {groups_members} gm
- ON (ra.userid=gm.userid)
- LEFT JOIN {groups} g
- ON (gm.groupid=g.id AND g.courseid={$course->id})
- /* and if groupings is enabled... */
- $gpjoin
-
- WHERE ra.userid IN ( $userids )
- AND ra.contextid in ( $contextids )
-
- ORDER BY ra.userid, ctx.depth DESC";
-
- $rs = $DB->get_recordset_sql($sql, $params);
- $extra = array();
-
- // Data structure -
- // $extra [ $userid ] [ 'group' ] [ $groupid => 'group name']
- // [ 'gping' ] [ $gpingid => 'gping name']
- // [ 'ra' ] [ [ "$ctxid:$roleid" => [ctxid => $ctxid
- // ctxdepth => $ctxdepth,
- // ctxpath => $ctxpath,
- // ctxname => 'name' (categories only)
- // ctxinstid =>
- // roleid => $roleid
-
- foreach ($rs as $rec) {
- $userid = $rec->userid;
-
- // Prime an initial user rec...
- if (!isset($extra[$userid])) {
- $extra[$userid] = array( 'group' => array(),
- 'gping' => array(),
- 'ra' => array() );
- }
-
- if (!empty($rec->gid)) {
- $extra[$userid]['group'][$rec->gid]= $rec->gname;
- }
- if (!empty($rec->gpid)) {
- $extra[$userid]['gping'][$rec->gpid]= $rec->gpname;
- }
- $rakey = $rec->ctxid . ':' . $rec->roleid;
- if (!isset($extra[$userid]['ra'][$rakey])) {
- $extra[$userid]['ra'][$rakey] = array('ctxid' => $rec->ctxid,
- 'ctxlevel' => $rec->ctxlevel,
- 'ctxinstanceid' => $rec->ctxinstanceid,
- 'ccname' => $rec->ccname,
- 'roleid' => $rec->roleid);
-
- }
- }
- $rs->close();
- return $extra;
-
-}
-
-