/** * Display an input field for amount. * * @param float $value * @param Prism\Money\Money $moneyFormatter * @param array $options * * @throws \InvalidArgumentException * * @return string */ public static function inputAmount($value, Prism\Money\Money $moneyFormatter, $options) { $currency = $moneyFormatter->getCurrency(); $symbol = $currency->getSymbol(); $currencyCode = $currency->getCode(); $html = '<div class="input-group">'; if ($symbol) { $html .= '<div class="input-group-addon">' . $symbol . '</div>'; } $name = Joomla\Utilities\ArrayHelper::getValue($options, 'name'); $id = ''; if (Joomla\Utilities\ArrayHelper::getValue($options, 'id')) { $id = 'id="' . Joomla\Utilities\ArrayHelper::getValue($options, 'id') . '"'; } $class = 'class="form-control '; if (Joomla\Utilities\ArrayHelper::getValue($options, 'class')) { $class .= Joomla\Utilities\ArrayHelper::getValue($options, 'class'); } $class .= '"'; if (!$value or !is_numeric($value)) { $value = 0.0; } $html .= '<input type="text" name="' . $name . '" value="' . $moneyFormatter->setAmount($value)->format() . '" ' . $id . ' ' . $class . ' />'; if ($currencyCode) { $html .= '<div class="input-group-addon">' . $currencyCode . '</div>'; } $html .= '</div>'; return $html; }
public function display($tpl = null) { $this->app = JFactory::getApplication(); $this->option = $this->app->input->get('option'); $this->state = $this->get('State'); $this->item = $this->get('Item'); // Get params $this->params = $this->state->get('params'); if (!$this->item) { $this->app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), 'notice'); $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute(), false)); return; } $this->container = Prism\Container::getContainer(); $this->prepareCurrency($this->container, $this->params); $this->prepareMoneyFormatter($this->container, $this->params); // Create an object that will contain the data during the payment process. $this->paymentSessionContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $this->item->id; $paymentSessionLocal = $this->app->getUserState($this->paymentSessionContext); // Create payment session object. if (!$paymentSessionLocal or !isset($paymentSessionLocal->step1)) { $paymentSessionLocal = $this->createPaymentSession(); } // Images $this->imageFolder = $this->params->get('images_directory', 'images/crowdfunding'); // Get money formatter. $this->money = $this->getMoneyFormatter($this->container, $this->params); $this->currency = $this->money->getCurrency(); // Set a link that points to project page $filter = JFilterInput::getInstance(); $host = JUri::getInstance()->toString(array('scheme', 'host')); $host = $filter->clean($host); $this->item->link = $host . JRoute::_(CrowdfundingHelperRoute::getDetailsRoute($this->item->slug, $this->item->catslug), false); // Set a link to image $this->item->link_image = $host . '/' . $this->imageFolder . '/' . $this->item->image; // Get wizard type $this->wizardType = $this->params->get('backing_wizard_type', 'three_steps'); $this->fourSteps = strcmp('four_steps', $this->wizardType) === 0; // Import 'crowdfundingpayment' plugins. JPluginHelper::importPlugin('crowdfundingpayment'); $this->layout = $this->getLayout(); switch ($this->layout) { case 'step2': // Step 2 on wizard in four steps. $this->prepareStep2(); break; case 'payment': // Step 2 $paymentSessionLocal = $this->preparePayment($paymentSessionLocal); break; case 'share': // Step 3 $paymentSessionLocal = $this->prepareShare($paymentSessionLocal); break; default: // Step 1 ( Rewards ) $paymentSessionLocal = $this->prepareRewards($paymentSessionLocal); break; } // Get project type and check for enabled rewards. $this->rewardsEnabled = CrowdfundingHelper::isRewardsEnabled($this->item->id); // Check days left. If there is no days, disable the button. $this->disabledButton = ''; if (!$this->item->days_left) { $this->disabledButton = 'disabled="disabled"'; } // Prepare the data of the layout $this->layoutData = new JData(array('layout' => $this->layout, 'item' => $this->item, 'paymentSession' => $paymentSessionLocal, 'rewards_enabled' => $this->rewardsEnabled)); $this->prepareDebugMode($paymentSessionLocal); $this->prepareDocument(); $this->paymentSession = $paymentSessionLocal; // Store the new values of the payment process to the user session. $this->app->setUserState($this->paymentSessionContext, $paymentSessionLocal); parent::display($tpl); }