Commit 9ae2530a authored by Aaron Wells's avatar Aaron Wells Committed by Gerrit Code Review
Browse files

Merge "Bug 1468156: Change plugin type of plugin multirecipientnotification to module"

parents 383752ee dd0e1dab
......@@ -140,7 +140,13 @@ function delete_all_notifications_submit() {
db_commit();
$SESSION->add_ok_msg(get_string('deletednotifications1', 'activity', $count));
redirect(get_config('wwwroot') . 'account/activity/index.php?type='.$type);
safe_require('module', 'multirecipientnotification');
if (PluginModuleMultirecipientnotification::is_active()) {
redirect(get_config('wwwroot') . 'module/multirecipientnotification/inbox.php?type='.$type);
}
else {
redirect(get_config('wwwroot') . 'account/activity/index.php?type='.$type);
}
}
$smarty = smarty(array('paginator'));
......
<?php
/**
*
* @package mahara
* @subpackage artefact-multirecipientnotification
* @author David Ballhausen, Tobias Zeuch
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
/**
* artefacttype - plugin class. Used for corresponding with the Mahara API and containing all needed functionality for Multirecipientnotification function
*/
class ArtefactTypeMultiRecipientNotification extends ArtefactType {
/**
* API-Function. This Artefact does not provide any blocks or items to render
* @see ArtefactType::render_self()
*/
public function render_self($options) {
return get_string('nothingtorender', 'artefact.multirecipientnotification');
}
/**
* API-Function. Get Plugin-Artefacttype Icon. Here (No icon provided)
* @param string $options
*/
public static function get_icon($options=null) {
}
/**
* API-Function. Is it possible to use more Artefacttypes than one of this type? Here: No!
*/
public static function is_singular() {
return true;
}
/**
* API-Function: Get plugin-Artefacttype specific links: Here: None
* @param integer $id
*/
public static function get_links($id) {
}
} // ArtefactTypeMultiRecipientNotification
<?php
/**
*
* @package mahara
* @subpackage artefact-multirecipientnotification
* @author David Ballhausen, Tobias Zeuch
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
/**
* artefacttype - plugin class. Used for corresponding with the Mahara API and containing all needed functionality for Multirecipientnotification function
*/
class ArtefactTypeOutbox extends ArtefactType {
/**
* API-Function. This Artefact does not provide any blocks or items to render
* @see ArtefactType::render_self()
*/
public function render_self($options) {
return get_string('nothingtorender', 'artefact.multirecipientnotification');
}
/**
* API-Function. Get Plugin-Artefacttype Icon. Here (No icon provided)
* @param string $options
*/
public static function get_icon($options=null) {
}
/**
* API-Function. Is it possible to use more Artefacttypes than one of this type? Here: No!
*/
public static function is_singular() {
return true;
}
/**
* API-Function: Get plugin-Artefacttype specific links: Here: None
* @param integer $id
*/
public static function get_links($id) {
}
} // ArtefactTypeOutbox
......@@ -30,7 +30,13 @@ class PluginBlocktypeInbox extends SystemBlocktype {
}
public static function get_link(BlockInstance $instance) {
$data = get_config('wwwroot') . 'account/activity/index.php';
safe_require('module', 'multirecipientnotification');
if (PluginModuleMultirecipientnotification::is_active()) {
$data = get_config('wwwroot') . 'module/multirecipientnotification/inbox.php';
}
else {
$data = get_config('wwwroot') . 'account/activity/index.php';
}
return sanitize_url($data);
}
......
......@@ -1450,10 +1450,18 @@ function activitylist_html($type='all', $limit=10, $offset=0) {
$values = array($userid);
$count = count_records_sql('SELECT COUNT(*)' . $from, $values);
safe_require('module', 'multirecipientnotification');
if (PluginModuleMultirecipientnotification::is_active()) {
$paginationurl = get_config('wwwroot') . 'module/multirecipientnotification/inbox.php?type=' . $type;
}
else {
$paginationurl = get_config('wwwroot') . 'account/activity/index.php?type=' . $type;
}
$pagination = build_pagination(array(
'id' => 'activitylist_pagination',
'url' => get_config('wwwroot') . 'account/activity/index.php?type=' . $type,
'url' => $paginationurl,
'jsonscript' => 'account/activity/index.json.php',
'datatable' => 'activitylist',
'count' => $count,
......
......@@ -4082,5 +4082,39 @@ function xmldb_core_upgrade($oldversion=0) {
change_field_precision($table, $field);
}
if ($oldversion < 2015072000) {
log_debug('Change installation of artefact plugin multirecipentNotification to plugin module');
// first, drop the old triggers
db_drop_trigger('update_unread_insert2', 'artefact_multirecipient_userrelation');
db_drop_trigger('update_unread_update2', 'artefact_multirecipient_userrelation');
db_drop_trigger('update_unread_delete2', 'artefact_multirecipient_userrelation');
// rename tables artefact_multirecipientnotifiaction_notification and
// Table: artefact_multirecipient_userrelation to module-prefix
execute_sql("ALTER TABLE artefact_multirecipient_notification RENAME TO module_multirecipient_notification");
execute_sql("ALTER TABLE artefact_multirecipient_userrelation RENAME TO module_multirecipient_userrelation");
//move event_subscrition entries for artefact plugin
//multirecipientnotification to table module_event_subscription
$subscriptions = get_records_array('artefact_event_subscription', 'plugin', 'multirecipientnotification');
delete_records('artefact_event_subscription', 'plugin', 'multirecipientnotification');
delete_records('artefact_installed_type', 'plugin', 'multirecipientnotification');
$installrecord = get_record('artefact_installed', 'name', 'multirecipientnotification');
if (is_object($installrecord)) {
insert_record('module_installed', $installrecord);
delete_records('artefact_installed', 'name', 'multirecipientnotification');
}
if (is_array($subscriptions)) {
foreach ($subscriptions as $subscription) {
insert_record('module_event_subscription', $subscription, 'id');
}
}
// recreate trigger
safe_require('module', 'multirecipientnotification');
PluginModuleMultirecipientnotification::postinst(0);
}
return $status;
}
......@@ -1979,8 +1979,9 @@ function build_userlist_html(&$data, $page, $admingroups) {
$resultcounttextsingular = get_string('user', 'group');
$resultcounttextplural = get_string('users', 'group');
}
$smarty->assign('admingroups', $admingroups);
safe_require('module', 'multirecipientnotification');
$smarty->assign('mrmoduleactive', PluginModuleMultirecipientnotification::is_active());
$data['tablerows'] = $smarty->fetch('user/userresults.tpl');
$pagination = build_pagination(array(
'id' => 'friendslist_pagination',
......@@ -2056,6 +2057,8 @@ function build_stafflist_html(&$data, $page, $listtype, $inst='mahara') {
else {
$smarty->assign('data', isset($data) ? $data : null);
}
safe_require('module', 'multirecipientnotification');
$smarty->assign('mrmoduleactive', PluginModuleMultirecipientnotification::is_active());
$data['tablerows'] = $smarty->fetch('institution/stafflist.tpl');
}
......
......@@ -16,7 +16,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 = 2015071500;
$config->version = 2015072000;
$config->series = '15.10';
$config->release = '15.10dev';
$config->minupgradefrom = 2009022600;
......
......@@ -2,21 +2,22 @@
# for developing/testing scenarios when you want to remove/reinstall the
# script without reinstalling the complete database
drop table IF EXISTS `multirecipientnotification_internal_recipients`;
drop table IF EXISTS `multirecipientnotification_internal_activity`;
DELETE FROM `artefact_cron` WHERE plugin='notificationoutbox';
DELETE FROM `artefact_event_subscription` WHERE plugin='notificationoutbox';
DELETE FROM `artefact_config` WHERE `plugin`='notificationoutbox';
delete from `artefact_installed_type` where plugin='notificationoutbox';
delete from `artefact_installed` where name='notificationoutbox';
# delete the old plugin installed as artefact
drop table IF EXISTS `artefact_multirecipient_userrelation`;
drop table IF EXISTS `artefact_multirecipient_notification`;
DELETE FROM `artefact_cron` WHERE plugin='multirecipientnotification';
DELETE FROM `artefact_event_subscription` WHERE plugin='multirecipientnotification';
DELETE FROM `artefact_config` WHERE `plugin`='multirecipientnotification';
delete from `artefact_installed_type` where plugin='multirecipientnotification';
delete from `artefact_installed` where name='multirecipientnotification';
DELETE FROM `artefact_installed_type` WHERE plugin='multirecipientnotification';
DELETE FROM `artefact_installed` WHERE name='multirecipientnotification';
# delete the new script installed as module
drop table IF EXISTS `module_multirecipient_userrelation`;
drop table IF EXISTS `module_multirecipient_notification`;
DELETE FROM `module_cron` WHERE plugin='multirecipientnotification';
DELETE FROM `module_event_subscription` WHERE plugin='multirecipientnotification';
DELETE FROM `module_config` WHERE `plugin`='multirecipientnotification';
DELETE FROM `module_installed_type` WHERE plugin='multirecipientnotification';
DELETE FROM `module_installed` WHERE name='multirecipientnotification';
......@@ -4,7 +4,7 @@
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="artefact_multirecipient_notification" COMMENT="notifications to (potentially) multiple recipients ">
<TABLE NAME="module_multirecipient_notification" COMMENT="notifications to (potentially) multiple recipients ">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" COMMENT="Primary Key"/>
<FIELD NAME="type" TYPE="int" LENGTH="10" NOTNULL="false" COMMENT="The type of message, e.g. notification"/>
......@@ -16,13 +16,13 @@
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="typefk" TYPE="foreign" FIELDS="type" REFTABLE="activity_type" REFFIELDS="id"/>
<KEY NAME="parentfk" TYPE="foreign" FIELDS="parent" REFTABLE="artefact_multirecipient_notification" REFFIELDS="id"/>
<KEY NAME="parentfk" TYPE="foreign" FIELDS="parent" REFTABLE="module_multirecipient_notification" REFFIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="ctimeix" FIELDS="ctime" UNIQUE="false"/>
</INDEXES>
</TABLE>
<TABLE NAME="artefact_multirecipient_userrelation" COMMENT="notifications to (potentially) multiple recipients ">
<TABLE NAME="module_multirecipient_userrelation" COMMENT="notifications to (potentially) multiple recipients ">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" COMMENT="Primary Key"/>
<FIELD NAME="role" TYPE="char" LENGTH="9" ENUM="true" ENUMVALUES="'sender','recipient'" NOTNULL="true" DEFAULT="recipient" COMMENT="the role of user-relation"/>
......@@ -33,7 +33,7 @@
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="notificationfk" TYPE="foreign" FIELDS="notification" REFTABLE="artefact_multirecipient_notification" REFFIELDS="id"/>
<KEY NAME="notificationfk" TYPE="foreign" FIELDS="notification" REFTABLE="module_multirecipient_notification" REFFIELDS="id"/>
<KEY NAME="usrfk" TYPE="foreign" FIELDS="usr" REFTABLE="usr" REFFIELDS="id"/>
</KEYS>
</TABLE>
......
......@@ -2,7 +2,7 @@
/**
*
* @package mahara
* @subpackage artefact-multirecipientnotification
* @subpackage module-multirecipientnotification
* @author David Ballhausen, Tobias Zeuch
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
......@@ -11,19 +11,29 @@
define('INTERNAL', 1);
define('MENUITEM', 'inbox');
define('SECTION_PLUGINTYPE', 'artefact');
define('SECTION_PLUGINTYPE', 'module');
define('SECTION_PLUGINNAME', 'multirecipientnotification');
define('SECTION_PAGE', 'inbox');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform.php');
safe_require('artefact', 'multirecipientnotification');
safe_require('module', 'multirecipientnotification');
global $USER;
global $THEME;
if (!PluginModuleMultirecipientnotification::is_active()) {
$redirTarget = get_config('wwwroot') . 'account/activity/inbox.php';
if (!empty($_SERVER['QUERY_STRING'])) {
// change path
$redirTarget .='?' . $_SERVER['QUERY_STRING'];
}
redirect($redirTarget);
exit;
}
// Add new title
define('TITLE', get_string('notification', 'artefact.multirecipientnotification'));
define('TITLE', get_string('notification', 'module.multirecipientnotification'));
// Make sure the unread message count is up to date whenever the
// user hits this page.
......@@ -145,8 +155,8 @@ function delete_all_notifications_submit() {
}
$query = 'SELECT msg.id AS id
FROM {artefact_multirecipient_notification} as msg
INNER JOIN {artefact_multirecipient_userrelation} as rel
FROM {module_multirecipient_notification} as msg
INNER JOIN {module_multirecipient_userrelation} as rel
ON msg.id = rel.notification
AND rel.usr = ?
AND rel.role = ?
......@@ -205,7 +215,7 @@ function delete_all_notifications_submit() {
db_commit();
$SESSION->add_ok_msg(get_string('deletednotifications1', 'activity', $count));
redirect(get_config('wwwroot') . 'artefact/multirecipientnotification/inbox.php?type=' . $type);
redirect(get_config('wwwroot') . 'module/multirecipientnotification/inbox.php?type=' . $type);
}
$smarty = smarty(array('paginator'));
......@@ -215,14 +225,14 @@ $smarty->assign('INLINEJAVASCRIPT', $paginationjavascript);
// Adding the links to out- and inbox
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('subsectionheading', get_string('labelinbox', 'artefact.multirecipientnotification'));
$smarty->assign('subsectionheading', get_string('labelinbox', 'module.multirecipientnotification'));
// show urls and titles
define('NOTIFICATION_SUBPAGE', 'inbox');
$smarty->assign('SUBPAGENAV', PluginArtefactMultirecipientnotification::submenu_items());
$smarty->assign('SUBPAGENAV', PluginModuleMultirecipientnotification::submenu_items());
$smarty->assign('deleteall', $deleteall);
$smarty->assign('activitylist', $activitylist);
// Changed to new tpl
$smarty->display('artefact:multirecipientnotification:indexin.tpl');
$smarty->display('module:multirecipientnotification:indexin.tpl');
......@@ -2,7 +2,7 @@
/**
*
* @package mahara
* @subpackage artefact-multirecipientnotification
* @subpackage module-multirecipientnotification
* @author David Ballhausen, Tobias Zeuch
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
......@@ -13,7 +13,7 @@ define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'multirecipientnotification');
safe_require('module', 'multirecipientnotification');
global $USER;
global $THEME;
......@@ -28,7 +28,7 @@ if ($readone) {
if ('notification_internal_activity' === $list) {
set_field($list, 'read', 1, 'id', $readone, 'usr', $USER->get('id'));
}
else if ('artefact_multirecipient_notification' === $list) {
else if ('module_multirecipient_notification' === $list) {
mark_as_read_mr(array($readone), $USER->get('id'));
}
$unread = $USER->add_unread(-1);
......@@ -58,8 +58,8 @@ if ($markasread) {
}
foreach ($ids as $list => $idsperlist) {
if ($idsperlist) {
if ('artefact_multirecipient_notification' === $list) {
$list = 'artefact_multirecipient_userrelation';
if ('module_multirecipient_notification' === $list) {
$list = 'module_multirecipient_userrelation';
$column = 'notification';
}
else {
......@@ -91,7 +91,7 @@ else if ($delete) {
db_begin();
$countdeleted = 0;
foreach ($ids as $list => $idsperlist) {
if ('artefact_multirecipient_notification' === $list) {
if ('module_multirecipient_notification' === $list) {
delete_messages_mr($idsperlist, $USER->get('id'));
}
else if ('notification_internal_activity' === $list) {
......
......@@ -2,7 +2,7 @@
/**
*
* @package mahara
* @subpackage artefact-multirecipientnotification
* @subpackage module-multirecipientnotification
* @author David Ballhausen, Tobias Zeuch
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
......@@ -13,7 +13,7 @@ define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'multirecipientnotification');
safe_require('module', 'multirecipientnotification');
global $USER;
global $THEME;
......
/**
* Multi-Recipient Notification Send Message
*
* @package mahara
* @subpackage module-multirecipientnotification
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*/
function initializeAutocomplete() {
jQuery( "#sendmessage_addnewrecipient" ).catcomplete({
delay: 0,
source: function(request, callback) {
getAutocompleteSource(request, callback);
},
select: function(event, ui) {
var userid = ui.item.userid;
var username = ui.item.label;
var userspan = document.createElement('span');
var jUserspan = jQuery(userspan);
var inputhidden = document.createElement('input');
var jInputhidden = jQuery(inputhidden);
jInputhidden.attr('type', 'hidden').attr('name', 'recipients[]').attr('value', userid);
jUserspan.append(jInputhidden);
var label = document.createElement('a');
var jLabel = jQuery(label);
jLabel.attr('href', config.wwwroot + 'admin/users/edit.php?id=' + userid);
jLabel.text(username);
jUserspan.append(jLabel);
var link = document.createElement('a');
var jLink = jQuery(link);
jLink.attr('onclick', 'removeRecipient("' + username + '")');
var img = document.createElement('img');
jUserspan.append(jLink);
jQuery('#sendmessage_addnewrecipient').before(jUserspan);
var jOnclicktext = jQuery('#sendmessage_addnewrecipient');
jOnclicktext.attr('value', '');
return false;
}
});
jQuery('#sendmessage_addnewrecipient').each(function() {
var default_value = this.value;
var jInput = jQuery(this);
jInput.focus(function () {
if (this.value === default_value) {
this.value = '';
}
});
jInput.blur(function() {
if (jQuery.trim(this.value) === '') {
this.value = default_value;
}
});
});
}
function removeRecipient(name) {
var onclicktext = jQuery('#sendmessage_addnewrecipient');
var list = onclicktext.parent();
list.children('div :contains("' + name + '")').remove();
var jOnclicktext = jQuery('#sendmessage_addnewrecipient');
jOnclicktext.attr('value', '');
}
function getAutocompleteSource(request, callback) {
var jOnclicklist = jQuery('#sendmessage_addnewrecipient').parent();
var ignoreusers = [];
jOnclicklist.find('input:hidden').each(function() {
ignoreusers.push(jQuery(this).val());
});
sendjsonrequest('sendmessage.json.php',
{
getuserlist : 1,
ignoreusers : JSON.stringify(ignoreusers),
request : request.term
},
'GET',
function (data) {
callback(data.data.autocompleteusers);
}
);
}
......@@ -2,7 +2,7 @@
/**
*
* @package mahara
* @subpackage artefact-multirecipientnotification
* @subpackage module-multirecipientnotification
* @author David Ballhausen, Tobias Zeuch
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
......
......@@ -2,7 +2,7 @@
/**
*
* @package mahara
* @subpackage artefact-multirecipientnotification
* @subpackage module-multirecipientnotification
* @author David Ballhausen, Tobias Zeuch
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
......@@ -12,13 +12,13 @@
defined('INTERNAL') || die();
require_once(dirname(dirname(dirname(__FILE__))) . '/lib/group.php');
require_once(dirname(__FILE__) . '/lib/multirecipientnotification.php');
require_once(get_config('docroot') . '/artefact/multirecipientnotification/lib/activityextend.php');
require_once(get_config('docroot') . '/module/multirecipientnotification/lib/activityextend.php');
/**
* artefact plugin class. Used for registering the plugin and his functions.
* module plugin class. Used for registering the plugin and his functions.
*/
class PluginArtefactMultirecipientnotification extends PluginArtefact {
class PluginModuleMultirecipientnotification extends PluginModule {
/**
* the maximum length of a userstring in the list of senders/recipients
* in the inbox or outbox view
......@@ -31,30 +31,12 @@ class PluginArtefactMultirecipientnotification extends PluginArtefact {
*/
public static function is_active() {
$active = false;
if (get_field('artefact_installed', 'active', 'name', 'multirecipientnotification')) {
if (get_field('module_installed', 'active', 'name', 'multirecipientnotification')) {
$active = true;
}
return $active;
}
/**
* API-Function get the provided artefacttypes. Here is it 'Multirecipientnotification'.
*
* @return array array with the provided artefacttypes
*/
public static function get_artefact_types() {
return array('Multirecipientnotification');
}
/**
* API-Function get the provided blocktypes. Here None.
*
* @return array array with the provided blocktypes
*/
public static function get_block_types() {
return array();
}