Elgg  Version 3.0
access.php
Go to the documentation of this file.
1 <?php
19 // bail if set to a unusable value
20 if (isset($vars['options_values'])) {
21  if (!is_array($vars['options_values']) || empty($vars['options_values'])) {
22  return;
23  }
24 }
25 
26 $entity_allows_comments = elgg_extract('entity_allows_comments', $vars, true);
27 unset($vars['entity_allows_comments']);
28 
29 $vars['class'] = elgg_extract_class($vars, 'elgg-input-access');
30 
31 // this will be passed to plugin hooks ['access:collections:write', 'user'] and ['default', 'access']
32 $params = [];
33 
34 $keys = [
35  'entity' => null,
36  'entity_type' => null,
37  'entity_subtype' => null,
38  'container_guid' => null,
39  'purpose' => 'read',
40 ];
41 foreach ($keys as $key => $default_value) {
42  $params[$key] = elgg_extract($key, $vars, $default_value);
43  unset($vars[$key]);
44 }
45 
46 /* @var ElggEntity $entity */
47 $entity = $params['entity'];
48 
49 if ($entity) {
50  $params['value'] = $entity->access_id;
51  $params['entity_type'] = $entity->type;
52  $params['entity_subtype'] = $entity->getSubtype();
53  $params['container_guid'] = $entity->container_guid;
54 
55  if ($entity_allows_comments && ($entity->access_id != ACCESS_PUBLIC)) {
56  $vars['data-comment-count'] = (int) $entity->countComments();
57  $vars['data-original-value'] = $entity->access_id;
58  }
59 }
60 
62 if (!$params['container_guid'] && $container) {
63  $params['container_guid'] = $container->guid;
64 }
65 
66 // don't call get_default_access() unless we need it
67 if (!isset($vars['value']) || $vars['value'] == ACCESS_DEFAULT) {
68  if ($entity) {
69  $vars['value'] = $entity->access_id;
70  } else if (empty($vars['options_values']) || !is_array($vars['options_values'])) {
71  $vars['value'] = get_default_access(null, $params);
72  } else {
73  $options_values_ids = array_keys(elgg_extract('options_values', $vars));
74  $vars['value'] = $options_values_ids[0];
75  }
76 }
77 
78 $params['value'] = elgg_extract('value', $vars);
79 
80 // don't call get_write_access_array() unless we need it
81 if (!isset($vars['options_values'])) {
82  $vars['options_values'] = get_write_access_array(0, 0, false, $params);
83 }
84 
85 if (!isset($vars['disabled'])) {
86  $vars['disabled'] = false;
87 }
88 
89 // if access is set to a value not present in the available options, add the option
90 if (!isset($vars['options_values'][$vars['value']])) {
91  $vars['options_values'][$vars['value']] = get_readable_access_level($vars['value']);
92 }
93 
94 echo elgg_view('input/select', $vars);
foreach($keys as $key=> $default_value) $entity
Definition: access.php:47
const ACCESS_DEFAULT
Definition: constants.php:11
if(isset($vars['options_values'])) $entity_allows_comments
Elgg access level input Displays a dropdown input field.
Definition: access.php:26
get_write_access_array($user_guid=0, $ignored=0, $flush=false, array $input_params=[])
Returns an array of access permissions that the user is allowed to save content with.
Definition: access.php:218
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:1153
$keys
Definition: access.php:34
$params
Definition: access.php:32
if($entity) $container
Definition: access.php:61
elgg echo
Translates a string.
Definition: languages.js:43
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:65
get_readable_access_level($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:397
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:1131
$vars['class']
Definition: access.php:29
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:55
const ACCESS_PUBLIC
Definition: constants.php:14
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:246
get_default_access(ElggUser $user=null, array $input_params=[])
Gets the default access permission.
Definition: access.php:127