Commit 5de932ec authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan
Browse files

Customised adding/editing a forum

Changed instance_config_form to take the group
Added creator field to instance so that adding an interaction instance works
Changed order of creating an instance and calling instance_config_save
parent 40d10a5e
......@@ -59,7 +59,7 @@ if (!$group->owner == $USER->get('id')) {
$elements = array_merge(
PluginInteraction::instance_config_base_form($plugin, $group, $instance),
call_static_method(generate_class_name('interaction', $plugin), 'instance_config_form'),
call_static_method(generate_class_name('interaction', $plugin), 'instance_config_form', $group, $instance),
array(
'submit' => array(
'type' => 'submitcancel',
......
......@@ -2,8 +2,72 @@
class PluginInteractionForum extends PluginInteraction {
public static function instance_config_form($instance=null) {
return array();
public static function instance_config_form($group, $instance=null) {
if (isset($instance)) {
$weight = get_record_sql(
'SELECT c.value as weight
FROM {interaction_forum_instance_config} c
WHERE c.field=\'weight\'
AND forum = ?',
array($instance->get('id'))
)->weight;
$moderators = get_column('interaction_forum_moderator', '"user"', 'forum', $instance->get('id'));
}
return array(
'weight' => array(
'type' => 'text',
'title' => get_string('weight', 'interaction.forum'),
'defaultvalue' => isset($weight) ? $weight : 0,
'rules' => array(
'required' => true,
'integer' => true
)
),
'moderator' => array(
'type' => 'userlist',
'title' => get_string('moderators', 'interaction.forum'),
'defaultvalue' => isset($moderators) ? $moderators : null,
'group' => $group->id,
'filter' => false,
'lefttitle' => get_string('potentialmoderators', 'interaction.forum'),
'righttitle' => get_string('currentmoderators', 'interaction.forum')
),
'submit' => array(
'type' => 'submit',
'value' => get_string('submit')
)
);
}
public static function instance_config_save($instance, $values){
delete_records(
'interaction_forum_moderator',
'forum', $instance->get('id')
);
foreach ($values['moderator'] as $user) {
insert_record(
'interaction_forum_moderator',
(object)array(
'user' => $user,
'forum' => $instance->get('id')
)
);
}
delete_records(
'interaction_forum_instance_config',
'forum', $instance->get('id'),
'field', 'weight'
);
insert_record(
'interaction_forum_instance_config',
(object)array(
'forum' => $instance->get('id'),
'field' => 'weight',
'value' => $values['weight']
)
);
}
public static function get_activity_types() {
......
......@@ -36,7 +36,7 @@ abstract class PluginInteraction extends Plugin {
/**
* override this to add extra pieform elements to the edit instance form
*/
public static abstract function instance_config_form($instance=null);
public static abstract function instance_config_form($group, $instance=null);
/**
* override this to save any extra fields in the instance form.
......@@ -98,6 +98,7 @@ abstract class InteractionInstance {
protected $group;
protected $plugin; // I wanted to make this private but then get_object_vars doesn't include it.
protected $ctime;
protected $creator;
protected $dirty;
public function __construct($id=0, $data=null) {
......@@ -213,13 +214,15 @@ 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']);
global $USER;
$instance->set('creator', $USER->get('id'));
$instance->set('title', $values['title']);
$instance->set('description', $values['description']);
if (empty($values['id'])) {
$instance->set('group', $values['group']);
}
call_static_method(generate_class_name('interaction', $values['plugin']), 'instance_config_save', $instance, $values);
$instance->commit();
call_static_method(generate_class_name('interaction', $values['plugin']), 'instance_config_save', $instance, $values);
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'));
......
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