Current File : /home/pacjaorg/public_html/kmm/administrator/components/com_djclassifieds/models/profiles.php |
<?php
/**
* @package DJ-Classifieds
* @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
* @license http://www.gnu.org/licenses GNU/GPL
* @author url: http://dj-extensions.com
* @author email: contact@dj-extensions.com
*/
defined ('_JEXEC') or die('Restricted access');
class DjClassifiedsModelProfiles extends JModelList{
public function __construct($config = array())
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'name', 'u.name',
'username', 'u.id',
'email', 'u.email',
'up.u_points', 'i.u_items',
'verified', 'p.verified',
'attachment', 'f.attachment',
'active', 'region'
);
}
parent::__construct($config);
}
protected function populateState($ordering = null, $direction = null)
{
// List state information.
parent::populateState('u.id', 'desc');
$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
$this->setState('filter.search', $search);
$verified = $this->getUserStateFromRequest($this->context.'.filter.verified', 'filter_verified');
$this->setState('filter.verified', $verified);
$attachment = $this->getUserStateFromRequest($this->context.'.filter.attachment', 'filter_attachment');
$this->setState('filter.attachment', $attachment);
$active = $this->getUserStateFromRequest($this->context.'.filter.active', 'filter_active');
$this->setState('filter.active', $active);
$region = $this->getUserStateFromRequest($this->context.'.filter.region', 'filter_region', '');
$this->setState('filter.region', $region);
$order = $this->getUserStateFromRequest($this->context.'.filter.order', 'filter_order');
if($order){
$this->setState('list.ordering', $order);
}
$order_dir = $this->getUserStateFromRequest($this->context.'.filter.order_Dir', 'filter_order_Dir');
if($order_dir){
$this->setState('list.direction', $order_dir);
}
}
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':'.$this->getState('filter.search');
$id .= ':'.$this->getState('filter.verified');
$id .= ':'.$this->getState('filter.attachment');
$id .= ':'.$this->getState('filter.active');
$id .= ':'.$this->getState('filter.region');
return parent::getStoreId($id);
}
public function _buildWhere()
{
$where = '';
$search = $this->getState('filter.search');
if (!empty($search)) {
$db = JFactory::getDBO();
$search_id = $db->Quote($db->escape($search, true));
$search = $db->Quote('%'.$db->escape($search, true).'%');
$where .= " AND (u.name LIKE ".$search." OR u.username LIKE ".$search." OR u.email LIKE ".$search." OR u.id=".$search_id.")";
}
$verified = $this->getState('filter.verified');
if (is_numeric($verified) && $verified!='-1') {
$where .= " AND p.verified=".$verified." ";
}
$attachment = $this->getState('filter.attachment');
if (is_numeric($attachment) && $attachment!='-1') {
if($attachment == '1'){
$where .= " AND f.attachment > 0 ";
}else{
$where .= " AND f.attachment IS NULL ";
}
}
$active = $this->getState('filter.active');
if (is_numeric($active) && $active!='-1') {
if($active == '1'){
$where .= " AND u.block=0 AND (u.activation = '0' OR u.activation = '') ";
}else{
$where .= " AND (u.block=1 OR (u.activation != '0' AND u.activation != '')) ";
}
}
$region = $this->getState('filter.region');
if (is_numeric($region) && $region != 0) {
$reglist = '';
$regs = DJClassifiedsRegion::getSubReg((int) $region);
$reglist = (int) $region;
foreach($regs as $r){
$reglist .= ','. $r->id;
}
$where .= ' AND p.region_id IN ('.$reglist.') ';
}
return $where;
}
protected function getListQuery()
{
$orderCol = $this->getState('list.ordering');
$orderDirn = $this->getState('list.direction');
$query = "SELECT p.*, u.*, up.u_points, i.u_items, f.attachment, p.user_id profile_id "
."FROM #__users u "
."LEFT JOIN (SELECT SUM(points) as u_points, user_id
FROM #__djcf_users_points GROUP BY user_id) up ON up.user_id=u.id "
."LEFT JOIN (SELECT COUNT(i.id) as u_items, i.user_id
FROM #__djcf_items i GROUP BY i.user_id) i ON i.user_id=u.id "
."LEFT JOIN #__djcf_profiles p ON p.user_id=u.id "
."LEFT JOIN (SELECT MAX(id) attachment, item_id FROM #__djcf_files WHERE type='profile' GROUP BY item_id) f ON f.item_id=u.id "
."WHERE 1 ".$this->_buildWhere()." ORDER BY ".$orderCol." ".$orderDirn;
JFactory::getApplication()->triggerEvent('onDJClassifiedsAdminProfilesQuery', array(&$query));
return $query;
}
function getBatchForm()
{
return JForm::getInstance('batch_profiles', JPATH_ROOT.'/administrator/components/com_djclassifieds/models/forms/batch_profiles.xml');
}
}