<?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\Site\Models;

// no direct access
defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Factory;
use BlackSheepResearch\Component\UserPoints\Site\UserPoints;
use BlackSheepResearch\Component\UserPoints\Site\Problems\Rule;

class Invite extends UserModel {

    function _getParamsAUP() {
        // Get the parameters of the active menu item
        $app = Factory::getApplication();
        $menus = $app->getMenu();
        $menu = $menus->getActive();
        $menuid = @$menu->id;
        $params = $menus->getParams($menuid);
        return $params;
    }

    function _getReferreid() {
        // check referre ID
        $referrerid = UserPoints::getReferreid();
        return $referrerid;
    }

    function _getRuleID($plugin_function) {
        return Rule::withRuleName($plugin_function)->id;
    }

    function _extractEmailsFromString($sChaine) {
        if (false !== preg_match_all('`\w(?:[-_.]?\w)*@\w(?:[-_.]?\w)*\.(?:[a-z]{2,4})`', $sChaine, $aEmails)) {
            if (is_array($aEmails[0]) && sizeof($aEmails[0]) > 0) {
                return array_unique($aEmails[0]);
            }
        }
        return null;
    }

    public function getForm($data = array(), $loadData = true) {
        $form = $this->loadForm('com_userpoints.invite', 'invite', array('control' => 'jform', 'load_data' => true));
        if (empty($form)) {
            return false;
        }
        return $form;
    }

}
