Your IP : 216.73.216.240


Current Path : /home/juvelize/www/administrator/components/com_zhgooglemap/models/
Upload File :
Current File : /home/juvelize/www/administrator/components/com_zhgooglemap/models/mapbufmrks.php

<?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');

/**
 * ZhGoogleBufmrks Model
 */
class ZhGoogleMapModelMapBufmrks extends JModelList
{
    var $mapList;
    var $groupList;
        var $userList;
    var $iconList;
        var $markerState;

        var $inserted = 0;
        var $errors = 0;
        var $warnings = 0;
        var $skipped = 0;
    
    /**
     * 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',
                'catid', 'h.catid', 'category_title',
                'markergroup', 'h.markergroup', 
                                'markerstate', 'h.status',
                                'published', 'h.published',
                '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);
                
        $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);
    
                $markerstate = $this->getUserStateFromRequest($this->context.'.filter.markerstate', 'filter_markerstate', '');
        $this->setState('filter.markerstate', $markerstate);
        
        // 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() 
    {
        // Create a new query object.
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        $user = JFactory::getUser();

        $query->select('h.id,h.title,h.catid,h.icontype,h.createdbyuser,h.status,h.published,h.publish_up,h.publish_down,'.
        'c.title as category, c.language as category_language,g.title as markergroupname, usr.username, usr.name fullusername'.
        '');
        $query->from('#__zhgooglemaps_marker_buffer as h');
        $query->leftJoin('#__categories as c on h.catid=c.id');
        $query->leftJoin('#__zhgooglemaps_markergroups as g on h.markergroup=g.id');
        $query->leftJoin('#__users as usr on h.createdbyuser=usr.id');

        $markerState = $this->getState('filter.markerstate');
        if (is_numeric($markerState)) {
            $query->where('h.status = '.(int) $markerState);
        }
                
        // Filter by markergroup.
        $markerGroup = $this->getState('filter.markergroup');
        if (is_numeric($markerGroup)) {
            $query->where('h.markergroup = '.(int) $markerGroup);
        }

        // Filter by published state
        $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 createdbyuser.
        $createdByUser = $this->getState('filter.createdbyuser');
        if (is_numeric($createdByUser)) {
            $query->where('h.createdbyuser = '.(int) $createdByUser);
        }

        // Filter by icontype
        $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.
        $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 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';
        }
        $query->order($db->escape($orderCol.' '.$orderDirn));
        
        return $query;
    }


    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 getmarkerState() 
    {
        if (!isset($this->markerState)) 
        {       
                    $stateList = array(
                         array("value"=>0, "text"=>JText::_('COM_ZHGOOGLEMAP_MAPBUFMRKS_DETAIL_STATUS_NEW')),
                         array("value"=>1, "text"=>JText::_('COM_ZHGOOGLEMAP_MAPBUFMRKS_DETAIL_STATUS_PROCESSED')),
                         array("value"=>8, "text"=>JText::_('COM_ZHGOOGLEMAP_MAPBUFMRKS_DETAIL_STATUS_SKIPPED')),
                         array("value"=>9, "text"=>JText::_('COM_ZHGOOGLEMAP_MAPBUFMRKS_DETAIL_STATUS_ERROR'))
                    );
                    $this->markerState = $stateList;
                    
        }

        return $this->markerState;
    }

    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_marker_buffer 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;
    }

}