public function get_access($user = null)
{
static $cached_access = array();
if (!$user instanceof User) {
$user = User::identify();
}
if (!isset($access[$this->id])) {
$cached_access[$this->id] = array();
}
if (isset($cached_access[$this->id][$user->id])) {
return $cached_access[$this->id][$user->id];
}
if ($user->can('super_user')) {
$cached_access[$this->id][$user->id] = ACL::get_bitmask('full');
return $cached_access[$this->id][$user->id];
}
// Collect a list of applicable tokens
$tokens = array('post_any', 'post_' . Post::type_name($this->content_type));
if ($user->id == $this->user_id) {
$tokens[] = 'own_posts';
}
$tokens = array_merge($tokens, $this->get_tokens());
// collect all possible token accesses on this post
$token_accesses = array();
foreach ($tokens as $token) {
$access = ACL::get_user_token_access($user, $token);
if ($access instanceof Bitmask) {
$token_accesses[] = ACL::get_user_token_access($user, $token)->value;
}
}
// now that we have all the accesses, loop through them to build the access to the particular post
if (in_array(0, $token_accesses)) {
$cached_access[$this->id][$user->id] = ACL::get_bitmask(0);
return $cached_access[$this->id][$user->id];
}
$cached_access[$this->id][$user->id] = ACL::get_bitmask(Utils::array_or($token_accesses));
return $cached_access[$this->id][$user->id];
}