/** * @param int $projectId * @param Joomla\Registry\Registry $params * @param object $paymentSession * * @return stdClass * @throws UnexpectedValueException */ public function prepareItem($projectId, $params, $paymentSession) { $project = new Crowdfunding\Project(JFactory::getDbo()); $project->load($projectId); if (!$project->getId()) { throw new UnexpectedValueException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_PROJECT")); } if ($project->isCompleted()) { throw new UnexpectedValueException(JText::_("COM_CROWDFUNDING_ERROR_COMPLETED_PROJECT")); } // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get("project_currency")); // Create amount object. $amount = new Crowdfunding\Amount($params); $amount->setCurrency($currency); $item = new stdClass(); $item->id = $project->getId(); $item->title = $project->getTitle(); $item->slug = $project->getSlug(); $item->catslug = $project->getCatSlug(); $item->rewardId = $paymentSession->rewardId; $item->starting_date = $project->getFundingStart(); $item->ending_date = $project->getFundingEnd(); $item->amount = $paymentSession->amount; $item->currencyCode = $currency->getCode(); $item->amountFormated = $amount->setValue($item->amount)->format(); $item->amountCurrency = $amount->setValue($item->amount)->formatCurrency(); return $item; }
/** * Method to get the field input markup. * * @return string The field input markup. * * @since 11.1 */ protected function getInput() { // Initialize some field attributes. $size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; $maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : ''; $readonly = (string) $this->element['readonly'] == 'true' ? ' readonly="readonly"' : ''; $disabled = (string) $this->element['disabled'] == 'true' ? ' disabled="disabled"' : ''; $class = !empty($this->element['class']) ? ' class="' . (string) $this->element['class'] . '"' : ""; $required = $this->required ? ' required aria-required="true"' : ''; $cssLayout = $this->element['css_layout'] ? $this->element['css_layout'] : "Bootstrap 2"; // Initialize JavaScript field attributes. $onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : ''; $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get("project_currency")); // Prepare amount object. $amount = new Crowdfunding\Amount($params, $this->value); $amount->setCurrency($currency); switch ($cssLayout) { case "Bootstrap 3": $html = array(); $html[] = '<div class="input-group">'; if ($currency->getSymbol()) { // Prepended $html[] = '<div class="input-group-addon">' . $currency->getSymbol() . '</div>'; } $html[] = '<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . ' value="' . $amount->format() . '"' . $class . $size . $disabled . $readonly . $maxLength . $onchange . $required . '/>'; // Prepend $html[] = '<div class="input-group-addon">' . $currency->getCode() . '</div>'; $html[] = '</div>'; break; default: // Bootstrap 2 $html = array(); if ($currency->getSymbol()) { // Prepended $html[] = '<div class="input-prepend input-append"><span class="add-on">' . $currency->getSymbol() . '</span>'; } else { // Append $html[] = '<div class="input-append">'; } $html[] = '<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . ' value="' . $amount->format() . '"' . $class . $size . $disabled . $readonly . $maxLength . $onchange . $required . '/>'; // Appended $html[] = '<span class="add-on">' . $currency->getCode() . '</span></div>'; break; } return implode("\n", $html); }
public function validate($data) { if (empty($data) or !is_array($data)) { throw new InvalidArgumentException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_REWARDS")); } $filter = JFilterInput::getInstance(); $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ // Create a currency object. $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get("project_currency")); // Create the object "amount". $amount = new Crowdfunding\Amount($params); $amount->setCurrency($currency); foreach ($data as $key => $item) { $item["amount"] = $amount->setValue($item["amount"])->parse(); // Filter data if (!is_numeric($item["amount"])) { $item["amount"] = 0; } $item["title"] = $filter->clean($item["title"], "string"); $item["title"] = Joomla\String\String::trim($item["title"]); $item["title"] = Joomla\String\String::substr($item["title"], 0, 128); $item["description"] = $filter->clean($item["description"], "string"); $item["description"] = Joomla\String\String::trim($item["description"]); $item["description"] = Joomla\String\String::substr($item["description"], 0, 500); $item["number"] = (int) $item["number"]; $item["delivery"] = Joomla\String\String::trim($item["delivery"]); $item["delivery"] = $filter->clean($item["delivery"], "string"); if (!empty($item["delivery"])) { $date = new JDate($item["delivery"]); $unixTime = $date->toUnix(); if ($unixTime < 0) { $item["delivery"] = ""; } } if (!$item["title"]) { throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_TITLE")); } if (!$item["description"]) { throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_DESCRIPTION")); } if (!$item["amount"]) { throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT")); } $data[$key] = $item; } return $data; }
public function validate($data) { if (!is_array($data) or count($data) === 0) { throw new InvalidArgumentException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_REWARDS')); } $filter = JFilterInput::getInstance(); $params = JComponentHelper::getParams('com_crowdfunding'); /** @var $params Joomla\Registry\Registry */ // Create a currency object. $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get('project_currency')); // Create the object 'amount'. $amount = new Crowdfunding\Amount($params); $amount->setCurrency($currency); foreach ($data as $key => &$item) { $item['amount'] = $amount->setValue($item['amount'])->parse(); // Filter data if (!is_numeric($item['amount'])) { $item['amount'] = 0; } $item['title'] = $filter->clean($item['title'], 'string'); $item['title'] = JString::trim($item['title']); $item['title'] = JString::substr($item['title'], 0, 128); $item['description'] = $filter->clean($item['description'], 'string'); $item['description'] = JString::trim($item['description']); $item['description'] = JString::substr($item['description'], 0, 500); $item['number'] = (int) $item['number']; $item['delivery'] = JString::trim($item['delivery']); $item['delivery'] = $filter->clean($item['delivery'], 'string'); if (!empty($item['delivery'])) { $date = new JDate($item['delivery']); $unixTime = $date->toUnix(); if ($unixTime < 0) { $item['delivery'] = ''; } } if (!$item['title']) { throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_TITLE')); } if (!$item['description']) { throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_DESCRIPTION')); } if (!$item['amount']) { throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_AMOUNT')); } } unset($item); return $data; }
return; } // Get project $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $projectId); if (!$project->getId()) { return; } // Get component params $componentParams = JComponentHelper::getParams('com_crowdfunding'); /** @var $componentParams Joomla\Registry\Registry */ $socialPlatform = $componentParams->get('integration_social_platform'); $imageFolder = $componentParams->get('images_directory', 'images/crowdfunding'); $imageWidth = $componentParams->get('image_width', 200); $imageHeight = $componentParams->get('image_height', 200); // Get currency $currencyId = $componentParams->get('project_currency'); $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $componentParams->get('project_currency')); $amount = new Crowdfunding\Amount($componentParams); $amount->setCurrency($currency); // Get social platform and a link to the profile $socialBuilder = new Prism\Integration\Profile\Builder(array('social_platform' => $socialPlatform, 'user_id' => $project->getUserId())); $socialBuilder->build(); $socialProfile = $socialBuilder->getProfile(); $socialProfileLink = !$socialProfile ? null : $socialProfile->getLink(); // Get amounts $fundedAmount = $amount->setValue($project->getGoal())->formatCurrency(); $raised = $amount->setValue($project->getFunded())->formatCurrency(); // Prepare the value that I am going to display $fundedPercents = JHtml::_('crowdfunding.funded', $project->getFundedPercent()); $user = JFactory::getUser($project->getUserId()); require JModuleHelper::getLayoutPath('mod_crowdfundingdetails', $params->get('layout', 'default'));
/** * Generates information about transaction amount. * * @param object $item * @param Crowdfunding\Amount $amount * @param Crowdfunding\Currencies $currencies * * @return string */ public static function transactionAmount($item, $amount, $currencies) { $item->txn_amount = floatval($item->txn_amount); $item->fee = floatval($item->fee); $currency = null; if ($currencies instanceof Crowdfunding\Currencies) { $currency = $currencies->getCurrencyByCode($item->txn_currency); } if ($currency instanceof Crowdfunding\Currency) { $amount->setCurrency($currency); $output = $amount->setValue($item->txn_amount)->formatCurrency(); } else { $output = $item->txn_amount; } if (!empty($item->fee)) { $fee = $currency instanceof Crowdfunding\Currency ? $amount->setValue($item->fee)->formatCurrency() : $item->fee; // Prepare project owner amount. $projectOwnerAmount = round($item->txn_amount - $item->fee, 2); $projectOwnerAmount = !empty($currency) ? $amount->setValue($projectOwnerAmount)->formatCurrency() : $projectOwnerAmount; $title = JText::sprintf("COM_CROWDFUNDING_TRANSACTION_AMOUNT_FEE", $projectOwnerAmount, $fee); $output .= '<a class="btn btn-micro hasTooltip" href="javascript:void(0);" title="' . addslashes($title) . '">'; $output .= '<i class="icon-question"></i>'; $output .= '</a>'; } return $output; }
public function display($tpl = null) { // Get model state. $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; } // Create an object that will contain the data during the payment process. $this->paymentSessionContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $this->item->id; $paymentSession = $this->app->getUserState($this->paymentSessionContext); // Create payment session object. if (!$paymentSession or !isset($paymentSession->step1)) { $paymentSession = new JData(); $paymentSession->step1 = false; } // Images $this->imageFolder = $this->params->get("images_directory", "images/crowdfunding"); // Get currency $this->currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get("project_currency")); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($this->currency); // 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 ? false : true; // Import "crowdfundingpayment" plugins. JPluginHelper::importPlugin('crowdfundingpayment'); $this->layout = $this->getLayout(); switch ($this->layout) { case "step2": $this->prepareStep2(); break; case "payment": $this->preparePayment($paymentSession); break; case "share": $this->prepareShare($paymentSession); break; default: // Pledge and Rewards $this->prepareRewards($paymentSession); break; } // Get project type and check for enabled rewards. $this->rewardsEnabled = true; if (!empty($this->item->type_id)) { $type = new Crowdfunding\Type(JFactory::getDbo()); $type->load($this->item->type_id); if ($type->getId() and !$type->isRewardsEnabled()) { $this->rewardsEnabled = false; } } // Check days left. If there is no days, disable the button. $this->disabledButton = ""; if (!$this->item->days_left) { $this->disabledButton = 'disabled="disabled"'; } $this->paymentSession = $paymentSession; // Prepare the data of the layout $this->layoutData = new JData(array("layout" => $this->layout, "item" => $this->item, "paymentSession" => $paymentSession)); $this->prepareDebugMode($paymentSession); $this->prepareDocument(); parent::display($tpl); }
/** * Prepare an amount, parsing it from formatted string to decimal value. * This is most used when a user post a data via form. * * @param float $value * * @return string|float */ public static function parseAmount($value) { $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get("project_currency")); // Parse the goal amount. $amount = new Crowdfunding\Amount($params, $value); $amount->setCurrency($currency); return $amount->parse(); }
public function getStatistics($project) { $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get("project_currency")); $amount = new Crowdfunding\Amount($params, $project->funded); $amount->setCurrency($currency); $projectData = CrowdfundingHelper::getProjectData($project->id); $html = array(); $html[] = '<div class="panel panel-default">'; $html[] = '<div class="panel-heading"><h5>' . JText::_("PLG_CONTENT_CROWDFUNDINGMANAGER_STATISTICS") . '</h5></div>'; $html[] = ' <table class="table table-bordered">'; // Hits $html[] = ' <tr>'; $html[] = ' <td>' . JText::_("PLG_CONTENT_CROWDFUNDINGMANAGER_HITS") . '</td>'; $html[] = ' <td>' . (int) $project->hits . '</td>'; $html[] = ' </tr>'; // Updates $html[] = ' <tr>'; $html[] = ' <td>' . JText::_("PLG_CONTENT_CROWDFUNDINGMANAGER_UPDATES") . '</td>'; $html[] = ' <td>' . JArrayHelper::getValue($projectData, "updates", 0, "integer") . '</td>'; $html[] = ' </tr>'; // Comments $html[] = ' <tr>'; $html[] = ' <td>' . JText::_("PLG_CONTENT_CROWDFUNDINGMANAGER_COMMENTS") . '</td>'; $html[] = ' <td>' . JArrayHelper::getValue($projectData, "comments", 0, "integer") . '</td>'; $html[] = ' </tr>'; // Funders $html[] = ' <tr>'; $html[] = ' <td>' . JText::_("PLG_CONTENT_CROWDFUNDINGMANAGER_FUNDERS") . '</td>'; $html[] = ' <td>' . JArrayHelper::getValue($projectData, "funders", 0, "integer") . '</td>'; $html[] = ' </tr>'; // Raised $html[] = ' <tr>'; $html[] = ' <td>' . JText::_("PLG_CONTENT_CROWDFUNDINGMANAGER_RAISED") . '</td>'; $html[] = ' <td>' . $amount->formatCurrency() . '</td>'; $html[] = ' </tr>'; $html[] = ' </table>'; $html[] = '</div>'; return implode("\n", $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; } // Create an object that will contain the data during the payment process. $this->paymentSessionContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $this->item->id; $paymentSession = $this->app->getUserState($this->paymentSessionContext); // Create payment session object. if (!$paymentSession or !isset($paymentSession->step1)) { $paymentSession = $this->createPaymentSession(); } // Images $this->imageFolder = $this->params->get('images_directory', 'images/crowdfunding'); // Get currency $this->currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get('project_currency')); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($this->currency); // 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 $paymentSession = $this->preparePayment($paymentSession); break; case 'share': // Step 3 $paymentSession = $this->prepareShare($paymentSession); break; default: // Step 1 ( Rewards ) $paymentSession = $this->prepareRewards($paymentSession); 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' => $paymentSession, 'rewards_enabled' => $this->rewardsEnabled)); $this->prepareDebugMode($paymentSession); $this->prepareDocument(); $this->paymentSession = $paymentSession; // Store the new values of the payment process to the user session. $this->app->setUserState($this->paymentSessionContext, $paymentSession); parent::display($tpl); }