Commit bbc5c936 authored by Dan Marsden's avatar Dan Marsden Committed by Richard Mansfield
Browse files

WR#70652 group category tidy up

parent 2ce36aaf
......@@ -35,6 +35,16 @@ json_headers();
$itemid = param_integer('itemid');
//first update all records that use this group id
$groups = get_records_assoc('group', 'groupcategory', $itemid);
if (!empty($groups)) {
foreach ($groups as $group) {
$group->groupcategory = 0;
update_record('group', $group);
}
}
//now delete actual category
if (!delete_records('group_category','id', $itemid)) {
json_reply('local', get_string('deletefailed','admin'));
}
......
......@@ -55,7 +55,7 @@ if (get_config('allowgroupcategories')) {
$elements['groupcategory'] = array(
'type' => 'select',
'title' => get_string('groupcategory', 'group'),
'options' => get_records_menu('group_category','','','displayorder', 'id,title'),
'options' => array('0'=>get_string('nocategoryselected', 'group')) + get_records_menu('group_category','','','displayorder', 'id,title'),
'defaultvalue' => '',
'help' => true);
}
......
......@@ -67,7 +67,7 @@ if (get_config('allowgroupcategories')) {
$elements['groupcategory'] = array(
'type' => 'select',
'title' => get_string('groupcategory', 'group'),
'options' => get_records_menu('group_category','','','displayorder', 'id,title'),
'options' => array('0'=>get_string('nocategoryselected', 'group')) + get_records_menu('group_category','','','displayorder', 'id,title'),
'defaultvalue' => $group_data->groupcategory,
'help' => true);
}
......
......@@ -34,7 +34,7 @@ require_once('group.php');
require_once('searchlib.php');
$filter = param_alpha('filter', 'notmember');
$offset = param_integer('offset', 0);
$groupcategory = param_integer('groupcategory', 0);
$groupcategory = param_variable('groupcategory', 0);
$groupsperpage = 20;
$query = param_variable('query', '');
......@@ -64,6 +64,7 @@ $elements['filter'] = array(
'defaultvalue' => $filter);
if (get_config('allowgroupcategories')) {
$options[0] = get_string('allcategories', 'group');
$options[-1] = get_string('categoryunassigned', 'group');
$options += get_records_menu('group_category','','','displayorder', 'id,title');
$elements['groupcategory'] = array(
'type' => 'select',
......
......@@ -36,18 +36,14 @@ define('SECTION_PAGE', 'mygroups');
require_once('group.php');
$filter = param_alpha('filter', 'all');
$offset = param_integer('offset', 'all');
$groupcategory = param_variable('groupcategory', 0);
$groupsperpage = 20;
$offset = (int)($offset / $groupsperpage) * $groupsperpage;
$results = group_get_associated_groups($USER->get('id'), $filter, $groupsperpage, $offset);
$form = pieform(array(
'name' => 'filter',
'method' => 'post',
'renderer' => 'oneline',
'elements' => array(
'options' => array(
$results = group_get_associated_groups($USER->get('id'), $filter, $groupsperpage, $offset, $groupcategory);
$elements = array();
$elements['options'] = array(
'type' => 'select',
'options' => array(
'all' => get_string('allmygroups', 'group'),
......@@ -56,13 +52,25 @@ $form = pieform(array(
'invite' => get_string('groupsiminvitedto', 'group'),
'request' => get_string('groupsiwanttojoin', 'group')
),
'defaultvalue' => $filter
),
'submit' => array(
'defaultvalue' => $filter);
if (get_config('allowgroupcategories')) {
$options[0] = get_string('allcategories', 'group');
$options[-1] = get_string('categoryunassigned', 'group');
$options += get_records_menu('group_category','','','displayorder', 'id,title');
$elements['groupcategory'] = array(
'type' => 'select',
'options' => $options,
'defaultvalue' => $groupcategory,
'help' => true);
}
$elements['submit'] = array(
'type' => 'submit',
'value' => get_string('filter')
)
),
'value' => get_string('filter'));
$form = pieform(array(
'name' => 'filter',
'method' => 'post',
'renderer' => 'oneline',
'elements' => $elements
));
$pagination = build_pagination(array(
......@@ -87,7 +95,7 @@ $smarty->assign('PAGEHEADING', TITLE);
$smarty->display('group/mygroups.tpl');
function filter_submit(Pieform $form, $values) {
redirect('/group/mygroups.php?filter=' . $values['options']);
redirect('/group/mygroups.php?filter=' . $values['options']. (!empty($values['groupcategory']) ? '&groupcategory=' . intval($values['groupcategory']) : ''));
}
?>
......@@ -73,6 +73,8 @@ $string['usersautoadded'] = 'Users auto-added?';
$string['usersautoaddeddescription'] = 'Automatically put all new users into this group?';
$string['groupcategory'] = 'Group category';
$string['allcategories'] = 'All categories';
$string['nocategoryselected'] = 'No category selected';
$string['categoryunassigned'] = 'Category unassigned';
$string['hasrequestedmembership'] = 'has requested membership of this group';
$string['hasbeeninvitedtojoin'] = 'has been invited to join this group';
$string['groupinvitesfrom'] = 'Invited to join:';
......
......@@ -265,6 +265,7 @@ function group_create($data) {
'name' => $data['name'],
'description' => $data['description'],
'grouptype' => $data['grouptype'],
'groupcategory' => $data['groupcategory'],
'jointype' => $data['jointype'],
'ctime' => $data['ctime'],
'mtime' => $data['ctime'],
......@@ -1122,7 +1123,7 @@ function group_sideblock() {
}
function group_get_associated_groups($userid, $filter='all', $limit=20, $offset=0) {
function group_get_associated_groups($userid, $filter='all', $limit=20, $offset=0, $category='') {
// Strangely, casting is only needed for invite, request and admin and only in
// postgres
......@@ -1140,6 +1141,15 @@ function group_get_associated_groups($userid, $filter='all', $limit=20, $offset=
}
// TODO: make it work on other databases?
$catsql = '';
if (!empty($category)) {
if ($category == -1) { //find unassigned groups
$catsql = " AND (g.groupcategory = 0 OR g.groupcategory = null)";
} else {
$catsql = ' AND g.groupcategory ='.$category;
}
}
// Different filters join on the different kinds of association
if ($filter == 'admin') {
$sql = "
......@@ -1205,7 +1215,7 @@ function group_get_associated_groups($userid, $filter='all', $limit=20, $offset=
$values[] = 0;
$count = count_records_sql('SELECT COUNT(*) FROM {group} g ' . $sql . ' WHERE g.deleted = ?', $values);
$count = count_records_sql('SELECT COUNT(*) FROM {group} g ' . $sql . ' WHERE g.deleted = ?'.$catsql, $values);
// almost the same as query used in find - common parts should probably be pulled out
// gets the groups filtered by above
......@@ -1217,13 +1227,14 @@ function group_get_associated_groups($userid, $filter='all', $limit=20, $offset=
FROM {group} g
LEFT JOIN {group_member} gm ON (gm.group = g.id)' .
$sql . '
WHERE g.deleted = ?
WHERE g.deleted = ?' .
$catsql . '
GROUP BY g.id, g.name, g.description, g.public, g.jointype, g.grouptype, t.membershiptype, t.reason, t.role
ORDER BY g.name
) g1
LEFT JOIN {group_member_request} gmr ON (gmr.group = g1.id)
GROUP BY g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.grouptype, g1.membershiptype, g1.reason, g1.role, g1.membercount';
$groups = get_records_sql_assoc($sql, $values, $offset, $limit);
if ($groups) {
......
......@@ -605,7 +605,11 @@ class PluginSearchInternal extends PluginSearch {
$sql .= 'AND id NOT IN (' . $grouproles . ')';
}
if (!empty($category)) {
$sql .= ' AND groupcategory ='.$category;
if ($category == -1) { //find unassigned groups
$sql .= " AND (groupcategory = 0 OR groupcategory = null)";
} else {
$sql .= ' AND groupcategory ='.$category;
}
}
$count = get_field_sql('SELECT COUNT(*) '.$sql, $values);
......
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