rsvp.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2011, StatusNet, Inc.
  5. *
  6. * RSVP for an event
  7. *
  8. * PHP version 5
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * @category Event
  24. * @package StatusNet
  25. * @author Evan Prodromou <evan@status.net>
  26. * @copyright 2011 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('GNUSOCIAL')) { exit(1); }
  31. /**
  32. * RSVP for an event
  33. *
  34. * @category Event
  35. * @package StatusNet
  36. * @author Evan Prodromou <evan@status.net>
  37. * @copyright 2011 StatusNet, Inc.
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  39. * @link http://status.net/
  40. */
  41. class RsvpAction extends FormAction
  42. {
  43. protected $form = 'RSVP';
  44. protected $event = null;
  45. function title()
  46. {
  47. // TRANS: Title for RSVP ("please respond") action.
  48. return _m('TITLE','New RSVP');
  49. }
  50. protected function doPreparation()
  51. {
  52. if ($this->trimmed('notice')) {
  53. $stored = Notice::getByID($this->trimmed('notice'));
  54. $this->event = Happening::fromStored($stored);
  55. } else {
  56. $this->event = Happening::getByKeys(['uri'=>$this->trimmed('event')]);
  57. }
  58. $this->formOpts['event'] = $this->event;
  59. }
  60. protected function doPost()
  61. {
  62. if ($this->trimmed('rsvp') === 'cancel') {
  63. $rsvp = RSVP::byEventAndActor($this->event, $this->scoped);
  64. try {
  65. $notice = $rsvp->getStored();
  66. $notice->deleteAs($this->scoped);
  67. } catch (NoResultException $e) {
  68. // Notice already gone
  69. $rsvp->delete();
  70. } catch (Exception $e) {
  71. // emergency cleanup in case database is screwed up
  72. $rsvp->delete();
  73. }
  74. return _m('Cancelled RSVP');
  75. }
  76. $verb = RSVP::verbFor(strtolower($this->trimmed('rsvp')));
  77. $options = array('source' => 'web');
  78. $act = new Activity();
  79. $act->id = UUID::gen();
  80. $act->verb = $verb;
  81. $act->time = time();
  82. $act->title = _m('RSVP');
  83. $act->actor = $this->scoped->asActivityObject();
  84. $act->target = $this->event->getStored()->asActivityObject();
  85. $act->objects = array(clone($act->target));
  86. $act->content = RSVP::toHTML($this->scoped, $this->event, RSVP::codeFor($verb));
  87. $act->context = new ActivityContext();
  88. $act->context->replyToID = $this->event->getUri();
  89. $stored = Notice::saveActivity($act, $this->scoped, $options);
  90. return _m('Saved RSVP');
  91. }
  92. }