<?php

/*
 * @component UserPoints
 * @copyright Copyright (C) 2015-2022 Bernard Gilly - Adrien Roussel - Martin Brampton
 * @license : GNU/GPL
 * @Website : https://remository.com
 */

namespace BlackSheepResearch\Component\UserPoints\Administrator\Controllers;

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Session\Session;
use BlackSheepResearch\Component\UserPoints\Administrator\AdminController;

class TemplateInviteControl extends AdminController {

    public function templateinvite() {
        $model = $this->getModel('templateinvite');
        $view = $this->getView('TemplateinviteHTML', 'html');
        // load coupons
        $_templateinvite = $model->_load_templateinvite();
        $this->viewdata['templateinvite'] = $_templateinvite[0];
        $this->viewdata['total'] = $_templateinvite[1];
        $this->viewdata['limit'] = $_templateinvite[2];
        $this->viewdata['limitstart'] = $_templateinvite[3];
        // Display
        $view->displaylist();
    }

    public function edittemplateinvite() {
        $model = $this->getModel('templateinvite');
        $view = $this->getView('TemplateinviteHTML', 'html');
        $result = $model->_edit_templateinvite();
        $this->viewdata['row'] = $result;
        // Display
        $view->edit_templateinvite();
    }

    public function savetemplateinvite() {
        Session::checkToken() or jexit(Text::_('JINVALID_TOKEN'));
        $model = $this->getModel('templateinvite');
        // save coupon(s)
        $model->_save_templateinvite();
    }

    public function applytemplateinvite() {
        Session::checkToken() or jexit(Text::_('JINVALID_TOKEN'));
        $model = $this->getModel('templateinvite');
        $apply = 1;
        $model->_save_templateinvite($apply);
    }

    public function deletetemplateinvite() {
        $model = $this->getModel('templateinvite');
        $model->_delete_templateinvite();
    }

    public function canceltemplateinvite() {
        $this->redirect("index.php?option=com_userpoints&task=templateinvite");
    }

}
