From a002d577364a1e92f693ff005d71bdaae14d67a5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 3 Feb 2011 16:39:52 -0500 Subject: [PATCH] save group privacy settings --- plugins/PrivateGroup/PrivateGroupPlugin.php | 65 ++++++++++++++++++++- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/plugins/PrivateGroup/PrivateGroupPlugin.php b/plugins/PrivateGroup/PrivateGroupPlugin.php index 66fd7430b1..67e1cfb65e 100644 --- a/plugins/PrivateGroup/PrivateGroupPlugin.php +++ b/plugins/PrivateGroup/PrivateGroupPlugin.php @@ -226,10 +226,69 @@ class PrivateGroupPlugin extends Plugin /** * Show group privacy controls on group edit form * - * @param Action $action EditgroupAction being executed - * - * + * @param GroupEditForm $form form being shown */ + + function onEndGroupEditFormData($form) + { + $gps = null; + + if (!empty($form->group)) { + $gps = Group_privacy_settings::staticGet('group_id', $form->group->id); + } + + $form->out->elementStart('li'); + $form->out->dropdown('allow_privacy', + _('Private messages'), + array(Group_privacy_settings::SOMETIMES => _('Sometimes'), + Group_privacy_settings::ALWAYS => _('Always'), + Group_privacy_settings::NEVER => _('Never')), + _('Whether to allow private messages to this group'), + false, + (empty($gps)) ? Group_privacy_settings::SOMETIMES : $gps->allow_privacy); + $form->out->elementEnd('li'); + $form->out->elementStart('li'); + $form->out->dropdown('allow_sender', + _('Private sender'), + array(Group_privacy_settings::EVERYONE => _('Everyone'), + Group_privacy_settings::MEMBER => _('Member'), + Group_privacy_settings::ADMIN => _('Admin')), + _('Who can send private messages to the group'), + false, + (empty($gps)) ? Group_privacy_settings::MEMBER : $gps->allow_sender); + $form->out->elementEnd('li'); + return true; + } + + function onEndGroupSaveForm($action) + { + $gps = null; + + if (!empty($action->group)) { + $gps = Group_privacy_settings::staticGet('group_id', $action->group->id); + } + + $orig = null; + + if (empty($gps)) { + $gps = new Group_privacy_settings(); + $gps->group_id = $action->group->id; + } else { + $orig = clone($gps); + } + + $gps->allow_privacy = $action->trimmed('allow_privacy'); + $gps->allow_sender = $action->trimmed('allow_sender'); + + if (empty($orig)) { + $gps->created = common_sql_now(); + $gps->insert(); + } else { + $gps->update($orig); + } + + return true; + } function onPluginVersion(&$versions) { -- 2.39.5