Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
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 
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  $guid = $item->getGUID();
60  $type = $item->getType();
61  $subtype = $item->getSubtype();
62 
63  $li_attrs['id'] = "elgg-$type-$guid";
64 
65  $li_attrs['class'][] = "elgg-item-$type";
66  if ($subtype) {
67  $li_attrs['class'][] = "elgg-item-$type-$subtype";
68  }
69  } else if (is_callable(array($item, 'getType'))) {
70  $li_attrs['id'] = "item-{$item->getType()}-{$item->id}";
71  }
72 
73  $list_items .= elgg_format_element('li', $li_attrs, $item_view);
74 }
75 
76 if ($position == 'before' || $position == 'both') {
77  echo $nav;
78 }
79 
80 if (empty($list_items) && $no_results) {
81  // there are scenarios where item views do not output html. In those cases show the no results info
82  echo elgg_view('page/components/no_results', $vars);
83 } else {
84  echo elgg_format_element('ul', ['class' => $list_classes], $list_items);
85 }
86 
87 if ($position == 'after' || $position == 'both') {
88  echo $nav;
89 }
$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:49
$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: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_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
$items
Definition: list.php:11
$pagination
Definition: list.php:24
if(isset($vars['item_class'])) $nav
Definition: list.php:47
if(!$display_name) $type
Definition: delete.php:27