Cancelling RSVPs now seems to work.

This commit is contained in:
Mikael Nordfeldth 2016-01-20 16:10:10 +01:00
parent 9accd953e4
commit 21cc737f5c
7 changed files with 50 additions and 249 deletions

View File

@ -28,9 +28,7 @@
* @link http://status.net/
*/
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Base class for UI widgets
@ -65,9 +63,13 @@ class Widget
* @param Action $out output helper, defaults to null
*/
function __construct(Action $out=null)
function __construct(Action $out=null, array $widgetOpts=array())
{
$this->out = $out;
if (!array_key_exists('scoped', $widgetOpts)) {
$this->widgetOpts['scoped'] = Profile::current();
}
$this->scoped = $this->widgetOpts['scoped'];
}
/**

View File

@ -78,9 +78,10 @@ class EventPlugin extends ActivityVerbHandlerPlugin
$m->connect('main/event/new',
array('action' => 'newevent'));
$m->connect('main/event/rsvp',
array('action' => 'newrsvp'));
$m->connect('main/event/rsvp/cancel',
array('action' => 'cancelrsvp'));
array('action' => 'rsvp'));
$m->connect('main/event/rsvp/:rsvp', // this will probably change to include event notice id
array('action' => 'rsvp'),
array('rsvp' => '[a-z]+'));
$m->connect('event/:id',
array('action' => 'showevent'),
array('id' => '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'));
@ -433,14 +434,7 @@ class EventPlugin extends ActivityVerbHandlerPlugin
$out->elementEnd('div');
if ($scoped instanceof Profile) {
$rsvp = $event->getRSVP($scoped);
if (empty($rsvp)) {
$form = new RSVPForm($out, array('event'=>$event));
} else {
$form = new CancelRSVPForm($out, array('rsvp'=>$rsvp));
}
$form = new RSVPForm($out, array('event'=>$event, 'scoped'=>$scoped));
$form->show();
}
$out->elementEnd('div');

View File

@ -1,89 +0,0 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
*
* Cancel the RSVP for an event
*
* PHP version 5
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Event
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* RSVP for an event
*
* @category Event
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
class CancelrsvpAction extends FormAction
{
protected $form = 'CancelRSVP';
function title()
{
// TRANS: Title for RSVP ("please respond") action.
return _m('TITLE','Cancel RSVP');
}
// FIXME: Merge this action with RSVPAction and add a 'cancel' thing there...
protected function doPreparation()
{
$rsvpId = $this->trimmed('rsvp');
if (empty($rsvpId)) {
// TRANS: Client exception thrown when referring to a non-existing RSVP ("please respond") item.
throw new ClientException(_m('No such RSVP.'));
}
$this->rsvp = RSVP::getKV('id', $rsvpId);
if (empty($this->rsvp)) {
// TRANS: Client exception thrown when referring to a non-existing RSVP ("please respond") item.
throw new ClientException(_m('No such RSVP.'));
}
$this->formOpts['rsvp'] = $this->rsvp;
}
protected function doPost()
{
$this->event = Happening::getKV('uri', $this->rsvp->event_uri);
if (empty($this->event)) {
// TRANS: Client exception thrown when referring to a non-existing event.
throw new ClientException(_m('No such event.'));
}
$notice = $this->rsvp->getNotice();
// NB: this will delete the rsvp, too
if (!empty($notice)) {
common_log(LOG_DEBUG, "Deleting notice...");
$notice->deleteAs($this->scoped);
} else {
common_log(LOG_DEBUG, "Deleting RSVP alone...");
$this->rsvp->delete();
}
}
}

View File

@ -40,11 +40,11 @@ if (!defined('GNUSOCIAL')) { exit(1); }
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
class NewrsvpAction extends FormAction
class RsvpAction extends FormAction
{
protected $form = 'RSVP';
protected $event;
protected $event = null;
function title()
{
@ -61,9 +61,19 @@ class NewrsvpAction extends FormAction
protected function doPost()
{
if ($this->trimmed('rsvp') === 'cancel') {
$rsvp = RSVP::byEventAndActor($this->event, $this->scoped);
try {
$notice = $rsvp->getStored();
$notice->deleteAs($this->scoped);
} catch (NoResultException $e) {
// Notice already gone
$rsvp->delete();
}
return _m('Cancelled RSVP');
}
$verb = RSVP::verbFor(strtolower($this->trimmed('submitvalue')));
$verb = RSVP::verbFor(strtolower($this->trimmed('rsvp')));
$options = array('source' => 'web');
$act = new Activity();

View File

@ -208,7 +208,7 @@ class RSVP extends Managed_DataObject
return $this->event_uri;
}
static function getStored()
public function getStored()
{
return Notice::getByKeys(['uri' => $this->getUri()]);
}
@ -218,6 +218,12 @@ class RSVP extends Managed_DataObject
return self::getByKeys(['uri' => $stored->getUri()]);
}
static function byEventAndActor(Happening $event, Profile $actor)
{
return self::getByKeys(['event_uri' => $event->getUri(),
'profile_id' => $actor->getID()]);
}
static function forEvent(Happening $event)
{
$keypart = sprintf('rsvp:for-event:%s', $event->getUri());

View File

@ -1,127 +0,0 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
*
* Form to RSVP for an event
*
* PHP version 5
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Event
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET')) { exit(1); }
/**
* A form to RSVP for an event
*
* @category General
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
class CancelRSVPForm extends Form
{
protected $rsvp = null;
function __construct($out=null, array $formOpts=array())
{
parent::__construct($out);
if (!isset($formOpts['rsvp'])) {
throw new ServerException('You must set the "rsvp" form option for RSVPForm.');
} elseif (!$formOpts['rsvp'] instanceof RSVP) {
throw new ServerException('The "rsvp" form option for RSVPForm must be an RSVP object.');
}
$this->rsvp = $formOpts['rsvp'];
}
/**
* ID of the form
*
* @return int ID of the form
*/
function id()
{
return 'form_event_rsvp';
}
/**
* class of the form
*
* @return string class of the form
*/
function formClass()
{
return 'ajax';
}
/**
* Action of the form
*
* @return string URL of the action
*/
function action()
{
return common_local_url('cancelrsvp');
}
/**
* Data elements of the form
*
* @return void
*/
function formData()
{
$this->out->elementStart('fieldset', array('id' => 'new_rsvp_data'));
$this->out->hidden('rsvp-id', $this->rsvp->getUri(), 'rsvp');
switch (RSVP::verbFor($this->rsvp->response)) {
case RSVP::POSITIVE:
// TRANS: Possible status for RSVP ("please respond") item.
$this->out->text(_m('You will attend this event.'));
break;
case RSVP::NEGATIVE:
// TRANS: Possible status for RSVP ("please respond") item.
$this->out->text(_m('You will not attend this event.'));
break;
case RSVP::POSSIBLE:
// TRANS: Possible status for RSVP ("please respond") item.
$this->out->text(_m('You might attend this event.'));
break;
}
$this->out->elementEnd('fieldset');
}
/**
* Action elements
*
* @return void
*/
function formActions()
{
// TRANS: Button text to cancel responding to an RSVP ("please respond") item.
$this->out->submit('rsvp-cancel', _m('BUTTON', 'Cancel'));
}
}

View File

@ -82,7 +82,7 @@ class RSVPForm extends Form
*/
function action()
{
return common_local_url('newrsvp');
return common_local_url('rsvp');
}
/**
@ -98,7 +98,7 @@ class RSVPForm extends Form
$this->out->text(_m('RSVP:'));
$this->out->hidden('event-id', $this->event->getUri(), 'event');
$this->out->hidden('submitvalue', '');
$this->out->hidden('rsvp', '');
$this->out->elementEnd('fieldset');
}
@ -110,26 +110,31 @@ class RSVPForm extends Form
*/
function formActions()
{
// TRANS: Button text for RSVP ("please respond") reply to confirm attendence.
$this->submitButton('yes', _m('BUTTON', 'Yes'));
// TRANS: Button text for RSVP ("please respond") reply to deny attendence.
$this->submitButton('no', _m('BUTTON', 'No'));
// TRANS: Button text for RSVP ("please respond") reply to indicate one might attend.
$this->submitButton('maybe', _m('BUTTON', 'Maybe'));
try {
$rsvp = RSVP::byEventAndActor($this->event, $this->scoped);
$this->submitButton('cancel', _m('BUTTON', 'Cancel'));
} catch (NoResultException $e) {
// TRANS: Button text for RSVP ("please respond") reply to confirm attendence.
$this->submitButton('yes', _m('BUTTON', 'Yes'));
// TRANS: Button text for RSVP ("please respond") reply to deny attendence.
$this->submitButton('no', _m('BUTTON', 'No'));
// TRANS: Button text for RSVP ("please respond") reply to indicate one might attend.
$this->submitButton('maybe', _m('BUTTON', 'Maybe'));
}
}
function submitButton($id, $label)
function submitButton($answer, $label)
{
$this->out->element(
'input',
array(
'type' => 'submit',
'id' => 'rsvp-submit',
'name' => $id,
'id' => 'rsvp-submit-'.$answer,
'name' => $answer,
'class' => 'submit',
'value' => $label,
'value' => $answer,
'title' => $label,
'onClick' => 'this.form.submitvalue.value = this.name; return true;'
'onClick' => 'this.form.rsvp.value = this.name; return true;'
)
);
}