issue 2658 Can be modified to delete the sub-menu in the menu

git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12133 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ovclas 2012-11-06 06:47:10 +00:00
parent 4b38ad8222
commit b46b3f9d0d

View file

@ -589,42 +589,77 @@
$args->menu_srl = $item_info->menu_srl; $args->menu_srl = $item_info->menu_srl;
// Get information of the menu // Get information of the menu
$menu_info = $oMenuAdminModel->getMenu($args->menu_srl); $menuInfo = $oMenuAdminModel->getMenu($args->menu_srl);
$menu_title = $menu_info->title; $menu_title = $menuInfo->title;
// check admin menu delete
$oAdmin = &getClass('admin'); $oAdmin = &getClass('admin');
if($menu_title == $oAdmin->getAdminMenuName() && $item_info->parent_srl == 0)return $this->stop('msg_cannot_delete_for_admin_topmenu'); if($menu_title == $oAdmin->getAdminMenuName() && $item_info->parent_srl == 0)
{
return $this->stop('msg_cannot_delete_for_admin_topmenu');
}
if($item_info->parent_srl) $parent_srl = $item_info->parent_srl; if($item_info->parent_srl) $parent_srl = $item_info->parent_srl;
// Display an error that the category cannot be deleted if it has a child node
$output = executeQuery('menu.getChildMenuCount', $args); // get menu properies with child menu
if(!$output->toBool()) return $output; $phpFile = sprintf("./files/cache/menu/%s.php", $args->menu_srl);
if($output->data->count>0) return new Object(-1, 'msg_cannot_delete_for_child'); $originMenu = NULL;
if(is_readable(FileHandler::getRealPath($phpFile)))
{
@include(FileHandler::getRealPath($phpFile));
if(is_array($menu->list))
{
$this->_searchMenu($menu->list, $args->menu_item_srl, $originMenu);
}
}
$oDB = DB::getInstance(); $oDB = DB::getInstance();
$oDB->begin(); $oDB->begin();
// Remove from the DB $this->_recursiveDeleteMenuItem($oDB, $menuInfo, $originMenu);
$output = executeQuery("menu.deleteMenuItem", $args);
if(!$output->toBool()) $oDB->commit();
// recreate menu cache file
$this->makeXmlFile($args->menu_srl);
$this->add('xml_file', $xml_file);
$this->add('menu_title', $menu_title);
$this->add('menu_item_srl', $parent_srl);
$this->setMessage('success_deleted');
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispMenuAdminManagement', 'menu_srl', $args->menu_srl);
$this->setRedirectUrl($returnUrl);
}
private function _deleteMenuItem(&$oDB, &$menuInfo, $node)
{
// Remove from the DB
$args->menu_srl = $menuSrl;
$args->menu_item_srl = $node['node_srl'];
$output = executeQuery("menu.deleteMenuItem", $args);
if(!$output->toBool())
{ {
$oDB->rollback(); $oDB->rollback();
return $output; return $output;
} }
// Update the xml file and get its location
$xml_file = $this->makeXmlFile($args->menu_srl); // Update the xml file and get its location
// Delete all of image buttons $xml_file = $this->makeXmlFile($args->menu_srl);
if($item_info->normal_btn) FileHandler::removeFile($item_info->normal_btn); // Delete all of image buttons
if($item_info->hover_btn) FileHandler::removeFile($item_info->hover_btn); if($node['normal_btn']) FileHandler::removeFile($node['normal_btn']);
if($item_info->active_btn) FileHandler::removeFile($item_info->active_btn); if($node['hover_btn']) FileHandler::removeFile($node['hover_btn']);
if($node['active_btn']) FileHandler::removeFile($node['active_btn']);
// Delete module // Delete module
if($item_info->is_shortcut != 'Y' && !preg_match('/^http/i',$item_info->url)) if($node['is_shortcut'] != 'Y' && !preg_match('/^http/i',$node['url']))
{ {
$oModuleController = getController('module'); $oModuleController = getController('module');
$oModuleModel = getModel('module'); $oModuleModel = getModel('module');
$moduleInfo = $oModuleModel->getModuleInfoByMid($item_info->url, $menu_info->site_srl); $moduleInfo = $oModuleModel->getModuleInfoByMid($node['url'], $menuInfo->site_srl);
if($moduleInfo->module_srl) if($moduleInfo->module_srl)
{ {
$output = $oModuleController->deleteModule($moduleInfo->module_srl); $output = $oModuleController->deleteModule($moduleInfo->module_srl);
@ -635,17 +670,25 @@
} }
} }
} }
return new Object(0, 'success');
}
$oDB->commit(); private function _recursiveDeleteMenuItem(&$oDB, &$menuInfo, $node)
{
$output = $this->_deleteMenuItem($oDB, $menuInfo, $node);
if(!$output->toBool())
{
return new Object(-1, $output->message);
}
$this->add('xml_file', $xml_file); if(is_array($node['list']))
$this->add('menu_title', $menu_title); {
$this->add('menu_item_srl', $parent_srl); foreach($node['list'] AS $key=>$value)
$this->setMessage('success_deleted'); {
$this->_recursiveDeleteMenuItem($oDB, $menuInfo, $value);
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispMenuAdminManagement', 'menu_srl', $args->menu_srl); }
$this->setRedirectUrl($returnUrl); }
} }
/** /**
* Move menu items * Move menu items