Elgg  Version 1.9
GroupItemVisibility.php
Go to the documentation of this file.
1 <?php
2 
13 
14  const REASON_NON_MEMBER = 'non_member';
15  const REASON_LOGGED_OUT = 'logged_out';
16  const REASON_NO_ACCESS = 'no_access';
17 
21  public $shouldHideItems = false;
22 
26  public $reasonHidden = '';
27 
38  static public function factory($container_guid, $use_cache = true) {
39  // cache because this may be called repeatedly during river display, and
40  // due to need to check group visibility, cache will be disabled for some
41  // get_entity() calls
42  static $cache = array();
43 
44  if (!$container_guid) {
45  return new Elgg_GroupItemVisibility();
46  }
47 
49  $user_guid = $user ? $user->guid : 0;
50 
51  $container_guid = (int) $container_guid;
52 
53  $cache_key = "$container_guid|$user_guid";
54  if (empty($cache[$cache_key]) || !$use_cache) {
55  // compute
56 
57  $container = get_entity($container_guid);
58  $is_visible = (bool) $container;
59 
60  if (!$is_visible) {
61  // see if it *really* exists...
62  $prev_access = elgg_set_ignore_access();
63  $container = get_entity($container_guid);
64  elgg_set_ignore_access($prev_access);
65  }
66 
67  $ret = new Elgg_GroupItemVisibility();
68 
69  if ($container && $container instanceof ElggGroup) {
70  /* @var ElggGroup $container */
71 
72  if ($is_visible) {
73  if ($container->getContentAccessMode() === ElggGroup::CONTENT_ACCESS_MODE_MEMBERS_ONLY) {
74  if ($user) {
75  if (!$container->isMember($user) && !$user->isAdmin()) {
76  $ret->shouldHideItems = true;
77  $ret->reasonHidden = self::REASON_NON_MEMBER;
78  }
79  } else {
80  $ret->shouldHideItems = true;
81  $ret->reasonHidden = self::REASON_LOGGED_OUT;
82  }
83  }
84  } else {
85  $ret->shouldHideItems = true;
86  $ret->reasonHidden = self::REASON_NO_ACCESS;
87  }
88  }
89  $cache[$cache_key] = $ret;
90  }
91 
92  $return = $cache[$cache_key];
93 
94  // don't exhaust memory in extreme uses
95  if (count($cache) > 500) {
96  reset($cache);
97  unset($cache[key($cache)]);
98  }
99 
100  return $return;
101  }
102 }
$return
Definition: opendd.php:15
static factory($container_guid, $use_cache=true)
Determine visibility of items within a container for the current user.
elgg_set_ignore_access($ignore=true)
Set if Elgg&#39;s access system should be ignored.
Definition: access.php:43
$user
Definition: ban.php:13
const CONTENT_ACCESS_MODE_MEMBERS_ONLY
Definition: ElggGroup.php:16
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:32
$user_guid
Avatar remove action.
Definition: remove.php:6
$container
Definition: access.php:30
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:604