Current Path :
/
home
/
develito
/
public_html
/
components
/
com_abook
/
helpers
/
Or
Select Your Path :
Upload File :
New :
File
Dir
/home/develito/public_html/components/com_abook/helpers/category.php
<?php /** * @version $Id: category.php 16235 2010-04-20 04:13:25Z pasamio $ * @package Joomla * @subpackage com_content * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License 3 or later; see LICENSE.txt */ // no direct access defined('_JEXEC') or die; // Component Helper jimport('joomla.application.component.helper'); jimport('joomla.application.categories'); /** * Contact Component Category Tree * * @static * @package Joomla * @subpackage com_contact * @since 1.6 */ class AbookCategories extends JCategories { public function __construct($options = array()) { $options['table'] = '#__abbook'; $options['extension'] = 'com_abook'; $options['statefield'] = 'state'; parent::__construct($options); } protected function _load($id) { $db = JFactory::getDbo(); $app = JFactory::getApplication(); $user = JFactory::getUser(); $extension = $this->_extension; // Record that has this $id has been checked $this->_checkedCategories[$id] = true; $query = $db->getQuery(true); // Right join with c for category $query->select('c.id, c.asset_id, c.access, c.alias, c.checked_out, c.checked_out_time, c.created_time, c.created_user_id, c.description, c.extension, c.hits, c.language, c.level, c.lft, c.metadata, c.metadesc, c.metakey, c.modified_time, c.note, c.params, c.parent_id, c.path, c.published, c.rgt, c.title, c.modified_user_id'); $case_when = ' CASE WHEN '; $case_when .= $query->charLength('c.alias', '!=', '0'); $case_when .= ' THEN '; $c_id = $query->castAsChar('c.id'); $case_when .= $query->concatenate(array($c_id, 'c.alias'), ':'); $case_when .= ' ELSE '; $case_when .= $c_id . ' END as slug'; $query->select($case_when) ->from('#__abcategories as c') ->where('(c.extension=' . $db->quote($extension) . ' OR c.extension=' . $db->quote('system') . ')'); if ($this->_options['access']) { $query->where('c.access IN (' . implode(',', $user->getAuthorisedViewLevels()) . ')'); } if ($this->_options['published'] == 1) { $query->where('c.published = 1'); $subQuery = ' (SELECT cat.id as id FROM #__abcategories AS cat JOIN #__abcategories AS parent ' . 'ON cat.lft BETWEEN parent.lft AND parent.rgt WHERE parent.extension = ' . $db->quote($extension) . ' AND parent.published != 1 GROUP BY cat.id) '; $query->join('LEFT', $subQuery . 'AS badcats ON badcats.id = c.id') ->where('badcats.id is null'); } $query->order('c.lft'); // Note: s for selected id if ($id != 'root') { // Get the selected category $query->where('s.id=' . (int) $id); if ($app->isSite() && JLanguageMultilang::isEnabled()) { $query->join('LEFT', '#__abcategories AS s ON (s.lft < c.lft AND s.rgt > c.rgt AND c.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')) OR (s.lft >= c.lft AND s.rgt <= c.rgt)'); } else { $query->join('LEFT', '#__abcategories AS s ON (s.lft <= c.lft AND s.rgt >= c.rgt) OR (s.lft > c.lft AND s.rgt < c.rgt)'); } } else { if ($app->isSite() && JLanguageMultilang::isEnabled()) { $query->where('c.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')'); } } // Note: i for item if ($this->_options['countItems'] == 1) { $queryjoin = $db->quoteName($this->_table) . ' AS i ON i.' . $db->quoteName($this->_field) . ' = c.id'; if ($this->_options['published'] == 1) { $queryjoin .= ' AND i.' . $this->_statefield . ' = 1'; } if ($this->_options['currentlang'] !== 0) { $queryjoin .= ' AND (i.language = ' . $db->quote('*') . ' OR i.language = ' . $db->quote($this->_options['currentlang']) . ')'; } $query->join('LEFT', $queryjoin); $query->select('COUNT(i.' . $db->quoteName($this->_key) . ') AS numitems'); } // Group by $query->group( 'c.id, c.asset_id, c.access, c.alias, c.checked_out, c.checked_out_time, c.created_time, c.created_user_id, c.description, c.extension, c.hits, c.language, c.level, c.lft, c.metadata, c.metadesc, c.metakey, c.modified_time, c.note, c.params, c.parent_id, c.path, c.published, c.rgt, c.title, c.modified_user_id' ); // Get the results $db->setQuery($query); $results = $db->loadObjectList('id'); $childrenLoaded = false; if (count($results)) { // Foreach categories foreach ($results as $result) { // Deal with root category if ($result->id == 1) { $result->id = 'root'; } // Deal with parent_id if ($result->parent_id == 1) { $result->parent_id = 'root'; } // Create the node if (!isset($this->_nodes[$result->id])) { // Create the JCategoryNode and add to _nodes $this->_nodes[$result->id] = new JCategoryNode($result, $this); // If this is not root and if the current node's parent is in the list or the current node parent is 0 if ($result->id != 'root' && (isset($this->_nodes[$result->parent_id]) || $result->parent_id == 1)) { // Compute relationship between node and its parent - set the parent in the _nodes field $this->_nodes[$result->id]->setParent($this->_nodes[$result->parent_id]); } // If the node's parent id is not in the _nodes list and the node is not root (doesn't have parent_id == 0), // then remove the node from the list if (!(isset($this->_nodes[$result->parent_id]) || $result->parent_id == 0)) { unset($this->_nodes[$result->id]); continue; } if ($result->id == $id || $childrenLoaded) { $this->_nodes[$result->id]->setAllLoaded(); $childrenLoaded = true; } } elseif ($result->id == $id || $childrenLoaded) { // Create the JCategoryNode $this->_nodes[$result->id] = new JCategoryNode($result, $this); if ($result->id != 'root' && (isset($this->_nodes[$result->parent_id]) || $result->parent_id)) { // Compute relationship between node and its parent $this->_nodes[$result->id]->setParent($this->_nodes[$result->parent_id]); } // If the node's parent id is not in the _nodes list and the node is not root (doesn't have parent_id == 0), // then remove the node from the list if (!(isset($this->_nodes[$result->parent_id]) || $result->parent_id == 0)) { unset($this->_nodes[$result->id]); continue; } if ($result->id == $id || $childrenLoaded) { $this->_nodes[$result->id]->setAllLoaded(); $childrenLoaded = true; } } } } else { $this->_nodes[$id] = null; } } }