rsvp.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2011, StatusNet, Inc.
  5. *
  6. * Form to 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. * A form to RSVP for an event
  33. *
  34. * @category General
  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 RSVPForm extends Form
  42. {
  43. protected $event = null;
  44. function __construct($out=null, array $formOpts=array())
  45. {
  46. parent::__construct($out);
  47. if (!isset($formOpts['event'])) {
  48. throw new ServerException('You must set the "event" form option for RSVPForm.');
  49. } elseif (!$formOpts['event'] instanceof Happening) {
  50. throw new ServerException('The "event" form option for RSVPForm must be a Happening object.');
  51. }
  52. $this->event = $formOpts['event'];
  53. }
  54. /**
  55. * ID of the form
  56. *
  57. * @return int ID of the form
  58. */
  59. function id()
  60. {
  61. return 'form_event_rsvp';
  62. }
  63. /**
  64. * class of the form
  65. *
  66. * @return string class of the form
  67. */
  68. function formClass()
  69. {
  70. return 'ajax';
  71. }
  72. /**
  73. * Action of the form
  74. *
  75. * @return string URL of the action
  76. */
  77. function action()
  78. {
  79. return common_local_url('rsvp');
  80. }
  81. /**
  82. * Data elements of the form
  83. *
  84. * @return void
  85. */
  86. function formData()
  87. {
  88. $this->out->elementStart('fieldset', array('id' => 'new_rsvp_data'));
  89. // TRANS: Field label on form to RSVP ("please respond") for an event.
  90. $this->out->text(_m('RSVP:'));
  91. $this->out->hidden('notice', $this->event->getStored()->getID(), 'event');
  92. $this->out->hidden('event', $this->event->getUri(), 'event'); // not used
  93. $this->out->hidden('rsvp', '');
  94. $this->out->elementEnd('fieldset');
  95. }
  96. /**
  97. * Action elements
  98. *
  99. * @return void
  100. */
  101. function formActions()
  102. {
  103. try {
  104. $rsvp = RSVP::byEventAndActor($this->event, $this->scoped);
  105. $this->submitButton('cancel', _m('BUTTON', 'Cancel'));
  106. } catch (NoResultException $e) {
  107. // TRANS: Button text for RSVP ("please respond") reply to confirm attendence.
  108. $this->submitButton('yes', _m('BUTTON', 'Yes'));
  109. // TRANS: Button text for RSVP ("please respond") reply to deny attendence.
  110. $this->submitButton('no', _m('BUTTON', 'No'));
  111. // TRANS: Button text for RSVP ("please respond") reply to indicate one might attend.
  112. $this->submitButton('maybe', _m('BUTTON', 'Maybe'));
  113. }
  114. }
  115. function submitButton($answer, $label)
  116. {
  117. $this->out->element(
  118. 'input',
  119. array(
  120. 'type' => 'submit',
  121. 'id' => 'rsvp-submit-'.$answer,
  122. 'name' => $answer,
  123. 'class' => 'submit',
  124. 'value' => $label,
  125. 'title' => $label,
  126. 'onClick' => 'this.form.rsvp.value = this.name; return true;'
  127. )
  128. );
  129. }
  130. }