PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/redirect/code/trunk/administrator/components/com_redirect/models/links.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 155 lines | 75 code | 18 blank | 62 comment | 6 complexity | 3996c60cab2747a6983328c7bf781045 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: links.php 578 2011-02-25 05:04:53Z eddieajau $
  4. * @package NewLifeInIT
  5. * @subpackage com_redirect
  6. * @copyright Copyright 2005 - 2010 New Life in IT Pty Ltd. All rights reserved.
  7. * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
  8. * @link http://www.theartofjoomla.com
  9. */
  10. defined('_JEXEC') or die('Invalid Request.');
  11. juimport('joomla.application.component.modellist');
  12. juimport('joomla.database.databasequery');
  13. /**
  14. * Links model for Redirect.
  15. *
  16. * @package NewLifeInIT
  17. * @subpackage com_redirect
  18. * @version 1.0
  19. */
  20. class RedirectModelLinks extends JModelList
  21. {
  22. /**
  23. * Class constructor.
  24. *
  25. * @param array $config An optional associative array of configuration settings.
  26. *
  27. * @return ArtofUserModelUsers
  28. * @since 1.1
  29. */
  30. public function __construct($config = array())
  31. {
  32. // Set the list ordering fields.
  33. if (empty($config['filter_fields'])) {
  34. $config['filter_fields'] = array(
  35. 'id', 'a.id',
  36. 'hits', 'a.hits',
  37. 'updated_date', 'a.updated_date',
  38. 'created_date', 'a.created_date',
  39. 'referer', 'a.referer',
  40. 'old_url', 'a.old_url',
  41. 'new_url', 'a.new_url',
  42. );
  43. }
  44. parent::__construct($config);
  45. }
  46. /**
  47. * Method to build an SQL query to load the list data.
  48. *
  49. * @return string An SQL query
  50. * @since 1.0
  51. */
  52. protected function getListQuery()
  53. {
  54. // Create a new query object.
  55. $query = new JDatabaseQuery;
  56. // Select all fields from the table.
  57. $query->select($this->getState('list.select', '*'));
  58. $query->from('`#__redirect_links`');
  59. // Filter the items over the search string if set.
  60. $search = $this->getState('filter.search');
  61. if (!empty($search)) {
  62. $query->where(
  63. '(`old_url` LIKE '.$this->_db->Quote('%'.$this->_db->getEscaped($search, true).'%') .
  64. ' OR `new_url` LIKE '.$this->_db->Quote('%'.$this->_db->getEscaped($search, true).'%') .
  65. ' OR `comment` LIKE '.$this->_db->Quote('%'.$this->_db->getEscaped($search, true).'%') .
  66. ' OR `referer` LIKE '.$this->_db->Quote('%'.$this->_db->getEscaped($search, true).'%').')'
  67. );
  68. }
  69. // Filter the items over the published state if set.
  70. if ($this->getState('check.state')) {
  71. $state_id = $this->getState('filter.state');
  72. if ($state_id !== '*' and $state_id !== null) {
  73. $query->where('`published` = '.(int)$state_id);
  74. }
  75. }
  76. // Add the list ordering clause.
  77. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.name')).' '.$this->_db->getEscaped($this->getState('list.direction', 'ASC')));
  78. //echo nl2br(str_replace('#__','jos_',(string) $query)).'<hr/>';
  79. return (string) $query;
  80. }
  81. /**
  82. * Method to get a store id based on model configuration state.
  83. *
  84. * This is necessary because the model is used by the component and
  85. * different modules that might need different sets of data or different
  86. * ordering requirements.
  87. *
  88. * @param string $context A prefix for the store id.
  89. * @return string A store id.
  90. * @since 1.0
  91. */
  92. protected function getStoreId($id = '')
  93. {
  94. // Compile the store id.
  95. $id .= ':'.$this->getState('list.select');
  96. $id .= ':'.$this->getState('list.start');
  97. $id .= ':'.$this->getState('list.limit');
  98. $id .= ':'.$this->getState('list.ordering');
  99. $id .= ':'.$this->getState('list.direction');
  100. $id .= ':'.$this->getState('filter.search');
  101. $id .= ':'.$this->getState('filter.state');
  102. return md5($id);
  103. }
  104. /**
  105. * Method to auto-populate the model state.
  106. *
  107. * This method should only be called once per instantiation and is designed
  108. * to be called on the first call to the getState() method unless the model
  109. * configuration flag to ignore the request is set.
  110. *
  111. * @return void
  112. * @since 1.0
  113. */
  114. protected function populateState()
  115. {
  116. $app = JFactory::getApplication('administrator');
  117. $user = JFactory::getUser();
  118. $params = JComponentHelper::getParams('com_redirect');
  119. $context = 'com_redirect.links.';
  120. // Load the filter state.
  121. $this->setState('filter.search', $app->getUserStateFromRequest($context.'filter.search', 'filter_search', ''));
  122. $this->setState('filter.state', $app->getUserStateFromRequest($context.'filter.state', 'filter_state', '0', 'string'));
  123. // Load the user parameters.
  124. $this->setState('user', $user);
  125. $this->setState('user.id', (int)$user->id);
  126. $this->setState('user.aid', (int)$user->get('aid'));
  127. // Load the check parameters.
  128. if ($this->state->get('filter.state') === '*') {
  129. $this->setState('check.state', false);
  130. } else {
  131. $this->setState('check.state', true);
  132. }
  133. // Load the parameters.
  134. $this->setState('params', $params);
  135. parent::populateState('updated_date', 'asc');
  136. }
  137. }