Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
gallery.php
Go to the documentation of this file.
1 <?php
2 
20 $items = $vars['items'];
22 $pagination = elgg_extract('pagination', $vars, true);
23 $position = elgg_extract('position', $vars, 'after');
24 $no_results = elgg_extract('no_results', $vars, '');
25 
26 if (!$items && $no_results) {
27  echo elgg_view('page/components/no_results', $vars);
28  return;
29 }
30 
31 if (!is_array($items) || count($items) == 0) {
32  return;
33 }
34 
35 elgg_push_context('gallery');
36 
37 $list_classes = ['elgg-gallery'];
38 if (isset($vars['gallery_class'])) {
39  $list_classes[] = $vars['gallery_class'];
40 }
41 
42 $item_classes = ['elgg-item'];
43 if (isset($vars['item_class'])) {
44  $item_classes[] = $vars['item_class'];
45 }
46 
47 $nav = ($pagination) ? elgg_view('navigation/pagination', $vars) : '';
48 
50 foreach ($items as $item) {
51  $item_view = elgg_view_list_item($item, $vars);
52  if (!$item_view) {
53  continue;
54  }
55 
56  $li_attrs = ['class' => $item_classes];
57 
58  if ($item instanceof \ElggEntity) {
59  $li_attrs['id'] = "elgg-{$item->getType()}-{$item->getGUID()}";
60  } else if (is_callable(array($item, 'getType'))) {
61  $li_attrs['id'] = "item-{$item->getType()}-{$item->id}";
62  }
63 
64  $list_items .= elgg_format_element('li', $li_attrs, $item_view);
65 }
66 
67 if ($position == 'before' || $position == 'both') {
68  echo $nav;
69 }
70 
71 if (empty($list_items) && $no_results) {
72  // there are scenarios where item views do not output html. In those cases show the no results info
73  echo elgg_view('page/components/no_results', $vars);
74 } else {
75  echo elgg_format_element('ul', ['class' => $list_classes], $list_items);
76 }
77 
78 if ($position == 'after' || $position == 'both') {
79  echo $nav;
80 }
81 
$items
Gallery view.
Definition: gallery.php:20
$pagination
Definition: gallery.php:22
$count
Definition: gallery.php:21
if(isset($vars['item_class'])) $nav
Definition: gallery.php:47
$vars['entity']
elgg_format_element($tag_name, array $attributes=array(), $text= '', array $options=array())
Format an HTML element.
Definition: output.php:218
elgg_view_list_item($item, array $vars=array())
View an item in a list.
Definition: views.php:1422
$item
Definition: item.php:12
elgg_pop_context()
Removes and returns the top context string from the stack.
Definition: pageowner.php:225
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
Definition: views.php:342
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1310
$no_results
Definition: gallery.php:24
elgg_push_context($context)
Push a context onto the top of the stack.
Definition: pageowner.php:215
$position
Definition: gallery.php:23
if(isset($vars['gallery_class'])) $item_classes
Definition: gallery.php:42
$list_items
Definition: gallery.php:49
$list_classes
Definition: gallery.php:37