discussion_replies.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Displays discussion replies for a discussion river item
  4. */
  5. $topic = elgg_extract('topic', $vars);
  6. $options = array(
  7. 'type' => 'object',
  8. 'subtype' => 'discussion_reply',
  9. 'container_guid' => $topic->guid,
  10. 'count' => true,
  11. 'distinct' => false,
  12. );
  13. $count = elgg_get_entities($options);
  14. if ($count) {
  15. $replies = elgg_get_entities(array_merge($options, [
  16. 'order_by' => 'e.time_created desc',
  17. 'count' => false,
  18. 'limit' => 3,
  19. ]));
  20. // why is this reversing it? because we're asking for the 3 latest
  21. // comments by sorting desc and limiting by 3, but we want to display
  22. // these comments with the latest at the bottom.
  23. $replies = array_reverse($replies);
  24. echo elgg_view_entity_list($replies, array('list_class' => 'elgg-river-comments'));
  25. if ($count > 3) {
  26. $more_count = $count - 3;
  27. $params = array(
  28. 'href' => $topic->getURL(),
  29. 'text' => elgg_echo('river:comments:more', array($more_count)),
  30. 'is_trusted' => true,
  31. );
  32. $link = elgg_view('output/url', $params);
  33. echo "<div class=\"elgg-river-more\">$link</div>";
  34. }
  35. }
  36. $form_vars = array('id' => "discussion-reply-{$topic->guid}", 'class' => 'hidden');
  37. $body_vars = array('topic' => $topic, 'inline' => true);
  38. echo elgg_view_form('discussion/reply/save', $form_vars, $body_vars);