Elgg  Version master
gallery.php
Go to the documentation of this file.
1 <?php
20 $pagination = elgg_extract('pagination', $vars, true);
21 $position = elgg_extract('position', $vars, 'after');
22 
23 if (!$items) {
24  echo elgg_view('page/components/no_results', $vars);
25  return;
26 }
27 
28 if (!is_array($items) || count($items) == 0) {
29  return;
30 }
31 
32 elgg_push_context('gallery');
33 
34 $list_classes = elgg_extract_class($vars, 'elgg-gallery', 'gallery_class');
35 
36 $item_classes = elgg_extract_class($vars, 'elgg-item', 'item_class');
37 
38 $nav = ($pagination) ? elgg_view('navigation/pagination', $vars) : '';
39 
40 $index = 0;
42 foreach ($items as $item) {
43  $item_view_vars = $vars;
44  $item_view_vars['list_item_index'] = $index;
45  $item_view = elgg_view_list_item($item, $item_view_vars);
46  if (empty($item_view)) {
47  continue;
48  }
49 
50  $li_attrs = ['class' => $item_classes];
51 
52  if ($item instanceof \ElggEntity) {
53  $li_attrs['id'] = "elgg-{$item->getType()}-{$item->getGUID()}";
54  } else if (is_callable([$item, 'getType'])) {
55  $li_attrs['id'] = "item-{$item->getType()}-{$item->id}";
56  }
57 
59  $index++;
60 }
61 
62 if ($position == 'before' || $position == 'both') {
63  echo $nav;
64 }
65 
66 if (empty($list_items)) {
67  // there are scenarios where item views do not output html. In those cases show the no results info
68  echo elgg_view('page/components/no_results', $vars);
69 } else {
70  echo elgg_format_element('ul', ['class' => $list_classes], $list_items);
71 }
72 
73 if ($position == 'after' || $position == 'both') {
74  echo $nav;
75 }
76 
78 
80 if (!$pagination && $limit !== false && !empty($items) && count($items) >= $limit) {
81  echo elgg_view('page/components/list/widget_more', $vars);
82 }
if(!$items) $item
Definition: delete.php:13
$limit
Definition: gallery.php:79
$items
Gallery view.
Definition: gallery.php:19
$pagination
Definition: gallery.php:20
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:276
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
elgg_pop_context()
Removes and returns the top context string from the stack.
Definition: context.php:62
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:177
$item_view
elgg_view_list_item($item, array $vars=[])
View an item in a list.
Definition: views.php:1253
$li_attrs
Definition: item.php:13
elgg_push_context(string $context)
Push a context onto the top of the stack.
Definition: context.php:52
$position
Definition: gallery.php:21
$vars
Definition: theme.php:5
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:145
$index
Definition: gallery.php:40
$item_classes
Definition: gallery.php:36
$nav
Definition: gallery.php:38
$list_items
Definition: gallery.php:41
$list_classes
Definition: gallery.php:34