protected static function _generateMenuEnumerationTree(Enumeration $enumeration) { static $enumerationIds = array(); $enumerationId = $enumeration->enumerationId; $enumerationsClosure = new EnumerationsClosure(); $descendants = $enumerationsClosure->getEnumerationTreeById($enumerationId); $displayOrder = 0; foreach ($descendants as $enum) { if (isset($enumerationIds[$enum->enumerationId])) { continue; } $enumerationIds[$enum->enumerationId] = true; $displayOrder += 10; $menu = new MenuItem(); $menu->siteSection = 'All'; $menu->type = 'freeform'; $menu->active = 1; $menu->title = $enum->name; //$menu->displayOrder = $displayOrder; $menu->displayOrder = $enum->enumerationId; // temporarily set displayOrder using the enumerationId $menu->parentId = $enumerationId; $menu->persist(); $enum->ormId = $menu->menuId; $enum->persist(); if ($enumerationId != $enum->enumerationId) { // prevents infinite loop self::_generateMenuEnumerationTree($enum); } } }
/** * Move menu */ public function ajaxMoveMenuItemAction() { $idFrom = (int) $this->_getParam('idFrom'); $idTo = (int) $this->_getParam('idTo'); $idBefore = (int) $this->_getParam('idBefore'); if ($idTo == 'menu') { $idTo = 0; } $menuItem = new MenuItem(); $menuItem->menuId = $idFrom; $menuItem->populate(); if ($idBefore > 0) { //this is the sibling reorder case $beforeMenuItem = new MenuItem(); $beforeMenuItem->menuId = $idBefore; $beforeMenuItem->populate(); $menuItem->updateDisplayOrder($beforeMenuItem->displayOrder); } else { //this is the hierarchy level move case $menuItem->parentId = $idTo; $menuItem->persist(); } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct(true); }