RSVP stuff, mostly forms.

Now fix CancelRSVP stuff so it gets by event_uri and can cancel existing RSVP.
This commit is contained in:
Mikael Nordfeldth 2016-01-19 01:33:09 +01:00
parent 84dda697d6
commit 477d71c0bf
4 changed files with 19 additions and 26 deletions

View File

@ -28,11 +28,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('STATUSNET')) { if (!defined('GNUSOCIAL')) { exit(1); }
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
exit(1);
}
/** /**
* RSVP for an event * RSVP for an event

View File

@ -54,16 +54,7 @@ class NewrsvpAction extends FormAction
protected function doPreparation() protected function doPreparation()
{ {
$eventId = $this->trimmed('event'); $this->event = Happening::getByKeys(['uri'=>$this->trimmed('event')]);
if (empty($eventId)) {
// TRANS: Client exception thrown when referring to a non-existing event.
throw new ClientException(_m('No such event.'));
}
$this->event = Happening::getKV('id', $eventId);
if (empty($this->event)) {
// TRANS: Client exception thrown when referring to a non-existing event.
throw new ClientException(_m('No such event.'));
}
$this->formOpts['event'] = $this->event; $this->formOpts['event'] = $this->event;
} }

View File

@ -28,11 +28,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('STATUSNET')) { if (!defined('STATUSNET')) { exit(1); }
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
exit(1);
}
/** /**
* A form to RSVP for an event * A form to RSVP for an event
@ -48,10 +44,15 @@ class CancelRSVPForm extends Form
{ {
protected $rsvp = null; protected $rsvp = null;
function __construct($rsvp, $out=null) function __construct($out=null, array $formOpts=array())
{ {
parent::__construct($out); parent::__construct($out);
$this->rsvp = $rsvp; if (!isset($formOpts['rsvp'])) {
throw new ServerException('You must set the "rsvp" form option for RSVPForm.');
} elseif (!$formOpts['rsvp'] instanceof Happening) {
throw new ServerException('The "rsvp" form option for RSVPForm must be an RSVP object.');
}
$this->rsvp = $formOpts['rsvp'];
} }
/** /**
@ -93,7 +94,7 @@ class CancelRSVPForm extends Form
{ {
$this->out->elementStart('fieldset', array('id' => 'new_rsvp_data')); $this->out->elementStart('fieldset', array('id' => 'new_rsvp_data'));
$this->out->hidden('rsvp-id', $this->rsvp->id, 'rsvp'); $this->out->hidden('rsvp-id', $this->rsvp->getUri(), 'rsvp');
switch (RSVP::verbFor($this->rsvp->response)) { switch (RSVP::verbFor($this->rsvp->response)) {
case RSVP::POSITIVE: case RSVP::POSITIVE:

View File

@ -44,10 +44,15 @@ class RSVPForm extends Form
{ {
protected $event = null; protected $event = null;
function __construct(Happening $event, $out=null) function __construct($out=null, array $formOpts=array())
{ {
parent::__construct($out); parent::__construct($out);
$this->event = $event; if (!isset($formOpts['event'])) {
throw new ServerException('You must set the "event" form option for RSVPForm.');
} elseif (!$formOpts['event'] instanceof Happening) {
throw new ServerException('The "event" form option for RSVPForm must be a Happening object.');
}
$this->event = $formOpts['event'];
} }
/** /**
@ -92,7 +97,7 @@ class RSVPForm extends Form
// TRANS: Field label on form to RSVP ("please respond") for an event. // TRANS: Field label on form to RSVP ("please respond") for an event.
$this->out->text(_m('RSVP:')); $this->out->text(_m('RSVP:'));
$this->out->hidden('event-id', $this->event->id, 'event'); $this->out->hidden('event-id', $this->event->getUri(), 'event');
$this->out->hidden('submitvalue', ''); $this->out->hidden('submitvalue', '');
$this->out->elementEnd('fieldset'); $this->out->elementEnd('fieldset');