Elgg  Version 2.3
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 
49 $index = 0;
51 foreach ($items as $item) {
52  $item_view_vars = $vars;
53  $item_view_vars['list_item_index'] = $index;
54  $item_view = elgg_view_list_item($item, $item_view_vars);
55  if (!$item_view) {
56  continue;
57  }
58 
59  $li_attrs = ['class' => $item_classes];
60 
61  if ($item instanceof \ElggEntity) {
62  $li_attrs['id'] = "elgg-{$item->getType()}-{$item->getGUID()}";
63  } else if (is_callable(array($item, 'getType'))) {
64  $li_attrs['id'] = "item-{$item->getType()}-{$item->id}";
65  }
66 
67  $list_items .= elgg_format_element('li', $li_attrs, $item_view);
68  $index++;
69 }
70 
71 if ($position == 'before' || $position == 'both') {
72  echo $nav;
73 }
74 
75 if (empty($list_items) && $no_results) {
76  // there are scenarios where item views do not output html. In those cases show the no results info
77  echo elgg_view('page/components/no_results', $vars);
78 } else {
80 }
81 
82 if ($position == 'after' || $position == 'both') {
83  echo $nav;
84 }
85 
$items
Gallery view.
Definition: gallery.php:20
if(!$items) $item
Definition: delete.php:17
$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:208
elgg_view_list_item($item, array $vars=array())
View an item in a list.
Definition: views.php:1557
elgg_pop_context()
Removes and returns the top context string from the stack.
Definition: pageowner.php:225
elgg echo
Translates a string.
Definition: languages.js:48
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
Definition: views.php:336
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:1375
$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
$index
Definition: gallery.php:49
if(isset($vars['gallery_class'])) $item_classes
Definition: gallery.php:42
$list_items
Definition: gallery.php:50
$list_classes
Definition: gallery.php:37