/** * This method checks for existing accounts current currencies. * If there is no account for a currency, it creates new one. * * @param integer $userId */ protected function createAccount($userId) { // Get Accounts jimport('virtualcurrency.accounts'); $accounts = new VirtualCurrencyAccounts(JFactory::getDbo()); $accounts->load($userId); $accountIds = array(); foreach ($accounts as $value) { $accountIds[] = $value["currency_id"]; } // Get currencies jimport('virtualcurrency.currencies'); $options = array("state" => 1); $currencies = new VirtualCurrencyCurrencies(JFactory::getDbo()); $currencies->load($options); jimport("virtualcurrency.account"); // Check and create accounts foreach ($currencies as $currency) { if (!in_array($currency["id"], $accountIds)) { $account = new VirtualCurrencyAccount(JFactory::getDbo()); $data = array("amount" => 0, "currency_id" => $currency["id"], "user_id" => $userId); $account->bind($data); $account->store(); } } }
<?php /** * @package Virtual Currency * @subpackage Modules * @author Todor Iliev * @copyright Copyright (C) 2014 Todor Iliev <*****@*****.**>. All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL */ // no direct access defined("_JEXEC") or die; jimport("itprism.init"); jimport("virtualcurrency.init"); $userId = JFactory::getUser()->get("id"); $accounts = null; if (!empty($userId)) { $accounts = new VirtualCurrencyAccounts(JFactory::getDbo()); $accounts->load($userId); $options = array("state" => VirtualCurrencyConstants::PUBLISHED); $currencies = new VirtualCurrencyCurrencies(JFactory::getDbo()); $currencies->load($options); } require JModuleHelper::getLayoutPath('mod_virtualcurrencyaccounts', $params->get('layout', 'default'));