Elgg  Version 6.1
access.php
Go to the documentation of this file.
1 <?php
14 $entity = elgg_extract('entity', $vars);
15 if (!$entity instanceof ElggEntity) {
16  return;
17 }
18 
19 $access = elgg_extract('access', $vars);
20 if (!isset($access)) {
21  $access = $entity->access_id;
22 }
23 
24 if ($access === false || !elgg_is_logged_in()) {
25  return;
26 }
27 
28 $access = (int) $access;
29 switch ($access) {
30  case ACCESS_PUBLIC:
31  case ACCESS_LOGGED_IN:
32  $icon_name = 'globe';
33  break;
34  case ACCESS_PRIVATE:
35  $icon_name = 'lock';
36  break;
37  default:
38  $icon_name = 'cog';
39  $collection = elgg_get_access_collection($access);
40  if ($collection instanceof \ElggAccessCollection && $collection->getSubtype() === 'friends') {
41  $icon_name = 'user';
42  }
43  break;
44 }
45 
46 $content = elgg_view('output/access', [
47  'value' => $access,
48 ]);
49 
50 echo elgg_view('object/elements/imprint/element', [
51  'icon_name' => elgg_extract('access_icon', $vars, $icon_name),
52  'content' => $content,
53  'class' => 'elgg-listing-access',
54 ]);
elgg_is_logged_in()
Returns whether or not the user is currently logged in.
Definition: sessions.php:43
if(!$entity instanceof ElggEntity) $access
Definition: access.php:19
foreach($keys as $key=> $default_value) $entity
Definition: access.php:44
$icon_name
Definition: element.php:3
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:256
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
if(isset($vars['options_values'])) $vars['class']
Elgg access level input Displays a dropdown input field.
Definition: access.php:26
const ACCESS_PRIVATE
Definition: constants.php:10
const ACCESS_LOGGED_IN
Definition: constants.php:11
const ACCESS_PUBLIC
Definition: constants.php:12
switch($access) $content
Definition: access.php:46
elgg_get_access_collection(int $collection_id)
Get a specified access collection.
Definition: access.php:164