Elgg  Version 1.11
list.php
Go to the documentation of this file.
1 <?php
2 
21 $items = $vars['items'];
23 $pagination = elgg_extract('pagination', $vars, true);
24 $position = elgg_extract('position', $vars, 'after');
25 $no_results = elgg_extract('no_results', $vars, '');
26 
27 if (!$items && $no_results) {
28  if ($no_results instanceof Closure) {
29  echo $no_results();
30  return;
31  }
32  echo "<p class='elgg-no-results'>$no_results</p>";
33  return;
34 }
35 
36 if (!is_array($items) || count($items) == 0) {
37  return;
38 }
39 
40 $list_classes = ['elgg-list'];
41 if (isset($vars['list_class'])) {
42  $list_classes[] = $vars['list_class'];
43 }
44 
45 $item_classes = ['elgg-item'];
46 if (isset($vars['item_class'])) {
47  $item_classes[] = $vars['item_class'];
48 }
49 
50 $nav = ($pagination) ? elgg_view('navigation/pagination', $vars) : '';
51 
53 foreach ($items as $item) {
54  $item_view = elgg_view_list_item($item, $vars);
55  if (!$item_view) {
56  continue;
57  }
58 
59  $li_attrs = ['class' => $item_classes];
60 
61  if ($item instanceof \ElggEntity) {
62  $guid = $item->getGUID();
63  $type = $item->getType();
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  } else if (is_callable(array($item, 'getType'))) {
73  $li_attrs['id'] = "item-{$item->getType()}-{$item->id}";
74  }
75 
76  $list_items .= elgg_format_element('li', $li_attrs, $item_view);
77 }
78 
79 if ($position == 'before' || $position == 'both') {
80  echo $nav;
81 }
82 
84 
85 if ($position == 'after' || $position == 'both') {
86  echo $nav;
87 }
$no_results
Definition: list.php:25
$position
Definition: list.php:24
if(isset($vars['list_class'])) $item_classes
Definition: list.php:45
$list_items
Definition: list.php:52
$count
Definition: list.php:22
if(!$items &&$no_results) if(!is_array($items)||count($items)==0) $list_classes
Definition: list.php:40
$guid
Removes an admin notice.
elgg_extract($key, array $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1246
elgg_format_element($tag_name, array $attributes=array(), $text= '', array $options=array())
Format an HTML element.
Definition: output.php:215
elgg_view_list_item($item, array $vars=array())
View an item in a list.
Definition: views.php:1378
$item
Definition: item.php:12
elgg echo
Translates a string.
Definition: languages.js:43
$type
Definition: add.php:8
elgg_view($view, $vars=array(), $bypass=false, $ignored=false, $viewtype= '')
Return a parsed view.
Definition: views.php:354
$items
Definition: list.php:11
$pagination
Definition: list.php:23
if(isset($vars['item_class'])) $nav
Definition: list.php:50
$subtype
Definition: river.php:12
if(file_exists($welcome)) $vars
Definition: upgrade.php:93