answer.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. $answer = elgg_extract('entity', $vars);
  3. if (!($answer instanceof ElggAnswer)) {
  4. return;
  5. }
  6. $question = $answer->getContainerEntity();
  7. $image = elgg_view_entity_icon($answer->getOwnerEntity(), 'small');
  8. // mark this as the correct answer?
  9. $correct_answer = $answer->getCorrectAnswerMetadata();
  10. if ($correct_answer) {
  11. $owner = $correct_answer->getOwnerEntity();
  12. $owner_name = htmlspecialchars($owner->name);
  13. $timestamp = htmlspecialchars(date(elgg_echo('friendlytime:date_format'), $correct_answer->time_created));
  14. $title = elgg_echo('questions:answer:checkmark:title', [$owner_name, $timestamp]);
  15. $image .= elgg_format_element('div', ['class' => 'questions-checkmark', 'title' => $title]);
  16. }
  17. // create subtitle
  18. $owner = $answer->getOwnerEntity();
  19. $owner_link = elgg_view('output/url', [
  20. 'text' => $owner->name,
  21. 'href' => $owner->getURL(),
  22. 'is_trusted' => true
  23. ]);
  24. $friendly_time = elgg_view_friendly_time($answer->time_created);
  25. $subtitle = $owner_link . ' ' . $friendly_time;
  26. // build entity menu
  27. $entity_menu = elgg_view_menu('entity', [
  28. 'entity' => $answer,
  29. 'handler' => 'answers',
  30. 'sort_by' => 'priority',
  31. 'class' => 'elgg-menu-hz',
  32. ]);
  33. $body = elgg_view('output/longtext', ['value' => $answer->description]);
  34. // show comments?
  35. if ($question->comments_enabled !== 'off') {
  36. $comment_count = $answer->countComments();
  37. if ($comment_count) {
  38. $comment_options = [
  39. 'type' => 'object',
  40. 'subtype' => 'comment',
  41. 'container_guid' => $answer->getGUID(),
  42. 'limit' => false,
  43. 'list_class' => 'elgg-river-comments',
  44. 'distinct' => false,
  45. 'full_view' => true,
  46. ];
  47. $body .= elgg_format_element('h3', ['class' => 'elgg-river-comments-tab mtm'], elgg_echo('comments'));
  48. $body .= elgg_list_entities($comment_options);
  49. }
  50. if ($answer->canComment()) {
  51. // show a comment form like in the river
  52. $body_vars = [
  53. 'entity' => $answer,
  54. 'inline' => true,
  55. ];
  56. $form = elgg_view_form('comment/save', [], $body_vars);
  57. $body .= elgg_format_element('div', ['class' => ['elgg-river-item', 'hidden'], 'id' => "comments-add-{$answer->getGUID()}"], $form);
  58. }
  59. }
  60. // build content
  61. $params = [
  62. 'entity' => $answer,
  63. 'title' => false,
  64. 'metadata' => $entity_menu,
  65. 'subtitle' => $subtitle,
  66. 'content' => $body,
  67. ];
  68. $summary = elgg_view('page/components/summary', $params);
  69. echo elgg_view_image_block($image, $summary);