Commit 8444c870 authored by Andrew Robert Nicols's avatar Andrew Robert Nicols Committed by Evan Goldenberg
Browse files

Function to select 'course' groups



Moved the SQL from view/index.php to lib/group.php so it can be used
elsewhere.
I considered testing the results of get_group_user_groups on type ===
'course', but this doesn't allow for future group types which also allow
submissions.
Signed-off-by: default avatarAndrew Robert Nicols <andrew.nicols@luns.net.uk>
Signed-off-by: default avatarEvan Goldenberg <evang@catalyst.net.nz>
parent f307844a
......@@ -1160,4 +1160,23 @@ function group_can_create_groups() {
}
return $creators == 'staff' && ($USER->get('staff') || $USER->is_institutional_staff());
}
function group_get_user_course_groups($userid=null) {
if (is_null($userid)) {
global $USER;
$userid = $USER->get('id');
}
if ($groups = get_records_sql_array(
"SELECT g.id, g.name
FROM {group_member} u
INNER JOIN {group} g ON (u.group = g.id AND g.deleted = 0)
INNER JOIN {grouptype} t ON t.name = g.grouptype
WHERE u.member = ?
AND t.submittableto = 1
ORDER BY g.name
", array($userid))) {
return $groups;
}
return array();
}
?>
......@@ -35,6 +35,7 @@ define('SECTION_PAGE', 'index');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('libroot') . 'view.php');
require_once('pieforms/pieform.php');
require_once('group.php');
define('TITLE', get_string('myviews', 'view'));
$limit = param_integer('limit', 5);
......@@ -46,14 +47,7 @@ $userid = $USER->get('id');
/* Get a list of groups that the user belongs to which views can
be sumitted. */
if (!$tutorgroupdata = @get_records_sql_array('SELECT g.id, g.name
FROM {group_member} u
INNER JOIN {group} g ON (u.group = g.id AND g.deleted = 0)
INNER JOIN {grouptype} t ON t.name = g.grouptype
WHERE u.member = ?
AND t.submittableto = 1
ORDER BY g.name', array($userid))) {
if (!$tutorgroupdata = group_get_user_course_groups()) {
$tutorgroupdata = array();
}
else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment