当前位置: 首页>>代码示例>>PHP>>正文


PHP ItemInterface::reorderChildren方法代码示例

本文整理汇总了PHP中Knp\Menu\ItemInterface::reorderChildren方法的典型用法代码示例。如果您正苦于以下问题:PHP ItemInterface::reorderChildren方法的具体用法?PHP ItemInterface::reorderChildren怎么用?PHP ItemInterface::reorderChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Knp\Menu\ItemInterface的用法示例。


在下文中一共展示了ItemInterface::reorderChildren方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sort

 /**
  * Reorder menu based on position attribute
  *
  * @param ItemInterface $menu
  */
 protected function sort(ItemInterface $menu)
 {
     if ($menu->hasChildren() && $menu->getDisplayChildren()) {
         $orderedChildren = [];
         $unorderedChildren = [];
         $hasOrdering = false;
         $children = $menu->getChildren();
         foreach ($children as &$child) {
             if ($child->hasChildren() && $child->getDisplayChildren()) {
                 $this->sort($child);
             }
             $position = $child->getExtra('position');
             if ($position !== null) {
                 $orderedChildren[$child->getName()] = (int) $position;
                 $hasOrdering = true;
             } else {
                 $unorderedChildren[] = $child->getName();
             }
         }
         if ($hasOrdering) {
             asort($orderedChildren);
             $menu->reorderChildren(array_merge(array_keys($orderedChildren), $unorderedChildren));
         }
     }
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:30,代码来源:BuilderChainProvider.php

示例2: moveChildToPosition

 /**
  * Moves child to specified position. Rearange other children accordingly.
  *
  * @param ItemInterface $item
  * @param ItemInterface $child    Child to move.
  * @param integer       $position Position to move child to.
  */
 public function moveChildToPosition(ItemInterface $item, ItemInterface $child, $position)
 {
     $name = $child->getName();
     $order = array_keys($item->getChildren());
     $oldPosition = array_search($name, $order);
     unset($order[$oldPosition]);
     $order = array_values($order);
     array_splice($order, $position, 0, $name);
     $item->reorderChildren($order);
 }
开发者ID:andrewkrug,项目名称:repucaution,代码行数:17,代码来源:MenuManipulator.php

示例3: reorderMenu

 /**
  * Reorder the menu
  *
  * @param \Knp\Menu\ItemInterface $menu
  *
  * @return MenuItem
  */
 private function reorderMenu($menu)
 {
     $menuItems = $menu->getChildren();
     usort($menuItems, array($this, 'menuSort'));
     $newMenuOrder = array();
     foreach ($menuItems as $menuItem) {
         $newMenuOrder[] = $menuItem->getName();
     }
     $menu->reorderChildren($newMenuOrder);
     return $menu;
 }
开发者ID:NaszvadiG,项目名称:Jumph,代码行数:18,代码来源:Builder.php

示例4: reorderMenuItems

 /**
  * Reorderd the items in the menu based on the extra data
  *
  * @param ItemInterface $menu
  */
 protected function reorderMenuItems(ItemInterface $menu)
 {
     $menuOrderArray = array();
     $addLast = array();
     $alreadyTaken = array();
     foreach ($menu->getChildren() as $menuItem) {
         if ($menuItem->hasChildren()) {
             $this->reorderMenuItems($menuItem);
         }
         $orderNumber = $menuItem->getExtra('orderNumber');
         if ($orderNumber != null) {
             if (!isset($menuOrderArray[$orderNumber])) {
                 $menuOrderArray[$orderNumber] = $menuItem->getName();
             } else {
                 $alreadyTaken[$orderNumber] = $menuItem->getName();
             }
         } else {
             $addLast[] = $menuItem->getName();
         }
     }
     ksort($menuOrderArray);
     if (!empty($alreadyTaken)) {
         foreach ($alreadyTaken as $key => $value) {
             $keysArray = array_keys($menuOrderArray);
             $position = array_search($key, $keysArray);
             if ($position === false) {
                 continue;
             }
             $menuOrderArray = array_merge(array_slice($menuOrderArray, 0, $position), array($value), array_slice($menuOrderArray, $position));
         }
     }
     ksort($menuOrderArray);
     if (!empty($addLast)) {
         foreach ($addLast as $value) {
             $menuOrderArray[] = $value;
         }
     }
     if (!empty($menuOrderArray)) {
         $menu->reorderChildren($menuOrderArray);
     }
 }
开发者ID:sumocoders,项目名称:framework-core-bundle,代码行数:46,代码来源:MenuBuilder.php

示例5: reorderMenuItems

 /**
  * Reorder Menus items
  * 
  * @param ItemInterface $menu
  */
 protected function reorderMenuItems(ItemInterface $menu)
 {
     $menuOrderArray = array();
     $addLast = array();
     $alreadyTaken = array();
     foreach ($menu->getChildren() as $key => $menuItem) {
         if ($menuItem->hasChildren()) {
             $this->reorderMenuItems($menuItem);
         }
         $orderNumber = $menuItem->getExtra('orderNumber');
         if ($orderNumber != null) {
             if (!isset($menuOrderArray[$orderNumber])) {
                 $menuOrderArray[$orderNumber] = $menuItem->getName();
             } else {
                 $alreadyTaken[$orderNumber] = $menuItem->getName();
                 // $alreadyTaken[] = array('orderNumber' => $orderNumber, 'name' => $menuItem->getName());
             }
         } else {
             $addLast[] = $menuItem->getName();
         }
     }
     // sort them after first pass
     ksort($menuOrderArray);
     // handle position duplicates
     if (count($alreadyTaken)) {
         foreach ($alreadyTaken as $key => $value) {
             // the ever shifting target
             $keysArray = array_keys($menuOrderArray);
             $position = array_search($key, $keysArray);
             if ($position === false) {
                 continue;
             }
             $menuOrderArray = array_merge(array_slice($menuOrderArray, 0, $position), array($value), array_slice($menuOrderArray, $position));
         }
     }
     // sort them after second pass
     ksort($menuOrderArray);
     // add items without ordernumber to the end
     if (count($addLast)) {
         foreach ($addLast as $key => $value) {
             $menuOrderArray[] = $value;
         }
     }
     if (count($menuOrderArray)) {
         $menu->reorderChildren($menuOrderArray);
     }
 }
开发者ID:artscorestudio,项目名称:website-bundle,代码行数:52,代码来源:MenuBuilder.php


注:本文中的Knp\Menu\ItemInterface::reorderChildren方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。