userpicker.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * User Picker. Sends an array of user guids.
  4. *
  5. * @package Elgg
  6. * @subpackage Core
  7. *
  8. * @uses $vars['values'] Array of user guids for already selected users or null
  9. * @uses $vars['limit'] Limit number of users (default 0 = no limit)
  10. * @uses $vars['name'] Name of the returned data array (default "members")
  11. * @uses $vars['handler'] Name of page handler used to power search (default "livesearch")
  12. *
  13. * Defaults to lazy load user lists in alphabetical order. User needs
  14. * to type two characters before seeing the user popup list.
  15. *
  16. * As users are selected they move down to a "users" box.
  17. * When this happens, a hidden input is created to return the GUID in the array with the form
  18. */
  19. if (empty($vars['name'])) {
  20. $vars['name'] = 'members';
  21. }
  22. $name = $vars['name'];
  23. $name = htmlspecialchars($name, ENT_QUOTES, 'UTF-8');
  24. $guids = (array)elgg_extract('values', $vars, array());
  25. if (!$guids) {
  26. // BC with earlier 1.x
  27. if (!empty($vars['value'])) {
  28. elgg_deprecated_notice("The input/userpicker view option 'value' is deprecated. Use 'values'.", "1.12");
  29. $guids = (array)elgg_extract('value', $vars, array());
  30. }
  31. }
  32. $handler = elgg_extract('handler', $vars, 'livesearch');
  33. $handler = htmlspecialchars($handler, ENT_QUOTES, 'UTF-8');
  34. $limit = (int)elgg_extract('limit', $vars, 0);
  35. ?>
  36. <div class="elgg-user-picker" data-limit="<?php echo $limit ?>" data-name="<?php echo $name ?>" data-handler="<?php echo $handler ?>">
  37. <input type="text" class="elgg-input-user-picker" size="30"/>
  38. <input type="checkbox" name="match_on" value="true" />
  39. <?php echo elgg_view('input/hidden', array('name' => $vars['name'])); ?>
  40. <label><?php echo elgg_echo('userpicker:only_friends'); ?></label>
  41. <ul class="elgg-user-picker-list">
  42. <?php
  43. foreach ($guids as $guid) {
  44. $entity = get_entity($guid);
  45. if ($entity) {
  46. echo elgg_view('input/userpicker/item', array(
  47. 'entity' => $entity,
  48. 'input_name' => $vars['name'],
  49. ));
  50. }
  51. }
  52. ?>
  53. </ul>
  54. </div>
  55. <script>
  56. require(['elgg/UserPicker'], function (UserPicker) {
  57. UserPicker.setup('.elgg-user-picker[data-name="<?php echo $name ?>"]');
  58. });
  59. </script>