Advertisement
Guest User

Untitled

a guest
Jun 24th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.93 KB | None | 0 0
  1. <?php
  2. class Page extends SiteTree {
  3.     private static $allowed_children = array ('*Page'); // Only Base Class Pages can be created as children.
  4.  
  5.     private static $db = array(
  6.     );
  7.  
  8.     private static $has_one = array(
  9.     );
  10.  
  11. }
  12. class Page_Controller extends ContentController {
  13.  
  14.     /**
  15.      * An array of actions that can be accessed via a request. Each array element should be an action name, and the
  16.      * permissions or conditions required to allow the user to access it.
  17.      *
  18.      * <code>
  19.      * array (
  20.      *     'action', // anyone can access this action
  21.      *     'action' => true, // same as above
  22.      *     'action' => 'ADMIN', // you must have ADMIN permissions to access this action
  23.      *     'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true
  24.      * );
  25.      * </code>
  26.      *
  27.      * @var array
  28.      */
  29.     private static $allowed_actions = array (
  30.     );
  31.  
  32.     public function __construct(){
  33.         echo __FILE__ . " on line " . __LINE__ . "<br>";
  34.         parent::__construct();
  35.     }
  36.  
  37.     public function init() {
  38.         parent::init();
  39.         // You can include any CSS or JS required by your project here.
  40.         // See: http://doc.silverstripe.org/framework/en/reference/requirements
  41.     }
  42.  
  43.     public function getPagesWithDepth(){
  44.         echo __FILE__ . " on line " . __LINE__ . "<br>";
  45.         $pageList = new ArrayList();
  46.         foreach( SiteTree::get() as $menuPage){
  47.             $pageList->push( ArrayData::create([
  48.                 'title' => $menuPage->getTitle(),
  49.                 'id' => $menuPage->ID,
  50.                 'depth' => $this->getHDepth($menuPage),
  51.                 'parentId' => ($menuPage->getParent())? $menuPage->getParent()->ID : 0
  52.             ]));
  53.         }
  54.         return $pageList;
  55.     }
  56.  
  57.     public function getHDepth( Page $menuPage){
  58.         if($menuPage->getParent()){
  59.             return $this->getHDepth($menuPage->getParent()) +1;
  60.         }
  61.         return 0; // stopping case
  62.     }
  63.  
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement