/** * This method validates project data before a user launch its campaign. * It works only on front-end. * * @param string $context * @param stdClass $item * @param Joomla\Registry\Registry $params * @param int $state * * @return null|array */ public function onContentValidateChangeState($context, &$item, &$params, $state) { if (strcmp('com_crowdfunding.projects.changestate', $context) !== 0) { return null; } // This validation have to be processed when the state is for launching (publishing) campaign. if ((int) $state !== 1) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp('html', $docType) !== 0) { return null; } $result = array('success' => false, 'message' => ''); // Get user ID. $userId = JFactory::getUser()->get('id'); // Get component parameters $componentParams = JComponentHelper::getParams('com_crowdfundingfinance'); /** @var $componentParams Joomla\Registry\Registry */ // Verify the number of campaigns per user at one time. $allowedActiveCampaigns = (int) $componentParams->get('protection_active_projects'); if ($allowedActiveCampaigns > 0) { // Get the number of active projects for a user. $userStatistics = new Crowdfunding\Statistics\User(JFactory::getDbo(), $userId); $activeCampaigns = (int) $userStatistics->getNumberOfActiveCampaigns(); // Validate number of active campaigns per user. if ($activeCampaigns >= $allowedActiveCampaigns) { $result['message'] = JText::sprintf('PLG_CONTENT_CROWDFUNDINGFRAUDPREVENTION_ERROR_ACTIVE_PROJECTS_D', $allowedActiveCampaigns); return $result; } } // Verify the number of campaigns per user per year. $allowedCampaignsPerYear = (int) $componentParams->get('protection_projects_per_year'); if ($allowedCampaignsPerYear > 0) { // Get the number of active projects for a user. $userStatistics = new Crowdfunding\Statistics\User(JFactory::getDbo(), $userId); $numberOfCampaigns = (int) $userStatistics->getNumberOfCampaignsInPeriod(); // Validate number of campaigns per year. if ($numberOfCampaigns >= $allowedCampaignsPerYear) { $result['message'] = JText::sprintf('PLG_CONTENT_CROWDFUNDINGFRAUDPREVENTION_ERROR_PROJECTS_YEAR_D', $allowedCampaignsPerYear); return $result; } } // Validation completed successfully. $result = array('success' => true); return $result; }
/** * This method does some validations before the system to provide payment methods. * * @param string $context This string gives information about that where it has been executed the trigger. * @param stdClass $item A project data. * @param Prism\Money\Money $money An Money object. * @param Joomla\Registry\Registry $params The parameters of the component * * @throws \InvalidArgumentException * * @return null|string */ public function onBeforePaymentAuthorize($context, &$item, &$money, &$params) { if (strcmp('com_crowdfunding.before.payment.authorize', $context) !== 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp('html', $docType) !== 0) { return null; } // Get user ID. $userId = JFactory::getUser()->get('id'); $html = array(); // Display login form if (!$userId) { $html[] = '<p class="bg-warning p-5">'; $html[] = '<span class="fa fa-exclamation-triangle"></span>'; $html[] = JText::_('PLG_CROWDFUNDINGPAYMENT_FRAUD_PREVENTION_ERROR_NOT_REGISTERED'); $html[] = '</p>'; } // Verifications // Get component parameters $componentParams = JComponentHelper::getParams('com_crowdfundingfinance'); /** @var $componentParams Joomla\Registry\Registry */ // Verify maximum allowed amount for contribution. $allowedContributedAmount = $money->setAmount($componentParams->get('protection_max_contributed_amount'))->parse(); // Validate maximum allowed amount. if ($allowedContributedAmount and $allowedContributedAmount < (double) $item->amount) { $html[] = '<p class="bg-warning p-5">'; $html[] = '<span class="fa fa-exclamation-triangle"></span>'; $html[] = JText::sprintf('PLG_CROWDFUNDINGPAYMENT_FRAUD_PREVENTION_ERROR_CONTRIBUTION_AMOUNT_S', $money->setAmount($allowedContributedAmount)->formatCurrency()); $html[] = '</p>'; } // Verify the number of payments per project. $allowedPaymentsPerProject = (int) $componentParams->get('protection_payments_per_project'); if ($allowedPaymentsPerProject > 0) { $userStatistics = new Crowdfunding\Statistics\User(JFactory::getDbo(), $userId); $paymentsPerProject = (int) $userStatistics->getNumberOfPayments($item->id); // Validate number of payments per project. if ($paymentsPerProject >= $allowedPaymentsPerProject) { $html[] = '<p class="bg-warning p-5">'; $html[] = '<span class="fa fa-exclamation-triangle"></span>'; $html[] = JText::sprintf('PLG_CROWDFUNDINGPAYMENT_FRAUD_PREVENTION_ERROR_PAYMENT_PER_PROJECT_D', $allowedPaymentsPerProject); $html[] = '</p>'; } } return count($html) > 0 ? implode("\n", $html) : null; }
/** * Display the view */ public function display($tpl = null) { $app = JFactory::getApplication(); /** @var $app JApplicationAdministrator */ // Get user ID $userId = $app->input->getInt("id"); $model = $this->getModel(); $this->state = $model->getState(); $this->item = $model->getItem($userId); $this->params = JComponentHelper::getParams($this->option); // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get("project_currency")); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); // Get number of rewards. $statistics = new Crowdfunding\Statistics\User(JFactory::getDbo(), $this->item->id); $this->projects = $statistics->getProjectsNumber(); $amounts = $statistics->getAmounts(); if (!empty($amounts["invested"])) { $this->investedAmount = (double) $amounts["invested"]['amount']; $this->investedTransactions = (int) $amounts["invested"]['number']; } if (!empty($amounts["received"])) { $this->receivedAmount = (double) $amounts["received"]['amount']; $this->receivedTransactions = (int) $amounts["received"]['number']; } // Get social profile $socialPlatform = $this->params->get("integration_social_platform"); if (!empty($socialPlatform)) { $options = array("social_platform" => $socialPlatform, "user_id" => $this->item->id); $profileBuilder = new Prism\Integration\Profile\Builder($options); $profileBuilder->build(); $this->socialProfile = $profileBuilder->getProfile(); $this->profileLink = $this->socialProfile->getLink(); } $this->rewards = new Crowdfunding\User\Rewards(JFactory::getDbo()); $this->rewards->load(array("user_id" => $this->item->id)); $this->returnUrl = base64_encode("index.php?option=com_crowdfunding&view=user&id=" . $this->item->id); // Prepare actions, behaviors, scripts and document $this->addToolbar(); $this->setDocument(); parent::display($tpl); }
public function display($tpl = null) { $this->option = JFactory::getApplication()->input->get('option'); $this->app = JFactory::getApplication(); // Get user ID $userId = $this->app->input->getInt('id'); $model = $this->getModel(); $this->state = $model->getState(); $this->item = $model->getItem($userId); $this->params = JComponentHelper::getParams($this->option); $this->money = $this->getMoneyFormatter($this->params); // Get number of rewards. $statistics = new Crowdfunding\Statistics\User(JFactory::getDbo(), $this->item->id); $this->projects = $statistics->getProjectsNumber(); $amounts = $statistics->getAmounts(); if (!empty($amounts['invested'])) { $this->investedAmount = (double) $amounts['invested']['amount']; $this->investedTransactions = (int) $amounts['invested']['number']; } if (!empty($amounts['received'])) { $this->receivedAmount = (double) $amounts['received']['amount']; $this->receivedTransactions = (int) $amounts['received']['number']; } // Get social profile if ($this->params->get('integration_social_platform')) { $this->socialProfile = CrowdfundingHelper::prepareIntegration($this->params->get('integration_social_platform'), $this->item->id); $this->profileLink = $this->socialProfile->getLink(); } $this->rewards = new Crowdfunding\User\Rewards(JFactory::getDbo()); $this->rewards->load(array('user_id' => $this->item->id)); $this->returnUrl = base64_encode('index.php?option=com_crowdfunding&view=user&id=' . $this->item->id); // Prepare actions, behaviors, scripts and document $this->addToolbar(); $this->setDocument(); parent::display($tpl); }