本文整理匯總了PHP中ElggMenuItem::setChildren方法的典型用法代碼示例。如果您正苦於以下問題:PHP ElggMenuItem::setChildren方法的具體用法?PHP ElggMenuItem::setChildren怎麽用?PHP ElggMenuItem::setChildren使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ElggMenuItem
的用法示例。
在下文中一共展示了ElggMenuItem::setChildren方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: orderMenuItem
/**
* Reorders menu item and adds an add button
*
* @param \ElggMenuItem $item menu item
* @param int $depth depth of the menu item
*
* @return \ElggMenuItem
*/
private static function orderMenuItem(\ElggMenuItem $item, $depth)
{
$depth = (int) $depth;
$children = $item->getChildren();
if (empty($children)) {
return $item;
}
// sort children
$ordered_children = [];
foreach ($children as $child) {
$child = self::orderMenuItem($child, $depth + 1);
$child_priority = $child->getPriority();
while (array_key_exists($child_priority, $ordered_children)) {
$child_priority++;
}
$ordered_children[$child_priority] = $child;
}
ksort($ordered_children);
$item->setChildren($ordered_children);
return $item;
}
示例2: menu_builder_order_menu_item
/**
* Reorders menu item and adds an add button
*
* @param ElggMenuItem $item menu item
* @param int $depth depth of the menu item
*
* @return ElggMenuItem
*/
function menu_builder_order_menu_item(ElggMenuItem $item, $depth)
{
$depth = (int) $depth;
if ($children = $item->getChildren()) {
// sort children
$ordered_children = array();
foreach ($children as $child) {
$child = menu_builder_order_menu_item($child, $depth + 1);
$child_priority = $child->getPriority();
while (array_key_exists($child_priority, $ordered_children)) {
$child_priority++;
}
$ordered_children[$child_priority] = $child;
if (isset($_SESSION["menu_builder_edit_mode"]) && $depth < 5) {
// add button
$child_add = ElggMenuItem::factory(array("name" => 'menu_builder_add', "text" => elgg_view_icon("round-plus"), "href" => '/menu_builder/edit?parent_guid=' . $child->getName(), "class" => "menu_builder_add_link", "title" => elgg_echo("menu_builder:edit_mode:add")));
$child->addChild($child_add);
}
}
ksort($ordered_children);
$item->setChildren($ordered_children);
}
return $item;
}