From: Mikael Nordfeldth Date: Tue, 19 Jan 2016 00:33:09 +0000 (+0100) Subject: RSVP stuff, mostly forms. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=477d71c0bfe080a1a3500f0d2d68989b29504a98;p=quix0rs-gnu-social.git RSVP stuff, mostly forms. Now fix CancelRSVP stuff so it gets by event_uri and can cancel existing RSVP. --- diff --git a/plugins/Event/actions/cancelrsvp.php b/plugins/Event/actions/cancelrsvp.php index 662a1de0b3..0db422c8c6 100644 --- a/plugins/Event/actions/cancelrsvp.php +++ b/plugins/Event/actions/cancelrsvp.php @@ -28,11 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - // This check helps protect against security problems; - // your code file can't be executed directly from the web. - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * RSVP for an event diff --git a/plugins/Event/actions/newrsvp.php b/plugins/Event/actions/newrsvp.php index 0e0810cd78..df58f5b62f 100644 --- a/plugins/Event/actions/newrsvp.php +++ b/plugins/Event/actions/newrsvp.php @@ -54,16 +54,7 @@ class NewrsvpAction extends FormAction protected function doPreparation() { - $eventId = $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->event = Happening::getByKeys(['uri'=>$this->trimmed('event')]); $this->formOpts['event'] = $this->event; } diff --git a/plugins/Event/forms/cancelrsvp.php b/plugins/Event/forms/cancelrsvp.php index 3047c57bee..5c0399135d 100644 --- a/plugins/Event/forms/cancelrsvp.php +++ b/plugins/Event/forms/cancelrsvp.php @@ -28,11 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - // This check helps protect against security problems; - // your code file can't be executed directly from the web. - exit(1); -} +if (!defined('STATUSNET')) { exit(1); } /** * A form to RSVP for an event @@ -48,10 +44,15 @@ class CancelRSVPForm extends Form { protected $rsvp = null; - function __construct($rsvp, $out=null) + function __construct($out=null, array $formOpts=array()) { 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->hidden('rsvp-id', $this->rsvp->id, 'rsvp'); + $this->out->hidden('rsvp-id', $this->rsvp->getUri(), 'rsvp'); switch (RSVP::verbFor($this->rsvp->response)) { case RSVP::POSITIVE: diff --git a/plugins/Event/forms/rsvp.php b/plugins/Event/forms/rsvp.php index 9d5cea7444..81cd335f87 100644 --- a/plugins/Event/forms/rsvp.php +++ b/plugins/Event/forms/rsvp.php @@ -44,10 +44,15 @@ class RSVPForm extends Form { protected $event = null; - function __construct(Happening $event, $out=null) + function __construct($out=null, array $formOpts=array()) { 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. $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->elementEnd('fieldset');