create_single_image.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Batch river view; showing only the thumbnail of the first image of the badge
  4. *
  5. * @author Cash Costello
  6. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
  7. *
  8. */
  9. $batch = $vars['item']->getObjectEntity();
  10. // Count images in batch
  11. $images_count = elgg_get_entities_from_relationship(array(
  12. 'relationship' => 'belongs_to_batch',
  13. 'relationship_guid' => $batch->getGUID(),
  14. 'inverse_relationship' => true,
  15. 'type' => 'object',
  16. 'subtype' => 'image',
  17. 'offset' => 0,
  18. 'count' => true
  19. ));
  20. // Get first image related to this batch
  21. $images = elgg_get_entities_from_relationship(array(
  22. 'relationship' => 'belongs_to_batch',
  23. 'relationship_guid' => $batch->getGUID(),
  24. 'inverse_relationship' => true,
  25. 'type' => 'object',
  26. 'subtype' => 'image',
  27. 'offset' => 0,
  28. 'limit' => 1,
  29. ));
  30. $album = $batch->getContainerEntity();
  31. if (!$album) {
  32. // something went quite wrong - this batch has no associated album
  33. return true;
  34. }
  35. $album_link = elgg_view('output/url', array(
  36. 'href' => $album->getURL(),
  37. 'text' => $album->getTitle(),
  38. 'is_trusted' => true,
  39. ));
  40. $subject = $vars['item']->getSubjectEntity();
  41. $subject_link = elgg_view('output/url', array(
  42. 'href' => $subject->getURL(),
  43. 'text' => $subject->name,
  44. 'class' => 'elgg-river-subject',
  45. 'is_trusted' => true,
  46. ));
  47. if ($images) {
  48. $attachments = elgg_view_entity_icon($images[0], 'tiny');
  49. $image_link = elgg_view('output/url', array(
  50. 'href' => $images[0]->getURL(),
  51. 'text' => $images[0]->getTitle(),
  52. 'is_trusted' => true,
  53. ));
  54. }
  55. if ($images_count > 1) {
  56. // View the comments of the album
  57. $vars['item']->object_guid = $album->guid;
  58. $responses = elgg_view('river/elements/responses', $vars);
  59. if ($responses) {
  60. $responses = "<div class=\"elgg-river-responses\">$responses</div>";
  61. }
  62. echo elgg_view('river/elements/layout', array(
  63. 'item' => $vars['item'],
  64. 'attachments' => $attachments,
  65. 'summary' => elgg_echo('image:river:created_single_entry', array($subject_link, $image_link, $images_count-1, $album_link)),
  66. ));
  67. } else {
  68. // View the comments of the image
  69. $vars['item']->object_guid = $images[0]->guid;
  70. $responses = elgg_view('river/elements/responses', $vars);
  71. if ($responses) {
  72. $responses = "<div class=\"elgg-river-responses\">$responses</div>";
  73. }
  74. echo elgg_view('river/elements/layout', array(
  75. 'item' => $vars['item'],
  76. 'attachments' => $attachments,
  77. 'summary' => elgg_echo('image:river:created', array($subject_link, $image_link, $album_link)),
  78. ));
  79. }