Elgg  Version 4.3
userpicker.php
Go to the documentation of this file.
1 <?php
23 $name = elgg_extract('name', $vars, 'members', false);
24 
25 $guids = (array) elgg_extract('values', $vars, elgg_extract('value', $vars, []));
26 
27 $params = elgg_extract('options', $vars, []);
28 
29 $friends_only = (bool) elgg_extract('only_friends', $vars, false);
30 $show_friends = (bool) elgg_extract('show_friends', $vars, !$friends_only);
31 if ($friends_only) {
32  $params['friends_only'] = true;
33 }
34 
35 $params['include_banned'] = (bool) elgg_extract('include_banned', $vars, false);
36 
37 if (!empty($params)) {
38  ksort($params);
39 
40  // We sign custom parameters, so that plugins can validate
41  // that the request is unaltered, if needed
43  $params['mac'] = $mac->getToken();
44 }
45 
46 $handler = elgg_extract('handler', $vars, 'livesearch');
47 $params['view'] = 'json'; // force json viewtype
48 
50  'class' => elgg_extract_class($vars, ['elgg-user-picker']),
51  'data-limit' => (int) elgg_extract('limit', $vars, 0),
52  'data-name' => $name,
54 ];
55 
57  'type' => 'text',
58  'class' => 'elgg-input-user-picker',
59  'size' => 30,
60  'placeholder' => elgg_extract('placeholder', $vars),
61 ]);
62 
63 $picker .= elgg_view('input/hidden', ['name' => $name]);
64 
65 if ($show_friends) {
66  $picker .= elgg_view('input/checkbox', [
67  'name' => 'match_on',
68  'value' => 'friends',
69  'default' => elgg_extract('match_on', $vars, 'users', false),
70  'label' => elgg_echo('userpicker:only_friends'),
71  ]);
73  $wrapper_options['data-match-on'] = 'friends';
74 } else {
75  $wrapper_options['data-match-on'] = elgg_extract('match_on', $vars, 'users', false);
76 }
77 
78 $items = '';
79 foreach ($guids as $guid) {
80  $entity = get_entity($guid);
81  if ($entity) {
82  $items .= elgg_view('input/autocomplete/item', [
83  'entity' => $entity,
84  'input_name' => $name,
85  ]);
86  }
87 }
88 
89 $picker .= elgg_format_element('ul', ['class' => 'elgg-list elgg-user-picker-list'], $items);
90 
92 
93 ?>
94 <script>
95  require(['elgg/UserPicker'], function (UserPicker) {
96  var name = <?= json_encode($name) ?>;
97  UserPicker.setup('.elgg-user-picker[data-name="' + name + '"]');
98  });
99 </script>
elgg_http_add_url_query_elements($url, array $elements)
Sets elements in a URL&#39;s query string.
Definition: elgglib.php:481
$guids
Definition: userpicker.php:25
$site name
Definition: settings.php:21
$friends_only
Definition: userpicker.php:29
$picker
Definition: userpicker.php:56
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
$wrapper_options
Definition: userpicker.php:49
$entity
Definition: reset.php:8
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
Definition: output.php:135
elgg require
Throw an error if the required package isn&#39;t present.
Definition: deprecated.js:176
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
$items
Definition: userpicker.php:78
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
if(!empty($params)) $handler
Definition: userpicker.php:46
elgg echo
Translates a string.
Definition: deprecated.js:530
$vars['head']
Definition: html.php:24
$params
Definition: userpicker.php:27
$show_friends
Definition: userpicker.php:30
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
$guid
Reset an ElggUpgrade.
Definition: reset.php:6
$name
User Picker.
Definition: userpicker.php:23
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:69