access.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Displays HTML with human readable representation of an access level
  4. *
  5. * @uses ElggEntity $vars['entity'] Optional. The entity whose access ID to display. If provided, additional logic is used to determine CSS classes
  6. * @uses int $vars['value'] Optional. Access ID to display.
  7. */
  8. $access_class = 'elgg-access';
  9. //sort out the access level for display
  10. if (isset($vars['entity']) && elgg_instanceof($vars['entity'])) {
  11. $access_id = $vars['entity']->access_id;
  12. // if within a group or shared access collection display group name and open/closed membership status
  13. // @todo have a better way to do this instead of checking against subtype / class.
  14. $container = $vars['entity']->getContainerEntity();
  15. if ($container && $container instanceof ElggGroup) {
  16. // we decided to show that the item is in a group, rather than its actual access level
  17. // not required. Group ACLs are prepended with "Group: " when written.
  18. //$access_id_string = elgg_echo('groups:group') . $container->name;
  19. $membership = $container->membership;
  20. if ($membership == ACCESS_PUBLIC) {
  21. $access_class .= ' elgg-access-group-open';
  22. } else {
  23. $access_class .= ' elgg-access-group-closed';
  24. }
  25. // @todo this is plugin specific code in core. Should be removed.
  26. } elseif ($container && $container->getSubtype() == 'shared_access') {
  27. $access_class .= ' shared_collection';
  28. } elseif ($access_id == ACCESS_PRIVATE) {
  29. $access_class .= ' elgg-access-private';
  30. }
  31. } else if (isset($vars['value'])) {
  32. $access_id = $vars['value'];
  33. }
  34. if (!isset($access_id)) {
  35. return true;
  36. }
  37. $access_id_string = get_readable_access_level($access_id);
  38. $attributes = array(
  39. 'title' => elgg_echo('access:help'),
  40. 'class' => $access_class,
  41. );
  42. echo elgg_format_element('span', $attributes, $access_id_string, array(
  43. 'encode_text' => true,
  44. ));