mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
Partial fix for MDL-8048, groups cleanup including hiding unimplemented buttons in GUI, fixing error strings.
This commit is contained in:
parent
5291907c45
commit
b1f627d9eb
@ -43,20 +43,13 @@ function groups_db_get_user($userid) {
|
||||
* or an error returned
|
||||
*/
|
||||
function groups_db_get_groups($courseid) {
|
||||
if (!$courseid) {
|
||||
if (! $courseid) {
|
||||
$groupid = false;
|
||||
} else {
|
||||
$groups = get_records('groups_courses_groups', 'courseid', $courseid,
|
||||
'', $fields='id, groupid');
|
||||
// Put the results into an array
|
||||
$groupids = array();
|
||||
if (!$groups) {
|
||||
$groupids = false;
|
||||
} else {
|
||||
foreach ($groups as $group) {
|
||||
array_push($groupids, $group->groupid);
|
||||
}
|
||||
}
|
||||
$groupids = groups_groups_to_groupids($groups, $courseid);
|
||||
}
|
||||
|
||||
return $groupids;
|
||||
@ -101,26 +94,16 @@ function groups_db_get_groups_for_user($userid, $courseid) {
|
||||
$groupids = false;
|
||||
} else {
|
||||
global $CFG;
|
||||
$table_prefix = $CFG->prefix;
|
||||
$sql = "SELECT g.id, userid
|
||||
FROM {$table_prefix}groups_members AS gm
|
||||
INNER JOIN {$table_prefix}groups AS g
|
||||
FROM {$CFG->prefix}groups_members AS gm
|
||||
INNER JOIN {$CFG->prefix}groups AS g
|
||||
ON gm.groupid = g.id
|
||||
INNER JOIN {$table_prefix}groups_courses_groups AS cg
|
||||
INNER JOIN {$CFG->prefix}groups_courses_groups AS cg
|
||||
ON g.id = cg.groupid
|
||||
WHERE cg.courseid = $courseid AND gm.userid=$userid";
|
||||
|
||||
$groups = get_records_sql($sql);
|
||||
|
||||
if (!$groups) {
|
||||
$groupids = false;
|
||||
} else {
|
||||
// Put the results into an array
|
||||
$groupids = array();
|
||||
foreach ($groups as $group) {
|
||||
array_push($groupids, $group->id);
|
||||
}
|
||||
}
|
||||
$groupids = groups_groups_to_groupids($groups, $courseid);
|
||||
}
|
||||
|
||||
return $groupids;
|
||||
@ -140,9 +123,8 @@ function groups_db_get_group_settings($groupid, $courseid=false) {
|
||||
$groupsettings = false;
|
||||
} else {
|
||||
global $CFG;
|
||||
$tableprefix = $CFG->prefix;
|
||||
$sql = "SELECT id, name, description, lang, theme, picture, hidepicture
|
||||
FROM {$tableprefix}groups
|
||||
FROM {$CFG->prefix}groups
|
||||
WHERE id = $groupid";
|
||||
$groupsettings = get_record_sql($sql);
|
||||
if ($courseid && $groupsettings) {
|
||||
@ -162,9 +144,10 @@ function groups_db_get_group_settings($groupid, $courseid=false) {
|
||||
* if an error occurred.
|
||||
*/
|
||||
function groups_db_users_in_common_group($userid1, $userid2) {
|
||||
$havecommongroup = false;
|
||||
$sql = "SELECT gm1.groupid, 1 FROM {$tableprefix}groups_members AS gm1 " .
|
||||
"INNER JOIN {$tableprefix}groups_members AS gm2 " .
|
||||
global $CFG;
|
||||
$havecommongroup = false;
|
||||
$sql = "SELECT gm1.groupid, 1 FROM {$CFG->prefix}groups_members AS gm1 " .
|
||||
"INNER JOIN {$CFG->prefix}groups_members AS gm2 " .
|
||||
"ON gm1.groupid =gm2.groupid" .
|
||||
"WHERE gm1.userid = $userid1 AND gm2.userid = $userid2";
|
||||
$commongroups = get_record_sql($sql);
|
||||
|
@ -109,9 +109,8 @@ function groups_db_get_grouping_settings($groupingid) {
|
||||
$groupingsettings = false;
|
||||
} else {
|
||||
global $CFG;
|
||||
$tableprefix = $CFG->prefix;
|
||||
$sql = "SELECT *
|
||||
FROM {$tableprefix}groups_groupings
|
||||
FROM {$CFG->prefix}groups_groupings
|
||||
WHERE id = $groupingid";
|
||||
$groupingsettings = get_record_sql($sql);
|
||||
}
|
||||
@ -214,10 +213,9 @@ function groups_db_grouping_exists($groupingid) {
|
||||
$belongstogroup = false;
|
||||
} else {
|
||||
global $CFG;
|
||||
$tableprefix = $CFG->prefix;
|
||||
$sql = "SELECT gm.id
|
||||
FROM {$tableprefix}groups_groupings_groups AS gg
|
||||
INNER JOIN {$tableprefix}groups_members AS gm
|
||||
FROM {$CFG->prefix}groups_groupings_groups AS gg
|
||||
INNER JOIN {$CFG->prefix}groups_members AS gm
|
||||
ON gg.groupid = gm.groupid
|
||||
WHERE gm.userid = $userid AND gg.groupingid = $groupingid";
|
||||
$belongstogroup = record_exists_sql($sql);
|
||||
|
@ -32,7 +32,7 @@ $delete = optional_param('delete', false, PARAM_BOOL);
|
||||
$course = groups_get_course_info($courseid);
|
||||
if (! $course) {
|
||||
$success = false;
|
||||
print_error('The course ID is invalid');
|
||||
print_error('invalidcourse'); //'The course ID is invalid'
|
||||
}
|
||||
|
||||
if ($success) {
|
||||
@ -83,7 +83,7 @@ if ($success) {
|
||||
redirect(groups_home_url($courseid, $groupid, $groupingid, false));
|
||||
}
|
||||
else {
|
||||
print_error('Error creating/updating group.');
|
||||
print_error('erroreditgrouping', 'group', groups_home_url($courseid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,10 @@ $groupingsettings->description= optional_param('description', PARAM_ALPHANUM);
|
||||
$course = groups_get_course_info($courseid);
|
||||
if (! $course) {
|
||||
$success = false;
|
||||
print_error('The course ID is invalid');
|
||||
print_error('invalidcourse'); //'The course ID is invalid'
|
||||
}
|
||||
if (GROUP_NOT_IN_GROUPING == $groupingid) {
|
||||
print_error('errornotingroupingedit', 'group', groups_home_url($courseid), get_string('notingrouping', 'group'));
|
||||
}
|
||||
|
||||
if ($success) {
|
||||
@ -59,7 +62,7 @@ if ($success) {
|
||||
redirect(groups_home_url($courseid, null, $groupingid, false));
|
||||
}
|
||||
else {
|
||||
print_error('Error creating/updating grouping.');
|
||||
print_error('erroreditgroup', 'group', groups_home_url($courseid));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -115,6 +118,20 @@ if ($success) {
|
||||
<p><label for="edit-description"><?php print_string('groupingdescription', 'group'); ?> </label></p>
|
||||
<p><?php print_textarea($usehtmleditor, 5, 45, 200, 400, 'description', $strdesc); ?></p>
|
||||
|
||||
<?php /* TODO:
|
||||
<fieldset>
|
||||
<legend><?php print_string('editgroupingpermissions', 'group'); ?></legend>
|
||||
<ol class="unlist para">
|
||||
<li><label><input type="checkbox" id="perm_viewowngroup" checked="checked" /> <?php print_string('viewowngroup', 'group'); ?></label></li>
|
||||
<li><label><input type="checkbox" id="perm_viewallgroupsmembers" checked="checked" /> <?php print_string('viewallgroupsmembers', 'group'); ?></label></li>
|
||||
<li><label><input type="checkbox" id="perm_viewallgroupsactivities" checked="checked" /> <?php print_string('viewallgroupsactivities', 'group'); ?></label></li>
|
||||
<li><label><input type="checkbox" id="perm_teachersgroupmark" /> <?php print_string('teachersgroupmark', 'group'); ?></label></li>
|
||||
<li><label><input type="checkbox" id="perm_teachersgroupview" /> <?php print_string('teachersgroupview', 'group'); ?></label></li>
|
||||
<li><label><input type="checkbox" id="perm_teachersoverride" /> <?php print_string('teachersoverride', 'group'); ?></label></li>
|
||||
</ol>
|
||||
</fieldset>
|
||||
*/ ?>
|
||||
|
||||
<p class="fitem">
|
||||
<label for="id_submit"> </label>
|
||||
<span class="f-element fsubmit">
|
||||
|
@ -19,32 +19,6 @@ $groupingid = optional_param('grouping', -1, PARAM_INT);
|
||||
$groupid = optional_param('group', false, PARAM_INT);
|
||||
$userid = optional_param('user', false, PARAM_INT);
|
||||
|
||||
function groups_param_action($prefix = 'b_') {
|
||||
$action = false;
|
||||
//($_SERVER['QUERY_STRING'] && preg_match("/$prefix(.+?)=(.+)/", $_SERVER['QUERY_STRING'], $matches)) { //b_(.*?)[&;]{0,1}/
|
||||
|
||||
if ($_POST) {
|
||||
$form_vars = $_POST;
|
||||
}
|
||||
elseif ($_GET) {
|
||||
$form_vars = $_GET;
|
||||
}
|
||||
if ($form_vars) {
|
||||
foreach ($form_vars as $key => $value) {
|
||||
//echo "$key => $value<br />\n";
|
||||
if (preg_match("/$prefix(.+)/", $key, $matches)) {
|
||||
$action = $matches[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($action && !preg_match('/^\w+$/', $action)) {
|
||||
$action = false;
|
||||
error('Action had wrong type.');
|
||||
}
|
||||
///if (debugging()) echo 'Debug: '.$action;
|
||||
return $action;
|
||||
}
|
||||
$action = groups_param_action();
|
||||
|
||||
// Get the course information so we can print the header and
|
||||
@ -52,7 +26,7 @@ $action = groups_param_action();
|
||||
$course = groups_get_course_info($courseid);
|
||||
if (! $course) {
|
||||
$success = false;
|
||||
print_error('The course ID is invalid');
|
||||
print_error('invalidcourse'); //'The course ID is invalid'
|
||||
}
|
||||
|
||||
if ($success) {
|
||||
@ -125,8 +99,8 @@ if ($success) {
|
||||
"-> $strgroups", '', '', true, '', user_login_string($course, $USER));
|
||||
|
||||
$usehtmleditor = false;
|
||||
|
||||
//groups_sort_language_strings();
|
||||
//TODO: eventually we'll implement all buttons, meantime hide the ones we haven't finised.
|
||||
$shownotdone = false;
|
||||
?>
|
||||
<form name="groupeditform" id="groupeditform" action="index.php" method="post">
|
||||
<input type="hidden" name="id" value="<?php echo $courseid; ?>" />
|
||||
@ -170,13 +144,17 @@ if ($success) {
|
||||
?>
|
||||
</select>
|
||||
|
||||
<p><input type="submit" name="b_updategroups" id="updategroups" value="<?php print_string('showgroupsingrouping', 'group'); ?>" /></p>
|
||||
<p><input type="submit" name="b_showgroupingsettingsform" id="showeditgroupingsettingsform" value="<?php print_string('editgroupingsettings', 'group'); ?>" /></p>
|
||||
<p><input type="submit" disabled="disabled" name="b_showgroupingpermsform" id="showeditgroupingpermissionsform" value="<?php print_string('editgroupingpermissions', 'group'); ?>" /></p>
|
||||
<p><input type="submit" disabled="disabled" name="b_deletegrouping" id="deletegrouping" value="<?php print_string('deletegrouping', 'group'); ?>" /></p>
|
||||
<p><input type="submit" name="b_showcreategroupingform" id="showcreategroupingform" value="<?php print_string('creategrouping', 'group'); ?>" /></p>
|
||||
<p><input type="submit" disabled="disabled" name="b_createautomaticgroupingform" id="showcreateautomaticgroupingform" value="<?php print_string('createautomaticgrouping', 'group'); ?>" /></p>
|
||||
<p><input type="submit" name="b_printerfriendly" id="printerfriendly" value="<?php print_string('printerfriendly', 'group'); ?>" /></p>
|
||||
<p><input type="submit" name="act_updategroups" id="updategroups" value="<?php print_string('showgroupsingrouping', 'group'); ?>" /></p>
|
||||
<p><input type="submit" name="act_showgroupingsettingsform" id="showeditgroupingsettingsform" value="<?php print_string('editgroupingsettings', 'group'); ?>" /></p>
|
||||
<?php if ($shownotdone) { ?>
|
||||
<p><input type="submit" disabled="disabled" name="act_showgroupingpermsform" id="showeditgroupingpermissionsform" value="<?php print_string('editgroupingpermissions', 'group'); ?>" /></p>
|
||||
<p><input type="submit" disabled="disabled" name="act_deletegrouping" id="deletegrouping" value="<?php print_string('deletegrouping', 'group'); ?>" /></p>
|
||||
<?php } ?>
|
||||
<p><input type="submit" name="act_showcreategroupingform" id="showcreategroupingform" value="<?php print_string('creategrouping', 'group'); ?>" /></p>
|
||||
<?php if ($shownotdone) { ?>
|
||||
<p><input type="submit" disabled="disabled" name="act_createautomaticgroupingform" id="showcreateautomaticgroupingform" value="<?php print_string('createautomaticgrouping', 'group'); ?>" /></p>
|
||||
<?php } ?>
|
||||
<p><input type="submit" name="act_printerfriendly" id="printerfriendly" value="<?php print_string('printerfriendly', 'group'); ?>" /></p>
|
||||
</td>
|
||||
<td>
|
||||
<p><label for="groups"><?php print_string('groupsinselectedgrouping', 'group'); ?></label></p>
|
||||
@ -210,13 +188,16 @@ if ($success) {
|
||||
?>
|
||||
</select>
|
||||
|
||||
<p><input type="submit" name="b_updatemembers" id="updatemembers" value="<?php print_string('showmembersforgroup', 'group'); ?>" /></p>
|
||||
<p><input type="submit" name="b_showgroupsettingsform" id="showeditgroupsettingsform" value="<?php print_string('editgroupsettings', 'group'); ?>" /></p>
|
||||
<p><input type="submit" name="b_deletegroup" onclick="onDeleteGroup()" id="deletegroup" value="<?php print_string('deleteselectedgroup', 'group'); ?>" /></p>
|
||||
<p><input type="submit" disabled="disabled" name="b_removegroup" id="removegroup" value="<?php print_string('removegroupfromselectedgrouping', 'group'); ?>" /></p>
|
||||
<p><input type="submit" name="b_showcreategroupform" id="showcreategroupform" value="<?php print_string('creategroupinselectedgrouping', 'group'); ?>" /></p>
|
||||
<p><input type="submit" disabled="disabled" name="b_addgroupstogroupingsform" id="showaddgroupstogroupingform" value="<?php print_string('addexistinggroupstogrouping', 'group'); ?>" /></p>
|
||||
|
||||
<p><input type="submit" name="act_updatemembers" id="updatemembers" value="<?php print_string('showmembersforgroup', 'group'); ?>" /></p>
|
||||
<p><input type="submit" name="act_showgroupsettingsform" id="showeditgroupsettingsform" value="<?php print_string('editgroupsettings', 'group'); ?>" /></p>
|
||||
<p><input type="submit" name="act_deletegroup" onclick="onDeleteGroup()" id="deletegroup" value="<?php print_string('deleteselectedgroup', 'group'); ?>" /></p>
|
||||
<?php if ($shownotdone) { ?>
|
||||
<p><input type="submit" disabled="disabled" name="act_removegroup" id="removegroup" value="<?php print_string('removegroupfromselectedgrouping', 'group'); ?>" /></p>
|
||||
<?php } ?>
|
||||
<p><input type="submit" name="act_showcreategroupform" id="showcreategroupform" value="<?php print_string('creategroupinselectedgrouping', 'group'); ?>" /></p>
|
||||
<?php if ($shownotdone) { ?>
|
||||
<p><input type="submit" disabled="disabled" name="act_addgroupstogroupingsform" id="showaddgroupstogroupingform" value="<?php print_string('addexistinggroupstogrouping', 'group'); ?>" /></p>
|
||||
<?php } ?>
|
||||
</td>
|
||||
<td>
|
||||
<p><label for="members"><?php print_string('membersofselectedgroup', 'group'); ?></label></p>
|
||||
@ -239,9 +220,10 @@ if ($success) {
|
||||
?>
|
||||
</select>
|
||||
|
||||
<p><input type="submit" disabled="disabled" name="b_removemembers" id="removemembers" value="<?php print_string('removeselectedusers', 'group'); ?>"/></p>
|
||||
<p><input type="submit" name="b_showaddmembersform" id="showaddmembersform" value="<?php print_string('adduserstogroup', 'group'); ?>" /></p>
|
||||
|
||||
<?php if ($shownotdone) { ?>
|
||||
<p><input type="submit" disabled="disabled" name="act_removemembers" id="removemembers" value="<?php print_string('removeselectedusers', 'group'); ?>"/></p>
|
||||
<?php } ?>
|
||||
<p><input type="submit" name="act_showaddmembersform" id="showaddmembersform" value="<?php print_string('adduserstogroup', 'group'); ?>" /></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -73,7 +73,7 @@ function groups_get_all_groups_for_user($userid) {
|
||||
if (! $groups) {
|
||||
return false;
|
||||
}
|
||||
// Put the results into an array
|
||||
// Put the results into an array. TODO: check.
|
||||
$groupids = array();
|
||||
foreach ($groups as $group) {
|
||||
array_push($groupids, $group->id);
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php
|
||||
/**
|
||||
* A grouping is a set of groups that belong to a course.
|
||||
* There may be any number of groupings for a course and a group may
|
||||
@ -155,6 +155,7 @@ function groups_get_users_not_in_any_group_in_grouping($courseid, $groupingid,
|
||||
*/
|
||||
function groups_user_is_in_multiple_groups($userid, $groupingid) {
|
||||
$inmultiplegroups = false;
|
||||
//TODO: $courseid?
|
||||
$groupids = groups_get_groups_for_user($courseid);
|
||||
if ($groupids != false) {
|
||||
$groupinggroupids = array();
|
||||
|
@ -126,25 +126,27 @@ function groups_get_grouping_displayname($groupingid) {
|
||||
* @return array The array of user ids, or false if an error occurred
|
||||
*/
|
||||
function groups_users_to_userids($users) {
|
||||
if (!$users) {
|
||||
$userids = false;
|
||||
} else {
|
||||
$userids = array();
|
||||
foreach($users as $user) {
|
||||
array_push($userids, $user->id);
|
||||
}
|
||||
}
|
||||
return $userids;
|
||||
if (! $users) {
|
||||
return false;
|
||||
}
|
||||
$userids = array();
|
||||
foreach($users as $user) {
|
||||
array_push($userids, $user->id);
|
||||
}
|
||||
return $userids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an array of groups (i.e of objects) and converts it in the
|
||||
* corresponding array of groupids.
|
||||
* @param $groups array The array of group
|
||||
* @return array The array of group ids, or false if an error occurred
|
||||
* Takes an array of groups (i.e of objects) and converts it to the
|
||||
* corresponding array of group IDs.
|
||||
* @param $groups array The array of group-like objects, only the $group->id member is required.
|
||||
* @return array The array of group IDs, or false if an error occurred
|
||||
*/
|
||||
function groups_groups_to_groupids($groups) {
|
||||
$groupids = array();
|
||||
if (! $groups) {
|
||||
return false;
|
||||
}
|
||||
$groupids = array();
|
||||
foreach ($groups as $group) {
|
||||
array_push($groupids, $group->id);
|
||||
}
|
||||
@ -274,4 +276,37 @@ function groups_home_url($courseid, $groupid=false, $groupingid=false, $html=tru
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first button action with the given prefix, taken from
|
||||
* POST or GET, otherwise returns false.
|
||||
* See /lib/moodlelib.php function optional_param.
|
||||
* @param $prefix 'act_' as in 'action'.
|
||||
* @return string The action without the prefix, or false if no action found.
|
||||
*/
|
||||
function groups_param_action($prefix = 'act_') {
|
||||
$action = false;
|
||||
//($_SERVER['QUERY_STRING'] && preg_match("/$prefix(.+?)=(.+)/", $_SERVER['QUERY_STRING'], $matches)) { //b_(.*?)[&;]{0,1}/
|
||||
|
||||
if ($_POST) {
|
||||
$form_vars = $_POST;
|
||||
}
|
||||
elseif ($_GET) {
|
||||
$form_vars = $_GET;
|
||||
}
|
||||
if ($form_vars) {
|
||||
foreach ($form_vars as $key => $value) {
|
||||
if (preg_match("/$prefix(.+)/", $key, $matches)) {
|
||||
$action = $matches[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($action && !preg_match('/^\w+$/', $action)) {
|
||||
$action = false;
|
||||
error('Action had wrong type.');
|
||||
}
|
||||
///if (debugging()) echo 'Debug: '.$action;
|
||||
return $action;
|
||||
}
|
||||
|
||||
?>
|
@ -13,6 +13,11 @@ $string['groupmemberdesc'] = 'Standard role for a member of a group.';
|
||||
$string['notingrouping'] = '[Not in a grouping]';
|
||||
|
||||
$string['errornotingrouping'] = 'Sorry, you can\'t create a group in $a';
|
||||
$string['errornotingroupingedit'] = 'Sorry, you can\'t edit grouping $a';
|
||||
$string['errorinvalidgrouping'] = 'Error, invalid grouping $a';
|
||||
$string['errorinvalidgroup'] = 'Error, invalid group $a';
|
||||
$string['erroreditgrouping'] = 'Error creating/updating grouping $a';
|
||||
$string['erroreditgroup'] = 'Error creating/updating grouping $a';
|
||||
|
||||
$string['groupings'] = 'Groupings';
|
||||
$string['grouping'] = 'Grouping';
|
||||
|
Loading…
x
Reference in New Issue
Block a user