Commit e572a3a6 authored by Nigel McNie's avatar Nigel McNie Committed by Penny Leach
Browse files

Renaming communities to groups step 1: everywhere in the code. Filenames and...

Renaming communities to groups step 1: everywhere in the code. Filenames and database changes to come.
parent f09c8703
......@@ -51,8 +51,8 @@ if ($stopmonitoring) {
delete_records('usr_watchlist_artefact', 'usr', $userid, 'artefact', $m[1]);
$count++;
}
else if (preg_match('/^stopcommunities\-(\d+)$/',$k,$m)) {
delete_records('usr_watchlist_community', 'usr', $userid, 'community', $m[1]);
else if (preg_match('/^stopgroups\-(\d+)$/',$k,$m)) {
delete_records('usr_watchlist_group', 'usr', $userid, 'group', $m[1]);
$count++;
}
}
......@@ -127,11 +127,11 @@ if ($type == 'views') {
ORDER BY v.mtime DESC';
$records = get_records_sql_array($sql, $values, $offset, $limit);
}
else if ($type == 'communities') {
$count = count_records('usr_watchlist_community', 'usr', $userid);
else if ($type == 'groups') {
$count = count_records('usr_watchlist_group', 'usr', $userid);
$sql = 'SELECT c.*
FROM ' . $prefix . 'community c
JOIN ' . $prefix . 'usr_watchlist_community w ON w.community = c.id
FROM ' . $prefix . 'group g
JOIN ' . $prefix . 'usr_watchlist_group w ON w.group = g.id
WHERE w.usr = ?
ORDER BY c.mtime DESC';
$records = get_records_sql_array($sql, array($userid), $offset, $limit);
......
......@@ -34,7 +34,7 @@ define('SECTION_PAGE', 'watchlist');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$viewstring = get_string('views', 'activity');
$communitystring = get_string('communities', 'activity');
$groupstring = get_string('groups', 'activity');
$artefactstring = get_string('artefacts', 'activity');
$monitoredstring = get_string('monitored', 'activity');
$allusersstring = get_string('allusers');
......@@ -50,8 +50,8 @@ var watchlist = new TableRenderer(
[
function(r, d) {
var url = '';
if (d.type == 'communities') {
url = '{$wwwroot}/contacts/communities/view.php?id=' + r.id;
if (d.type == 'groups') {
url = '{$wwwroot}/contacts/groups/view.php?id=' + r.id;
}
else if (d.type == 'views') {
url = '{$wwwroot}/view/view.php?view=' + r.id;
......@@ -79,9 +79,9 @@ watchlist.updateOnLoad();
watchlist.rowfunction = function(r, n) { return TR({'id': r.id, 'class': 'view r' + (n % 2)}); }
function changeTitle(title) {
var titles = { 'views': '{$viewstring}', 'communities': '{$communitystring}', 'artefacts': '{$artefactstring}' };
var titles = { 'views': '{$viewstring}', 'groups': '{$groupstring}', 'artefacts': '{$artefactstring}' };
$('typeheader').innerHTML = '{$monitoredstring} ' + titles[title];
if (title != 'communities') {
if (title != 'groups') {
$('typeandchildren').innerHTML = '{$andchildren}';
}
else {
......@@ -130,7 +130,7 @@ function statusChange() {
}
changeTitle(typevalue);
$('messagediv').innerHTML = '';
if (typevalue == 'communities') {
if (typevalue == 'groups') {
$('user').options.length = 0;
$('user').disabled = true;
}
......
......@@ -28,22 +28,22 @@ define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('community.php');
require_once('group.php');
json_headers();
$leave = param_integer('leave');
if (!$community = get_record('community', 'id', $leave)) {
json_reply(true, get_string('invalidcommunity'));
if (!$group = get_record('group', 'id', $leave)) {
json_reply(true, get_string('invalidgroup'));
}
if (!community_user_can_leave($community)) {
json_reply(true, get_string('couldnotleavecommunity'));
if (!group_user_can_leave($group)) {
json_reply(true, get_string('couldnotleavegroup'));
}
community_remove_user($community->id, $USER->get('id'));
group_remove_user($group->id, $USER->get('id'));
json_reply(false, get_string('leftcommunity'));
json_reply(false, get_string('leftgroup'));
?>
......@@ -26,10 +26,10 @@
define('INTERNAL', 1);
define('MENUITEM', 'mycontacts');
define('SUBMENUITEM', 'myownedcommunities');
define('SUBMENUITEM', 'myownedgroups');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('createcommunity'));
define('TITLE', get_string('creategroup'));
$prefix = get_config('dbprefix');
......@@ -42,20 +42,20 @@ if ($USER->get('admin') || $USER->get('staff')) {
$joinoptions['controlled'] = get_string('membershiptype.controlled');
}
$createcommunity = pieform(array(
'name' => 'createcommunity',
$creategroup = pieform(array(
'name' => 'creategroup',
'method' => 'post',
'plugintype' => 'core',
'pluginname' => 'communities',
'pluginname' => 'groups',
'elements' => array(
'name' => array(
'type' => 'text',
'title' => get_string('communityname'),
'title' => get_string('groups'),
'rules' => array( 'required' => true, 'maxlength' => 128 ),
),
'description' => array(
'type' => 'wysiwyg',
'title' => get_string('communitydescription'),
'title' => get_string('groupdescription'),
'rows' => 10,
'cols' => 80,
),
......@@ -68,27 +68,27 @@ $createcommunity = pieform(array(
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('savecommunity'), get_string('cancel')),
'value' => array(get_string('savegroup'), get_string('cancel')),
),
),
));
function createcommunity_validate(Pieform $form, $values) {
function creategroup_validate(Pieform $form, $values) {
global $USER;
global $SESSION;
$cid = get_field('community', 'id', 'owner', $USER->get('id'), 'name', $values['name']);
$cid = get_field('group', 'id', 'owner', $USER->get('id'), 'name', $values['name']);
if ($cid) {
$form->set_error('name', get_string('communityalreadyexists'));
$form->set_error('name', get_string('groupalreadyexists'));
}
}
function createcommunity_cancel_submit() {
redirect('/contacts/communities/owned.php');
function creategroup_cancel_submit() {
redirect('/contacts/groups/owned.php');
}
function createcommunity_submit(Pieform $form, $values) {
function creategroup_submit(Pieform $form, $values) {
global $USER;
global $SESSION;
......@@ -97,7 +97,7 @@ function createcommunity_submit(Pieform $form, $values) {
$now = db_format_timestamp(time());
$id = insert_record(
'community',
'group',
(object) array(
'name' => $values['name'],
'description' => $values['description'],
......@@ -112,29 +112,29 @@ function createcommunity_submit(Pieform $form, $values) {
// If the user is a staff member, they should be added as a tutor automatically
if ($values['membershiptype'] == 'controlled' && $USER->get('staff')) {
log_debug('Adding staff user to community');
log_debug('Adding staff user to group');
insert_record(
'community_member',
'group_member',
(object) array(
'community' => $id,
'member' => $USER->get('id'),
'ctime' => $now,
'tutor' => 1
'group' => $id,
'member' => $USER->get('id'),
'ctime' => $now,
'tutor' => 1
)
);
}
$SESSION->add_ok_msg(get_string('communitysaved'));
$SESSION->add_ok_msg(get_string('groupsaved'));
db_commit();
redirect('/contacts/communities/owned.php');
redirect('/contacts/groups/owned.php');
}
$smarty = smarty();
$smarty->assign('createcommunity', $createcommunity);
$smarty->assign('creategroup', $creategroup);
$smarty->display('contacts/communities/create.tpl');
$smarty->display('contacts/groups/create.tpl');
?>
......@@ -26,19 +26,19 @@
define('INTERNAL', 1);
define('MENUITEM', 'mycontacts');
define('SUBMENUITEM', 'myownedcommunities');
define('SUBMENUITEM', 'myownedgroups');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('editcommunity'));
define('TITLE', get_string('editgroup'));
$id = param_integer('id');
$prefix = get_config('dbprefix');
$community_data = get_record('community', 'id', $id, 'owner', $USER->get('id'));
$group_data = get_record('group', 'id', $id, 'owner', $USER->get('id'));
if (!$community_data) {
if (!$group_data) {
$SESSION->add_error_msg(get_string('canteditdontown'));
redirect('/contacts/communities/owned.php');
redirect('/contacts/groups/owned.php');
}
$joinoptions = array(
......@@ -50,30 +50,30 @@ if ($USER->get('admin') || $USER->get('staff')) {
$joinoptions['controlled'] = get_string('membershiptype.controlled');
}
$editcommunity = pieform(array(
'name' => 'editcommunity',
$editgroup = pieform(array(
'name' => 'editgroup',
'method' => 'post',
'plugintype' => 'core',
'pluginname' => 'communities',
'pluginname' => 'groups',
'elements' => array(
'name' => array(
'type' => 'text',
'title' => get_string('communityname'),
'title' => get_string('groupname'),
'rules' => array( 'required' => true, 'maxlength' => 128 ),
'defaultvalue' => $community_data->name,
'defaultvalue' => $group_data->name,
),
'description' => array(
'type' => 'wysiwyg',
'title' => get_string('communitydescription'),
'title' => get_string('groupdescription'),
'rows' => 10,
'cols' => 70,
'defaultvalue' => $community_data->description,
'defaultvalue' => $group_data->description,
),
'membershiptype' => array(
'type' => 'select',
'title' => get_string('membershiptype'),
'options' => $joinoptions,
'defaultvalue' => $community_data->jointype,
'defaultvalue' => $group_data->jointype,
'help' => true,
),
'id' => array(
......@@ -82,27 +82,27 @@ $editcommunity = pieform(array(
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('savecommunity'), get_string('cancel')),
'value' => array(get_string('savegroup'), get_string('cancel')),
),
),
));
function editcommunity_validate(Pieform $form, $values) {
function editgroup_validate(Pieform $form, $values) {
global $USER;
global $SESSION;
$cid = get_field('community', 'id', 'owner', $USER->get('id'), 'name', $values['name']);
$cid = get_field('group', 'id', 'owner', $USER->get('id'), 'name', $values['name']);
if ($cid && $cid != $values['id']) {
$form->set_error('name', get_string('communityalreadyexists'));
$form->set_error('name', get_string('groupalreadyexists'));
}
}
function editcommunity_cancel_submit() {
redirect('/contacts/communities/owned.php');
function editgroup_cancel_submit() {
redirect('/contacts/groups/owned.php');
}
function editcommunity_submit(Pieform $form, $values) {
function editgroup_submit(Pieform $form, $values) {
global $USER;
global $SESSION;
......@@ -111,7 +111,7 @@ function editcommunity_submit(Pieform $form, $values) {
$now = db_format_timestamp(time());
update_record(
'community',
'group',
(object) array(
'id' => $values['id'],
'name' => $values['name'],
......@@ -122,17 +122,17 @@ function editcommunity_submit(Pieform $form, $values) {
'id'
);
$SESSION->add_ok_msg(get_string('communitysaved'));
$SESSION->add_ok_msg(get_string('groupsaved'));
db_commit();
redirect('/contacts/communities/owned.php');
redirect('/contacts/groups/owned.php');
}
$smarty = smarty();
$smarty->assign('editcommunity', $editcommunity);
$smarty->assign('editgroup', $editgroup);
$smarty->display('contacts/communities/edit.tpl');
$smarty->display('contacts/groups/edit.tpl');
?>
......@@ -28,7 +28,7 @@ define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('community.php');
require_once('group.php');
json_headers();
......@@ -39,23 +39,23 @@ $offset = param_integer('offset', 0);
$prefix = get_config('dbprefix');
$userid = $USER->get('id');
if (empty($owned)) { // just get communities this user is a member of.
$data = get_member_communities($userid, $offset, $limit);
$count = get_record_sql('SELECT COUNT(distinct c.id) AS count
FROM ' . $prefix . 'community c
JOIN ' . $prefix . 'community_member cm ON cm.community = c.id
WHERE c.owner != ? AND cm.member = ?', array($userid, $userid));
if (empty($owned)) { // just get groups this user is a member of.
$data = get_member_groups($userid, $offset, $limit);
$count = get_record_sql('SELECT COUNT(distinct g.id) AS count
FROM ' . $prefix . 'group g
JOIN ' . $prefix . 'group_member gm ON gm.group = g.id
WHERE g.owner != ? AND gm.member = ?', array($userid, $userid));
$count = $count->count;
}
else {
$count = count_records_sql('SELECT COUNT(*) FROM ' . $prefix . 'community c WHERE c.owner = ?',
$count = count_records_sql('SELECT COUNT(*) FROM ' . $prefix . 'group g WHERE g.owner = ?',
array($userid));
$datasql = 'SELECT c.id,c.jointype,c.name,c.owner,count(distinct cmr.community) as requestcount, COUNT(distinct v.view) AS hasviews
FROM ' . $prefix . 'community c
LEFT JOIN ' . $prefix . 'community_member_request cmr ON cmr.community = c.id
LEFT JOIN ' . $prefix . 'view_access_community v ON v.community = c.id
$datasql = 'SELECT g.id,g.jointype,g.name,g.owner,count(distinct gmr.group) as requestcount, COUNT(distinct v.view) AS hasviews
FROM ' . $prefix . 'group g
LEFT JOIN ' . $prefix . 'group_member_request gmr ON gmr.group = g.id
LEFT JOIN ' . $prefix . 'view_access_group v ON v.group = c.id
WHERE c.owner = ?
GROUP BY c.id,c.jointype,c.name,c.owner';
......
......@@ -26,22 +26,22 @@
define('INTERNAL', 1);
define('MENUITEM', 'mycontacts');
define('SUBMENUITEM', 'mycommunities');
define('SUBMENUITEM', 'mygroups');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'contacts');
define('SECTION_PAGE', 'communities');
define('SECTION_PAGE', 'groups');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('mycommunities'));
define('TITLE', get_string('mygroups'));
$viewurl = get_config('wwwroot') . 'contacts/communities/view.php?id=';
$leftsuccess = get_string('leftcommunity');
$leftfailed = get_string('leftcommunityfailed');
$viewurl = get_config('wwwroot') . 'contacts/groups/view.php?id=';
$leftsuccess = get_string('leftgroup');
$leftfailed = get_string('leftgroupfailed');
$javascript = <<<EOF
var communitylist = new TableRenderer(
'communitylist',
'getcommunities.json.php',
var grouplist = new TableRenderer(
'grouplist',
'getgroups.json.php',
[
function (r) {
return TD(null, A({'href': '{$viewurl}' + r.id}, r.name));
......@@ -50,18 +50,18 @@ var communitylist = new TableRenderer(
if (r.jointype == 'controlled') {
return TD(null);
}
return TD(null, A({'href': '', 'onclick': 'leaveCommunity(' + r.id + '); return false;'}, '[X]'));
return TD(null, A({'href': '', 'onclick': 'leaveGroup(' + r.id + '); return false;'}, '[X]'));
}
]
);
communitylist.updateOnLoad();
grouplist.updateOnLoad();
function leaveCommunity(id) {
function leaveGroup(id) {
var pd = {'leave': id}
sendjsonrequest('communityleave.json.php', pd, 'GET', function (data) {
sendjsonrequest('groupleave.json.php', pd, 'GET', function (data) {
if (!data.error) {
communitylist.doupdate();
grouplist.doupdate();
}
}, function () {
watchlist.doupdate();
......@@ -71,6 +71,6 @@ function leaveCommunity(id) {
EOF;
$smarty = smarty(array('tablerenderer'));
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->display('contacts/communities/index.tpl');
$smarty->display('contacts/groups/index.tpl');
?>
......@@ -37,20 +37,20 @@ $dbprefix = get_config('dbprefix');
if ($action == 'delete') {
$id = param_integer('id');
// check owner
$owner = get_field('community', 'owner', 'id', $id);
$owner = get_field('group', 'owner', 'id', $id);
if ($owner != $USER->get('id')) {
json_reply('local', get_string('cantdeletecommunitydontown'));
json_reply('local', get_string('cantdeletegroupdontown'));
}
db_begin();
delete_records('usr_watchlist_community', 'community', $id);
delete_records('view_access_community', 'community', $id);
delete_records('community_member_invite', 'community', $id);
delete_records('community_member_request', 'community', $id);
delete_records('community_member', 'community', $id);
delete_records('community', 'id', $id);
delete_records('usr_watchlist_group', 'group', $id);
delete_records('view_access_group', 'group', $id);
delete_records('group_member_invite', 'group', $id);
delete_records('group_member_request', 'group', $id);
delete_records('group_member', 'group', $id);
delete_records('group', 'id', $id);
db_commit();
json_reply(null, get_string('deletecommunitysuccessful'));
json_reply(null, get_string('deletegroupsuccessful'));
}
json_reply('local', 'Unknown action');
......
......@@ -26,26 +26,26 @@
define('INTERNAL', 1);
define('MENUITEM', 'mycontacts');
define('SUBMENUITEM', 'myownedcommunities');
define('SUBMENUITEM', 'myownedgroups');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'contacts');
define('SECTION_PAGE', 'ownedcommunities');
define('SECTION_PAGE', 'ownedgroups');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('myownedcommunities'));
define('TITLE', get_string('myownedgroups'));
$viewurl = get_config('wwwroot') . 'contacts/communities/view.php?id=';
$editurl = get_config('wwwroot') . 'contacts/communities/edit.php?id=';
$viewurl = get_config('wwwroot') . 'contacts/groups/view.php?id=';
$editurl = get_config('wwwroot') . 'contacts/groups/edit.php?id=';
$editstr = json_encode(get_string('edit'));
$edithelp = get_help_icon('core', 'communities', null, null, null, 'communityeditlink');
$edithelp = get_help_icon('core', 'groups', null, null, null, 'groupeditlink');
$deletestr = json_encode(get_string('delete'));
$confirmdelete_hasviews = json_encode(get_string('communityconfirmdeletehasviews'));
$confirmdelete = json_encode(get_string('communityconfirmdelete'));
$confirmdelete_hasviews = json_encode(get_string('groupconfirmdeletehasviews'));
$confirmdelete = json_encode(get_string('groupconfirmdelete'));
$javascript = <<<EOF
var communitylist = new TableRenderer(
'communitylist',
'getcommunities.json.php',
var grouplist = new TableRenderer(
'grouplist',
'getgroups.json.php',
[
function (r) {
return TD(null, A({'href': '{$viewurl}' + r.id}, r.name));
......@@ -87,7 +87,7 @@ var communitylist = new TableRenderer(
},
'POST',
function (data) {
communitylist.doupdate();
grouplist.doupdate();
}
);
});
......@@ -97,15 +97,15 @@ var communitylist = new TableRenderer(
]
);
communitylist.updateOnLoad();
communitylist.owned = 1;
communitylist.statevars.push('owned');
grouplist.updateOnLoad();
grouplist.owned = 1;
grouplist.statevars.push('owned');
EOF;
$smarty = smarty(array('tablerenderer'));
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->display('contacts/communities/owned.tpl');
$smarty->display('contacts/groups/owned.tpl');
?>
......@@ -28,7 +28,7 @@ define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('community.php');
require_once('group.php');
json_headers();
......@@ -43,10 +43,10 @@ $offset = param_integer('offset', 0);
$count = 0;
$data = array();
if (!$membership = user_can_access_community($id)) {
community_json_empty();
if (!$membership = user_can_access_group($id)) {
group_json_empty();
}
$community = get_record('community', 'id', $id);
$group = get_record('group', 'id', $id);
$prefix = get_config('dbprefix');
$dbnow = db_format_timestamp(time());
......@@ -57,7 +57,7 @@ switch ($type) {
$values = array($id);
if (!$submitted) {
$where .= ' OR (
a.community = ?
a.group = ?
AND ( v.startdate IS NULL OR v.startdate < ? )
AND ( v.stopdate IS NULL OR v.stopdate > ? )
AND ( a.startdate IS NULL OR a.startdate < ? )
......@@ -73,7 +73,7 @@ switch ($type) {
$count = count_records_sql('
SELECT COUNT(DISTINCT id)
FROM ' . $prefix . 'view v
LEFT OUTER JOIN ' . $prefix . 'view_access_community a ON a.view=v.id
LEFT OUTER JOIN ' . $prefix . 'view_access_group a ON a.view=v.id
' . $where,
$values
);
......@@ -81,7 +81,7 @@ switch ($type) {
$data = get_records_sql_array('
SELECT DISTINCT v.*, u.username, u.firstname, u.lastname, u.preferredname, u.id AS usr
FROM ' . $prefix . 'view v
LEFT OUTER JOIN ' . $prefix . 'view_access_community a ON a.view=v.id
LEFT OUTER JOIN ' . $prefix . 'view_access_group a ON a.view=v.id
INNER JOIN ' . $prefix.'usr u ON v.owner = u.id ' . $where,
$values,
$offset,
......@@ -97,21 +97,21 @@ switch ($type) {