Elgg  Version master
access.php
Go to the documentation of this file.
1 <?php
9 $class = elgg_extract_class($vars, 'elgg-access');
11 
12 $entity = elgg_extract('entity', $vars);
13 if ($entity instanceof \ElggEntity) {
14  $access_id = $entity->access_id;
15 }
16 
17 if (!isset($access_id)) {
18  return;
19 }
20 
21 $access_id = (int) $access_id;
22 switch ($access_id) {
23  case ACCESS_PUBLIC:
24  $class[] = 'elgg-access-public';
25  break;
26 
27  case ACCESS_LOGGED_IN:
28  $class[] = 'elgg-access-loggedin';
29  break;
30 
31  case ACCESS_PRIVATE:
32  $class[] = 'elgg-access-private';
33  break;
34 
35  default:
37  $owner = false;
38  if ($collection) {
39  $owner = $collection->getOwnerEntity();
40  }
41 
42  if ($owner instanceof ElggGroup) {
43  $class[] = 'elgg-access-group';
44  $membership = $owner->membership;
45  if ($membership == ACCESS_PUBLIC) {
46  $class[] = 'elgg-access-group-open';
47  } else {
48  $class[] = 'elgg-access-group-closed';
49  }
50  } else {
51  if ($collection && !empty($collection->getSubtype())) {
52  $class[] = 'elgg-access-' . elgg_get_friendly_title($collection->getSubtype());
53  } else {
54  $class[] = 'elgg-access-limited';
55  }
56  }
57  break;
58 }
59 
60 echo elgg_format_element('span', [
61  'title' => elgg_echo('access:help'),
62  'class' => $class,
64  'encode_text' => true,
65 ]);
foreach($keys as $key=> $default_value) $entity
Definition: access.php:44
$owner
Definition: upload.php:7
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
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:254
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
elgg_get_friendly_title(string $title)
When given a title, returns a version suitable for inclusion in a URL.
Definition: output.php:192
elgg_get_readable_access_level(int $entity_access_id)
Return the name of an ACCESS_* constant or an access collection, but only if the logged in user has w...
Definition: access.php:196
$access_id
Definition: access.php:10
const ACCESS_PUBLIC
Definition: constants.php:12
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:145
elgg_extract_class(array $array, array|string $existing=[], string $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:277
$class
Displays HTML with human readable representation of an access level.
Definition: access.php:9
elgg_get_access_collection(int $collection_id)
Get a specified access collection.
Definition: access.php:164