Created
January 23, 2013 08:36
-
-
Save piotr-cz/4603186 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Removes the admin menu item for a given component | |
* | |
* This method was pilfered from JInstallerComponent::_removeAdminMenus() | |
* /libraries/joomla/installer/adapters/component.php : _removeAdminMenus | |
* | |
* @param int $id The component's #__extensions id | |
* | |
* @return bool True on success, false on failure | |
* | |
* @ref http://stackoverflow.com/questions/10642936/component-without-admin-menu | |
* @note matching element name + type gives uniqueness | |
* @note Could use $parent->stepStack: Array([0] => Array('type' => 'menu', 'id' => 826)); | |
*/ | |
protected function removeAdminMenus() | |
{ | |
// Initialise Variables | |
$db = JFactory::getDbo(); | |
$query = $db->getQuery(true); | |
$table = JTable::getInstance('menu'); | |
// Get component id | |
$id = JTable::getInstance('extension')->find(array('name' => 'com_linkfiles', 'client_id' => 1)); | |
// Get the ids of the menu items | |
$query | |
->select( 'id' ) | |
->from( '#__menu' ) | |
->where( $db->qn('client_id') . ' = ' . $db->q( 1 ) ) | |
->where( $db->qn('component_id') . ' = ' . (int) $id ) | |
; | |
$db->setQuery($query); | |
$ids = $db->loadColumn(); | |
// Check for error | |
if ($error = $db->getErrorMsg()) | |
{ | |
return false; | |
} | |
elseif ( !empty($ids)) | |
{ | |
// Iterate the items to delete each one. | |
foreach ($ids as $menuid) | |
{ | |
if (!$table->delete((int) $menuid)) | |
{ | |
return false; | |
} | |
} | |
// Rebuild the whole tree | |
$table->rebuild(); | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment