<?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();
jimport('joomla.application.component.controller');
/**
 * MarketplaceControllerMpusers 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 MarketplaceControllerMpusers extends JControllerAdmin
{
    protected $text_prefix='COM_MARKETPLACE_MPUSERS';
    /**
     * __construct function
     *
     * @param array $config var
     */
    public function __construct($config = array())
    {
        parent::__construct($config);
        $this->registerTask('block', 'changeBlock');
        $this->registerTask('unblock', 'changeBlock');
    }
    /**
     * GetModel function
     *
     * @param string $name   var
     * @param string $prefix var
     * @param array  $config var
     * 
     * @return void
     */
    public function getModel(
        $name = 'Mpusers',
        $prefix = 'MarketplaceModel',
        $config = array('ignore_request' => true)
    ) {
        return parent::getModel($name, $prefix, $config);
    }
    /**
     * Synchronizeuser function
     *
     * @return void
     */
    function synchronizeuser()
    {
        $ids = $this->input->get('cid', array(), 'array');
        if (empty($ids)) {
            JError::raiseWarning(500, JText::_('COM_USERS_USERS_NO_ITEM_SELECTED'));
        } else {
            $model = $this->getModel('mpusers');
            $msg = $model->synchronizeuser($ids);
            $cache = JFactory::getCache('com_marketplace');
            $cache->clean();
            $this->setRedirect(
                'index.php?option=com_marketplace&view=mpusers',
                $msg
            );
        }
    }
    /**
     * ChangeBlock function
     *
     * @return void
     */
    public function changeBlock()
    {
        JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
        $ids    = $this->input->get('cid', array(), 'array');
        $values = array('block' => 1, 'unblock' => 0);
        $task   = $this->getTask();
        $value  = JArrayHelper::getValue($values, $task, 0, 'int');
        if (empty($ids)) {
            JError::raiseWarning(500, JText::_('COM_USERS_USERS_NO_ITEM_SELECTED'));
        } else {
            // Get the model.
            $model = $this->getModel();
            // Change the state of the records.
            if (!$model->block($ids, $value)) {
                JError::raiseWarning(500, $model->getError());
            } else {
                if ($value == 1) {
                    $this->setMessage(
                        JText::plural(
                            'COM_USERS_N_USERS_BLOCKED',
                            count($ids)
                        )
                    );
                } elseif ($value == 0) {
                    $this->setMessage(
                        JText::plural('COM_USERS_N_USERS_UNBLOCKED', count($ids))
                    );
                }
            }
        }
        $this->setRedirect('index.php?option=com_marketplace&view=mpusers');
    }
    /**
     * Activate function
     *
     * @return void
     */
    public function activate()
    {
        // Check for request forgeries.
        JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
        $ids = $this->input->get('cid', array(), 'array');
        if (empty($ids)) {
            JError::raiseWarning(500, JText::_('COM_USERS_USERS_NO_ITEM_SELECTED'));
        } else {
            // Get the model.
            $model = $this->getModel();
            // Change the state of the records.
            if (!$model->activate($ids)) {
                JError::raiseWarning(500, $model->getError());
            } else {
                $this->setMessage(
                    JText::plural('COM_USERS_N_USERS_ACTIVATED', count($ids))
                );
            }
        }
        $this->setRedirect('index.php?option=com_marketplace&view=mpusers');
    }
}
