PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/contentmanager/code/trunk/administrator/components/com_contentmanager/models/templates.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 122 lines | 54 code | 20 blank | 48 comment | 4 complexity | 2e8f53a4c4941bce79b5bfc11a4465d6 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: templates.php 198 2010-01-25 19:43:52Z eddieajau $
  4. * @copyright Copyright (C) 2009 New Life in IT Pty Ltd. All rights reserved.
  5. * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
  6. * @link http://www.theartofjoomla.com
  7. */
  8. // no direct access
  9. defined('_JEXEC') or die;
  10. jximport2('jxtended.application.component.modellist');
  11. /**
  12. * @package TAOJ.ContentManager
  13. * @subpackage com_contentmanager
  14. */
  15. class ContentManagerModelTemplates extends JxModelList
  16. {
  17. /**
  18. * Model context string.
  19. *
  20. * @var string
  21. */
  22. public $_context = 'com_contentmanager.templates';
  23. /**
  24. * Overridden method to lazy load data from the request/session as necessary
  25. *
  26. * @access public
  27. * @param string $key The key of the state item to return
  28. * @param mixed $default The default value to return if it does not exist
  29. * @return mixed The requested value by key
  30. * @since 1.0
  31. */
  32. function _populateState()
  33. {
  34. $app = &JFactory::getApplication();
  35. $search = $app->getUserStateFromRequest($this->_context.'.search', 'search');
  36. $this->setState('filter.search', $search);
  37. $published = $app->getUserStateFromRequest($this->_context.'.published', 'published', 1);
  38. $this->setState('filter.published', ($published == '*' ? null : $published));
  39. // List state information
  40. $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'));
  41. $this->setState('list.limit', $limit);
  42. $limitstart = $app->getUserStateFromRequest($this->_context.'.limitstart', 'limitstart', 0);
  43. $this->setState('list.start', $limitstart);
  44. $orderCol = $app->getUserStateFromRequest($this->_context.'.ordercol', 'filter_order', 'a.title');
  45. $this->setState('list.ordering', $orderCol);
  46. $orderDirn = $app->getUserStateFromRequest($this->_context.'.orderdirn', 'filter_order_Dir', 'asc');
  47. $this->setState('list.direction', $orderDirn);
  48. }
  49. /**
  50. * Method to get a store id based on model configuration state.
  51. *
  52. * This is necessary because the model is used by the component and
  53. * different modules that might need different sets of data or different
  54. * ordering requirements.
  55. *
  56. * @param string $id A prefix for the store id.
  57. *
  58. * @return string A store id.
  59. */
  60. public function _getStoreId($id = '')
  61. {
  62. // Compile the store id.
  63. $id .= ':'.$this->getState('list.start');
  64. $id .= ':'.$this->getState('list.limit');
  65. $id .= ':'.$this->getState('list.ordering');
  66. $id .= ':'.$this->getState('list.direction');
  67. $id .= ':'.$this->getState('filter.search');
  68. $id .= ':'.$this->getState('filter.published');
  69. return md5($id);
  70. }
  71. /**
  72. * @param boolean True to join selected foreign information
  73. *
  74. * @return string
  75. */
  76. function _getListQuery($resolveFKs = true)
  77. {
  78. $query = new JXQuery;
  79. $query->select($this->getState('list.select', 'a.title, a.icon, a.id, a.published, a.checked_out, a.checked_out_time'));
  80. $query->from('#__taoj_contentmanager_xmltemplates AS a');
  81. if ($resolveFKs) {
  82. // checked out
  83. $query->select('co.name AS editor');
  84. $query->join('LEFT', '#__users AS co ON co.id=a.checked_out');
  85. }
  86. // Filter by published state
  87. $published = $this->getState('filter.published');
  88. if (is_numeric($published)) {
  89. $query->where('a.published = ' . (int) $published);
  90. }
  91. // Filter by search in title
  92. $search = $this->getState('filter.search');
  93. if (!empty($search)) {
  94. $search = $this->_db->Quote('%'.$this->_db->getEscaped( $search, true ).'%', false);
  95. $query->where('(a.title LIKE '.$search.')');
  96. }
  97. // Add the list ordering clause.
  98. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.title')).' '.$this->_db->getEscaped($this->getState('list.direction', 'ASC')));
  99. //echo nl2br(str_replace('#__','jos_',$query->toString()));
  100. return $query;
  101. }
  102. }