Update the active and order values and then return the object.

@param $menuName

@return Menu
@throws \Exception
508911
public function render($menuName)
    {
        // We set active at the last possible moment.
        $this->updateActive();

        $menu = $this->getMenuObject($menuName);

        if (! $menu) {
            throw new \Exception("Menu {$menuName} not found.");
        }

        return $menu;
    }
112040
public function addMenu(Menu $menu)
    {
        $menu->setArticle($this);
        $this->menus[] = $menu;

        return $this;
    }
660596
public static function display($menuName, $type = null, array $options = [])
    {
        // GET THE MENU - sort collection in blade
        $menu = static::where('name', '=', $menuName)
            ->with(['parent_items.children' => function ($q) {
                $q->orderBy('order');
            }])
            ->first();

        // Check for Menu Existence
        if (!isset($menu)) {
            return false;
        }

        event(new MenuDisplay($menu));

        // Convert options array into object
        $options = (object) $options;

        // Set static vars values for admin menus
        if (in_array($type, ['admin', 'admin_menu'])) {
            $permissions = Admin::model('Permission')->all();
            $dataTypes = Admin::model('DataType')->all();
            $prefix = trim(route('admin.dashboard', [], false), '/');
            $user_permissions = null;

            if (!Auth::guest()) {
                $user = Admin::model('User')->find(Auth::id());
                $user_permissions = $user->role->permissions->pluck('key')->toArray();
            }

            $options->user = (object) compact('permissions', 'dataTypes', 'prefix', 'user_permissions');

            // change type to blade template name - TODO funky names, should clean up later
            $type = 'admin::menu.'.$type;
        } else {
            if (is_null($type)) {
                $type = 'admin::menu.default';
            } elseif ($type == 'bootstrap' && !view()->exists($type)) {
                $type = 'admin::menu.bootstrap';
            }
        }

        if (!isset($options->locale)) {
            $options->locale = app()->getLocale();
        }

        return new \Illuminate\Support\HtmlString(
            \Illuminate\Support\Facades\View::make($type, ['items' => $menu->parent_items->sortBy('order'), 'options' => $options])->render()
        );
    }
585280
public function update($setName)
    {
        $db = Database::connection();
        $db->update(
            'FileSets',
            array('fsName' => $setName),
            array('fsID' => $this->fsID)
        );

        return static::getByID($this->fsID);
    }
475806
public function addPriority($objectName) {
    	try{
			if (empty($objectName))
				throw new Exception('Paramer "objectName" is required');


    		$params = array (
    		'objectName' => $objectName
    		);

    		$ret = $this->SendRequest->curl('/chatroom/message/priority/add.json',$params,'urlencoded','im','POST');
    		if(empty($ret))
    			throw new Exception('bad request');
    		return $ret;

    	}catch (Exception $e) {
    		print_r($e->getMessage());
    	}
   }
380164
public function getIndex($indexName)
    {
        if (isset($this->globalIndexConsumed[$indexName])) {
            return $this->globalIndexConsumed[$indexName];
        }

        if (isset($this->localIndexConsumed[$indexName])) {
            return $this->localIndexConsumed[$indexName];
        }

        //TODO: exception
        //or return null?
        throw new \Exception;
    }
754306
public function addPlatformItem($menuName, $url, $order = 50, $tooltip = false)
    {
        $this->addItem('CorePluginsAdmin_MenuPlatform', $menuName, $url, $order, $tooltip);
    }
1152307
public function ajaxAction(Request $request, $menuId)
    {
        $entityId = $request->query->get('id');
        $currentId = $request->query->get('currentId');

        $objectManager = $this->getDoctrine()->getManager();
        $filter = array(
            'menu' => $objectManager->getReference('ClasticMenuBundle:Menu', $menuId),
            'parent' => null,
        );

        if (intval($entityId)) {
            $filter['parent'] = $objectManager->getReference('ClasticMenuBundle:MenuItem', (int) $request->query->get('id'));
        }

        $items = $this->getDoctrine()
            ->getRepository('ClasticMenuBundle:MenuItem')
            ->findBy($filter);

        $data = array_map(function (MenuItem $item) use ($currentId) {
            return array(
                'id' => $item->getId(),
                'text' => $item->getTitle(),
                'children' => true,
                'state' => array(
                    'disabled' => ($item->getId() != $currentId),
                ),
            );
        }, $items);

        if (!$currentId && is_null($filter['parent'])) {
            $data[] = array(
                'id' => 'current',
                'text' => 'New Item',
                'children' => false,
                'state' => array(
                    'disabled' => false,
                ),
            );
        }

        return new JsonResponse($data);
    }
