Commit a2c09d63 authored by Matthew Kolb's avatar Matthew Kolb Committed by Robert Lyon

Send forum posts now. Addresses bug #817373 and #817372.

This patch has been altered to have the configuration option
set in:
Groups -> Edit -> General :  Send forum posts immediately

To allow for per group access to functionality
Only users who fall into the following categories can check
the 'send now' for all members.
$USER->get('admin')
$USER->get('staff')
$USER->is_institutional_admin()
$USER->is_institutional_staff();

Change-Id: I5f1c4d13e89e587577abac438dd1cdc4625aa604
Signed-off-by: default avatarMatthew Kolb <matt.kolb@yahoo.com>
Signed-off-by: default avatarMatt Kolb <matt.kolb@deltak-innovation.com>
Signed-off-by: default avatarMatt Kolb <matt.kolb@yahoo.com>
parent f07a056a
......@@ -64,7 +64,8 @@ else {
'suggestfriends' => 0,
'urlid' => null,
'editwindowstart' => null,
'editwindowend' => null
'editwindowend' => null,
'sendnow' => 0
);
}
......@@ -369,7 +370,20 @@ $elements['viewnotify'] = array(
'description' => get_string('viewnotifydescription', 'group'),
'defaultvalue' => $group_data->viewnotify
);
if ($cancreatecontrolled) {
$elements['sendnow'] = array(
'type' => 'checkbox',
'title' => get_string('allowsendnow', 'group'),
'description' => get_string('allowsendnowdescription', 'group'),
'defaultvalue' => $group_data->sendnow
);
}
else {
$form['elements']['sendnow'] = array(
'type' => 'hidden',
'value' => $group_data->sendnow,
);
}
$form['elements']['settings']['elements'] = $elements;
$editgroup = pieform($form);
......@@ -451,7 +465,8 @@ function editgroup_submit(Pieform $form, $values) {
'invitefriends' => intval($values['invitefriends']),
'suggestfriends' => intval($values['suggestfriends']),
'editwindowstart' => db_format_timestamp($values['editwindowstart']),
'editwindowend' => db_format_timestamp($values['editwindowend'])
'editwindowend' => db_format_timestamp($values['editwindowend']),
'sendnow' => intval($values['sendnow'])
);
if (
......
......@@ -72,6 +72,7 @@ define('GROUP', $parent->group);
$membership = user_can_access_forum((int)$parent->forum);
$moderator = (bool)($membership & INTERACTION_FORUM_MOD);
$admintutor = (bool) group_get_user_admintutor_groups();
if (!isset($postid)) { // post reply
if ($parent->deleted) {
......@@ -114,7 +115,7 @@ else { // edit post
$parent->ctime = relative_date(get_string('strftimerecentfullrelative', 'interaction.forum'), get_string('strftimerecentfull'), $parent->ctime);
$editform = pieform(array(
$editform = array(
'name' => 'editpost',
'successcallback' => isset($post) ? 'editpost_submit' : 'addpost_submit',
'autofocus' => 'body',
......@@ -140,6 +141,12 @@ $editform = pieform(array(
'maxlength' => 65536,
),
),
'sendnow' => array(
'type' => 'checkbox',
'title' => get_string('sendnow', 'interaction.forum'),
'description' => get_string('sendnowdescription', 'interaction.forum', get_config_plugin('interaction', 'forum', 'postdelay')),
'defaultvalue' => false,
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(
......@@ -157,7 +164,13 @@ $editform = pieform(array(
'value' => isset($post) ? $post->editrecord : false
)
),
));
);
if ((!$moderator && !$admintutor && !group_sendnow($parent->group)) || get_config_plugin('interaction', 'forum', 'postdelay') <= 0) {
unset($editform['elements']['sendnow']);
}
$editform = pieform($editform);
function editpost_validate(Pieform $form, $values) {
if ($baddomain = get_first_blacklisted_domain($values['body'])) {
......@@ -203,6 +216,7 @@ function addpost_submit(Pieform $form, $values) {
'body' => $values['body'],
'ctime' => db_format_timestamp(time())
);
$sendnow = isset($values['sendnow']) && $values['sendnow'] ? 1 : 0;
// See if the same content has been submitted in the last 5 seconds. If so, don't add this post.
$oldpost = get_record_select('interaction_forum_post', 'topic = ? AND poster = ? AND parent = ? AND subject = ? AND body = ? AND ctime > ?',
array($post->topic, $post->poster, $post->parent, $post->subject, $post->body, db_format_timestamp(time() - 5)),
......@@ -220,8 +234,12 @@ function addpost_submit(Pieform $form, $values) {
if (!empty($newbody) && $newbody != $post->body) {
set_field('interaction_forum_post', 'body', $newbody, 'id', $postid);
}
$delay = get_config_plugin('interaction', 'forum', 'postdelay');
if ($sendnow == 0) {
$delay = get_config_plugin('interaction', 'forum', 'postdelay');
}
else {
$delay = 0;
}
if (!is_null($delay) && $delay == 0) {
PluginInteractionForum::interaction_forum_new_post(array($postid));
}
......
......@@ -65,6 +65,7 @@ $forumconfig = get_records_assoc('interaction_forum_instance_config', 'forum', $
define('GROUP', $forum->groupid);
$membership = user_can_access_forum((int)$forumid);
$moderator = (bool)($membership & INTERACTION_FORUM_MOD);
$admintutor = (bool) group_get_user_admintutor_groups();
if (!$membership || ($forumconfig['createtopicusers']->value == 'moderators' && !$moderator)) {
throw new AccessDeniedException(get_string('cantaddtopic', 'interaction.forum'));
......@@ -135,6 +136,12 @@ $editform = array(
'description' => get_string('closeddescription', 'interaction.forum'),
'defaultvalue' => isset($topic) ? $topic->closed : !empty($forumconfig['closetopics']->value),
),
'sendnow' => array(
'type' => 'checkbox',
'title' => get_string('sendnow', 'interaction.forum'),
'description' => get_string('sendnowdescription', 'interaction.forum', get_config_plugin('interaction', 'forum', 'postdelay')),
'defaultvalue' => false,
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(
......@@ -154,7 +161,10 @@ $editform = array(
),
);
if(!$moderator){
if (!$moderator) {
if (!group_sendnow($forum->groupid) && !$admintutor) {
unset($editform['elements']['sendnow']);
}
unset($editform['elements']['sticky']);
unset($editform['elements']['closed']);
}
......@@ -185,6 +195,7 @@ function addtopic_submit(Pieform $form, $values) {
'closed' => isset($values['closed']) && $values['closed'] ? 1 : 0
), 'id', true
);
$sendnow = isset($values['sendnow']) && $values['sendnow'] ? 1 : 0;
$post = (object)array(
'topic' => $topicid,
'poster' => $USER->get('id'),
......@@ -208,7 +219,12 @@ function addtopic_submit(Pieform $form, $values) {
));
}
db_commit();
$delay = get_config_plugin('interaction', 'forum', 'postdelay');
if ($sendnow == 0) {
$delay = get_config_plugin('interaction', 'forum', 'postdelay');
}
else {
$delay = 0;
}
if (!is_null($delay) && $delay == 0) {
PluginInteractionForum::interaction_forum_new_post(array($postid));
}
......
......@@ -120,6 +120,8 @@ $string['Reply'] = 'Reply';
$string['replyforumpostnotificationsubjectline'] = 'Re: %s';
$string['Re:'] = 'Re: ';
$string['replyto'] = 'Reply to: ';
$string['sendnow'] = 'Send message now';
$string['sendnowdescription'] = 'Send message immediately instead of waiting at least %s minutes for it to send.';
$string['Sticky'] = 'Sticky';
$string['stickydescription'] = 'Sticky topics are at the top of every page';
$string['stickytopics'] = 'Sticky topics';
......
......@@ -92,6 +92,8 @@ $string['groupinvitesfrom'] = 'Invited to join:';
$string['requestedmembershipin'] = 'Requested membership in:';
$string['viewnotify'] = 'Shared page notifications';
$string['viewnotifydescription'] = 'If checked, a notification will be sent to every group member whenever a member shares one of their pages with the group or a new group page is created. Enabling this setting in very large groups can produce a lot of notifications.';
$string['allowsendnow'] = 'Send forum posts immediately';
$string['allowsendnowdescription'] = 'If checked, any group member will be able to choose to send forum posts immediately. If unchecked, only group administrators, tutors and moderators can do so';
$string['hiddengroup'] = 'Hide group';
$string['hiddengroupdescription'] = 'Do not list this group on the "Find groups" page.';
$string['hidemembers'] = 'Hide membership';
......
......@@ -393,6 +393,7 @@
<FIELD NAME="urlid" TYPE="char" LENGTH="30" NOTNULL="false" />
<FIELD NAME="editwindowstart" TYPE="datetime" NOTNULL="false" />
<FIELD NAME="editwindowend" TYPE="datetime" NOTNULL="false" />
<FIELD NAME="sendnow" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
......
......@@ -3174,5 +3174,12 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2014032400) {
$table = new XMLDBTable('group');
$field = new XMLDBField('sendnow');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
}
return $status;
}
......@@ -434,7 +434,8 @@ function group_create($data) {
'invitefriends' => $data['invitefriends'],
'suggestfriends' => $data['suggestfriends'],
'editwindowstart' => $data['editwindowstart'],
'editwindowend' => $data['editwindowend']
'editwindowend' => $data['editwindowend'],
'sendnow' => $data['sendnow'],
),
'id',
true
......@@ -2325,3 +2326,17 @@ function group_homepage_url($group, $full=true, $useid=false) {
}
return $url;
}
/**
* Returns whether 'send now' is set for all memebers or not
* If not set only admins/tutors/moderators can use 'send now'
*
* @param string $groupid the id of the group
* @return boolean
*/
function group_sendnow($groupid) {
if (!$sendnow = get_field('group', 'sendnow', 'id', $groupid)) {
return false;
}
return !empty($sendnow);
}
......@@ -15,7 +15,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/index.php/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2014022700;
$config->version = 2014032400;
$config->release = '1.9.0dev';
$config->minupgradefrom = 2009022600;
$config->minupgraderelease = '1.1.0 (release tag 1.1.0_RELEASE)';
......
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