function build_menu_from_form(&$elements_ids, $level = 0) { $menu = null; $menu_element_id = $elements_ids['id']; $menu_name = retrieve(POST, 'menu_element_' . $menu_element_id . '_name', '', TSTRING_UNCHANGE); $menu_url = retrieve(POST, 'menu_element_' . $menu_element_id . '_url', ''); $menu_image = retrieve(POST, 'menu_element_' . $menu_element_id . '_image', ''); $array_size = count($elements_ids); if ($array_size == 1 && $level > 0) { $menu = new LinksMenuLink($menu_name, $menu_url, $menu_image); } else { $menu = new LinksMenu($menu_name, $menu_url, $menu_image); unset($elements_ids['id']); $array_size = count($elements_ids); for ($i = 0; $i < $array_size; $i++) { $menu->add(build_menu_from_form($elements_ids[$i], $level + 1)); } } $menu->set_auth(Authorizations::build_auth_array_from_form(AUTH_MENUS, 'menu_element_' . $menu_element_id . '_auth')); return $menu; }
function build_menu_from_form($elements_ids, $level = 0) { $menu = null; $menu_element_id = $elements_ids['id']; $menu_name = retrieve(POST, 'menu_element_' . $menu_element_id . '_name', '', TSTRING_UNCHANGE); $menu_url = retrieve(POST, 'menu_element_' . $menu_element_id . '_url', ''); $menu_image = retrieve(POST, 'menu_element_' . $menu_element_id . '_image', ''); $array_size = count($elements_ids); if ($array_size == 1 && $level > 0) { // If it's a menu, there's only one element; $menu = new LinksMenuLink($menu_name, $menu_url, $menu_image); } else { $menu = new LinksMenu($menu_name, $menu_url, $menu_image); // We unset the id key of the array unset($elements_ids['id']); $array_size = count($elements_ids); for ($i = 0; $i < $array_size; $i++) { // We build all its children and add it to its father $menu->add(build_menu_from_form($elements_ids[$i], $level + 1)); } } $menu->set_auth(Authorizations::build_auth_array_from_form(Menu::MENU_AUTH_BIT, 'menu_element_' . $menu_element_id . '_auth')); return $menu; }