當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。