@copyright Copyright (C) 2015. All Rights Reserved @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html Support Groups /-----------------------------------------------------------------------------------------------------------------------------*/ // No direct access to this file defined('_JEXEC') or die('Restricted access'); // import Joomla view library jimport('joomla.application.component.view'); jimport('joomla.application.module.helper'); /** * Supportgroups View class for the Map */ class SupportgroupsViewMap extends JViewLegacy { // Overwriting JView display method function display($tpl = null) { // get combined params of both component and menu $this->app = JFactory::getApplication(); $this->params = $this->app->getParams(); $this->menu = $this->app->getMenu()->getActive(); // get the user object $this->user = JFactory::getUser(); // Initialise variables. $this->items = $this->get('Items'); if (isset($this->items) && SupportgroupsHelper::checkArray($this->items)) { // check if clustering of the markers should be set $this->setClustering($this->items); } // set the default display $this->initScript = "setMapData(1,'totals');"; $this->backTo = 1; $this->backType = 'totals'; $this->groupsFilter = false; $this->backToRef = ''; // check if it should be another $input = array('facility' => 'int','area' => 'int','region' => 'int','country' => 'int'); $inputLang = array('facility' => JText::_('COM_SUPPORTGROUPS_FACILITY'),'area' => JText::_('COM_SUPPORTGROUPS_AREA'),'region' => JText::_('COM_SUPPORTGROUPS_REGION'),'country' => JText::_('COM_SUPPORTGROUPS_COUNTRY')); $getDetails = array('facility' => 'facility','area' => 'area','region' => 'region','country' => 'country'); $filtering = $this->app->input->getArray($input); foreach ($filtering as $key => $filter) { if ($filter) { // we can only add one $this->initScript = "setMapData(".(int) $filter.",'".$getDetails[$key]."');"; // set main call back $this->backTo = $filter; $this->backType = $getDetails[$key]; // groupsFilter $this->groupsFilter = '&'.$key.'='.(int)$filter; // set back to groups $this->backToRef = ''; } } // Set the toolbar $this->addToolBar(); // set the document $this->_prepareDocument(); // Check for errors. if (count($errors = $this->get('Errors'))) { throw new Exception(implode("\n", $errors), 500); } parent::display($tpl); } /** * Get the Google API Key and set to URL if not reached limit * * @return string The url to the Google API */ public function getGoogleAPI() { $api_key = $this->params->get('api-key'); if ($api_key) { return 'https://maps.googleapis.com/maps/api/js?key='.$api_key.'&callback=getMapScript'; } return 'https://maps.googleapis.com/maps/api/js?sensor=false&callback=getMapScript'; } /** * Cluster Switch * @var boolean */ public $cluster = false; /** * Clustering control method * * @params object $items The Support Group Values * * @return void * */ private function setClustering(&$items) { $cluster = $this->params->get('cluster', null); if ($cluster) { $cluster_at = $this->params->get('cluster_at', 300); $total = count($items); if ($cluster_at <= $total) { $this->cluster = true; } } } /** * Prepares the document */ protected function _prepareDocument() { // always make sure jquery is loaded. JHtml::_('jquery.framework'); // Load the header checker class. require_once( JPATH_COMPONENT_SITE.'/helpers/headercheck.php' ); // Initialize the header checker. $HeaderCheck = new supportgroupsHeaderCheck; // Load uikit options. $uikit = $this->params->get('uikit_load'); // Set script size. $size = $this->params->get('uikit_min'); // Set css style. $style = $this->params->get('uikit_style'); // The uikit css. if ((!$HeaderCheck->css_loaded('uikit.min') || $uikit == 1) && $uikit != 2 && $uikit != 3) { $this->document->addStyleSheet(JURI::root(true) .'/media/com_supportgroups/uikit-v2/css/uikit'.$style.$size.'.css', (SupportgroupsHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); } // The uikit js. if ((!$HeaderCheck->js_loaded('uikit.min') || $uikit == 1) && $uikit != 2 && $uikit != 3) { $this->document->addScript(JURI::root(true) .'/media/com_supportgroups/uikit-v2/js/uikit'.$size.'.js', (SupportgroupsHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); } // Load the script to find all uikit components needed. if ($uikit != 2) { // Set the default uikit components in this view. $uikitComp = array(); $uikitComp[] = 'data-uk-grid'; $uikitComp[] = 'uk-placeholder'; } // Load the needed uikit components in this view. if ($uikit != 2 && isset($uikitComp) && SupportgroupsHelper::checkArray($uikitComp)) { // load just in case. jimport('joomla.filesystem.file'); // loading... foreach ($uikitComp as $class) { foreach (SupportgroupsHelper::$uk_components[$class] as $name) { // check if the CSS file exists. if (JFile::exists(JPATH_ROOT.'/media/com_supportgroups/uikit-v2/css/components/'.$name.$style.$size.'.css')) { // load the css. $this->document->addStyleSheet(JURI::root(true) .'/media/com_supportgroups/uikit-v2/css/components/'.$name.$style.$size.'.css', (SupportgroupsHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); } // check if the JavaScript file exists. if (JFile::exists(JPATH_ROOT.'/media/com_supportgroups/uikit-v2/js/components/'.$name.$size.'.js')) { // load the js. $this->document->addScript(JURI::root(true) .'/media/com_supportgroups/uikit-v2/js/components/'.$name.$size.'.js', (SupportgroupsHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (SupportgroupsHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); } } } } // load the meta description if ($this->params->get('menu-meta_description')) { $this->document->setDescription($this->params->get('menu-meta_description')); } // load the key words if set if ($this->params->get('menu-meta_keywords')) { $this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords')); } // check the robot params if ($this->params->get('robots')) { $this->document->setMetadata('robots', $this->params->get('robots')); } // Add the JavaScript for JStore $this->document->addScript(JURI::root() .'media/com_supportgroups/js/jquery.json.min.js'); $this->document->addScript(JURI::root() .'media/com_supportgroups/js/jstorage.min.js'); // check if we should use browser storage $setBrowserStorage = $this->params->get('set_browser_storage', null); if ($setBrowserStorage) { // check what (Time To Live) show we use $storageTimeToLive = $this->params->get('storage_time_to_live', 'global'); if ('global' == $storageTimeToLive) { // use the global session time $session = JFactory::getSession(); // must have it in milliseconds $expire = ($session->getExpire()*60)* 1000; } else { // use the Supportgroups Global setting if (0 != $storageTimeToLive) { // this will convert the time into milliseconds $storageTimeToLive = $storageTimeToLive * 1000; } $expire = $storageTimeToLive; } } else { // set to use no storage $expire = 10; } // set an error message if needed $this->document->addScriptDeclaration("var returnError = '
".JText::_('COM_SUPPORTGROUPS_PLEASE_TRY_AGAIN_LATER').".