Commit 3383d816 authored by Aaron Wells's avatar Aaron Wells
Browse files

Notifications for new wall posts (Bug 547333)

Change-Id: Ib0de08d1ed51baa1f5e58ec1b805eacf034bb541
parent dc96746e
......@@ -38,3 +38,8 @@ $string['postsizelimitdescription'] = "You can limit the size of wall posts here
$string['postsizelimitmaxcharacters'] = "Maximum number of characters";
$string['postsizelimitinvalid'] = "This is not a valid number.";
$string['postsizelimittoosmall'] = "The limit cannot be lower than zero.";
// Notification strings
$string['newwallpostnotificationsubject'] = "New post on your wall";
$string['newwallpostnotificationmessage'] = "%s";
$string['typewallpost'] = 'Wall post';
......@@ -10,6 +10,7 @@
*/
defined('INTERNAL') || die();
require_once('activity.php');
class PluginBlocktypeWall extends MaharaCoreBlocktype {
......@@ -111,6 +112,22 @@ class PluginBlocktypeWall extends MaharaCoreBlocktype {
if ($prevversion == 0) {
set_config_plugin('blocktype', 'wall', 'defaultpostsizelimit', 1500); // 1500 characters
}
if ($prevversion < 2016011400) {
$status = ensure_record_exists(
'activity_type',
(object)array('name' => 'wallpost'),
(object)array(
'name' => 'wallpost',
'admin' => 0,
'delay' => 0,
'allowonemethod' => 1,
'defaultmethod' => 'email',
'plugintype' => 'blocktype',
'pluginname' => 'wall'
)
);
}
}
public static function delete_instance(BlockInstance $instance) {
......@@ -219,6 +236,7 @@ EOF;
);
insert_record('blocktype_wall_post', $record);
activity_occurred('wallpost', $record, 'blocktype', 'wall');
$instance = new BlockInstance($values['instance']);
$owner = $instance->get_view()->get('owner');
......@@ -310,3 +328,54 @@ EOF;
return array();
}
}
class ActivityTypeBlocktypeWallWallpost extends ActivityTypePlugin {
protected $from;
protected $text;
protected $instance;
public function get_plugintype() {
return 'blocktype';
}
public function get_pluginname() {
return 'wall';
}
public function get_required_parameters() {
return array('from', 'text', 'instance');
}
public function __construct($data, $cron = false) {
global $CFG;
parent::__construct($data, $cron);
$wallinstance = new BlockInstance($data->instance);
$owner = $wallinstance->get_view()->get('owner');
// Posted on their own wall. Don't send a notification.
if ($owner == $data->from) {
$this->users = array();
return;
}
$this->users = array(get_user($owner));
$this->fromuser = $data->from;
$this->strings = (object) array(
'subject' => (object) array(
'key' => 'newwallpostnotificationsubject',
'section' => 'blocktype.wall'
),
'message' => (object) array(
'key' => 'newwallpostnotificationmessage',
'section' => 'blocktype.wall',
'args' => array(html2text($data->text))
),
'urltext' => (object) array(
'key' => 'wholewall',
'section' => 'blocktype.wall'
)
);
$this->url = 'blocktype/wall/wall.php?id=' . $data->instance;
}
}
......@@ -12,5 +12,5 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2009111201;
$config->release = '1.0.3';
$config->version = 2016011400;
$config->release = '1.1.0';
......@@ -4221,5 +4221,40 @@ function xmldb_core_upgrade($oldversion=0) {
change_field_precision($table, $field);
}
if ($oldversion < 2016012800) {
log_debug('Upgrade wall block and add wall notifications to default inbox block');
if ($data = check_upgrades('blocktype.wall')) {
upgrade_plugin($data);
}
// Find the inbox block from the dashboard template page
$foundit = false;
$dashboardtemplateid = get_field('view', 'id', 'type', 'dashboard', 'owner', 0, 'template', 1);
$defaultinboxblocks = get_records_select_array('block_instance', 'view=? AND blocktype=?', array($dashboardtemplateid, 'inbox'));
$specialinboxtitle = get_string('topicsimfollowing');
if ($defaultinboxblocks) {
safe_require('blocktype', 'inbox');
foreach ($defaultinboxblocks as $blockrec) {
// There are two default inbox blocks. One has just "newpost" notifications, which gives it a special title.
// We want the other one.
$bi = new BlockInstance($blockrec->id, $blockrec);
if ($bi->get_title() == $specialinboxtitle) {
continue;
}
else {
$oldconfigdata = $blockrec->configdata;
$newconfigdata = unserialize($oldconfigdata);
$newconfigdata['wallpost'] = true;
$newconfigdata = serialize($newconfigdata);
log_debug('Updating all user inbox blocks that are still on the default settings');
execute_sql('UPDATE {block_instance} SET configdata=? WHERE blocktype=? AND configdata=?', array($newconfigdata, 'inbox', $oldconfigdata));
$foundit = true;
}
}
}
if (!$foundit) {
log_debug('Couldn\'t find default inbox block, so it won\'t be updated.');
}
}
return $status;
}
......@@ -2654,6 +2654,7 @@ function install_system_dashboard_view() {
'institutionmessage' => true,
'maharamessage' => true,
'usermessage' => true,
'wallpost' => true,
'viewaccess' => true,
'watchlist' => true,
'maxitems' => '5',
......
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2015110600;
$config->version = 2016012800;
$config->series = '16.04';
$config->release = '16.04dev';
$config->minupgradefrom = 2012080604;
......
......@@ -16,6 +16,8 @@
<span class="icon icon-comments text-default left" role="presentation" aria-hidden="true"></span>
{elseif $i->type == 'annotationfeedback'}
<span class="icon icon-comments-o text-default left" role="presentation" aria-hidden="true"></span>
{elseif $i->type == 'wallpost'}
<span class="icon icon-wall text-default left" role="presentation" aria-hidden="true"></span>
{else}
<span class="icon icon-wrench text-default left" role="presentation" aria-hidden="true"></span>
{/if}
......
......@@ -24,6 +24,8 @@
<span class="icon icon-comments type-icon" role="presentation" aria-hidden="true"></span>
{elseif $item->type == 'annotationfeedback'}
<span class="icon icon-comments-o type-icon" role="presentation" aria-hidden="true"></span>
{elseif $item->type == 'wallpost'}
<span class="icon icon-wall type-icon" role="presentation" aria-hidden="true"></span>
{else}
<span class="icon icon-wrench type-icon" role="presentation" aria-hidden="true"></span>
{/if}
......
......@@ -10,6 +10,8 @@
<span class="icon icon-comments type-icon" role="presentation" aria-hidden="true"></span>
{elseif $item->type == 'annotationfeedback'}
<span class="icon icon-comments-o type-icon" role="presentation" aria-hidden="true"></span>
{elseif $item->type == 'wallpost'}
<span class="icon icon-wall type-icon" role="presentation" aria-hidden="true"></span>
{else}
<span class="icon icon-wrench type-icon" role="presentation" aria-hidden="true"></span>
{/if}
......
......@@ -10,6 +10,8 @@
<span class="icon icon-comments type-icon" role="presentation" aria-hidden="true"></span>
{elseif $item->type == 'annotationfeedback'}
<span class="icon icon-comments-o type-icon" role="presentation" aria-hidden="true"></span>
{elseif $i->type == 'wallpost'}
<span class="icon icon-wall type-icon text-default left" role="presentation" aria-hidden="true"></span>
{else}
<span class="icon icon-wrench type-icon" role="presentation" aria-hidden="true"></span>
{/if}
......
@javascript @core @blocktype @blocktype_wall
Feature: The wall block should send out notifications
In order to make it easier for the wall owner to know about new wall posts
So they can respond to those new wall posts
Background:
Given the following "users" exist:
| username | password | email | firstname | lastname | institution | authname | role |
| userA | Kupuhipa1 | test01@example.com | Pete | Mc | mahara | internal | member |
| userB | Kupuhipa1 | test02@example.com | Son | Nguyen | mahara | internal | member |
Scenario: Wall post notifications
The wall post must generate a notification (Bug 547333)
Given I log in as "userB" with password "Kupuhipa1"
And I go to "/user/find.php"
And I follow "Pete Mc"
And I fill in "Hello" in WYSIWYG editor
And I press "Post"
And I log out
And I log in as "userA" with password "Kupuhipa1"
And I follow "mail"
Then I should see "New post on your wall"
When I click on "New post on your wall"
Then I should see "Hello"
And I should see "View whole wall"
When I follow "View whole wall"
Then I should see "Pete Mc: Wall"
And I should see "Son Nguyen"
And I should see "Hello"
\ No newline at end of file
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