Current Path :
/
home
/
develito
/
httpdocs
/
components
/
com_dmod
/
models
/
Or
Select Your Path :
Upload File :
New :
File
Dir
/home/develito/httpdocs/components/com_dmod/models/category.php
<?php /*------------------------------------------------------------------------ # com_dmod - Dmod Module Manager # ------------------------------------------------------------------------ # author Jesus Vargas Garita # copyright Copyright (C) 2010 www.joomlahill.com. All Rights Reserved. # @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL # Websites: http://www.joomlahill.com # Technical Support: Forum - http://www.joomlahill.com/forum -------------------------------------------------------------------------*/ defined('_JEXEC') or die; class DmodModelCategory extends JModelList { protected $_item = null; protected $_articles = null; protected $_siblings = null; protected $_children = null; protected $_parent = null; protected $_category = null; protected $_categories = null; public function __construct($config = array()) { if (empty($config['filter_fields'])) { $config['filter_fields'] = array( 'id', 'a.id', 'name', 'a.name', 'con_position', 'a.con_position', 'suburb', 'a.suburb', 'state', 'a.state', 'country', 'a.country', 'ordering', 'a.ordering', ); } parent::__construct($config); } public function &getItems() { // Invoke the parent getItems method to get the main list $items = parent::getItems(); // Convert the params field into an object, saving original in _params for ($i = 0, $n = count($items); $i < $n; $i++) { $item = &$items[$i]; if (!isset($this->_params)) { $params = new JRegistry(); $params->loadString($item->params); $item->params = $params; } } return $items; } protected function getListQuery() { $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); // Select required fields from the categories. $query->select($this->getState('list.select', 'a.*') . ',' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, ' . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END AS catslug '); $query->from('`#__dmod` AS a'); $query->where('a.access IN ('.$groups.')'); $query->select('m.module AS module'); $query->join('LEFT', '`#__modules` AS m ON m.id = a.module'); $query->select('c.title AS cat'); $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); // Filter by category. if ($categoryId = $this->getState('category.id')) { $query->where('a.catid = '.(int) $categoryId); $query->where('c.access IN ('.$groups.')'); } // Filter by state $state = $this->getState('filter.published'); if (is_numeric($state)) { $query->where('a.published = '.(int) $state); } // Filter by start and end dates. $nullDate = $db->Quote($db->getNullDate()); $nowDate = $db->Quote(JFactory::getDate()->toSql()); // Set sortname ordering if selected if ($this->getState('list.ordering') == 'sortname') { $query->order($db->escape('a.sortname1').' '.$db->escape($this->getState('list.direction', 'ASC'))); $query->order($db->escape('a.sortname2').' '.$db->escape($this->getState('list.direction', 'ASC'))); $query->order($db->escape('a.sortname3').' '.$db->escape($this->getState('list.direction', 'ASC'))); } else { $query->order($db->escape($this->getState('list.ordering', 'a.ordering')).' '.$db->escape($this->getState('list.direction', 'ASC'))); } return $query; } protected function populateState($ordering = null, $direction = null) { // Initialise variables. $app = JFactory::getApplication(); $params = JComponentHelper::getParams('com_dmod'); $db = $this->getDbo(); // List state information $format = JRequest::getWord('format'); if ($format=='feed') { $limit = $app->getCfg('feed_limit'); } else { $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit')); } $this->setState('list.limit', $limit); $limitstart = JRequest::getVar('limitstart', 0, '', 'int'); $this->setState('list.start', $limitstart); $orderCol = JRequest::getCmd('filter_order', 'ordering'); if (!in_array($orderCol, $this->filter_fields)) { $orderCol = 'ordering'; } $this->setState('list.ordering', $orderCol); $listOrder = JRequest::getCmd('filter_order_Dir', 'ASC'); if (!in_array(strtoupper($listOrder), array('ASC', 'DESC', ''))) { $listOrder = 'ASC'; } $this->setState('list.direction', $listOrder); $id = JRequest::getVar('id', 0, '', 'int'); $this->setState('category.id', $id); $user = JFactory::getUser(); if ((!$user->authorise('core.edit.state', 'com_contact')) && (!$user->authorise('core.edit', 'com_contact'))){ // limit to published for people who can't edit or edit.state. $this->setState('filter.published', 1); // Filter by start and end dates. $this->setState('filter.publish_date', true); } $this->setState('filter.language',$app->getLanguageFilter()); // Load the parameters. $this->setState('params', $params); } public function getCategory() { if(!is_object($this->_item)) { $app = JFactory::getApplication(); $menu = $app->getMenu(); $active = $menu->getActive(); $params = new JRegistry(); $params->loadString($active->params); $options = array(); $options['countItems'] = $params->get('show_cat_items', 1) || $params->get('show_empty_categories', 0); $categories = JCategories::getInstance('Dmod', $options); $this->_item = $categories->get($this->getState('category.id', 'root')); if(is_object($this->_item)) { $this->_children = $this->_item->getChildren(); $this->_parent = false; if($this->_item->getParent()) { $this->_parent = $this->_item->getParent(); } $this->_rightsibling = $this->_item->getSibling(); $this->_leftsibling = $this->_item->getSibling(false); } else { $this->_children = false; $this->_parent = false; } } return $this->_item; } public function getParent() { if(!is_object($this->_item)) { $this->getCategory(); } return $this->_parent; } function &getLeftSibling() { if(!is_object($this->_item)) { $this->getCategory(); } return $this->_leftsibling; } function &getRightSibling() { if(!is_object($this->_item)) { $this->getCategory(); } return $this->_rightsibling; } function &getChildren() { if(!is_object($this->_item)) { $this->getCategory(); } return $this->_children; } }