Commit 5eef6992 authored by Darrin Hodges and Nathan Mares and Jiri Baum's avatar Darrin Hodges and Nathan Mares and Jiri Baum Committed by Hugh Davenport
Browse files

Date limits for groups (bug #1017354) - view/edit



Add date limits (from-until) to groups; members will only be able to make
changes in the group during the specified time period.

This commit adds support for viewing and editing the date limits.

Change-Id: Ic37124dbb36c104e9771ae7859393076480214be
Signed-off-by: default avatarJiri Baum <jiri@catalyst-au.net>
parent dca581ab
......@@ -64,6 +64,7 @@ class PluginBlocktypeGroupInfo extends SystemBlocktype {
$dwoo = smarty_core();
$dwoo->assign('group', $data);
$dwoo->assign('editwindow', group_format_editwindow($data));
return $dwoo->fetch('blocktype:groupinfo:groupinfo.tpl');
}
......
......@@ -47,6 +47,10 @@ if ($id = param_integer('id', null)) {
}
$group_data = $group_data[0];
// Fix dates to unix timestamps instead of formatted timestamps.
$group_data->editwindowstart = isset($group_data->editwindowstart) ? strtotime($group_data->editwindowstart) : null;
$group_data->editwindowend = isset($group_data->editwindowend) ? strtotime($group_data->editwindowend) : null;
}
else {
define('TITLE', get_string('creategroup', 'group'));
......@@ -75,6 +79,8 @@ else {
'invitefriends' => 0,
'suggestfriends' => 0,
'urlid' => null,
'editwindowstart' => null,
'editwindowend' => null
);
}
......@@ -313,6 +319,34 @@ $elements['groupparticipationreports'] = array(
'defaultvalue' => $group_data->groupparticipationreports,
);
$elements['editability'] = array(
'type' => 'html',
'title' => get_string('editability', 'group'),
'value' => '',
);
$currentdate = getdate();
$elements['editwindowstart'] = array (
'type' => 'date',
'title' => get_string('windowstart', 'group'),
'defaultvalue' => $group_data->editwindowstart,
'description' => "Group cannot be edited by members before this date",
'minyear' => $currentdate['year'],
'maxyear' => $currentdate['year'] + 20,
'time' => true
);
$elements['editwindowend'] = array (
'type' => 'date',
'title' => get_string('windowend', 'group'),
'defaultvalue' => $group_data->editwindowend,
'description' => "Group cannot be edited by members after this date",
'minyear' => $currentdate['year'],
'maxyear' => $currentdate['year'] + 20,
'time' => true
);
$elements['general'] = array(
'type' => 'html',
'title' => get_string('general'),
......@@ -398,6 +432,9 @@ function editgroup_validate(Pieform $form, $values) {
if (!empty($values['suggestfriends']) && empty($values['open']) && empty($values['request'])) {
$form->set_error('suggestfriends', get_string('suggestfriendsrequesterror', 'group'));
}
if (!empty($values['editwindowstart']) && !empty($values['editwindowend']) && ($values['editwindowstart'] >= $values['editwindowend'])) {
$form->set_error('editwindowend', get_string('editwindowendbeforestart', 'group'));
}
}
function editgroup_cancel_submit() {
......@@ -429,6 +466,8 @@ function editgroup_submit(Pieform $form, $values) {
'groupparticipationreports' => intval($values['groupparticipationreports']),
'invitefriends' => intval($values['invitefriends']),
'suggestfriends' => intval($values['suggestfriends']),
'editwindowstart' => db_format_timestamp($values['editwindowstart']),
'editwindowend' => db_format_timestamp($values['editwindowend'])
);
if (get_config('cleanurls') && isset($values['urlid'])) {
......
......@@ -94,10 +94,12 @@ if ($groups['data']) {
}
$groups['data'] = get_records_sql_array("
SELECT g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.request, g1.grouptype, g1.submittableto,
g1.hidemembers, g1.hidemembersfrommembers, g1.urlid, g1.role, g1.membershiptype, g1.membercount, COUNT(gmr.member) AS requests
g1.hidemembers, g1.hidemembersfrommembers, g1.urlid, g1.role, g1.membershiptype, g1.membercount, COUNT(gmr.member) AS requests,
g1.editwindowstart, g1.editwindowend
FROM (
SELECT g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto,
g.hidemembers, g.hidemembersfrommembers, g.urlid, t.role, t.membershiptype, COUNT(gm.member) AS membercount
g.hidemembers, g.hidemembersfrommembers, g.urlid, t.role, t.membershiptype, COUNT(gm.member) AS membercount,
g.editwindowstart, g.editwindowend
FROM {group} g
LEFT JOIN {group_member} gm ON (gm.group = g.id)
LEFT JOIN (
......@@ -119,11 +121,11 @@ if ($groups['data']) {
) t ON t.id = g.id
WHERE g.id IN (" . implode($groupids, ',') . ')
GROUP BY g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto,
g.hidemembers, g.hidemembersfrommembers, g.urlid, t.role, t.membershiptype
g.hidemembers, g.hidemembersfrommembers, g.urlid, t.role, t.membershiptype, g.editwindowstart, g.editwindowend
) 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.request, g1.grouptype, g1.submittableto,
g1.hidemembers, g1.hidemembersfrommembers, g1.urlid, g1.role, g1.membershiptype, g1.membercount
g1.hidemembers, g1.hidemembersfrommembers, g1.urlid, g1.role, g1.membershiptype, g1.membercount, g1.editwindowstart, g1.editwindowend
ORDER BY g1.name',
array($USER->get('id'), $USER->get('id'), $USER->get('id'), $USER->get('id'))
);
......
......@@ -78,6 +78,8 @@ if ($USER->is_logged_in()) {
}
}
$editwindow = group_format_editwindow($group);
$view = group_get_homepage_view($group->id);
$viewcontent = $view->build_columns();
......@@ -102,6 +104,7 @@ $smarty->assign('INLINEJAVASCRIPT', $inlinejs);
$smarty->assign('viewid', $view->get('id'));
$smarty->assign('viewcontent', $viewcontent);
$smarty->assign('group', $group);
$smarty->assign('editwindow', $editwindow);
$smarty->assign('returnto', 'view');
$smarty->assign('SUBPAGETOP', 'group/groupuserstatus.tpl');
$smarty->display('group/view.tpl');
......@@ -76,6 +76,13 @@ $string['groupalreadyexists'] = 'A group by this name already exists.';
$string['invalidshortname'] = 'Invalid group short name';
$string['shortnameformat'] = 'Group short names can be from 2 to 255 characters in length and contain only alphanumeric characters, ".", "-", and "_"';
$string['Created'] = 'Created';
$string['Available'] = 'Available';
$string['editability'] = 'Editability';
$string['windowstart'] = 'Start date';
$string['windowend'] = 'End date';
$string['editwindowbetween'] = 'Between';
$string['editwindowfrom'] = 'From';
$string['editwindowuntil'] = 'Until';
$string['groupadmins'] = 'Group admininistrators';
$string['editroles'] = 'Create and edit pages';
$string['editrolesdescription'] = 'Roles with permission to create and edit group pages.';
......@@ -117,6 +124,7 @@ $string['suggestgroupnotificationmessage'] = '%s suggested that you join the gro
$string['recommendationssent'] = '%d recommendation(s) sent';
$string['suggestinvitefriends'] = 'You cannot enable both friend invitations and recommendations.';
$string['suggestfriendsrequesterror'] = 'You can only enable friend recommendations on open or request groups.';
$string['editwindowendbeforestart'] = 'The end date must be after the start date.';
$string['editgroupmembership'] = 'Edit group membership';
$string['editmembershipforuser'] = 'Edit membership for %s';
......
......@@ -415,6 +415,8 @@ function group_create($data) {
'groupparticipationreports' => $data['groupparticipationreports'],
'invitefriends' => $data['invitefriends'],
'suggestfriends' => $data['suggestfriends'],
'editwindowstart' => $data['editwindowstart'],
'editwindowend' => $data['editwindowend']
),
'id',
true
......@@ -1443,10 +1445,37 @@ function group_prepare_usergroups_for_display($groups, $returnto='mygroups') {
unset($group->membercount);
}
$group->editwindow = group_format_editwindow($group);
$group->settingsdescription = group_display_settings($group);
}
}
/*
* Formats the edit window of a group into human readable format.
*/
function group_format_editwindow($group) {
$dateformat = 'strftimedatetimeshort';
$editwindowstart = isset($group->editwindowstart) ? strtotime($group->editwindowstart) : null;
$editwindowend = isset($group->editwindowend) ? strtotime($group->editwindowend) : null;
if (empty($editwindowstart) && empty($editwindowend)) {
$formatted = "";
}
else if (!empty($editwindowstart) && empty($editwindowend)) {
$formatted = get_string('editwindowfrom', 'group') . ' ' . format_date($editwindowstart, $dateformat);
}
else if (empty($editwindowstart) && !empty($editwindowend)) {
$formatted = get_string('editwindowuntil', 'group') . ' ' . format_date($editwindowend, $dateformat);
}
else {
$formatted = get_string('editwindowbetween', 'group') . ' ' . format_date($editwindowstart, $dateformat) . " and " . format_date($editwindowend, $dateformat);
}
return $formatted;
}
/*
* Used by admin/groups/groups.php and admin/groups/groups.json.php for listing groups.
*/
......
......@@ -5,3 +5,6 @@
{if $group->membercount}
<div class="s"><a href="{$WWWROOT}group/members.php?id={$group->id}">{$group->membercount} {if $group->membercount > 1}{str tag=members section=group}{else}{str tag=member section=group}{/if}</a></div>
{/if}
{if $group->editwindow}
<div>{str tag=Available section=group}: {$group->editwindow}</div>
{/if}
......@@ -6,6 +6,7 @@
{/foreach}</li>
{if $group->categorytitle}<li><label>{str tag=groupcategory section=group}:</label> {$group->categorytitle}</li>{/if}
<li><label class="groupinfolabel">{str tag=Created section=group}:</label> {$group->ctime}</li>
{if $editwindow}<li><label class="groupinfolabel">{str tag=Available section=group}:</label> {$editwindow}</li>{/if}
<li class="last">
{if $group->membercount}<span><label>{str tag=Members section=group}:</label>&nbsp;{$group->membercount}</span>{/if}
<span><label>{str tag=Views section=view}:</label>&nbsp;{$group->viewcount}</span>
......
Supports Markdown
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