Commit 370f3af6 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Fix group category code for renamed column, ensure category is null for uncategorised groups.


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 2deaa570
...@@ -39,7 +39,7 @@ $itemid = param_integer('itemid'); ...@@ -39,7 +39,7 @@ $itemid = param_integer('itemid');
$groups = get_records_assoc('group', 'category', $itemid); $groups = get_records_assoc('group', 'category', $itemid);
if (!empty($groups)) { if (!empty($groups)) {
foreach ($groups as $group) { foreach ($groups as $group) {
$group->groupcategory = null; $group->category = null;
update_record('group', $group); update_record('group', $group);
} }
} }
......
...@@ -52,7 +52,7 @@ $elements['grouptype'] = array( ...@@ -52,7 +52,7 @@ $elements['grouptype'] = array(
'defaultvalue' => 'standard.open', 'defaultvalue' => 'standard.open',
'help' => true); 'help' => true);
if (get_config('allowgroupcategories')) { if (get_config('allowgroupcategories')) {
$elements['groupcategory'] = array( $elements['category'] = array(
'type' => 'select', 'type' => 'select',
'title' => get_string('groupcategory', 'group'), 'title' => get_string('groupcategory', 'group'),
'options' => array('0'=>get_string('nocategoryselected', 'group')) + get_records_menu('group_category','','','displayorder', 'id,title'), 'options' => array('0'=>get_string('nocategoryselected', 'group')) + get_records_menu('group_category','','','displayorder', 'id,title'),
...@@ -117,7 +117,7 @@ function creategroup_submit(Pieform $form, $values) { ...@@ -117,7 +117,7 @@ function creategroup_submit(Pieform $form, $values) {
'name' => $values['name'], 'name' => $values['name'],
'description' => $values['description'], 'description' => $values['description'],
'grouptype' => $grouptype, 'grouptype' => $grouptype,
'groupcategory' => intval($values['groupcategory']), 'category' => empty($values['category']) ? null : intval($values['category']),
'jointype' => $jointype, 'jointype' => $jointype,
'public' => intval($values['public']), 'public' => intval($values['public']),
'usersautoadded' => intval($values['usersautoadded']), 'usersautoadded' => intval($values['usersautoadded']),
......
...@@ -35,7 +35,7 @@ define('TITLE', get_string('editgroup', 'group')); ...@@ -35,7 +35,7 @@ define('TITLE', get_string('editgroup', 'group'));
$id = param_integer('id'); $id = param_integer('id');
define('GROUP', $id); define('GROUP', $id);
$group_data = get_record_sql("SELECT g.id, g.name, g.description, g.grouptype, g.jointype, g.public, g.usersautoadded, g.groupcategory $group_data = get_record_sql("SELECT g.id, g.name, g.description, g.grouptype, g.jointype, g.public, g.usersautoadded, g.category
FROM {group} g FROM {group} g
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role = 'admin') INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role = 'admin')
WHERE g.id = ? WHERE g.id = ?
...@@ -64,11 +64,11 @@ $elements['grouptype'] = array( ...@@ -64,11 +64,11 @@ $elements['grouptype'] = array(
'defaultvalue' => $group_data->grouptype . '.' . $group_data->jointype, 'defaultvalue' => $group_data->grouptype . '.' . $group_data->jointype,
'help' => true); 'help' => true);
if (get_config('allowgroupcategories')) { if (get_config('allowgroupcategories')) {
$elements['groupcategory'] = array( $elements['category'] = array(
'type' => 'select', 'type' => 'select',
'title' => get_string('groupcategory', 'group'), 'title' => get_string('groupcategory', 'group'),
'options' => array('0'=>get_string('nocategoryselected', 'group')) + 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, 'defaultvalue' => $group_data->category,
'help' => true); 'help' => true);
} }
$elements['public'] = array( $elements['public'] = array(
...@@ -133,7 +133,7 @@ function editgroup_submit(Pieform $form, $values) { ...@@ -133,7 +133,7 @@ function editgroup_submit(Pieform $form, $values) {
'name' => $values['name'], 'name' => $values['name'],
'description' => $values['description'], 'description' => $values['description'],
'grouptype' => $grouptype, 'grouptype' => $grouptype,
'groupcategory' => intval($values['groupcategory']), 'category' => empty($values['category']) ? null : intval($values['category']),
'jointype' => $jointype, 'jointype' => $jointype,
'mtime' => $now, 'mtime' => $now,
'usersautoadded' => intval($values['usersautoadded']), 'usersautoadded' => intval($values['usersautoadded']),
......
...@@ -265,7 +265,7 @@ function group_create($data) { ...@@ -265,7 +265,7 @@ function group_create($data) {
'name' => $data['name'], 'name' => $data['name'],
'description' => $data['description'], 'description' => $data['description'],
'grouptype' => $data['grouptype'], 'grouptype' => $data['grouptype'],
'groupcategory' => $data['groupcategory'], 'category' => $data['category'],
'jointype' => $data['jointype'], 'jointype' => $data['jointype'],
'ctime' => $data['ctime'], 'ctime' => $data['ctime'],
'mtime' => $data['ctime'], 'mtime' => $data['ctime'],
...@@ -1141,15 +1141,6 @@ function group_get_associated_groups($userid, $filter='all', $limit=20, $offset= ...@@ -1141,15 +1141,6 @@ function group_get_associated_groups($userid, $filter='all', $limit=20, $offset=
} }
// TODO: make it work on other databases? // 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 // Different filters join on the different kinds of association
if ($filter == 'admin') { if ($filter == 'admin') {
$sql = " $sql = "
...@@ -1215,6 +1206,16 @@ function group_get_associated_groups($userid, $filter='all', $limit=20, $offset= ...@@ -1215,6 +1206,16 @@ function group_get_associated_groups($userid, $filter='all', $limit=20, $offset=
$values[] = 0; $values[] = 0;
$catsql = '';
if (!empty($category)) {
if ($category == -1) { //find unassigned groups
$catsql = ' AND g.category IS NULL';
} else {
$catsql = ' AND g.category = ?';
$values[] = $category;
}
}
$count = count_records_sql('SELECT COUNT(*) FROM {group} g ' . $sql . ' WHERE g.deleted = ?'.$catsql, $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 // almost the same as query used in find - common parts should probably be pulled out
......
...@@ -606,16 +606,17 @@ class PluginSearchInternal extends PluginSearch { ...@@ -606,16 +606,17 @@ class PluginSearchInternal extends PluginSearch {
} }
if (!empty($category)) { if (!empty($category)) {
if ($category == -1) { //find unassigned groups if ($category == -1) { //find unassigned groups
$sql .= " AND (groupcategory = 0 OR groupcategory = null)"; $sql .= " AND category IS NULL";
} else { } else {
$sql .= ' AND groupcategory ='.$category; $sql .= ' AND category = ?';
$values[] = $category;
} }
} }
$count = get_field_sql('SELECT COUNT(*) '.$sql, $values); $count = get_field_sql('SELECT COUNT(*) '.$sql, $values);
if ($count > 0) { if ($count > 0) {
$sql = 'SELECT id, name, description, grouptype, jointype, ctime, mtime ' . $sql . 'ORDER BY name'; $sql = 'SELECT id, name, description, grouptype, jointype, ctime, mtime ' . $sql . ' ORDER BY name';
$data = get_records_sql_array($sql, $values, $offset, $limit); $data = get_records_sql_array($sql, $values, $offset, $limit);
} }
......
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