Is the the current page accessible to Guests?

Permalink
I have an element that I only want to show on the page if the page is accessible to guests.
So I want to determine if the current page is accessible to guests.

The following code works:
$gl = new GroupList($c);
$gArray = $gl->getGroupList();
foreach ($gArray as $group) {
   if ($group->getGroupID() == GUEST_GROUP_ID AND $group->canRead()) {
      echo 'TRUE';
   };
};


Is this the right way to find out if the current page is accessible to guests?

Thanks,
Marcus.

mrowell
 
mrowell replied on at Permalink Best Answer Reply
mrowell
I believe this is the way to determine is guest can view the current page with 5.6+

$pk = PermissionKey::getByHandle('view_page');
   $pk->setPermissionObject($c);
   $gg = GroupPermissionAccessEntity::getOrCreate(Group::getByID(GUEST_GROUP_ID));
   $accessEntities = array($gg);
   $visibleToGuest = false;
   $list = $pk->getAccessListItems(PermissionKey::ACCESS_TYPE_ALL, $accessEntities);
   foreach($list as $l) {
      if ($l->getAccessType() == PermissionKey::ACCESS_TYPE_INCLUDE) {
         $visibleToGuest = true;
      }
      if ($l->getAccessType() == PermissionKey::ACCESS_TYPE_EXCLUDE) {
         $visibleToGuest = false;
      }
   }
mrowell replied on at Permalink Reply
mrowell