qnashowanswer.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 / revising an answer
  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 QnashowanswerForm extends Form
  44. {
  45. /**
  46. * The answer to show
  47. */
  48. protected $answer = null;
  49. /**
  50. * The question this is an answer to
  51. */
  52. protected $question = null;
  53. /**
  54. * Constructor
  55. *
  56. * @param HTMLOutputter $out output channel
  57. * @param QnA_Answer $answer answer to revise
  58. */
  59. function __construct($out = null, $answer = null)
  60. {
  61. parent::__construct($out);
  62. $this->answer = $answer;
  63. $this->question = $answer->getQuestion();
  64. }
  65. /**
  66. * ID of the form
  67. *
  68. * @return int ID of the form
  69. */
  70. function id()
  71. {
  72. return 'show-' . $this->answer->id;
  73. }
  74. /**
  75. * Action of the form
  76. *
  77. * @return string URL of the action
  78. */
  79. function action()
  80. {
  81. return common_local_url('qnareviseanswer');
  82. }
  83. /**
  84. * Include a session token for CSRF protection
  85. *
  86. * @return void
  87. */
  88. function sessionToken()
  89. {
  90. $this->out->hidden(
  91. 'token',
  92. common_session_token()
  93. );
  94. }
  95. /**
  96. * Legend of the Form
  97. *
  98. * @return void
  99. */
  100. function formLegend()
  101. {
  102. // TRANS: Form legend for showing the answer.
  103. $this->out->element('legend', null, _m('Answer'));
  104. }
  105. /**
  106. * Data elements
  107. *
  108. * @return void
  109. */
  110. function formData()
  111. {
  112. $this->out->hidden(
  113. 'qna-answer-id',
  114. 'answer-' . $this->answer->id,
  115. 'id'
  116. );
  117. $this->out->raw($this->answer->asHTML());
  118. }
  119. /**
  120. * Action elements
  121. *
  122. * @return void
  123. */
  124. function formActions()
  125. {
  126. $user = common_current_user();
  127. if (empty($user)) {
  128. return;
  129. }
  130. if (empty($this->question->closed)) {
  131. if ($user->id == $this->question->profile_id) {
  132. if (empty($this->answer->best)) {
  133. $this->out->submit(
  134. 'qna-best-answer',
  135. // TRANS: Button text for marking an answer as "best".
  136. _m('BUTTON', 'Best'),
  137. 'submit',
  138. 'best',
  139. // TRANS: Title for button text marking an answer as "best".
  140. _m('Mark this answer as the best answer.')
  141. );
  142. }
  143. }
  144. /*
  145. * @todo FIXME: Revise is disabled until we figure out the
  146. * Ostatus bits This comment is just a reminder
  147. * that the UI for this works.
  148. */
  149. /*
  150. if ($user->id == $this->answer->profile_id) {
  151. $this->out->submit(
  152. 'revise',
  153. // TRANS: Button text for revising an answer.
  154. _m('BUTTON', 'Revise'),
  155. 'submit',
  156. null,
  157. // TRANS: Title for button text for revising an answer.
  158. _m('Revise your answer.')
  159. );
  160. }
  161. */
  162. }
  163. }
  164. /**
  165. * Class of the form.
  166. *
  167. * @return string the form's class
  168. */
  169. function formClass()
  170. {
  171. return 'form_answer_show ajax';
  172. }
  173. }