Elgg  Version 1.9
list.php
Go to the documentation of this file.
1 <?php
20 $items = $vars['items'];
21 $offset = elgg_extract('offset', $vars);
24 $base_url = elgg_extract('base_url', $vars, '');
25 $pagination = elgg_extract('pagination', $vars, true);
26 $offset_key = elgg_extract('offset_key', $vars, 'offset');
27 $position = elgg_extract('position', $vars, 'after');
28 $no_results = elgg_extract('no_results', $vars, '');
29 
30 if (!$items && $no_results) {
31  echo "<p>$no_results</p>";
32  return;
33 }
34 
35 if (!is_array($items) || count($items) == 0) {
36  return;
37 }
38 
39 $list_class = 'elgg-list';
40 if (isset($vars['list_class'])) {
41  $list_class = "$list_class {$vars['list_class']}";
42 }
43 
44 $item_class = 'elgg-item';
45 if (isset($vars['item_class'])) {
46  $item_class = "$item_class {$vars['item_class']}";
47 }
48 
49 $html = "";
50 $nav = "";
51 
52 if ($pagination && $count) {
53  $nav .= elgg_view('navigation/pagination', array(
54  'base_url' => $base_url,
55  'offset' => $offset,
56  'count' => $count,
57  'limit' => $limit,
58  'offset_key' => $offset_key,
59  ));
60 }
61 
62 $html .= "<ul class=\"$list_class\">";
63 foreach ($items as $item) {
64  $li = elgg_view_list_item($item, $vars);
65  if ($li) {
66  $item_classes = array($item_class);
67 
68  if (elgg_instanceof($item)) {
69  $id = "elgg-{$item->getType()}-{$item->getGUID()}";
70 
71  $item_classes[] = "elgg-item-" . $item->getType();
72  $subtype = $item->getSubType();
73  if ($subtype) {
74  $item_classes[] = "elgg-item-" . $item->getType() . "-" . $subtype;
75  }
76  } else {
77  $id = "item-{$item->getType()}-{$item->id}";
78  }
79 
80  $item_classes = implode(" ", $item_classes);
81 
82  $html .= "<li id=\"$id\" class=\"$item_classes\">$li</li>";
83  }
84 }
85 $html .= '</ul>';
86 
87 if ($position == 'before' || $position == 'both') {
88  $html = $nav . $html;
89 }
90 
91 if ($position == 'after' || $position == 'both') {
92  $html .= $nav;
93 }
94 
95 echo $html;
$no_results
Definition: list.php:28
$position
Definition: list.php:27
if(!$items &&$no_results) if(!is_array($items)||count($items)==0) $list_class
Definition: list.php:39
$count
Definition: list.php:23
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:1464
elgg_view_list_item($item, array $vars=array())
View an item in a list.
Definition: views.php:1345
elgg_instanceof($entity, $type=null, $subtype=null, $class=null)
Checks if $entity is an ElggEntity and optionally for type and subtype.
Definition: entities.php:1886
$nav
Definition: list.php:50
$item
Definition: item.php:12
elgg echo
Translates a string.
Definition: languages.js:43
$limit
Definition: list.php:22
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:25
$offset_key
Definition: list.php:26
if(isset($vars['item_class'])) $html
Definition: list.php:49
if(isset($vars['list_class'])) $item_class
Definition: list.php:44
$subtype
Definition: river.php:10
if(!$collection_name) $id
Definition: add.php:17
$base_url
Definition: list.php:24
$offset
Definition: list.php:21
if(file_exists($welcome)) $vars
Definition: upgrade.php:93