entity.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Discussion reply view for an entity returned in a search
  4. *
  5. * Display largely controlled by a set of overrideable volatile data:
  6. * - search_icon (defaults to entity icon)
  7. * - search_matched_title
  8. * - search_matched_description
  9. * - search_matched_extra
  10. * - search_url (defaults to entity->getURL())
  11. * - search_time (defaults to entity->time_updated or entity->time_created)
  12. *
  13. * @uses $vars['entity'] Entity returned in a search
  14. */
  15. $entity = $vars['entity'];
  16. if (empty($entity) || !elgg_instanceof($entity, 'object', 'discussion_reply')) {
  17. return;
  18. }
  19. $topic = $entity->getContainerEntity();
  20. if (empty($topic) || !elgg_instanceof($topic, 'object', 'groupforumtopic')) {
  21. return;
  22. }
  23. $icon = $entity->getVolatileData('search_icon');
  24. if (!$icon) {
  25. // display the entity's owner by default if available.
  26. // @todo allow an option to switch to displaying the entity's icon instead.
  27. $type = $entity->getType();
  28. if ($type == 'user' || $type == 'group') {
  29. $icon = elgg_view_entity_icon($entity, 'tiny');
  30. } elseif ($owner = $entity->getOwnerEntity()) {
  31. $icon = elgg_view_entity_icon($owner, 'tiny');
  32. } else {
  33. // display a generic icon if no owner, though there will probably be
  34. // other problems if the owner can't be found.
  35. $icon = elgg_view_entity_icon($entity, 'tiny');
  36. }
  37. }
  38. $title = $entity->getVolatileData('search_matched_title');
  39. $description = $entity->getVolatileData('search_matched_description');
  40. $extra_info = $entity->getVolatileData('search_matched_extra');
  41. $url = $entity->getVolatileData('search_url');
  42. if (!$title) {
  43. $title = elgg_echo('discussion:search:title', array($topic->title));
  44. }
  45. if (!$url) {
  46. $url = $topic->getURL();
  47. }
  48. $title = "<a href=\"$url\">$title</a>";
  49. $time = $entity->getVolatileData('search_time');
  50. if (!$time) {
  51. $tc = $entity->time_created;
  52. $tu = $entity->time_updated;
  53. $time = elgg_view_friendly_time(($tu > $tc) ? $tu : $tc);
  54. }
  55. $body = "<p class=\"mbn\">$title</p>$description";
  56. if ($extra_info) {
  57. $body .= "<p class=\"elgg-subtext\">$extra_info</p>";
  58. }
  59. $body .= "<p class=\"elgg-subtext\">$time</p>";
  60. echo elgg_view_image_block($icon, $body);