Elgg  Version 2.3
list.php
Go to the documentation of this file.
1 <?php
2 
22 $items = $vars['items'];
24 $pagination = elgg_extract('pagination', $vars, true);
25 $position = elgg_extract('position', $vars, 'after');
26 $no_results = elgg_extract('no_results', $vars, '');
27 
28 if (!$items && $no_results) {
29  echo elgg_view('page/components/no_results', $vars);
30  return;
31 }
32 
33 if (!is_array($items) || count($items) == 0) {
34  return;
35 }
36 
37 $list_classes = ['elgg-list'];
38 if (isset($vars['list_class'])) {
39  $list_classes[] = $vars['list_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  $guid = $item->guid;
63  $type = $item->type;
64  $subtype = $item->getSubtype();
65 
66  $li_attrs['id'] = "elgg-$type-$guid";
67 
68  $li_attrs['class'][] = "elgg-item-$type";
69  if ($subtype) {
70  $li_attrs['class'][] = "elgg-item-$type-$subtype";
71  }
72  } elseif (is_callable(array($item, 'getType'))) {
73  $type = $item->getType();
74 
75  $li_attrs['id'] = "item-$type-{$item->id}";
76  }
77 
78  $list_items .= elgg_format_element('li', $li_attrs, $item_view);
79  $index++;
80 }
81 
82 if ($position == 'before' || $position == 'both') {
83  echo $nav;
84 }
85 
86 if (empty($list_items) && $no_results) {
87  // there are scenarios where item views do not output html. In those cases show the no results info
88  echo elgg_view('page/components/no_results', $vars);
89 } else {
91 }
92 
93 if ($position == 'after' || $position == 'both') {
94  echo $nav;
95 }
$no_results
Definition: list.php:26
$position
Definition: list.php:25
if(isset($vars['list_class'])) $item_classes
Definition: list.php:42
$list_items
Definition: list.php:50
if(!$items) $item
Definition: delete.php:17
$count
Definition: list.php:23
if(!$items &&$no_results) if(!is_array($items)||count($items)==0) $list_classes
Definition: list.php:37
$subtype
Definition: delete.php:28
$guid
Removes an admin notice.
$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 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
$items
Definition: list.php:11
$pagination
Definition: list.php:24
if(isset($vars['item_class'])) $nav
Definition: list.php:47
$index
Definition: list.php:49
if(!$display_name) $type
Definition: delete.php:27