Commit 9beeb7ee authored by Penny Leach's avatar Penny Leach
Browse files

More work on interactions:

- base class now has more functions and a few abstract ones
- edit and delete are provided by interaction/, not the plugin (with class functions to return pieforms)
- added deleted flag and creator (fk to usr) on the interaction_instance table
- added a README about how to write a new interaction plugin
parent 9e1a0c3f
To create a new interaction plugin, you must subclass the two classes in lib.php
and create the following entry points:
index.php?group=x - lists all instances in the given group
view.php?id=x display page for one instance.
The following strings are contract strings for an interaction plugin:
(example from forum)
$string['name'] = 'Forum';
$string['nameplural'] = 'Forums';
$string['addtitle'] = 'Add forum';
$string['edittitle'] = 'Edit forum';
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage group-interaction
* @author Penny Leach <penny@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('MENUITEM', 'groups');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('docroot') . 'interaction/lib.php');
require_once('pieforms/pieform.php');
$id = param_integer('id');
$instance = interaction_instance_from_id($id);
$group = get_record('group', 'id', $instance->get('group'));
if (!$group->owner == $USER->get('id')) {
throw new AccessDeniedException(get_string('notallowedtodeleteinteraction', 'group'));
}
define('TITLE', get_string('deleteinteraction', 'group', get_string('name', 'interaction.' . $instance->get('plugin')), $instance->get('title')));
// submit handler in interaction/lib.php
$form = pieform(array(
'name' => 'delete_interaction',
'elements' => array(
'title' => array(
'value' => get_string('deleteinteractionsure', 'group'),
),
'id' => array(
'type' => 'hidden',
'value' => $id,
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('yes'), get_string('no')),
'goto' => get_config('wwwroot') . 'interaction/' . $instance->get('plugin') . '/index.php?group=' . $group->id
)
)
));
$smarty = smarty();
$smarty->assign('form', $form);
$smarty->assign('heading', TITLE);
$smarty->assign('group', $group);
$smarty->display('interaction/delete.tpl');
?>
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage group-interaction
* @author Penny Leach <penny@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('MENUITEM', 'groups');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('docroot') . 'interaction/lib.php');
require_once('pieforms/pieform.php');
$id = param_integer('id', 0);
if (!empty($id)) {
$instance = interaction_instance_from_id($id);
$plugin = $instance->get('plugin');
$groupid = $instance->get('group');
define('TITLE', get_string('edittitle', 'interaction.' . $plugin));
}
else {
$instance = null;
$plugin = param_alphanum('plugin');
$groupid = param_integer('group');
define('TITLE', get_string('addtitle', 'interaction.' . $plugin));
}
safe_require('interaction', $plugin);
if (!$group = get_record('group', 'id', $groupid)) {
throw new GroupNotFoundException('groupnotfound', 'group', $groupid);
}
if (!$group->owner == $USER->get('id')) {
throw new AccessDeniedException(get_string('notallowedtoeditinteraction', 'group'));
}
$elements = array_merge(
PluginInteraction::instance_config_base_form($plugin, $group, $instance),
call_static_method(generate_class_name('interaction', $plugin), 'instance_config_form'),
array(
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('save'), get_string('cancel')),
'goto' => get_config('wwwroot') . 'group/view.php?id=' . $groupid,
)
)
);
// save, validate and cancelhandlers are in interaction/lib.php
$form = pieform(array(
'name' => 'edit_interaction',
'elements' => $elements
)
);
$smarty = smarty();
$smarty->assign('form', $form);
$smarty->assign('heading', TITLE);
$smarty->assign('group', $group);
$smarty->display('interaction/edit.tpl');
?>
......@@ -31,7 +31,46 @@ defined('INTERNAL') || die();
* Base interaction plugin class
* @abstract
*/
abstract class PluginInteraction extends Plugin { }
abstract class PluginInteraction extends Plugin {
public static abstract function instance_config_form($instance=null);
public static function instance_config_base_form($plugin, $group, $instance=null) {
return array(
'id' => array(
'type' => 'hidden',
'value' => (isset($instance) ? $instance->get('id') : 0),
),
'plugin' => array(
'type' => 'hidden',
'value' => $plugin,
),
'group' => array(
'type' => 'hidden',
'value' => $group->id
),
'title' => array(
'type' => 'text',
'title' => get_string('title'),
'defaultvalue' => (isset($instance) ? $instance->get('title') : ''),
'rules' => array(
'required' => true,
)
),
'description' => array(
'type' => 'wysiwyg',
'title' => get_string('description'),
'rows' => 10,
'cols' => 70,
'defaultvalue' => (isset($instance) ? $instance->get('description') : ''),
'rules' => array(
'required' => true,
)
),
);
}
}
/**
......@@ -120,8 +159,8 @@ abstract class InteractionInstance {
$this->dirty = false;
return;
}
delete_records('interaction_instance', 'id', $this->id);
set_field('interaction_instance', 'deleted', 1, 'id', $this->id);
$this->dirty = false;
}
......@@ -139,6 +178,47 @@ function interaction_check_plugin_sanity($pluginname) {
}
}
function interaction_instance_from_id($id) {
if (!$interaction = get_record('interaction_instance', 'id', $id)) {
throw new InteractionInstanceNotFoundException(get_string('interactioninstancenotfound', 'error', $id));
}
$classname = generate_interaction_instance_class_name($interaction->plugin);
safe_require('interaction', $interaction->plugin);
return new $classname($id, $interaction);
}
function edit_interaction_validation(Pieform $form, $values) {
safe_require('interaction', $values['plugin']);
if (is_callable(array(generate_class_name('interaction', $values['plugin'])))) {
call_static_method(generate_class_name('interaction', $values['plugin']));
}
}
function edit_interaction_submit(Pieform $form, $values) {
safe_require('interaction', $values['plugin']);
$classname = generate_interaction_instance_class_name($values['plugin']);
$instance = new $classname($values['id']);
$instance->set('title', $values['title']);
$instance->set('description', $values['description']);
if (empty($values['id'])) {
$instance->set('group', $values['group']);
}
$instance->commit();
global $SESSION;
$SESSION->add_ok_msg(get_string('interactionsaved', 'group', get_string('name', 'interaction.' . $values['plugin'])));
redirect('/interaction/' . $values['plugin'] . '/view.php?id=' . $instance->get('id'));
}
function delete_interaction_submit(Pieform $form, $values) {
require_once(get_config('docroot') . 'interaction/lib.php');
$instance = interaction_instance_from_id($values['id']);
$instance->delete();
global $SESSION;
$SESSION->add_ok_msg(get_string('interactiondeleted', 'group', get_string('name', 'interaction.' . $instance->get('plugin'))));
redirect('/interaction/' . $values['plugin'] . 'index.php?group=' . $instance->get('group'));
}
?>
......@@ -29,6 +29,7 @@ defined('INTERNAL') || die();
// group
$string['groupname'] = 'Group Name';
$string['creategroup'] = 'Create Group';
$string['groupnotfound'] = 'Group with id %s was not found';
$string['groupmemberrequests'] = 'Pending membership requests';
$string['addgroup'] = 'Add new group';
$string['sendinvitation'] = 'Send invite';
......@@ -181,5 +182,10 @@ $string['newusermessage'] = 'New message from %s';
// Group interactions
$string['groupinteractions'] = 'Group Interactions';
$string['nointeractions'] = 'There are no interactions in this group';
$string['notallowedtoeditinteractions'] = 'You are not allowed to add or edit interactions in this group';
$string['notallowedtodeleteinteractions'] = 'You are not allowed to delete interactions in this group';
$string['interactionsaved'] = '%s saved successfully';
$string['deleteinteraction'] = 'Delete %s \'%s\'';
$string['deleteinteractionsure'] = 'Are you sure you want to do this? It cannot be undone.';
$string['interactiondeleted'] = '%s deleted successfully';
?>
......@@ -282,11 +282,14 @@
<FIELD NAME="title" TYPE="text" NOTNULL="true" />
<FIELD NAME="description" TYPE="text" NOTNULL="false" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="creator" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="deleted" TYPE="int" LENGTH="1" DEFAULT="0" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="pluginfk" TYPE="foreign" FIELDS="plugin" REFTABLE="interaction_installed" REFFIELDS="name" />
<KEY NAME="groupfk" TYPE="foreign" FIELDS="group" REFTABLE="group" REFFIELDS="id" />
<KEY NAME="creatorfk" TYPE="foregin" FIELDS="creator" REFTABLE="usr" REFFIELDS="id" />
</KEYS>
</TABLE>
<!-- user related tables -->
......
{include file="header.tpl"}
{include file="sidebar.tpl"}
{include file="columnleftstart.tpl"}
<h2>{$group->name|escape}</h2>
<h3>{$heading|escape}</h3>
{$form}
{include file="columnleftend.tpl"}
{include file="footer.tpl"}
{include file="header.tpl"}
{include file="sidebar.tpl"}
{include file="columnleftstart.tpl"}
<h2>{$group->name|escape}</h2>
<h3>{$heading|escape}</h3>
{$form}
{include file="columnleftend.tpl"}
{include file="footer.tpl"}
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