/contentmanager/code/trunk/administrator/components/com_contentmanager/models/templates.php
PHP | 122 lines | 54 code | 20 blank | 48 comment | 4 complexity | 2e8f53a4c4941bce79b5bfc11a4465d6 MD5 | raw file
- <?php
- /**
- * @version $Id: templates.php 198 2010-01-25 19:43:52Z eddieajau $
- * @copyright Copyright (C) 2009 New Life in IT Pty Ltd. All rights reserved.
- * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
- * @link http://www.theartofjoomla.com
- */
-
- // no direct access
- defined('_JEXEC') or die;
-
- jximport2('jxtended.application.component.modellist');
-
- /**
- * @package TAOJ.ContentManager
- * @subpackage com_contentmanager
- */
- class ContentManagerModelTemplates extends JxModelList
- {
- /**
- * Model context string.
- *
- * @var string
- */
- public $_context = 'com_contentmanager.templates';
-
- /**
- * Overridden method to lazy load data from the request/session as necessary
- *
- * @access public
- * @param string $key The key of the state item to return
- * @param mixed $default The default value to return if it does not exist
- * @return mixed The requested value by key
- * @since 1.0
- */
- function _populateState()
- {
- $app = &JFactory::getApplication();
-
- $search = $app->getUserStateFromRequest($this->_context.'.search', 'search');
- $this->setState('filter.search', $search);
-
- $published = $app->getUserStateFromRequest($this->_context.'.published', 'published', 1);
- $this->setState('filter.published', ($published == '*' ? null : $published));
-
- // List state information
- $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'));
- $this->setState('list.limit', $limit);
-
- $limitstart = $app->getUserStateFromRequest($this->_context.'.limitstart', 'limitstart', 0);
- $this->setState('list.start', $limitstart);
-
- $orderCol = $app->getUserStateFromRequest($this->_context.'.ordercol', 'filter_order', 'a.title');
- $this->setState('list.ordering', $orderCol);
-
- $orderDirn = $app->getUserStateFromRequest($this->_context.'.orderdirn', 'filter_order_Dir', 'asc');
- $this->setState('list.direction', $orderDirn);
- }
-
- /**
- * Method to get a store id based on model configuration state.
- *
- * This is necessary because the model is used by the component and
- * different modules that might need different sets of data or different
- * ordering requirements.
- *
- * @param string $id A prefix for the store id.
- *
- * @return string A store id.
- */
- public function _getStoreId($id = '')
- {
- // Compile the store id.
- $id .= ':'.$this->getState('list.start');
- $id .= ':'.$this->getState('list.limit');
- $id .= ':'.$this->getState('list.ordering');
- $id .= ':'.$this->getState('list.direction');
- $id .= ':'.$this->getState('filter.search');
- $id .= ':'.$this->getState('filter.published');
-
- return md5($id);
- }
-
- /**
- * @param boolean True to join selected foreign information
- *
- * @return string
- */
- function _getListQuery($resolveFKs = true)
- {
- $query = new JXQuery;
-
- $query->select($this->getState('list.select', 'a.title, a.icon, a.id, a.published, a.checked_out, a.checked_out_time'));
-
- $query->from('#__taoj_contentmanager_xmltemplates AS a');
-
- if ($resolveFKs) {
- // checked out
- $query->select('co.name AS editor');
- $query->join('LEFT', '#__users AS co ON co.id=a.checked_out');
- }
-
- // Filter by published state
- $published = $this->getState('filter.published');
- if (is_numeric($published)) {
- $query->where('a.published = ' . (int) $published);
- }
-
- // Filter by search in title
- $search = $this->getState('filter.search');
- if (!empty($search)) {
- $search = $this->_db->Quote('%'.$this->_db->getEscaped( $search, true ).'%', false);
- $query->where('(a.title LIKE '.$search.')');
- }
-
- // Add the list ordering clause.
- $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.title')).' '.$this->_db->getEscaped($this->getState('list.direction', 'ASC')));
-
- //echo nl2br(str_replace('#__','jos_',$query->toString()));
- return $query;
- }
- }