<?php

/*
 * @component UserPoints
 * @copyright Copyright (C) 2008-2016 Bernard Gilly - Adrien Roussel - Martin Brampton
 * @license : GNU/GPL
 * @Website : https://www.remository.com
 */
defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Language\Text;
use BlackSheepResearch\Component\UserPoints\Site\UserPoints;
use BlackSheepResearch\Component\UserPoints\Site\Problems\PointsUser;

class plgOsmembershipUp_active extends CMSPlugin {

    public function onMembershipActive($row, $options = array()) {
        // *** Login rule available only on frontend ***
        $lang = Factory::getLanguage();
        $lang->load('com_userpoints', JPATH_SITE);
        $refer_rule_id = 'up_osm_activate_'.$row->plan_id;
        $pointsuser = PointsUser::withUserID($row->user_id);
        $information = Text::_('Referral for subscription by').' - '.$pointsuser->referreid;
        UserPoints::userpoints($refer_rule_id, $pointsuser->referraluser, 0.0, '', $information);
        $reward_rule_id = 'up_osm_activate_reward_'.$row->plan_id;
        UserPoints::userpoints($reward_rule_id, $pointsuser->referreid, 0.0, '', Text::_('Reward for subscription'));
    }
}