1336011
public function update($id, MenuRequest $request)
    {
        try {
            $menu = $this->repository->find($id);

            if (empty($menu)) {
                Cms::notification('Menu not found', 'warning');

                return redirect(route($this->routeBase.'.menus.index'));
            }

            $menu = $this->repository->update($menu, $request->all());
            Cms::notification('Menu updated successfully.', 'success');

            if (!$menu) {
                Cms::notification('Menu could not be updated.', 'danger');
            }
        } catch (Exception $e) {
            Cms::notification($e->getMessage() ?: 'Menu could not be updated.', 'danger');
        }

        return redirect(route($this->routeBase.'.menus.edit', [$id]));
    }
82862
public function indexAction(Request $request, $menuid)
    {
        $menuRepo = $this->getDoctrine()->getManager()->getRepository(
            $this->container->getParameter('kunstmaan_menu.entity.menu.class')
        );

        /** @var BaseMenu $menu */
        $menu = $menuRepo->find($menuid);
        if ($menu->getLocale() != $request->getLocale()) {
            /** @var BaseMenu $translatedMenu */
            $translatedMenu = $menuRepo->findOneBy(['locale' => $request->getLocale(), 'name' => $menu->getName()]);
            $menuid = $translatedMenu->getId();
        }

        $configurator = $this->getAdminListConfigurator($request, $menuid);
        $itemRoute = function (EntityInterface $item) use ($menuid) {
            return array(
                'path' => 'kunstmaanmenubundle_admin_menuitem_move_up',
                'params' => array(
                    'menuid' => $menuid,
                    'item' => $item->getId(),
                ),
            );
        };
        $configurator->addItemAction(new SimpleItemAction($itemRoute, 'arrow-up', 'kuma_admin_list.action.move_up'));

        $itemRoute = function (EntityInterface $item) use ($menuid) {
            return array(
                'path' => 'kunstmaanmenubundle_admin_menuitem_move_down',
                'params' => array(
                    'menuid' => $menuid,
                    'item' => $item->getId(),
                ),
            );
        };
        $configurator->addItemAction(new SimpleItemAction($itemRoute, 'arrow-down', 'kuma_admin_list.action.move_down'));

        return parent::doIndexAction($configurator, $request);
    }
518845
public function changePositionAction($pageId, $menuName, $newPosition)
    {
        if ($this->getRequest()->isXmlHttpRequest())
        {
            $pageMenuRepo = $this->getDoctrine()->getRepository('FulgurioLightCMSBundle:PageMenu');
            $pageMenu = $pageMenuRepo->findOneBy(array('page' => $pageId, 'label' => $menuName));
            if ($pageMenu)
            {
                if ($newPosition == $pageMenu->getPosition())
                {
                    // No change
                }
                else if ($newPosition > $pageMenu->getPosition())
                {
                    if ($newPosition <= $pageMenuRepo->getLastMenuPosition($pageMenu->getLabel()))
                    {
                        // Down !
                        $pageMenuRepo->upMenuPagesPosition($pageMenu->getLabel(), $pageMenu->getPosition() + 1, $newPosition);
                        $pageMenu->setPosition($newPosition);
                        $em = $this->getDoctrine()->getManager();
                        $em->persist($pageMenu);
                        $em->flush();
                    }
                }
                else if ($pageMenu->getPosition() > 1)
                {
                    // Up !
                    $pageMenuRepo->downMenuPagesPosition($pageMenu->getLabel(), $newPosition, $pageMenu->getPosition());
                    $pageMenu->setPosition($newPosition);
                    $em = $this->getDoctrine()->getManager();
                    $em->persist($pageMenu);
                    $em->flush();
                }
                else {
                    // doesn t happen
                }
            }
            return new Response();
        }
        throw new AccessDeniedException();
    }
