From 64762fd890e8482319190af55518699c384a4d7a Mon Sep 17 00:00:00 2001 From: Matt Thomas Date: Thu, 10 Jul 2014 14:54:41 -0400 Subject: [PATCH 01/14] Implements adding category items as sub-menu items --- helper.php | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/helper.php b/helper.php index c9aeae3..175fd2e 100644 --- a/helper.php +++ b/helper.php @@ -25,6 +25,7 @@ class modMenuwrenchHelper public function __construct($params) { $this->app = JFactory::getApplication(); + $this->db = JFactory::getDbo(); $this->menu = $this->app->getMenu(); $this->active = $this->menu->getActive(); $this->params = $params; @@ -65,6 +66,16 @@ function getBranches() $items[$item->id] = $item; + // If menu item is a category, add all articles as menu items + if ($item->query['view'] === 'category') + { + $items[$item->id]->children = $this->linkCategoryItems( + $this->getCategoryItems($item->query['id']), + $item->query['id'], + $item->id + ); + } + unset($items[$key]); if ($item->parent_id != 1) @@ -118,6 +129,52 @@ function getBranches() return $items; } + /** + * Get all of the published articles in a given category + * + * @param $categoryId + * + * @return mixed + */ + private function getCategoryItems($categoryId) + { + + $query = $this->db->getQuery(true); + + $query + ->select($this->db->quoteName(array('id', 'alias', 'title'))) + ->from($this->db->quoteName('#__content')) + ->where($this->db->quoteName('state') . ' = ' . $this->db->quote('1'), ' AND ') + ->where($this->db->quoteName('catid') . ' = ' . $this->db->quote($categoryId)) + ->order('ordering ASC'); + + // Reset the query using our newly populated query object. + $this->db->setQuery($query); + + // Load the results as a list of stdClass objects (see later for more options on retrieving data). + return $this->db->loadObjectList(); + } + + /** + * Generate single article item link, based on supplied parameters + * + * @param $items + * @param $catId + * @param $itemId + * + * @return mixed + */ + private function linkCategoryItems($items, $catId, $itemId) + { + foreach ($items as $item) + { + $item->link = 'index.php?option=com_content&view=article&id=' . $item->id . ':' . $item->alias . '&catid=' . $catId . '&Itemid=' . $itemId; + } + + return $items; + + } + /** * Renders the menu * @@ -176,7 +233,8 @@ public function render($item, $containerTag = '