Example #1
0
 /**
  * Remove pages from already-loaded PageArray aren't visible or accessible
  *
  * @param PageArray $items
  * @param string $includeMode Optional inclusion mode:
  * 	- 'hidden': Allow pages with 'hidden' status'
  * 	- 'unpublished': Allow pages with 'unpublished' or 'hidden' status
  * 	- 'all': Allow all pages (not much point in calling this method)
  * @return PageArray
  *
  */
 protected function filterListable(PageArray $items, $includeMode = '')
 {
     if ($includeMode === 'all') {
         return $items;
     }
     $itemsAllowed = new PageArray();
     foreach ($items as $item) {
         if ($includeMode === 'unpublished') {
             $allow = $item->status < Page::statusTrash;
         } else {
             if ($includeMode === 'hidden') {
                 $allow = $item->status < Page::statusUnpublished;
             } else {
                 $allow = $item->status < Page::statusHidden;
             }
         }
         if ($allow) {
             $allow = $item->listable();
         }
         // confirm access
         if ($allow) {
             $itemsAllowed->add($item);
         }
     }
     $itemsAllowed->resetTrackChanges(true);
     return $itemsAllowed;
 }