918118
public function create(Menu $menu)
    {
        $model = $this->repository->createModel();

        return view('menus::admin.create-menulink')
            ->with(compact('model', 'menu'));
    }
1360668
public function nextValue($sequenceName)
    {
        if (isset($this->sequences[$sequenceName])) {
            $value = $this->sequences[$sequenceName]['value'];
            $this->sequences[$sequenceName]['value']++;
            if ($this->sequences[$sequenceName]['value'] >= $this->sequences[$sequenceName]['max']) {
                unset($this->sequences[$sequenceName]);
            }

            return $value;
        }

        $this->conn->beginTransaction();

        try {
            $platform = $this->conn->getDatabasePlatform();
            $sql      = 'SELECT sequence_value, sequence_increment_by'
                . ' FROM ' . $platform->appendLockHint($this->generatorTableName, LockMode::PESSIMISTIC_WRITE)
                . ' WHERE sequence_name = ? ' . $platform->getWriteLockSQL();
            $stmt     = $this->conn->executeQuery($sql, [$sequenceName]);
            $row      = $stmt->fetch(FetchMode::ASSOCIATIVE);

            if ($row !== false) {
                $row = array_change_key_case($row, CASE_LOWER);

                $value = $row['sequence_value'];
                $value++;

                if ($row['sequence_increment_by'] > 1) {
                    $this->sequences[$sequenceName] = [
                        'value' => $value,
                        'max' => $row['sequence_value'] + $row['sequence_increment_by'],
                    ];
                }

                $sql  = 'UPDATE ' . $this->generatorTableName . ' ' .
                       'SET sequence_value = sequence_value + sequence_increment_by ' .
                       'WHERE sequence_name = ? AND sequence_value = ?';
                $rows = $this->conn->executeUpdate($sql, [$sequenceName, $row['sequence_value']]);

                if ($rows !== 1) {
                    throw new DBALException('Race-condition detected while updating sequence. Aborting generation');
                }
            } else {
                $this->conn->insert(
                    $this->generatorTableName,
                    ['sequence_name' => $sequenceName, 'sequence_value' => 1, 'sequence_increment_by' => 1]
                );
                $value = 1;
            }

            $this->conn->commit();
        } catch (Throwable $e) {
            $this->conn->rollBack();
            throw new DBALException('Error occurred while generating ID with TableGenerator, aborted generation: ' . $e->getMessage(), 0, $e);
        }

        return $value;
    }
729288
public function getLastMenuPosition($menuName)
    {
        $query = $this->getEntityManager()->createQuery('SELECT MAX(m.position) FROM FulgurioLightCMSBundle:PageMenu m WHERE m.label=:menuName');
        $query->setParameter('menuName', $menuName);
        return $query->getSingleScalarResult();
    }
361243
public function menuAction()
    {
        $loader = $this->get('phlexible_gui.menu.loader');
        $items = $loader->load();
        $data = $items->toArray();

        return new JsonResponse($data);
    }
906213
public function create($name){
        $this->menuCollection[$name] = new MenuCollection;
        $this->menuCollection[$name]->setName($name);

        return $this->menuCollection[$name];
    }
1217553
public function updateMenuItemAction(Request $request, MenuItem $menuItem)
    {
        $em = $this->getDoctrine()->getManager();

        if (!$menuItem) {
            throw $this->createNotFoundException('Unable to find MenuItem entity.');
        }

        $editForm = $this->createMenuItemEditForm($menuItem);
        $editForm->handleRequest($request);
        if ($editForm->isValid()) {
            $this->get('amulen.page.service.menu')->reorder($menuItem->getMenu());
            if($menuItem->getPage()){
                $menuItem->setPageSlug($menuItem->getPage());
            }
            $em->flush();

            return $this->redirect($this->generateUrl('admin_menu_items', array('id' => $menuItem->getMenu()->getId())));
        }

        return array(
            'entity' => $menuItem,
            'edit_form' => $editForm->createView(),
            'delete_form' => $deleteForm->createView(),
        );
    }