entity.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Default 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 = elgg_extract('entity', $vars);
  16. if (!($entity instanceof ElggAnswer)) {
  17. return;
  18. }
  19. $question = $entity->getContainerEntity();
  20. // entity icon
  21. $icon = $entity->getVolatileData('search_icon');
  22. if (!$icon) {
  23. // display the entity's owner by default if available.
  24. $owner = $entity->getOwnerEntity();
  25. $icon = elgg_view_entity_icon($owner, 'tiny');
  26. }
  27. // search results
  28. $description = $entity->getVolatileData('search_matched_description');
  29. $extra_info = $entity->getVolatileData('search_matched_extra');
  30. $url = $entity->getVolatileData('search_url');
  31. if (!$url) {
  32. $url = $entity->getURL();
  33. }
  34. // make title
  35. $answer_link = elgg_view('output/url', [
  36. 'text' => elgg_echo('questions:search:answer:title'),
  37. 'href' => $entity->getURL(),
  38. 'is_trusted' => true,
  39. ]);
  40. $question_link = elgg_view('output/url', [
  41. 'text' => $question->title,
  42. 'href' => $question->getURL(),
  43. 'is_trusted' => true,
  44. ]);
  45. $title = elgg_echo('generic_comment:on', [$answer_link, $question_link]);
  46. // question in a group?
  47. $question_container = $question->getContainerEntity();
  48. if (($question_container instanceof ElggGroup) && (elgg_get_page_owner_guid() !== $question_container->getGUID())) {
  49. $group_link = elgg_view('output/url', [
  50. 'text' => $question_container->name,
  51. 'href' => $question_container->getURL(),
  52. 'is_trusted' => true,
  53. ]);
  54. $title .= ' ' . elgg_echo('river:ingroup', [$group_link]);
  55. }
  56. // time part
  57. $time = $entity->getVolatileData('search_time');
  58. if (!$time) {
  59. $tc = $entity->time_created;
  60. $tu = $entity->time_updated;
  61. $time = elgg_view_friendly_time(($tu > $tc) ? $tu : $tc);
  62. }
  63. // build result
  64. $body = elgg_format_element('p', ['class' => 'mbn'], $title);
  65. $body .= $description;
  66. if ($extra_info) {
  67. $body .= elgg_format_element('p', ['class' => 'elgg-subtext'], $extra_info);
  68. }
  69. $body .= elgg_format_element('p', ['class' => 'elgg-subtext'], $time);
  70. echo elgg_view_image_block($icon, $body);