Your IP : 216.73.216.240
<?php
/*------------------------------------------------------------------------
# com_zhgooglemap - Zh GoogleMap
# ------------------------------------------------------------------------
# author: Dmitry Zhuk
# copyright: Copyright (C) 2011 zhuk.cc. All Rights Reserved.
# license: http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
# website: http://zhuk.cc
# Technical Support Forum: http://forum.zhuk.cc/
-------------------------------------------------------------------------*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
use Joomla\Utilities\ArrayHelper;
// import the Joomla modellist library
jimport('joomla.application.component.modellist');
/**
* ZhGooglePlacemarks Model
*/
class ZhGoogleMapModelPlacemarks extends JModelList
{
var $mapList;
var $groupList;
var $userList;
var $iconList;
/**
* Constructor.
*
* @param array An optional associative array of configuration settings.
* @see JController
* @since 1.6
*/
public function __construct($config = array())
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'id', 'h.id',
'title', 'h.title',
'mapid', 'h.mapid',
'catid', 'h.catid', 'category_title',
'ordering', 'h.ordering',
'access', 'h.access', 'access_level',
'markergroup', 'h.markergroup',
'published', 'h.published',
'rating_value', 'h.rating_value',
'icontype', 'h.icontype',
'h.createdbyuser',
);
}
parent::__construct($config);
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return void
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
// Initialise variables.
parent::populateState('h.title','asc');
$app = JFactory::getApplication();
$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
$this->setState('filter.search', $search);
$mapid = $this->getUserStateFromRequest($this->context.'.filter.mapid', 'filter_mapid', '');
$this->setState('filter.mapid', $mapid);
$published = $this->getUserStateFromRequest($this->context.'.filter.published', 'filter_published', '');
$this->setState('filter.published', $published);
$markergroup = $this->getUserStateFromRequest($this->context.'.filter.markergroup', 'filter_markergroup', '');
$this->setState('filter.markergroup', $markergroup);
$icontype = $this->getUserStateFromRequest($this->context.'.filter.icontype', 'filter_icontype', '');
$this->setState('filter.icontype', $icontype);
$categoryId = $this->getUserStateFromRequest($this->context.'.filter.category_id', 'filter_category_id');
$this->setState('filter.category_id', $categoryId);
$createdbyuser = $this->getUserStateFromRequest($this->context.'.filter.createdbyuser', 'filter_createdbyuser', '');
$this->setState('filter.createdbyuser', $createdbyuser);
$access = $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', 0, 'int');
$this->setState('filter.access', $access);
// menu item parameters
$id = JRequest::getInt('id');
$this->setState('map.id', $id);
$placemarklistid = JRequest::getVar('placemarklistid');
$this->setState('map.placemarklistid', $placemarklistid);
$explacemarklistid = JRequest::getVar('explacemarklistid');
$this->setState('map.explacemarklistid', $explacemarklistid);
$grouplistid = JRequest::getVar('grouplistid');
$this->setState('map.grouplistid', $grouplistid);
$categorylistid = JRequest::getVar('categorylistid');
$this->setState('map.categorylistid', $categorylistid);
$usermarkersfilter = JRequest::getVar('usermarkersfilter');
$this->setState('map.usermarkersfilter', $usermarkersfilter);
$load_bootstrap = JRequest::getVar('load_bootstrap');
$this->setState('map.load_bootstrap', $load_bootstrap);
$thumbnail = JRequest::getVar('thumbnail');
$this->setState('map.thumbnail', $thumbnail);
$imagegalery = JRequest::getVar('imagegalery');
$this->setState('map.imagegalery', $imagegalery);
$hidedescriptionhtml = JRequest::getVar('hidedescriptionhtml');
$this->setState('map.hidedescriptionhtml', $hidedescriptionhtml);
$showdescriptionfullhtml = JRequest::getVar('showdescriptionfullhtml');
$this->setState('map.showdescriptionfullhtml', $showdescriptionfullhtml);
$header_fixed = JRequest::getVar('header_fixed');
$this->setState('map.header_fixed', $header_fixed);
// Options for filter
//
$option_filter_map = JRequest::getVar('option_filter_map');
$this->setState('map.option_filter_map', $option_filter_map);
$option_filter_icon = JRequest::getVar('option_filter_icon');
$this->setState('map.option_filter_icon', $option_filter_icon);
$option_filter_publish = JRequest::getVar('option_filter_publish');
$this->setState('map.option_filter_publish', $option_filter_publish);
$option_filter_group = JRequest::getVar('option_filter_group');
$this->setState('map.option_filter_group', $option_filter_group);
$option_filter_category = JRequest::getVar('option_filter_category');
$this->setState('map.option_filter_category', $option_filter_category);
$option_filter_rating = JRequest::getVar('option_filter_rating');
$this->setState('map.option_filter_rating', $option_filter_rating);
$option_filter_access = JRequest::getVar('option_filter_access');
$this->setState('map.option_filter_access', $option_filter_access);
$option_filter_user = JRequest::getVar('option_filter_user');
$this->setState('map.option_filter_user', $option_filter_user);
$option_filter_id = JRequest::getVar('option_filter_id');
$this->setState('map.option_filter_id', $option_filter_id);
//
// Load the parameters.
$params = JComponentHelper::getParams('com_zhgooglemap');
$this->setState('params', $params);
}
/**
* Method to build an SQL query to load the list data.
*
* @return string An SQL query
*/
protected function getListQuery()
{
// TODO - begin
// -- change where when
// - hide map filter
// - hide status filter
// - hide category
// - hide group
// TODO - end
// Create a new query object.
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$user = JFactory::getUser();
$query->select('h.id,h.title,h.mapid,h.published,h.publish_up,h.publish_down,h.catid,h.icontype,h.ordering,h.rating_value,h.createdbyuser,h.access,'.
'c.title as category,m.title as mapname, g.title as markergroupname, usr.username, usr.name fullusername,'.
'ag.title as access_level');
$query->from('#__zhgooglemaps_markers as h');
$query->leftJoin('#__categories as c on h.catid=c.id');
$query->leftJoin('#__zhgooglemaps_maps as m on h.mapid=m.id');
$query->leftJoin('#__zhgooglemaps_markergroups as g on h.markergroup=g.id');
$query->leftJoin('#__users as usr on h.createdbyuser=usr.id');
$query->leftJoin('#__viewlevels as ag ON ag.id = h.access');
// Filter by access level.
if ((int)$this->state->get('map.option_filter_access') == 0
|| (int)$this->state->get('map.option_filter_access') == 2 )
{
if ($access = $this->getState('filter.access'))
{
$query->where('h.access = ' . (int) $access);
}
}
// Implement View Level Access
/* Use only map filter setting
if (!$user->authorise('core.admin'))
{
$groups = implode(',', $user->getAuthorisedViewLevels());
$query->where('h.access IN (' . $groups . ')');
}
*/
// Filter by mapid.
if ((int)$this->getState('map.option_filter_map') == 0
|| (int)$this->getState('map.option_filter_map') == 2 )
{
$mapId = $this->getState('filter.mapid');
if (is_numeric($mapId)) {
$query->where('h.mapid = '.(int) $mapId);
}
}
// Filter by published state
if ((int)$this->getState('map.option_filter_publish') == 0
|| (int)$this->getState('map.option_filter_publish') == 2 )
{
$published = $this->getState('filter.published');
if (is_numeric($published)) {
$query->where('h.published = '.(int) $published);
} elseif ($published === '') {
$query->where('(h.published IN (0, 1))');
}
}
// Filter by markergroup.
if ((int)$this->getState('map.option_filter_group') == 0
|| (int)$this->getState('map.option_filter_group') == 2 )
{
$markerGroup = $this->getState('filter.markergroup');
if (is_numeric($markerGroup)) {
$query->where('h.markergroup = '.(int) $markerGroup);
}
}
// Filter by createdbyuser.
if ((int)$this->getState('map.option_filter_user') == 0
|| (int)$this->getState('map.option_filter_user') == 2 )
{
$createdByUser = $this->getState('filter.createdbyuser');
if (is_numeric($createdByUser)) {
$query->where('h.createdbyuser = '.(int) $createdByUser);
}
}
// Filter by icontype
if ((int)$this->getState('map.option_filter_icon') == 0
|| (int)$this->getState('map.option_filter_icon') == 2 )
{
$icontype = $this->getState('filter.icontype');
if ($icontype != "") {
$query->where('h.icontype = \''.$db->escape($icontype).'\'');
}
}
// Filter by search in title
$search = $this->getState('filter.search');
if (!empty($search)) {
$search = $db->Quote('%'.$db->escape($search, true).'%', false);
$query->where('(h.title LIKE '.$search.')');
}
// Filter by a single or group of categories.
if ((int)$this->getState('map.option_filter_category') == 0
|| (int)$this->getState('map.option_filter_category') == 2 )
{
$categoryId = $this->getState('filter.category_id');
if (is_numeric($categoryId)) {
$query->where('h.catid = '.(int) $categoryId);
}
else if (is_array($categoryId)) {
if(version_compare(JVERSION, '3.5.0', 'ge'))
{
$categoryId = ArrayHelper::toInteger($categoryId);
}
else
{
JArrayHelper::toInteger($categoryId);
}
$categoryId = implode(',', $categoryId);
$query->where('h.catid IN ('.$categoryId.')');
}
}
//
// Add parameters - begin
//
$addWhereClause = '';
$id = $this->getState('map.id');
$placemarklistid = $this->getState('map.placemarklistid');
$explacemarklistid = $this->getState('map.explacemarklistid');
$grouplistid = $this->getState('map.grouplistid');
$categorylistid = $this->getState('map.categorylistid');
if ($this->getState('map.usermarkersfilter') == "")
{
// All - do not analyze map parameters
$usermarkersfilter = (int)$this->getState('map.usermarkersfilter');
}
else
{
$usermarkersfilter = (int)$this->getState('map.usermarkersfilter');
}
if ((int)$id != 0)
{
$addWhereClause .= ' and h.mapid='.(int)$id;
}
if ($explacemarklistid != "")
{
$tmp_expl_ids = explode(',', str_replace(';',',', $explacemarklistid));
if(version_compare(JVERSION, '3.5.0', 'ge'))
{
$tmp_expl_ids = ArrayHelper::toInteger($tmp_expl_ids);
}
else
{
JArrayHelper::toInteger($tmp_expl_ids);
}
$tmp_expl_ids = implode(',', $tmp_expl_ids);
if (strpos($tmp_expl_ids, ','))
{
$addWhereClause .= ' and h.id NOT IN ('.$tmp_expl_ids.')';
}
else
{
$addWhereClause .= ' and h.id != '.(int)$tmp_expl_ids;
}
}
if ($placemarklistid != "")
{
$tmp_pl_ids = explode(',', str_replace(';',',', $placemarklistid));
if(version_compare(JVERSION, '3.5.0', 'ge'))
{
$tmp_pl_ids = ArrayHelper::toInteger($tmp_pl_ids);
}
else
{
JArrayHelper::toInteger($tmp_pl_ids);
}
$tmp_pl_ids = implode(',', $tmp_pl_ids);
if (strpos($tmp_pl_ids, ','))
{
$addWhereClause .= ' and h.id IN ('.$tmp_pl_ids.')';
}
else
{
$addWhereClause .= ' and h.id = '.(int)$tmp_pl_ids;
}
}
if ($grouplistid != "")
{
$tmp_grp_ids = explode(',', str_replace(';',',', $grouplistid));
if(version_compare(JVERSION, '3.5.0', 'ge'))
{
$tmp_grp_ids = ArrayHelper::toInteger($tmp_grp_ids);
}
else
{
JArrayHelper::toInteger($tmp_grp_ids);
}
$tmp_grp_ids = implode(',', $tmp_grp_ids);
if (strpos($tmp_grp_ids, ','))
{
$addWhereClause .= ' and h.markergroup IN ('.$tmp_grp_ids.')';
}
else
{
$addWhereClause .= ' and h.markergroup = '.(int)$tmp_grp_ids;
}
}
if ($categorylistid != "")
{
$tmp_cat_ids = explode(',', str_replace(';',',', $categorylistid));
if(version_compare(JVERSION, '3.5.0', 'ge'))
{
$tmp_cat_ids = ArrayHelper::toInteger($tmp_cat_ids);
}
else
{
JArrayHelper::toInteger($tmp_cat_ids);
}
$tmp_cat_ids = implode(',', $tmp_cat_ids);
if (strpos($tmp_cat_ids, ','))
{
$addWhereClause .= ' and h.catid IN ('.$tmp_cat_ids.')';
}
else
{
$addWhereClause .= ' and h.catid = '.(int)$tmp_cat_ids;
}
}
switch ($usermarkersfilter)
{
case 0:
$addWhereClause .= ' and h.published=1';
break;
case 1:
$currentUser = JFactory::getUser();
$addWhereClause .= ' and h.published=1';
$addWhereClause .= ' and h.createdbyuser='.(int)$currentUser->id;
break;
case 2:
$currentUser = JFactory::getUser();
$currentUserGroups = implode(',', $currentUser->getAuthorisedViewLevels());
$addWhereClause .= ' and h.published=1';
$addWhereClause .= ' and h.access IN (' . $currentUserGroups . ')';
break;
default:
$addWhereClause .= ' and h.published=1';
break;
}
$query->where('1=1'. $addWhereClause);
$nullDate = $db->Quote($db->getNullDate());
$nowDate = $db->Quote(JFactory::getDate()->toSQL());
$query->where('(h.publish_up = ' . $nullDate . ' OR h.publish_up <= ' . $nowDate . ')');
$query->where('(h.publish_down = ' . $nullDate . ' OR h.publish_down >= ' . $nowDate . ')');
//
// Add parameters - end
//
// Add the list ordering clause.
$orderCol = $this->state->get('list.ordering');
$orderDirn = $this->state->get('list.direction');
if ($orderCol == 'ordering' || $orderCol == 'category_title') {
$orderCol = 'c.title '.$orderDirn.', h.ordering';
}
$query->order($db->escape($orderCol.' '.$orderDirn));
return $query;
}
public function getmapList()
{
if (!isset($this->mapList))
{
$this->_db->setQuery($this->_db->getQuery(true)
->select('h.title as text, h.id as value ')
->from('#__zhgooglemaps_maps as h')
->leftJoin('#__categories as c ON h.catid=c.id')
->where('1=1')
->order('h.title'));
$this->mapList = $this->_db->loadObjectList();
// Custom Fields
//if (!$this->mapList = $this->_db->loadObjectList())
//{
// $this->setError($this->_db->getError());
//}
}
return $this->mapList;
}
public function getgroupList()
{
if (!isset($this->groupList))
{
$this->_db->setQuery($this->_db->getQuery(true)
->select('h.title as text, h.id as value ')
->from('#__zhgooglemaps_markergroups as h')
->leftJoin('#__categories as c ON h.catid=c.id')
->where('1=1')
->order('h.title'));
$this->groupList = $this->_db->loadObjectList();
// Custom Fields
//if (!$this->mapList = $this->_db->loadObjectList())
//{
// $this->setError($this->_db->getError());
//}
}
return $this->groupList;
}
public function getuserList()
{
if (!isset($this->userList))
{
$this->_db->setQuery($this->_db->getQuery(true)
->select('h.name as text, h.id as value ')
->from('#__users as h')
->where('1=1'));
$this->userList = $this->_db->loadObjectList();
// Custom Fields
//if (!$this->mapList = $this->_db->loadObjectList())
//{
// $this->setError($this->_db->getError());
//}
}
return $this->userList;
}
public function geticonList()
{
if (!isset($this->iconList))
{
$this->_db->setQuery($this->_db->getQuery(true)
->select('distinct h.icontype as text, h.icontype as value ')
->from('#__zhgooglemaps_markers as h')
->leftJoin('#__categories as c ON h.catid=c.id')
->where('1=1')
->order('h.icontype'));
$this->iconList = $this->_db->loadObjectList();
// Custom Fields
//if (!$this->mapList = $this->_db->loadObjectList())
//{
// $this->setError($this->_db->getError());
//}
}
return $this->iconList;
}
}