<?php
/**
 * Marketplace - Component Marketplace 
 * ******************************************************************
 *
 * PHP version 7.0
 *
 * @category   Component
 * @package    Joomla
 * @author     WebKul software private limited <support@webkul.com>
 * @copyright  2010 WebKul software private limited
 * @license    http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @version    GIT:5.2
 * @filesource http://store.webkul.com
 * @link       Technical Support:  webkul.uvdesk.com
 * ******************************************************************
 */
// no direct access

defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.model');
if (!class_exists('MarketplaceModelAsktoadmin')) {
    /**
     * Marketplace Model Asktoadmin class
     * 
     * @category Component
     * @package  Joomla
     * @author   WebKul software private limited <support@webkul.com>
     * @license  http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
     * @link     Technical Support:  webkul.uvdesk.com
     */
    class MarketplaceModelAsktoadmin extends JModelLegacy
    {
        /**
         * __construct function
         */
        function __construct()
        {
            parent::__construct();
        }
        /**
         * Get Admin List function
         *
         * @return void
         */
        function getAdminlist()
        {
            $query=$this->_db->getQuery(true);
            $query->select($this->_db->quoteName('u.email'))
                ->from($this->_db->quoteName('#__users', 'u'))
                ->join(
                    "LEFT",
                    $this->_db->quoteName(
                        '#__user_usergroup_map',
                        'm'
                    )." ON(".$this->_db->quoteName('m.user_id').
                    "=".$this->_db->quoteName('u.id').")"
                )
                ->where($this->_db->quoteName('m.group_id').'=8');
            $this->_db->setQuery($query);
            try{
                return $this->_db->loadObjectList();
            }catch(Exception $e){
                JFactory::getApplication()->enqueueMessage(
                    $e->getMessage(),
                    'error'
                );
                return false;
            }
        }
        /**
         * Store Seller Message function
         *
         * @param integer $seller_id var
         * @param string  $subject   var
         * @param string  $message   var
         * 
         * @return void
         */
        public function storeSellerMessage($seller_id=0, $subject="", $message="")
        {
            $config = JFactory::getConfig();  
            $site_offset = $config->get('offset');
            $jdate=JFactory::getDate('now', $site_offset);  
            
            // Create and populate an object.
            $profile = new stdClass();
            $profile->seller_id = $seller_id;
            $profile->subject=$subject;
            $profile->message=$message;
            $profile->time=$jdate->format('Y-m-d H:i:s', true);

            // Insert the object into the user profile table.
            $result = JFactory::getDbo()->insertObject(
                '#__marketplace_ask_admin', $profile
            );
        }
        /**
         * Get Seller Message function
         *
         * @param integer $seller_id var
         * 
         * @return void
         */
        public function getSellerMessage($seller_id=0)
        {
            $db = JFactory::getDbo();
            $query = $db->getQuery(true);
            $query->select('*')
                ->from($db->quoteName('#__marketplace_ask_admin'))
                ->where($db->quoteName('seller_id')." = ".$seller_id)
                ->order('time DESC');
            $db->setQuery($query);
            try {
                return $db->loadObjectList();
            } catch(Exception $e) {
                return array();
            }
        }
    }
}
