Пример #1
0
 /**
  * Recursive menu items by parents branch extrusion
  * 
  * @access public
  * @param array $menuItemsByParents
  * @param array $menuItemsPerParent
  * @param bool $treeFlag ,default is false
  * @param int $depthLevel ,default is 0
  * 
  * @return array parent children with children appended under it
  */
 public function sortMenuItemsByParents(&$menuItemsByParents, &$menuItemsPerParent, $treeFlag = false, $depthLevel = 0)
 {
     $tree = array();
     foreach ($menuItemsPerParent as $menuItem) {
         $menuItem->children = array();
         if (isset($menuItemsByParents[$menuItem->getId()])) {
             $depthLevel++;
             // get all children under menu item
             $menuItem->children = $this->sortMenuItemsByParents($menuItemsByParents, $menuItemsByParents[$menuItem->getId()], $treeFlag, $depthLevel);
             $depthLevel--;
         }
         if ($treeFlag === false) {
             $tree[] = $menuItem;
             // append children under direct parent
             if (count($menuItem->children) > 0) {
                 $tree = array_merge($tree, $menuItem->children);
                 unset($menuItem->children);
             }
         } else {
             $menuItemTitle = $menuItem->getTitle();
             $menuTitle = $this->inflector->underscore($menuItem->getMenu()->getTitle());
             if ($menuItem->getType() == MenuItemEntity::TYPE_PAGE && is_object($menuItem->getPage())) {
                 $path = $menuItem->getPage()->getPath();
             } else {
                 $path = $menuItem->getDirectUrl();
             }
             $menuItemArray = array('depth' => $depthLevel, 'path' => $path, 'weight' => $menuItem->getWeight(), 'title_underscored' => $this->inflector->underscore($menuItemTitle), 'children' => $menuItem->children);
             $tree[$menuTitle][$menuItemTitle] = $menuItemArray;
         }
     }
     return $tree;
 }
Пример #2
0
 /**
  * setup form
  * 
  * 
  * @uses \ReflectionClass
  * @uses Inflector
  * 
  * @access public
  * @param string $name ,default is null
  * @param array $options ,default is null
  */
 public function __construct($name = null, $options = null)
 {
     if (is_null($name)) {
         $reflection = new \ReflectionClass($this);
         $inflector = new Inflector();
         $name = $inflector->underscore($reflection->getShortName());
     }
     $auth = new AuthenticationService();
     $storage = $auth->getIdentity();
     if ($auth->hasIdentity() && in_array(Role::ADMIN_ROLE, $storage['roles'])) {
         $this->isAdminUser = true;
     }
     parent::__construct($name, $options);
 }