Commit 43bc2da4 authored by Nigel McNie's avatar Nigel McNie
Browse files

Merge branch 'grouprework'

Conflicts:

	htdocs/group/view.php
	htdocs/lang/en.utf8/mahara.php
	htdocs/lib/group.php
	htdocs/search/internal/lib.php
parents c1482b03 3bf3443e
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2007 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Clare Lenihan <clare@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('MENUITEM', 'groups');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require('group.php');
$groupid = param_integer('id');
$group = get_record('group', 'id', $groupid, 'owner', $USER->get('id'));
if (!$group) {
throw new AccessDeniedException(get_string('cantdeletegroupdontown'));
}
define('TITLE', get_string('deletespecifiedgroup', 'mahara', $group->name));
$views = count_records_sql(
'SELECT COUNT(a.*)
FROM {view_access_group} a
WHERE a.group = ?',
array($groupid)
);
$form = pieform(array(
'name' => 'deletegroup',
'autofocus' => false,
'method' => 'post',
'elements' => array(
'submit' => array(
'type' => 'submitcancel',
'title' => $views ? get_string('groupconfirmdeletehasviews') : get_string('groupconfirmdelete'),
'value' => array(get_string('yes'), get_string('no')),
'goto' => get_config('wwwroot') . 'group/view.php?id=' . $groupid
)
),
));
$smarty = smarty();
$smarty->assign('heading', TITLE);
$smarty->assign('form', $form);
$smarty->display('group/delete.tpl');
function deletegroup_submit(Pieform $form, $values) {
global $USER, $groupid;
db_begin();
delete_records('view_access_group', 'group', $groupid);
delete_records('group_member_invite', 'group', $groupid);
delete_records('group_member_request', 'group', $groupid);
delete_records('group_member', 'group', $groupid);
delete_records('group', 'id', $groupid);
db_commit();
redirect('/group/mygroups.php');
}
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2007 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Clare Lenihan <clare@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('MENUITEM', 'groups/find');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('findgroups'));
require('group.php');
require('searchlib.php');
$filter = param_alpha('filter', 'notmember');
$offset = param_integer('offset', 0);
$groupsperpage = 20;
$query = param_variable('query', '');
$searchform = pieform(array(
'name' => 'search',
'method' => 'post',
'renderer' => 'oneline',
'elements' => array(
'query' => array(
'type' => 'text',
'defaultvalue' => $query
),
'filter' => array(
'type' => 'select',
'options' => array(
'notmember' => get_string('groupsnotin', 'group'),
'member' => get_string('groupsimin', 'group'),
'all' => get_string('allgroups', 'group')
),
'defaultvalue' => $filter
),
'search' => array(
'type' => 'submit',
'value' => get_string('search')
)
)
));
if ($filter == 'member') {
$type = 'member';
}
else if ($filter == 'notmember') {
$type = 'notmember';
}
else if ($filter == 'all'){
$type = 'all';
}
$groups = search_group($query, $groupsperpage, $offset, $type);
// gets more data about the groups found by search_group
// including type if the user is associated with the group in some way
// and the first three members by id
// does this by finding the lowest id, then the next lowest, then the third lowest in subselects
// which is just horrible :(
if ($groups['data']) {
$groupids = array();
foreach ($groups['data'] as $group) {
$groupids[] = $group->id;
}
$groups['data'] = get_records_sql_array(
'SELECT g.id, g.name, g.description, g.owner, g.jointype, m.member1 AS member1, m.member2 AS member2, t.type, MIN(gm.member) AS member3, COUNT(gm2.*) AS membercount, COUNT(gmr.*) AS requests
FROM {group} g
LEFT JOIN (
SELECT m.member AS member1, g.id AS group, MIN(gm.member) AS member2
FROM {group} g
LEFT JOIN (
SELECT g.id AS group, MIN(gm.member) AS member
FROM {group} g
LEFT JOIN {group_member} gm ON (gm.group = g.id)
GROUP BY 1
) m on m.group = g.id
LEFT JOIN {group_member} gm ON (gm.group = g.id AND m.member != gm.member)
GROUP BY 1, 2
) m ON m.group = g.id
LEFT JOIN {group_member} gm ON (gm.group = g.id AND gm.member != m.member1 AND gm.member != m.member2)
LEFT JOIN {group_member} gm2 ON (gm2.group = g.id)
LEFT JOIN {group_member_request} gmr ON gmr.group = g.id
LEFT JOIN (
SELECT g.id, CAST(\'owner\' AS TEXT) AS type
FROM {group} g
WHERE g.owner = ?
UNION SELECT g.id, CAST(\'member\' AS TEXT) AS type
FROM {group} g
INNER JOIN {group_member} gm ON (g.id = gm.group AND gm.member = ?)
WHERE g.owner != gm.member
UNION SELECT g.id, CAST(\'invite\' AS TEXT) AS type
FROM {group} g
INNER JOIN {group_member_invite} gmi ON (gmi.group = g.id AND gmi.member = ?)
UNION SELECT g.id, CAST(\'request\' AS TEXT) AS type
FROM {group} g
INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)
) t ON t.id = g.id
WHERE g.id IN (' . implode($groupids, ',') . ')
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8
ORDER BY g.name',
array($USER->get('id'), $USER->get('id'), $USER->get('id'), $USER->get('id'))
);
}
setup_groups($groups['data'], 'find');
$pagination = build_pagination(array(
'url' => 'find.php?filter=' . $filter . '&amp;query=' . $query,
'count' => $groups['count'],
'limit' => $groupsperpage,
'offset' => $offset
));
function search_submit(Pieform $form, $values) {
redirect('/group/find.php?filter=' . $values['filter'] . (isset($values['query']) ? '&query=' . urlencode($values['query']) : ''));
}
$smarty = smarty();
$smarty->assign('heading', TITLE);
$smarty->assign('form', $searchform);
$smarty->assign('groups', $groups['data']);
$smarty->assign('pagination', $pagination['html']);
$smarty->display('group/find.tpl');
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2007 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Clare Lenihan <clare@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('MENUITEM', 'groups');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require('group.php');
$groupid = param_integer('id');
$returnto = param_alpha('returnto', 'mygroups');
$group = get_record('group', 'id', $groupid);
if (!$group) {
throw new GroupNotFoundException(get_string('groupnotfound', 'mahara', $groupid));
}
define('TITLE', get_string('leavespecifiedgroup', 'mahara', $group->name));
$membership = user_can_access_group($group);
if (!($membership & GROUP_MEMBERSHIP_MEMBER)) {
throw new AccessDeniedException(get_string('notamember'));
}
if (!group_user_can_leave($group)) {
throw new AccessDeniedException(get_string('cantleavegroup'));
}
$views = count_records_sql(
'SELECT COUNT(v.*)
FROM {view} v
INNER JOIN {view_access_group} a
ON a.group = ?
AND a.view = v.id
WHERE v.owner = ?',
array($groupid, $USER->get('id'))
);
$form = pieform(array(
'name' => 'leavegroup',
'autofocus' => false,
'method' => 'post',
'elements' => array(
'submit' => array(
'type' => 'submitcancel',
'title' => $views ? get_string('groupconfirmleavehasviews') : get_string('groupconfirmleave'),
'value' => array(get_string('yes'), get_string('no')),
'goto' => get_config('wwwroot') . ($returnto == 'find' ? 'group/find.php' : 'group/mygroups.php')
),
'returnto' => array(
'type' => 'hidden',
'value' => $returnto
)
),
));
$smarty = smarty();
$smarty->assign('heading', TITLE);
$smarty->assign('form', $form);
$smarty->display('group/leave.tpl');
function leavegroup_submit(Pieform $form, $values) {
global $USER, $SESSION, $groupid;
group_remove_user($groupid, $USER->get('id'));
$SESSION->add_ok_msg(get_string('leftgroup'));
redirect($values['returnto'] == 'find' ? '/group/find.php' : '/group/mygroups.php');
}
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2007 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Clare Lenihan <clare@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('MENUITEM', 'groups/mygroups');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('mygroups'));
require('group.php');
$filter = param_alpha('filter', 'all');
$offset = param_integer('offset', 'all');
$groupsperpage = 20;
$offset = (int)($offset / $groupsperpage) * $groupsperpage;
$form = pieform(array(
'name' => 'filter',
'method' => 'post',
'renderer' => 'oneline',
'elements' => array(
'options' => array(
'type' => 'select',
'options' => array(
'all' => get_string('allmygroups', 'group'),
'owner' => get_string('groupsiown', 'group'),
'member' => get_string('groupsimin', 'group'),
'invite' => get_string('groupsiminvitedto', 'group'),
'request' => get_string('groupsiwanttojoin', 'group')
),
'defaultvalue' => $filter
),
'submit' => array(
'type' => 'submit',
'value' => get_string('filter')
)
),
));
// different filters join on the different kinds of association
if ($filter == 'all') {
$sql = '
INNER JOIN (
SELECT g.id, CAST(\'owner\' AS TEXT) AS type
FROM {group} g
WHERE g.owner = ?
UNION SELECT g.id, CAST(\'member\' AS TEXT) AS type
FROM {group} g
INNER JOIN {group_member} gm ON (g.id = gm.group AND gm.member = ?)
WHERE g.owner != gm.member
UNION SELECT g.id, CAST(\'invite\' AS TEXT) AS type
FROM {group} g
INNER JOIN {group_member_invite} gmi ON (gmi.group = g.id AND gmi.member = ?)
UNION SELECT g.id, CAST(\'request\' AS TEXT) AS type
FROM {group} g
INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)
) t ON t.id = g.id';
$values = array($USER->get('id'), $USER->get('id'), $USER->get('id'), $USER->get('id'));
}
else if ($filter == 'owner') {
$sql = '
INNER JOIN (
SELECT g.id, CAST(\'owner\' AS TEXT) AS type
FROM {group} g
WHERE g.owner = ?
) t ON t.id = g.id';
$values = array($USER->get('id'));
}
else if ($filter == 'member') {
$sql = '
INNER JOIN (
SELECT g.id, CAST(\'owner\' AS TEXT) AS type
FROM {group} g
WHERE g.owner = ?
UNION SELECT g.id, CAST(\'member\' AS TEXT) AS type
FROM {group} g
INNER JOIN {group_member} gm ON (g.id = gm.group AND gm.member = ?)
WHERE g.owner != gm.member
) t ON t.id = g.id';
$values = array($USER->get('id'), $USER->get('id'));
}
else if ($filter == 'invite') {
$sql = '
INNER JOIN (
SELECT g.id, CAST(\'invite\' AS TEXT) AS type
FROM {group} g
INNER JOIN {group_member_invite} gmi ON (gmi.group = g.id AND gmi.member = ?)
) t ON t.id = g.id';
$values = array($USER->get('id'));
}
else if ($filter == 'request') {
$sql = '
INNER JOIN (
SELECT g.id, CAST(\'request\' AS TEXT) AS type
FROM {group} g
INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)
) t ON t.id = g.id';
$values = array($USER->get('id'));
}
$count = count_records_sql('SELECT COUNT(g.*) FROM {group} g ' . $sql, $values);
// almost the same as query used in find - common parts should probably be pulled out
// gets the groups filtered by
// including type if the user is associated with the group in some way
// and the first three members by id
// does this by finding the lowest id, then the next lowest, then the third lowest in subselects
// which is just horrible :(
$sql = 'SELECT g.id, g.name, g.description, g.owner, g.jointype, m.member1 AS member1, m.member2 AS member2, t.type, MIN(gm.member) AS member3, COUNT(gm2.*) AS membercount, COUNT(gmr.*) AS requests
FROM {group} g
LEFT JOIN (
SELECT m.member AS member1, g.id AS group, MIN(gm.member) AS member2
FROM {group} g
LEFT JOIN (
SELECT g.id AS group, MIN(gm.member) AS member
FROM {group} g
LEFT JOIN {group_member} gm ON (gm.group = g.id)
GROUP BY 1
) m on m.group = g.id
LEFT JOIN {group_member} gm ON (gm.group = g.id AND m.member != gm.member)
GROUP BY 1, 2
) m ON m.group = g.id
LEFT JOIN {group_member} gm ON (gm.group = g.id AND gm.member != m.member1 AND gm.member != m.member2)
LEFT JOIN {group_member} gm2 ON (gm2.group = g.id)
LEFT JOIN {group_member_request} gmr ON (gmr.group = g.id)' .
$sql . '
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8
ORDER BY g.name';
$groups = get_records_sql_array($sql, $values, $offset, $groupsperpage);
$pagination = build_pagination(array(
'url' => 'mygroups.php?filter=' . $filter,
'count' => $count,
'limit' => $groupsperpage,
'offset' => $offset
));
setup_groups($groups, 'mygroups');
$smarty = smarty();
$smarty->assign('groups', $groups);
$smarty->assign('form', $form);
$smarty->assign('filter', $filter);
$smarty->assign('pagination', $pagination['html']);
$smarty->assign('searchingforgroups', array('<a href="' . get_config('wwwroot') . 'group/find.php">', '</a>'));
$smarty->display('group/mygroups.tpl');
function filter_submit(Pieform $form, $values) {
redirect('/group/mygroups.php?filter=' . $values['options']);
}
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2007 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Clare Lenihan <clare@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('MENUITEM', 'groups');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require('group.php');
$groupid = param_integer('id');
$returnto = param_alpha('returnto', 'mygroups');
$group = get_record('group', 'id', $groupid);
if (!$group) {
throw new GroupNotFoundException(get_string('groupnotfound', 'mahara', $groupid));
}
if ($group->jointype != 'request'
|| record_exists('group_member', 'group', $groupid, 'member', $USER->get('id'))
|| record_exists('group_member_request', 'group', $groupid, 'member', $USER->get('id'))) {
throw new AccessDeniedException(get_string('cannotrequestjoingroup'));
}
define('TITLE', get_string('requestjoinspecifiedgroup', 'mahara', $group->name));
$form = pieform(array(
'name' => 'requestjoingroup',
'autofocus' => false,
'method' => 'post',
'elements' => array(
'reason' => array(
'type' => 'text',
'title' => get_string('reason'),
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('yes'), get_string('no')),
'goto' => get_config('wwwroot') . ($returnto == 'find' ? 'group/find.php' : 'group/mygroups.php')
),
'returnto' => array(
'type' => 'hidden',
'value' => $returnto
)
),
));
$smarty = smarty();
$smarty->assign('heading', TITLE);
$smarty->assign('form', $form);
$smarty->display('group/requestjoin.tpl');
function requestjoingroup_submit(Pieform $form, $values) {
global $SESSION, $USER, $group;
insert_record(
'group_member_request',
(object)array(
'group' => $group->id,
'member' => $USER->get('id'),
'ctime' => db_format_timestamp(time()),
'reason' => isset($values['reason']) ? $values['reason'] : null
)
);
if (isset($values['reason'])) {
$message = get_string('grouprequestmessagereason', 'mahara', display_name($USER, get_record('usr', 'id', $group->owner)), $group->name, $values['reason']);
}
else {
$message = get_string('grouprequestmessage', 'mahara', display_name($USER, $group->owner), $group->name);
}
require_once('activity.php');
activity_occurred('maharamessage',
array('users' => array($group->owner),
'subject' => get_string('grouprequestsubject'),
'message' => $message,
'url' => get_config('wwwroot') . 'group/view.php?id=' . $group->id));
$SESSION->add_ok_msg(get_string('grouprequestsent'));
redirect($values['returnto'] == 'find' ? '/group/find.php' : '/group/mygroups.php');
}
?>
...@@ -50,7 +50,7 @@ if (!empty($joincontrol)) { ...@@ -50,7 +50,7 @@ if (!empty($joincontrol)) {
case 'leave': case 'leave':
// make sure they're a member and can leave // make sure they're a member and can leave
if ($ismember && $group->jointype != 'controlled') { if ($ismember && $group->jointype != 'controlled') {
group_remove_member($id, $USER->get('id')); group_remove_user($id, $USER->get('id'));
$SESSION->add_ok_msg(get_string('leftgroup', 'group')); $SESSION->add_ok_msg(get_string('leftgroup', 'group'));
} }
else { else {
......
...@@ -46,7 +46,7 @@ $offset = param_integer('offset', 0); ...@@ -46,7 +46,7 @@ $offset = param_integer('offset', 0);
switch($type) { switch($type) {
case 'group': case 'group':
$data = search_group($query, $limit, $offset, true); $data = search_group($query, $limit, $offset, 'all');
$data['type'] = 'group'; $data['type'] = 'group';
break; break;