/** * @author Matthew McNaney <mcnaney at gmail dot com> * @version $Id$ */ function menu_install(&$content) { PHPWS_Core::initModClass('menu', 'Menu_Item.php'); $menu = new Menu_Item(); $menu->title = dgettext('menu', 'Main menu'); $menu->template = 'basic'; $menu->pin_all = 1; $result = $menu->save(); if (PHPWS_Error::isError($result)) { PHPWS_Error::log($result); return false; } else { $content[] = dgettext('menu', 'Default menu created successfully.'); return true; } }
private function moveMenu(\Request $request) { $move_id = $request->getVar('move_id'); $move_menu = new Menu_Item($move_id); if ($request->isVar('next_id')) { $next_id = $request->getVar('next_id'); $next_menu = new Menu_Item($next_id); } else { $next_id = 0; } if ($request->isVar('prev_id')) { $prev_id = $request->getVar('prev_id'); $prev_menu = new Menu_Item($prev_id); } else { $prev_id = 0; } $db = \Database::newDB(); $tbl = $db->addTable('menus'); $queue = $tbl->getField('queue'); if ($next_id == 0) { // moved to end of list $exp = $db->getExpression('max(' . $queue . ')', 'max_queue'); $tbl->addField($exp); $last_queue = $db->selectColumn(); $tbl->addValue('queue', $db->getExpression($queue . ' - 1')); $tbl->addFieldConditional('queue', $move_menu->queue, '>'); $db->update(); $move_menu->queue = $last_queue; } elseif ($prev_id == 0) { // moved to beginning of list $tbl->addValue('queue', $db->getExpression($queue . ' + 1')); $tbl->addFieldConditional('queue', $move_menu->queue, '<'); $db->update(); $move_menu->queue = 1; } else { // moved in the middle of list if ($move_menu->queue < $next_menu->queue) { $tbl->addValue('queue', $db->getExpression($queue . ' - 1')); $tbl->addFieldConditional('queue', $move_menu->queue, '>='); $tbl->addFieldConditional('queue', $next_menu->queue, '<'); $move_menu->queue = $prev_menu->queue; } else { $tbl->addValue('queue', $db->getExpression($queue . ' + 1')); $tbl->addFieldConditional('queue', $next_menu->queue, '>='); $tbl->addFieldConditional('queue', $move_menu->queue, '<'); $move_menu->queue = $next_menu->queue; } $db->update(); } $move_menu->save(); }