cancelrsvp.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2011, StatusNet, Inc.
  5. *
  6. * Cancel the 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('STATUSNET')) {
  31. // This check helps protect against security problems;
  32. // your code file can't be executed directly from the web.
  33. exit(1);
  34. }
  35. /**
  36. * RSVP for an event
  37. *
  38. * @category Event
  39. * @package StatusNet
  40. * @author Evan Prodromou <evan@status.net>
  41. * @copyright 2011 StatusNet, Inc.
  42. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  43. * @link http://status.net/
  44. */
  45. class CancelrsvpAction extends Action
  46. {
  47. protected $user = null;
  48. protected $rsvp = null;
  49. protected $event = null;
  50. /**
  51. * Returns the title of the action
  52. *
  53. * @return string Action title
  54. */
  55. function title()
  56. {
  57. // TRANS: Title for RSVP ("please respond") action.
  58. return _m('TITLE','Cancel RSVP');
  59. }
  60. /**
  61. * For initializing members of the class.
  62. *
  63. * @param array $argarray misc. arguments
  64. *
  65. * @return boolean true
  66. */
  67. function prepare($argarray)
  68. {
  69. parent::prepare($argarray);
  70. if ($this->boolean('ajax')) {
  71. StatusNet::setApi(true); // short error results!
  72. }
  73. $rsvpId = $this->trimmed('rsvp');
  74. if (empty($rsvpId)) {
  75. // TRANS: Client exception thrown when referring to a non-existing RSVP ("please respond") item.
  76. throw new ClientException(_m('No such RSVP.'));
  77. }
  78. $this->rsvp = RSVP::getKV('id', $rsvpId);
  79. if (empty($this->rsvp)) {
  80. // TRANS: Client exception thrown when referring to a non-existing RSVP ("please respond") item.
  81. throw new ClientException(_m('No such RSVP.'));
  82. }
  83. $this->event = Happening::getKV('id', $this->rsvp->event_id);
  84. if (empty($this->event)) {
  85. // TRANS: Client exception thrown when referring to a non-existing event.
  86. throw new ClientException(_m('No such event.'));
  87. }
  88. $this->user = common_current_user();
  89. if (empty($this->user)) {
  90. // TRANS: Client exception thrown when trying tp RSVP ("please respond") while not logged in.
  91. throw new ClientException(_m('You must be logged in to RSVP for an event.'));
  92. }
  93. return true;
  94. }
  95. /**
  96. * Handler method
  97. *
  98. * @param array $argarray is ignored since it's now passed in in prepare()
  99. *
  100. * @return void
  101. */
  102. function handle($argarray=null)
  103. {
  104. parent::handle($argarray);
  105. if ($this->isPost()) {
  106. $this->cancelRSVP();
  107. } else {
  108. $this->showPage();
  109. }
  110. return;
  111. }
  112. /**
  113. * Add a new event
  114. *
  115. * @return void
  116. */
  117. function cancelRSVP()
  118. {
  119. try {
  120. $notice = $this->rsvp->getNotice();
  121. // NB: this will delete the rsvp, too
  122. if (!empty($notice)) {
  123. common_log(LOG_DEBUG, "Deleting notice...");
  124. $notice->delete();
  125. } else {
  126. common_log(LOG_DEBUG, "Deleting RSVP alone...");
  127. $this->rsvp->delete();
  128. }
  129. } catch (ClientException $ce) {
  130. $this->error = $ce->getMessage();
  131. $this->showPage();
  132. return;
  133. }
  134. if ($this->boolean('ajax')) {
  135. $this->startHTML('text/xml;charset=utf-8');
  136. $this->elementStart('head');
  137. // TRANS: Page title after sending a notice.
  138. $this->element('title', null, _m('Event saved'));
  139. $this->elementEnd('head');
  140. $this->elementStart('body');
  141. $form = new RSVPForm($this->event, $this);
  142. $form->show();
  143. $this->elementEnd('body');
  144. $this->endHTML();
  145. }
  146. }
  147. /**
  148. * Show the event form
  149. *
  150. * @return void
  151. */
  152. function showContent()
  153. {
  154. if (!empty($this->error)) {
  155. $this->element('p', 'error', $this->error);
  156. }
  157. $form = new CancelRSVPForm($this->rsvp, $this);
  158. $form->show();
  159. return;
  160. }
  161. /**
  162. * Return true if read only.
  163. *
  164. * MAY override
  165. *
  166. * @param array $args other arguments
  167. *
  168. * @return boolean is read only action?
  169. */
  170. function isReadOnly($args)
  171. {
  172. if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
  173. $_SERVER['REQUEST_METHOD'] == 'HEAD') {
  174. return true;
  175. } else {
  176. return false;
  177. }
  178. }
  179. }