Skip to content

Commit

Permalink
Partial fix for MDL-8048, groups cleanup including hiding unimplement…
Browse files Browse the repository at this point in the history
…ed buttons in GUI, fixing error strings.
  • Loading branch information
nfreear committed Jan 17, 2007
1 parent 5291907 commit b1f627d
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 99 deletions.
39 changes: 11 additions & 28 deletions group/db/dbbasicgrouplib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions group/db/dbgroupinglib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -214,10 +213,9 @@ function groups_db_is_member_of_some_group_in_grouping($userid, $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);
Expand Down
4 changes: 2 additions & 2 deletions group/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
$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) {
Expand Down Expand Up @@ -83,7 +83,7 @@
redirect(groups_home_url($courseid, $groupid, $groupingid, false));
}
else {
print_error('Error creating/updating group.');
print_error('erroreditgrouping', 'group', groups_home_url($courseid));
}
}
}
Expand Down
21 changes: 19 additions & 2 deletions group/grouping.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
$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) {
Expand Down Expand Up @@ -59,7 +62,7 @@
redirect(groups_home_url($courseid, null, $groupingid, false));
}
else {
print_error('Error creating/updating grouping.');
print_error('erroreditgroup', 'group', groups_home_url($courseid));
}
}
}
Expand Down Expand Up @@ -115,6 +118,20 @@
<p><label for="edit-description"><?php print_string('groupingdescription', 'group'); ?>&nbsp;</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">&nbsp;</label>
<span class="f-element fsubmit">
Expand Down
74 changes: 28 additions & 46 deletions group/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,14 @@
$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
// check the course id is valid
$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) {
Expand Down Expand Up @@ -125,8 +99,8 @@ function groups_param_action($prefix = 'b_') {
"-> $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; ?>" />
Expand Down Expand Up @@ -170,13 +144,17 @@ function groups_param_action($prefix = 'b_') {
?>
</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>
Expand Down Expand Up @@ -210,13 +188,16 @@ function groups_param_action($prefix = 'b_') {
?>
</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>
Expand All @@ -239,9 +220,10 @@ function groups_param_action($prefix = 'b_') {
?>
</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>
Expand Down
2 changes: 1 addition & 1 deletion group/lib/basicgrouplib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion group/lib/groupinglib.php
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
Expand Down
63 changes: 49 additions & 14 deletions group/lib/utillib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

?>
5 changes: 5 additions & 0 deletions lang/en_utf8/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
$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';
Expand Down

0 comments on commit b1f627d

Please sign in to comment.