| Current Path : /home/purehotels/public_html/administrator/components/com_easyfolderlistingpro/models/ |
| Current File : /home/purehotels/public_html/administrator/components/com_easyfolderlistingpro/models/profiles.php |
<?php
/**
* @version 3.2
* @author Michael A. Gilkes (michael@valorapps.com)
* @copyright Michael Albert Gilkes
* @license GNU/GPLv3
Easy Folder Listing Pro Component for Joomla!
Copyright (C) 2012-2016 Michael Albert Gilkes (Valor Apps)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
/**
* EasyFolderListingPro Profiles Model
*/
class EasyFolderListingProModelProfiles extends JModelList
{
public function __construct($config = array())
{
/* Add all fields that may be filtered and sorted */
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'id', 'a.id',
'title', 'a.title',
'folder', 'a.folder',
'published', 'a.published',
'checked_out', 'a.checked_out',
'checked_out_time', 'a.checked_out_time',
'access', 'a.access', 'access_level',
);
}
parent::__construct($config);
}
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':'.$this->getState('filter.search');
$id .= ':'.$this->getState('filter.access');
$id .= ':'.$this->getState('filter.published');
return parent::getStoreId($id);
}
public function getTable($type = 'Profile', $prefix = 'EasyFolderListingProTable', $config = array())
{
return JTable::getInstance($type, $prefix, $config);
}
protected function populateState($ordering = null, $direction = null)
{
$app = JFactory::getApplication('administrator');
//Adjust the context to support modal layouts.
if ($layout = $app->input->get('layout'))
{
$this->context .= '.' . $layout;
}
//Load the filter state.
$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
$this->setState('filter.search', $search);
$published = $this->getUserStateFromRequest($this->context.'.filter.published', 'filter_published', '');
$this->setState('filter.published', $published);
$access = $this->getUserStateFromRequest($this->context.'.filter.access', 'filter_access', 0, 'int');
$this->setState('filter.access', $access);
//List state information.
parent::populateState('a.title', 'asc');
}
function getListQuery()
{
//Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
$user = JFactory::getUser();
// Select the required fields from the table.
$query->select(
$this->getState(
'list.select',
'a.id, a.title, a.folder, a.published, a.access, a.checked_out, a.checked_out_time'
)
);
$query->from('#__eflp_profiles AS a');
//Join over the users for the checked out user.
$query->select('uc.name AS editor');
$query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
//Join over the asset groups.
$query->select('ag.title AS access_level');
$query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
//Filter by access level.
if ($access = $this->getState('filter.access'))
{
$query->where('a.access = ' . (int) $access);
}
//Implement View Level Access
if (!$user->authorise('core.admin'))
{
$groups = implode(',', $user->getAuthorisedViewLevels());
$query->where('a.access IN ('.$groups.')');
}
//Filter by published state
$published = $this->getState('filter.published');
if (is_numeric($published))
{
$query->where('a.published = ' . (int) $published);
}
elseif ($published === '')
{
$query->where('(a.published IN (0, 1))');
}
// Filter by search in title
$search = $this->getState('filter.search');
if (!empty($search))
{
if (stripos($search, 'id:') === 0)
{
$query->where('a.id = '.(int) substr($search, 3));
}
else
{
$search = $db->Quote('%'.$db->escape($search, true).'%');
$query->where('(a.title LIKE '.$search.' OR a.folder LIKE '.$search.')');
}
}
// Add the list ordering clause.
$orderCol = $this->state->get('list.ordering', 'a.title');
$orderDirn = $this->state->get('list.direction', 'asc');
//sqlsrv change: since you can't order by an alias in sqlsvr
if ($orderCol == 'access_level')
{
$orderCol = 'ag.title';
}
$query->order($db->escape($orderCol . ' ' . $orderDirn));
return $query;
}
}