qnashowquestion.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Form for showing / revising an answer
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Form
  23. * @package StatusNet
  24. * @author Zach Copley <zach@status.net>
  25. * @copyright 2011 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET')) {
  30. exit(1);
  31. }
  32. require_once INSTALLDIR . '/lib/util/form.php';
  33. /**
  34. * Form for showing a question
  35. *
  36. * @category Form
  37. * @package StatusNet
  38. * @author Zach Copley <zach@status.net>
  39. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  40. * @link http://status.net/
  41. *
  42. */
  43. class QnashowquestionForm extends Form
  44. {
  45. /**
  46. * The question to show
  47. */
  48. var $question = null;
  49. /**
  50. * Constructor
  51. *
  52. * @param HTMLOutputter $out output channel
  53. * @param QnA_Question $question the question to show
  54. */
  55. function __construct($out = null, $question = null)
  56. {
  57. parent::__construct($out);
  58. $this->question = $question;
  59. }
  60. /**
  61. * ID of the form
  62. *
  63. * @return int ID of the form
  64. */
  65. function id()
  66. {
  67. return 'question-' . $this->question->id;
  68. }
  69. /**
  70. * Action of the form
  71. *
  72. * @return string URL of the action
  73. */
  74. function action()
  75. {
  76. return common_local_url('qnaclosequestion');
  77. }
  78. /**
  79. * Include a session token for CSRF protection
  80. *
  81. * @return void
  82. */
  83. function sessionToken()
  84. {
  85. $this->out->hidden(
  86. 'token',
  87. common_session_token()
  88. );
  89. }
  90. /**
  91. * Legend of the Form
  92. *
  93. * @return void
  94. */
  95. function formLegend()
  96. {
  97. // TRANS: Form legend for revising the answer.
  98. $this->out->element('legend', null, _m('LEGEND','Question'));
  99. }
  100. /**
  101. * Data elements
  102. *
  103. * @return void
  104. */
  105. function formData()
  106. {
  107. $this->out->hidden(
  108. 'qna-question-id',
  109. 'question-' . $this->question->id,
  110. 'id'
  111. );
  112. $this->out->hidden(
  113. 'answer-action',
  114. common_local_url(
  115. 'qnanewanswer',
  116. null,
  117. array('id' => 'question-' . $this->question->id)
  118. )
  119. );
  120. $this->out->raw($this->question->asHTML());
  121. }
  122. /**
  123. * Action elements
  124. *
  125. * @return void
  126. */
  127. function formActions()
  128. {
  129. $user = common_current_user();
  130. if (empty($user)) {
  131. return;
  132. }
  133. if (empty($this->question->closed)) {
  134. if ($user->id == $this->question->profile_id) {
  135. $this->out->submit(
  136. 'qna-question-close',
  137. // TRANS: Button text for closing a question.
  138. _m('BUTTON', 'Close'),
  139. 'submit',
  140. 'submit',
  141. // TRANS: Title for button text for closing a question.
  142. _m('Close the question to no one can answer it anymore.')
  143. );
  144. }
  145. }
  146. }
  147. /**
  148. * Class of the form.
  149. *
  150. * @return string the form's class
  151. */
  152. function formClass()
  153. {
  154. return 'form_question_show ajax';
  155. }
  156. }