Elgg  Version 4.3
list.php
Go to the documentation of this file.
1 <?php
20 
21 if (!$items) {
22  echo elgg_view('page/components/no_results', $vars);
23  echo elgg_view('page/components/list/out_of_bounds', $vars);
24  return;
25 }
26 
27 if (!is_array($items) || count($items) == 0) {
28  return;
29 }
30 
31 $position = elgg_extract('position', $vars, 'after');
32 $pagination_behaviour = elgg_extract('pagination_behaviour', $vars, elgg_get_config('pagination_behaviour'));
33 $pagination = (bool) elgg_extract('pagination', $vars, true);
34 if (elgg_in_context('widget')) {
35  // widgets do not show pagination
36  $pagination = false;
37 }
38 
39 $pagination_before_options = (array) elgg_extract('pagination_before_options', $vars, []);
40 unset($vars['pagination_before_options']);
41 $pagination_after_options = (array) elgg_extract('pagination_after_options', $vars, []);
42 unset($vars['pagination_after_options']);
43 
44 if (in_array($pagination_behaviour, ['ajax-append', 'ajax-append-auto'])) {
45  $vars['position'] = $position = 'both';
46 
47  // set before options
48  $pagination_before_options['pagination_show_numbers'] = false;
49  $pagination_before_options['pagination_show_next'] = false;
50  $pagination_before_options['pagination_show_previous'] = true;
51  $pagination_before_options['pagination_previous_text'] = elgg_echo('ajax:pagination:load_more');
52 
53  // set after options
54  $pagination_after_options['pagination_show_numbers'] = false;
55  $pagination_after_options['pagination_show_next'] = true;
56  $pagination_after_options['pagination_show_previous'] = false;
57  $pagination_after_options['pagination_next_text'] = elgg_echo('ajax:pagination:load_more');
58 }
59 
60 $list_classes = elgg_extract_class($vars, 'elgg-list', 'list_class');
61 
62 $list_item_view = elgg_extract('list_item_view', $vars);
64  $list_item_view = 'page/components/list/item';
65 }
66 
67 $index = 0;
69 foreach ($items as $item) {
70  $item_view_vars = $vars;
71  $item_view_vars['list_item_index'] = $index;
72  $item_view = elgg_view_list_item($item, $item_view_vars);
73  if (!$item_view) {
74  continue;
75  }
76 
77  $list_item_vars = $vars;
78  $list_item_vars['content'] = $item_view;
79  $list_item_vars['item'] = $item;
80 
81  $list_items .= elgg_view($list_item_view, $list_item_vars);
82 
83  $index++;
84 }
85 
86 $result = '';
87 if ($pagination && ($position == 'before' || $position == 'both')) {
88  $pagination_options = array_merge($vars, $pagination_before_options);
89  $pagination_options['position'] = 'before';
90 
91  $result .= elgg_view('navigation/pagination', $pagination_options);
92 }
93 
94 if (empty($list_items)) {
95  // there are scenarios where item views do not output html. In those cases show the no results info
96  $result .= elgg_view('page/components/no_results', $vars);
97 } else {
98  $result .= elgg_format_element('ul', ['class' => $list_classes], $list_items);
99 }
100 
101 if ($pagination && ($position == 'after' || $position == 'both')) {
102  $pagination_options = array_merge($vars, $pagination_after_options);
103  $pagination_options['position'] = 'after';
104 
105  $result .= elgg_view('navigation/pagination', $pagination_options);
106 }
107 
109 if (!$pagination && $limit !== false && !empty($items) && count($items) >= $limit) {
110  $result .= elgg_view('page/components/list/widget_more', $vars);
111 }
112 
113 $base_url = elgg_extract('base_url', $vars);
114 if (!empty($base_url)) {
115  // strip offset and limit from base url as they always change when navigating and therefore should not be part of base url
116  $base_url = elgg_http_add_url_query_elements($base_url, ['offset' => null, 'limit' => null]);
117 }
118 
122  elgg_extract('item_view', $vars),
123  elgg_extract('type', $vars),
124  elgg_extract('subtype', $vars),
125  elgg_extract('offset_key', $vars),
126  elgg_extract('pagination_class', $vars),
127  $base_url,
128 ])->getToken();
129 
130 $container_classes = ['elgg-list-container'];
131 if ($pagination && ($pagination_behaviour !== 'navigate')) {
132  $container_classes[] = "elgg-list-container-{$pagination_behaviour}";
133  if ($pagination_behaviour === 'ajax-append-auto') {
134  // make sure default logic for ajax append works
135  $container_classes[] = 'elgg-list-container-ajax-append';
136  }
137 
138  if (elgg_view_exists("page/components/list/{$pagination_behaviour}.js")) {
139  elgg_require_js("page/components/list/{$pagination_behaviour}");
140  }
141 }
142 
143 echo elgg_format_element('div', ['class' => $container_classes, 'id' => "list-container-{$id}"], $result);
if(!$items) $item
Definition: delete.php:13
elgg_http_add_url_query_elements($url, array $elements)
Sets elements in a URL&#39;s query string.
Definition: elgglib.php:481
elgg_view_exists($view, $viewtype= '', $recurse=true)
Returns whether the specified view exists.
Definition: views.php:152
$list_items
Definition: list.php:68
if(elgg_in_context('widget')) $pagination_before_options
Definition: list.php:39
if($pagination &&($position== 'after'||$position== 'both')) $limit
Definition: list.php:108
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:569
$pagination_behaviour
Definition: list.php:32
if(!$pagination &&$limit!==false &&!empty($items)&&count($items) >=$limit) $base_url
Definition: list.php:113
elgg_view_list_item($item, array $vars=[])
View an item in a list.
Definition: views.php:1266
$list_item_view
Definition: list.php:62
elgg_in_context($context)
Check if this context exists anywhere in the stack.
Definition: context.php:78
$items
View a list of items.
Definition: list.php:19
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
Definition: output.php:135
if(!$items) if(!is_array($items)||count($items)==0) $position
Definition: list.php:31
elgg_require_js($name)
Request that Elgg load an AMD module onto the page.
$container_classes
Definition: list.php:130
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:547
$pagination
Definition: list.php:33
if(in_array($pagination_behaviour, ['ajax-append', 'ajax-append-auto'])) $list_classes
Definition: list.php:60
foreach($items as $item) $result
Definition: list.php:86
elgg echo
Translates a string.
Definition: deprecated.js:530
$vars['head']
Definition: html.php:24
if(empty($list_item_view)||!elgg_view_exists($list_item_view)) $index
Definition: list.php:67
elgg_build_hmac($data)
Get an HMAC token builder/validator object.
Definition: actions.php:54
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:179
if($item->getSelected()) $item_view
Definition: item.php:67
elgg_get_config($name, $default=null)
Get an Elgg configuration value.
$pagination_after_options
Definition: list.php:41
if(!empty($base_url)) $id
Definition: list.php:119