本文整理汇总了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;
}