Elgg  Version 3.0
userpicker.php
Go to the documentation of this file.
1 <?php
25 $name = elgg_extract('name', $vars, 'members', false);
26 
27 $guids = (array) elgg_extract('values', $vars, elgg_extract('value', $vars, []));
28 
29 $params = elgg_extract('options', $vars, []);
30 
31 $friends_only = (bool) elgg_extract('only_friends', $vars, false);
32 $show_friends = (bool) elgg_extract('show_friends', $vars, !$friends_only);
33 if ($friends_only) {
34  $params['friends_only'] = true;
35 }
36 
37 $params['include_banned'] = (bool) elgg_extract('include_banned', $vars, false);
38 
39 if (!empty($params)) {
40  ksort($params);
41 
42  // We sign custom parameters, so that plugins can validate
43  // that the request is unaltered, if needed
45  $params['mac'] = $mac->getToken();
46 }
47 
48 $handler = elgg_extract('handler', $vars, 'livesearch');
49 $params['view'] = 'json'; // force json viewtype
51 
52 $limit = (int) elgg_extract('limit', $vars, 0);
53 
54 $attrs = [
55  'class' => elgg_extract_class($vars, ['elgg-user-picker']),
56  'data-limit' => $limit,
57  'data-name' => $name,
58  'data-handler' => $handler,
59 ];
60 
61 ?>
62 <div <?= elgg_format_attributes($attrs) ?>>
63  <input type="text" class="elgg-input-user-picker" size="30" />
64  <?php
65 
66  echo elgg_view('input/hidden', ['name' => $name]);
67 
68  if ($show_friends) {
69  echo elgg_view('input/checkbox', [
70  'name' => 'match_on',
71  'value' => 'friends',
72  'default' => elgg_extract('match_on', $vars, 'users', false),
73  'label' => elgg_echo('userpicker:only_friends'),
74  ]);
75  } elseif ($friends_only) {
76  echo elgg_view('input/hidden', [
77  'name' => 'match_on',
78  'value' => 'friends',
79  ]);
80  } else {
81  echo elgg_view('input/hidden', [
82  'name' => 'match_on',
83  'value' => elgg_extract('match_on', $vars, 'users', false),
84  ]);
85  }
86  ?>
87  <ul class="elgg-list elgg-user-picker-list">
88  <?php
89  foreach ($guids as $guid) {
90  $entity = get_entity($guid);
91  if ($entity) {
92  echo elgg_view('input/autocomplete/item', [
93  'entity' => $entity,
94  'input_name' => $name,
95  ]);
96  }
97  }
98  ?>
99  </ul>
100 </div>
101 <script>
102  require(['elgg/UserPicker'], function (UserPicker) {
103  var name = <?= json_encode($name) ?>;
104  UserPicker.setup('.elgg-user-picker[data-name="' + name + '"]');
105  });
106 </script>
elgg_http_add_url_query_elements($url, array $elements)
Sets elements in a URL&#39;s query string.
Definition: elgglib.php:942
$guids
Definition: userpicker.php:27
$friends_only
Definition: userpicker.php:31
$attrs
Definition: userpicker.php:54
if(!empty($params)) $handler
Definition: userpicker.php:48
$guid
Removes an admin notice.
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
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
$limit
Definition: userpicker.php:52
$entity
Definition: reset.php:8
elgg echo
Translates a string.
Definition: languages.js:43
elgg require
Throw an error if the required package isn&#39;t present.
Definition: elgglib.js:164
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif(is_callable([$item, 'getType']))
Definition: item.php:39
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
$site name
$vars['type']
Definition: save.php:11
$params
Definition: userpicker.php:29
$show_friends
Definition: userpicker.php:32
elgg_build_hmac($data)
Get an HMAC token builder/validator object.
Definition: actions.php:62
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:246
$name
Definition: userpicker.php:25
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:87