Ejemplo n.º 1
0
 /**
  * @param int $projectId
  * @param Joomla\Registry\Registry $params
  * @param stdClass $paymentSession
  *
  * @throws UnexpectedValueException
  * @throws InvalidArgumentException
  * @throws OutOfBoundsException
  * @throws RuntimeException
  *
  * @return stdClass
  */
 public function prepareItem($projectId, $params, $paymentSession)
 {
     $container = Prism\Container::getContainer();
     $containerHelper = new Crowdfunding\Container\Helper();
     $project = $containerHelper->fetchProject($container, $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
     $money = $containerHelper->fetchMoneyFormatter($container, $params);
     $currency = $money->getCurrency();
     $item = new stdClass();
     $item->id = $project->getId();
     $item->title = $project->getTitle();
     $item->slug = $project->getSlug();
     $item->catslug = $project->getCatSlug();
     $item->starting_date = $project->getFundingStart();
     $item->ending_date = $project->getFundingEnd();
     $item->user_id = $project->getUserId();
     $item->rewardId = $paymentSession->rewardId;
     $item->amount = $paymentSession->amount;
     $item->currencyCode = $currency->getCode();
     $item->amountFormated = $money->setAmount($item->amount)->format();
     $item->amountCurrency = $money->setAmount($item->amount)->formatCurrency();
     return $item;
 }
Ejemplo n.º 2
0
 /**
  * Method to get the field input markup.
  *
  * @return  string  The field input markup.
  *
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @throws \OutOfBoundsException
  */
 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 = !empty($this->element['css_layout']) ? (string) $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 */
     // Get the currency and money formatter from the container.
     $container = Prism\Container::getContainer();
     $containerHelper = new Crowdfunding\Container\Helper();
     $moneyFormatter = $containerHelper->fetchMoneyFormatter($container, $params);
     $moneyFormatter->setAmount($this->value);
     $currency = $moneyFormatter->getCurrency();
     $html = array();
     if ($cssLayout === 'Bootstrap 3') {
         $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="' . $moneyFormatter->format() . '"' . $class . $size . $disabled . $readonly . $maxLength . $onchange . $required . '/>';
         // Prepend
         $html[] = '<div class="input-group-addon">' . $currency->getCode() . '</div>';
         $html[] = '</div>';
     } else {
         // Bootstrap 2
         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="' . $moneyFormatter->format() . '"' . $class . $size . $disabled . $readonly . $maxLength . $onchange . $required . '/>';
         // Appended
         $html[] = '<span class="add-on">' . $currency->getCode() . '</span></div>';
     }
     return implode("\n", $html);
 }
$projectId = $app->input->getInt('id');
if (!$projectId) {
    return;
}
$container = Prism\Container::getContainer();
/** @var  $container Joomla\DI\Container */
$containerHelper = new Crowdfunding\Container\Helper();
// Get Project object from the container.
$project = $containerHelper->fetchProject($container, $projectId);
if (!$project->getId()) {
    return;
}
// Get component params
$componentParams = JComponentHelper::getParams('com_crowdfunding');
/** @var  $componentParams Joomla\Registry\Registry */
$money = $containerHelper->fetchMoneyFormatter($container, $componentParams);
$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 social platform and a link to the profile
$config = new Joomla\Registry\Registry(array('platform' => $socialPlatform, 'user_id' => $project->getUserId()));
$socialBuilder = new Prism\Integration\Profile\Factory($config);
$socialProfile = $socialBuilder->create();
$socialProfileLink = !$socialProfile ? null : $socialProfile->getLink();
// Get amounts
$fundedAmount = $money->setAmount($project->getGoal())->formatCurrency();
$raised = $money->setAmount($project->getFunded())->formatCurrency();
// Prepare the value that I am going to display
$fundedPercents = JHtml::_('crowdfunding.funded', $project->getFundedPercent());
$user = JFactory::getUser($project->getUserId());