Skip to content

Commit

Permalink
Merge pull request #41 from eddieajau/menumod
Browse files Browse the repository at this point in the history
Added a new link on the module manager page to add a module for that menutype
  • Loading branch information
chdemko committed Dec 16, 2011
2 parents c2cfa3e + 441dd53 commit d968264
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 58 deletions.
87 changes: 62 additions & 25 deletions administrator/components/com_menus/models/menus.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
/**
* @version $Id$
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*
* @package Joomla.Administrator
* @subpackage com_menus
*/

// no direct access
Expand All @@ -13,22 +15,24 @@
/**
* Menu List Model for Menus.
*
* @package Joomla.Administrator
* @subpackage com_menus
* @since 1.6
* @package Joomla.Administrator
* @subpackage com_menus
* @since 1.6
*/
class MenusModelMenus extends JModelList
{
/**
* Constructor.
*
* @param array An optional associative array of configuration settings.
* @param array An optional associative array of configuration settings.
*
* @see JController
* @since 1.6
* @since 1.6
*/
public function __construct($config = array())
{
if (empty($config['filter_fields'])) {
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'id', 'a.id',
'title', 'a.title',
Expand All @@ -42,24 +46,27 @@ public function __construct($config = array())
/**
* Overrides the getItems method to attach additional metrics to the list.
*
* @return mixed An array of data items on success, false on failure.
* @since 1.6.1
* @return mixed An array of data items on success, false on failure.
*
* @since 1.6.1
*/
public function getItems()
{
// Get a storage key.
$store = $this->getStoreId('getItems');

// Try to load the data from internal storage.
if (!empty($this->cache[$store])) {
if (!empty($this->cache[$store]))
{
return $this->cache[$store];
}

// Load the list items.
$items = parent::getItems();

// If emtpy or an error, just return.
if (empty($items)) {
if (empty($items))
{
return array();
}

Expand Down Expand Up @@ -87,43 +94,44 @@ public function getItems()
$db->setQuery($query);
$countPublished = $db->loadAssocList('menutype', 'count_published');

if ($db->getErrorNum()) {
if ($db->getErrorNum())
{
$this->setError($db->getErrorMsg());
return false;
}

// Get the unpublished menu counts.
$query->clear('where')
->where('m.published = 0')
->where('m.menutype IN ('.$menuTypes.')')
;
->where('m.menutype IN ('.$menuTypes.')');
$db->setQuery($query);
$countUnpublished = $db->loadAssocList('menutype', 'count_published');

if ($db->getErrorNum()) {
if ($db->getErrorNum())
{
$this->setError($db->getErrorMsg());
return false;
}

// Get the trashed menu counts.
$query->clear('where')
->where('m.published = -2')
->where('m.menutype IN ('.$menuTypes.')')
;
->where('m.menutype IN ('.$menuTypes.')');
$db->setQuery($query);
$countTrashed = $db->loadAssocList('menutype', 'count_published');

if ($db->getErrorNum()) {
if ($db->getErrorNum())
{
$this->setError($db->getErrorMsg());
return false;
}

// Inject the values back into the array.
foreach ($items as $item)
{
$item->count_published = isset($countPublished[$item->menutype]) ? $countPublished[$item->menutype] : 0;
$item->count_unpublished = isset($countUnpublished[$item->menutype]) ? $countUnpublished[$item->menutype] : 0;
$item->count_trashed = isset($countTrashed[$item->menutype]) ? $countTrashed[$item->menutype] : 0;
$item->count_published = isset($countPublished[$item->menutype]) ? $countPublished[$item->menutype] : 0;
$item->count_unpublished = isset($countUnpublished[$item->menutype]) ? $countUnpublished[$item->menutype] : 0;
$item->count_trashed = isset($countTrashed[$item->menutype]) ? $countTrashed[$item->menutype] : 0;
}

// Add the items to the internal cache.
Expand All @@ -135,7 +143,9 @@ public function getItems()
/**
* Method to build an SQL query to load the list data.
*
* @return string An SQL query
* @return string An SQL query
*
* @since 1.6
*/
protected function getListQuery()
{
Expand All @@ -161,7 +171,12 @@ protected function getListQuery()
*
* Note. Calling getState in this method will result in recursion.
*
* @since 1.6
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
Expand All @@ -172,12 +187,34 @@ protected function populateState($ordering = null, $direction = null)
parent::populateState('a.id', 'asc');
}

/**
* Gets the extension id of the core mod_menu module.
*
* @return integer
*
* @since 2.5
*/
public function getModMenuId()
{
$db = $this->getDbo();
$query = $db->getQuery(true);

$query->select('e.extension_id')
->from('#__extensions AS e')
->where('e.type = ' . $db->quote('module'))
->where('e.element = ' . $db->quote('mod_menu'))
->where('e.client_id = 0');
$db->setQuery($query);

return $db->loadResult();
}

/**
* Gets a list of all mod_mainmenu modules and collates them by menutype
*
* @return array
* @return array
*/
function &getModules()
public function &getModules()
{
$model = JModel::getInstance('Menu', 'MenusModel', array('ignore_request' => true));
$result = &$model->getModules();
Expand Down
42 changes: 21 additions & 21 deletions administrator/components/com_menus/views/menus/tmpl/default.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
/**
* @version $Id$
* @package Joomla.Administrator
* @subpackage com_menus
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @package Joomla.Administrator
* @subpackage com_menus
*
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;
Expand All @@ -16,12 +16,13 @@
JHtml::_('behavior.tooltip');
JHtml::_('behavior.multiselect');

$uri = JFactory::getUri();
$return = base64_encode($uri);
$user = JFactory::getUser();
$userId = $user->get('id');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$uri = JFactory::getUri();
$return = base64_encode($uri);
$user = JFactory::getUser();
$userId = $user->get('id');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$modMenuId = (int) $this->get('ModMenuId');
?>
<script type="text/javascript">
Joomla.submitbutton = function(task) {
Expand Down Expand Up @@ -104,11 +105,9 @@
<?php echo $item->count_trashed; ?></a>
</td>
<td class="left">
<ul>
<?php
if (isset($this->modules[$item->menutype])) :
foreach ($this->modules[$item->menutype] as &$module) :
?>
<?php if (isset($this->modules[$item->menutype])) : ?>
<ul>
<?php foreach ($this->modules[$item->menutype] as &$module) : ?>
<li>
<?php if ($canEdit) : ?>
<a class="modal" href="<?php echo JRoute::_('index.php?option=com_modules&task=module.edit&id='.$module->id.'&return='.$return.'&tmpl=component&layout=modal');?>" rel="{handler: 'iframe', size: {x: 1024, y: 450}, onClose: function() {window.location.reload()}}" title="<?php echo JText::_('COM_MENUS_EDIT_MODULE_SETTINGS');?>">
Expand All @@ -117,11 +116,12 @@
<?php echo JText::sprintf('COM_MENUS_MODULE_ACCESS_POSITION', $this->escape($module->title), $this->escape($module->access_title), $this->escape($module->position)); ?>
<?php endif; ?>
</li>
<?php
endforeach;
endif;
?>
</ul>
<?php endforeach; ?>
</ul>
<?php elseif ($modMenuId) : ?>
<a href="<?php echo JRoute::_('index.php?option=com_modules&task=module.add&eid=' . $modMenuId . '&params[menutype]='.$item->menutype); ?>">
<?php echo JText::_('COM_MENUS_ADD_MENU_MODULE'); ?></a>
<?php endif; ?>
</td>
<td class="center">
<?php echo $item->id; ?>
Expand Down
56 changes: 45 additions & 11 deletions administrator/components/com_modules/controllers/module.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
/**
* @version $Id$
* @package Joomla.Administrator
* @subpackage com_modules
*
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
Expand All @@ -13,14 +15,18 @@
/**
* Module controller class.
*
* @package Joomla.Administrator
* @subpackage com_modules
* @version 1.6
* @package Joomla.Administrator
* @subpackage com_modules
* @version 1.6
*/
class ModulesControllerModule extends JControllerForm
{
/**
* Override parent add method.
*
* @return mixed True if the record can be added, a JError object if not.
*
* @since 1.6
*/
public function add()
{
Expand All @@ -29,35 +35,60 @@ public function add()

// Get the result of the parent method. If an error, just return it.
$result = parent::add();
if ($result instanceof Exception) {
if ($result instanceof Exception)
{
return $result;
}

// Look for the Extension ID.
$extensionId = JRequest::getInt('eid');
if (empty($extensionId)) {
$extensionId = $app->input->get('eid', 0, 'int');
if (empty($extensionId))
{
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.'&layout=edit', false));
return JError::raiseWarning(500, JText::_('COM_MODULES_ERROR_INVALID_EXTENSION'));
}

$app->setUserState('com_modules.add.module.extension_id', $extensionId);
$app->setUserState('com_modules.add.module.params', null);

// Parameters could be coming in for a new item, so let's set them.
$params = $app->input->get('params', array(), 'array');
$app->setUserState('com_modules.add.module.params', $params);
}

/**
* Override parent cancel method to reset the add module state.
*
* @param string $key The name of the primary key of the URL variable.
*
* @return boolean True if access level checks pass, false otherwise.
*
* @since 11.1
*/
public function cancel($key = null)
{
// Initialise variables.
$app = JFactory::getApplication();

parent::cancel();
$result = parent::cancel();

$app->setUserState('com_modules.add.module.extension_id', null);
$app->setUserState('com_modules.add.module.params', null);

return $result;
}

/**
* Override parent allowSave method.
*
* Extended classes can override this if necessary.
*
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key.
*
* @return boolean
*
* @since 1.6
*/
protected function allowSave($data, $key = 'id')
{
Expand All @@ -74,10 +105,11 @@ protected function allowSave($data, $key = 'id')
/**
* Function that allows child controller access to model data after the data has been saved.
*
* @param JModel $model The data model object.
* @param JModel $model The data model object.
*
* @return void
* @since 1.6
* @return void
*
* @since 1.6
*/
protected function postSaveHook(JModel &$model, $validData = array())
{
Expand All @@ -95,5 +127,7 @@ protected function postSaveHook(JModel &$model, $validData = array())
$app->setUserState('com_modules.add.module.extension_id', null);
break;
}

$app->setUserState('com_modules.add.module.params', null);
}
}
Loading

0 comments on commit d968264

Please sign in to comment.