the-art-of-joomla-archive /redirect/code/trunk/administrator/components/com_redirect/models/links.php

Language PHP Lines 155
MD5 Hash 3996c60cab2747a6983328c7bf781045 Estimated Cost $1,730 (why?)
Repository https://bitbucket.org/eddieajau/the-art-of-joomla-archive View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
 * @version		$Id: links.php 578 2011-02-25 05:04:53Z eddieajau $
 * @package		NewLifeInIT
 * @subpackage	com_redirect
 * @copyright	Copyright 2005 - 2010 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
 */

defined('_JEXEC') or die('Invalid Request.');

juimport('joomla.application.component.modellist');
juimport('joomla.database.databasequery');

/**
 * Links model for Redirect.
 *
 * @package		NewLifeInIT
 * @subpackage	com_redirect
 * @version		1.0
 */
class RedirectModelLinks extends JModelList
{
	/**
	 * Class constructor.
	 *
	 * @param	array	$config	An optional associative array of configuration settings.
	 *
	 * @return	ArtofUserModelUsers
	 * @since	1.1
	 */
	public function __construct($config = array())
	{
		// Set the list ordering fields.
		if (empty($config['filter_fields'])) {
			$config['filter_fields'] = array(
				'id', 'a.id',
				'hits', 'a.hits',
				'updated_date', 'a.updated_date',
				'created_date', 'a.created_date',
				'referer', 'a.referer',
				'old_url', 'a.old_url',
				'new_url', 'a.new_url',
			);
		}

		parent::__construct($config);
	}

	/**
	 * Method to build an SQL query to load the list data.
	 *
	 * @return	string		An SQL query
	 * @since	1.0
	 */
	protected function getListQuery()
	{
		// Create a new query object.
		$query = new JDatabaseQuery;

		// Select all fields from the table.
		$query->select($this->getState('list.select', '*'));
		$query->from('`#__redirect_links`');

		// Filter the items over the search string if set.
		$search = $this->getState('filter.search');
		if (!empty($search)) {
			$query->where(
				'(`old_url` LIKE '.$this->_db->Quote('%'.$this->_db->getEscaped($search, true).'%') .
				' OR `new_url` LIKE '.$this->_db->Quote('%'.$this->_db->getEscaped($search, true).'%') .
				' OR `comment` LIKE '.$this->_db->Quote('%'.$this->_db->getEscaped($search, true).'%') .
				' OR `referer` LIKE '.$this->_db->Quote('%'.$this->_db->getEscaped($search, true).'%').')'
			);
		}

		// Filter the items over the published state if set.
		if ($this->getState('check.state')) {
			$state_id = $this->getState('filter.state');
			if ($state_id !== '*' and $state_id !== null) {
				$query->where('`published` = '.(int)$state_id);
			}
		}

		// Add the list ordering clause.
		$query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.name')).' '.$this->_db->getEscaped($this->getState('list.direction', 'ASC')));

		//echo nl2br(str_replace('#__','jos_',(string) $query)).'<hr/>';
		return (string) $query;
	}

	/**
	 * 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		$context	A prefix for the store id.
	 * @return	string		A store id.
	 * @since	1.0
	 */
	protected function getStoreId($id = '')
	{
		// Compile the store id.
		$id	.= ':'.$this->getState('list.select');
		$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.state');

		return md5($id);
	}

	/**
	 * Method to auto-populate the model state.
	 *
	 * This method should only be called once per instantiation and is designed
	 * to be called on the first call to the getState() method unless the model
	 * configuration flag to ignore the request is set.
	 *
	 * @return	void
	 * @since	1.0
	 */
	protected function populateState()
	{
		$app		= JFactory::getApplication('administrator');
		$user		= JFactory::getUser();
		$params		= JComponentHelper::getParams('com_redirect');
		$context	= 'com_redirect.links.';

		// Load the filter state.
		$this->setState('filter.search', $app->getUserStateFromRequest($context.'filter.search', 'filter_search', ''));
		$this->setState('filter.state', $app->getUserStateFromRequest($context.'filter.state', 'filter_state', '0', 'string'));

		// Load the user parameters.
		$this->setState('user',	$user);
		$this->setState('user.id', (int)$user->id);
		$this->setState('user.aid', (int)$user->get('aid'));

		// Load the check parameters.
		if ($this->state->get('filter.state') === '*') {
			$this->setState('check.state', false);
		} else {
			$this->setState('check.state', true);
		}

		// Load the parameters.
		$this->setState('params', $params);

		parent::populateState('updated_date', 'asc');
	}
}
Back to Top