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');
// import Joomla modelform library
jimport('joomla.application.component.modeladmin');
/**
* ZhGoogleMarker Model
*/
class ZhGoogleMapModelMapMarker extends JModelAdmin
{
var $mapList;
var $mapapikey;
var $mapapiversion;
var $markerGroupList;
var $contactList;
var $userList;
var $tabList;
var $mapStreetViewList;
var $mapDefLat;
var $mapDefLng;
var $mapTypeList;
var $categoryList;
var $categoryListType;
var $httpsprotocol;
var $map_height;
/**
* Returns a reference to the a Table object, always creating it.
*
* @param type The table type to instantiate
* @param string A prefix for the table class name. Optional.
* @param array Configuration array for model. Optional.
* @return JTable A database object
* @since 1.6
*/
public function getTable($type = 'MapMarker', $prefix = 'ZhGoogleMapTable', $config = array())
{
return JTable::getInstance($type, $prefix, $config);
}
/**
* Method to get the record form.
*
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
* @return mixed A JForm object on success, false on failure
* @since 1.6
*/
public function getForm($data = array(), $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_zhgooglemap.mapmarker', 'mapmarker', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form))
{
return false;
}
return $form;
}
/**
* Method to get the script that have to be included on the form
*
* @return string Script files
*/
public function getScript()
{
return 'administrator/components/com_zhgooglemap/models/forms/mapmarker.js';
}
/**
* Method to get a single record.
*
* @param integer $pk The id of the primary key.
*
* @return mixed Object on success, false on failure.
*/
public function getItem($pk = null)
{
if ($item = parent::getItem($pk))
{
if (!empty($item->id))
{
$item->tags = new JHelperTags;
$item->tags->getTagIds($item->id, 'com_zhgooglemap.mapmarker');
}
}
return $item;
}
/**
* Method to get the data that should be injected in the form.
*
* @return mixed The data for the form.
* @since 1.6
*/
protected function loadFormData()
{
// Check the session for previously entered form data.
$data = JFactory::getApplication()->getUserState('com_zhgooglemap.edit.mapmarker.data', array());
if (empty($data))
{
$data = $this->getItem();
}
return $data;
}
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 getmarkerGroupList()
{
if (!isset($this->markerGroupList))
{
$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->markerGroupList = $this->_db->loadObjectList();
// Custom Fields
//if (!$this->markerGroupList = $this->_db->loadObjectList())
//{
// $this->setError($this->_db->getError());
//}
}
return $this->markerGroupList;
}
public function getcontactList()
{
if (!isset($this->contactList))
{
$this->_db->setQuery($this->_db->getQuery(true)
->select('h.name as text, h.id as value ')
->from('#__contact_details as h')
->leftJoin('#__categories as c ON h.catid=c.id')
->where('(h.published=0 OR h.published=1)')
->order('h.name'));
$this->contactList = $this->_db->loadObjectList();
// Custom Fields
//if (!$this->contactList = $this->_db->loadObjectList())
//{
// $this->setError($this->_db->getError());
//}
}
return $this->contactList;
}
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 gettabList()
{
if (!isset($this->tabList))
{
$this->_db->setQuery($this->_db->getQuery(true)
->select('h.title as text, h.id as value ')
->from('#__zhgooglemaps_infobubbles as h')
->leftJoin('#__categories as c ON h.catid=c.id')
->where('1=1')
->order('h.title'));
$this->tabList = $this->_db->loadObjectList();
// Custom Fields
//if (!$this->tabList = $this->_db->loadObjectList())
//{
// $this->setError($this->_db->getError());
//}
}
return $this->tabList;
}
public function getAPIKey()
{
// Get global params
$params = JComponentHelper::getParams( 'com_zhgooglemap' );
return $mapapikey = $params->get( 'map_map_key', '' );
}
public function getAPIVersion()
{
// Get global params
$params = JComponentHelper::getParams( 'com_zhgooglemap' );
return $mapapiversion = $params->get( 'map_api_version', '' );
}
public function getDefLat()
{
// Get global params
$params = JComponentHelper::getParams( 'com_zhgooglemap' );
return $mapDefLat = $params->get( 'map_lat', '' );
}
public function getDefLng()
{
// Get global params
$params = JComponentHelper::getParams( 'com_zhgooglemap' );
return $mapDefLng = $params->get( 'map_lng', '' );
}
public function getMapTypeGoogle()
{
// Get global params
$params = JComponentHelper::getParams( 'com_zhgooglemap' );
return $mapMapTypeGoogle = $params->get( 'map_type_google', '' );
}
public function getMapTypeOSM()
{
// Get global params
$params = JComponentHelper::getParams( 'com_zhgooglemap' );
return $mapMapTypeOSM = $params->get( 'map_type_osm', '' );
}
public function getMapTypeCustom()
{
// Get global params
$params = JComponentHelper::getParams( 'com_zhgooglemap' );
return $mapMapTypeCustom = $params->get( 'map_type_custom', '' );
}
public function getHttpsProtocol()
{
// Get global params
$params = JComponentHelper::getParams( 'com_zhgooglemap' );
return $httpsprotocol = $params->get( 'httpsprotocol', '' );
}
public function getMapHeight()
{
// Get global params
$params = JComponentHelper::getParams( 'com_zhgooglemap' );
return $map_height = $params->get( 'map_height', '' );
}
public function getmapStreetViewList()
{
if (!isset($this->mapStreetViewList))
{
$this->_db->setQuery($this->_db->getQuery(true)
->select('h.title as text, h.id as value ')
->from('#__zhgooglemaps_streetviews as h')
->leftJoin('#__categories as c ON h.catid=c.id')
->where('1=1')
->order('h.title'));
$this->mapStreetViewList = $this->_db->loadObjectList();
// Custom Fields
//if (!$this->mapStreetViewList = $this->_db->loadObjectList())
//{
// $this->setError($this->_db->getError());
//}
}
return $this->mapStreetViewList;
}
public function getmapTypeList()
{
if (!isset($this->mapTypeList))
{
$this->_db->setQuery($this->_db->getQuery(true)
->select('h.*, c.title as category ')
->from('#__zhgooglemaps_maptypes as h')
->leftJoin('#__categories as c ON h.catid=c.id')
->where('h.published=1')
->order('h.title'));
$this->mapTypeList = $this->_db->loadObjectList();
// Custom Fields
//if (!$this->mapTypeList = $this->_db->loadObjectList())
//{
// $this->setError($this->_db->getError());
//}
}
return $this->mapTypeList;
}
public function getCategoryList()
{
// Get global params
$params = JComponentHelper::getParams( 'com_zhgooglemap' );
$cat_list_type = $params->get( 'category_list_type', '' );
if ($cat_list_type == "")
{
$cat_list_type = 0;
}
else
{
$cat_list_type = (int)$cat_list_type;
}
if ($cat_list_type == 1)
{
if (!isset($this->categoryList))
{
$this->_db->setQuery($this->_db->getQuery(true)
->select('h.title as text, h.id as value')
->from('#__categories as h')
->where('h.extension = \'com_zhgooglemap\' AND h.published IN (0,1)')
->order('h.title'));
$this->categoryList = $this->_db->loadObjectList();
// Custom Fields
//if (!$this->categoryList = $this->_db->loadObjectList())
//{
// $this->setError($this->_db->getError());
//}
}
}
return $this->categoryList;
}
public function getCategoryListType()
{
// Get global params
$params = JComponentHelper::getParams( 'com_zhgooglemap' );
$cat_list_type = $params->get( 'category_list_type', '' );
if ($cat_list_type == "")
{
$categoryListType = 0;
}
else
{
$categoryListType = (int)$cat_list_type;
}
return $categoryListType;
}
/**
* Method to save the form data.
*
* @param array $data The form data.
*
* @return boolean True on success.
*
* @since 1.6
*/
public function save($data)
{
$app = JFactory::getApplication();
// Alter the title for save as copy
if ($app->input->get('task') == 'save2copy')
{
list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
$data['title'] = $title;
$data['alias'] = $alias;
}
if (parent::save($data))
{
return true;
}
return false;
}
}