qnalistitem.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2011, StatusNet, Inc.
  5. *
  6. * Adapter to show QnA in a nicer way
  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 QnA
  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. * An adapter to show QnA in a nicer way
  37. *
  38. * @category QnA
  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 QnAListItem extends NoticeListItemAdapter
  46. {
  47. /**
  48. * Custom HTML output for our notices
  49. *
  50. * @param Notice $notice
  51. * @param HTMLOutputter $out
  52. */
  53. function showNotice(Notice $notice, $out)
  54. {
  55. switch ($notice->object_type) {
  56. case QnA_Question::OBJECT_TYPE:
  57. return $this->showNoticeQuestion($notice, $out);
  58. case QnA_Answer::OBJECT_TYPE:
  59. return $this->showNoticeAnswer($notice, $out);
  60. default:
  61. throw new Exception(
  62. // TRANS: Exception thrown when performing an unexpected action on a question.
  63. // TRANS: %s is the unpexpected object type.
  64. sprintf(_m('Unexpected type for QnA plugin: %s.'),
  65. $notice->object_type
  66. )
  67. );
  68. }
  69. }
  70. function showNoticeQuestion(Notice $notice, $out)
  71. {
  72. $user = common_current_user();
  73. // @hack we want regular rendering, then just add stuff after that
  74. $nli = new NoticeListItem($notice, $out);
  75. $nli->showNotice();
  76. $out->elementStart('div', array('class' => 'e-content question-description'));
  77. $question = QnA_Question::getByNotice($notice);
  78. if (!empty($question)) {
  79. $form = new QnashowquestionForm($out, $question);
  80. $form->show();
  81. } else {
  82. // TRANS: Error message displayed when question data is not present.
  83. $out->text(_m('Question data is missing.'));
  84. }
  85. $out->elementEnd('div');
  86. // @fixme
  87. $out->elementStart('div', array('class' => 'e-content'));
  88. }
  89. function showNoticeAnswer(Notice $notice, $out)
  90. {
  91. $user = common_current_user();
  92. $answer = QnA_Answer::getByNotice($notice);
  93. $question = $answer->getQuestion();
  94. $nli = new NoticeListItem($notice, $out);
  95. $nli->showNotice();
  96. $out->elementStart('div', array('class' => 'e-content answer-content'));
  97. if (!empty($answer)) {
  98. $form = new QnashowanswerForm($out, $answer);
  99. $form->show();
  100. } else {
  101. // TRANS: Error message displayed when answer data is not present.
  102. $out->text(_m('Answer data is missing.'));
  103. }
  104. $out->elementEnd('div');
  105. // @todo FIXME
  106. $out->elementStart('div', array('class' => 'e-content'));
  107. }
  108. }