Example #1
0
 /**
  * Displays a calendar control field based on Twitter Bootstrap 3
  *
  * @param   string $value      The date value
  * @param   string $name       The name of the text field
  * @param   string $id         The id of the text field
  * @param   string $format     The date format
  * @param   mixed  $attributes Additional HTML attributes
  *
  * @return  string  HTML markup for a calendar field
  *
  * @since   1.5
  * @see     http://eonasdan.github.io/bootstrap-datetimepicker/
  */
 public static function calendar($value, $name, $id, $format = 'Y-m-d', array $attributes = array())
 {
     static $done;
     if ($done === null) {
         $done = array();
     }
     $readonly = (!empty($attributes['readonly']) and $attributes['readonly'] === 'readonly');
     $disabled = (!empty($attributes['disabled']) and $attributes['disabled'] === 'disabled');
     if (is_array($attributes)) {
         $attributes['class'] = !empty($attributes['class']) ? $attributes['class'] : 'form-control';
         $attributes['class'] = trim($attributes['class'] . ' hasTooltip');
         $attributes = Joomla\Utilities\ArrayHelper::toString($attributes);
     }
     // Format value when not nulldate ('0000-00-00 00:00:00'), otherwise blank it as it would result in 1970-01-01.
     if ((int) $value && $value !== JFactory::getDbo()->getNullDate()) {
         $date = new DateTime($value, new DateTimeZone('UTC'));
         $inputvalue = $date->format($format);
     } else {
         $inputvalue = '';
     }
     // Load the calendar behavior
     JHtml::_('Prism.ui.bootstrap3Datepicker');
     $languageTag = JFactory::getLanguage()->getTag();
     $locale = substr($languageTag, 0, 2);
     // Only display the triggers once for each control.
     if (!in_array($id, $done, true)) {
         $calendarDateFormat = Prism\Utilities\DateHelper::formatCalendarDate($format);
         $document = JFactory::getDocument();
         $document->addScriptDeclaration('jQuery(document).ready(function($) {
                     jQuery("#' . $id . '_datepicker").datetimepicker({
                         format: "' . $calendarDateFormat . '",
                         locale: "' . \JString::strtolower($locale) . '",
                         allowInputToggle: true
                     });
                 });');
         $done[] = $id;
     }
     // Hide button using inline styles for readonly/disabled fields
     $btn_style = $readonly || $disabled ? ' style="display:none;"' : '';
     return '<div class="input-group date" id="' . $id . '_datepicker">
                 <input type="text" title="' . ($inputvalue ? JHtml::_('date', $value, null, null) : '') . '"
                 name="' . $name . '" id="' . $id . '" value="' . htmlspecialchars($inputvalue, ENT_COMPAT, 'UTF-8') . '" ' . $attributes . ' />
                 <span class="input-group-addon" id="' . $id . '_img">
                     <span class="fa fa-calendar" id="' . $id . '_icon"' . $btn_style . '></span>
                 </span>
             </div>';
 }
 protected function prepareRewards()
 {
     $model = JModelLegacy::getInstance('Rewards', 'CrowdfundingModel', $config = array('ignore_request' => false));
     // Get state
     $this->state = $model->getState();
     // Get params
     $this->projectId = $this->state->get('rewards.project_id');
     // Check if rewards are enabled.
     if (!$this->rewardsEnabled) {
         $this->app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_REWARDS_DISABLED'), 'notice');
         $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getFormRoute($this->projectId, 'manager'), false));
         return;
     }
     $this->items = $model->getItems($this->projectId);
     // Get project and validate it
     $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $this->projectId);
     $project = $project->getProperties();
     $this->item = Joomla\Utilities\ArrayHelper::toObject($project);
     // Check if the item exists.
     if (!CrowdfundingHelper::isAuthorized($this->userId, $this->item, 'rewards')) {
         $this->app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_SOMETHING_WRONG'), 'notice');
         $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute()));
         return;
     }
     // Get money formatter.
     $container = Prism\Container::getContainer();
     $this->money = $this->getMoneyFormatter($container, $this->params);
     $this->currency = $this->getCurrency($container, $this->params);
     // Get calendar date format.
     $this->dateFormatCalendar = $this->params->get('date_format_calendar', JText::_('DATE_FORMAT_LC4'));
     $language = JFactory::getLanguage();
     $languageTag = $language->getTag();
     $js = '
         // Rewards calendar date format.
         var projectWizard = {
             dateFormat: "' . Prism\Utilities\DateHelper::formatCalendarDate($this->dateFormatCalendar) . '",
             locale: "' . substr($languageTag, 0, 2) . '"
         };
     ';
     $this->document->addScriptDeclaration($js);
     // Prepare rewards images.
     $this->rewardsImagesEnabled = (bool) $this->params->get('rewards_images', 0);
     $this->rewardsImagesUri = CrowdfundingHelper::getImagesFolderUri($this->userId);
     $this->options['column_left'] = (!$this->rewardsImagesEnabled or count($this->items) === 0) ? 12 : 8;
     $this->options['column_right'] = (!$this->rewardsImagesEnabled or count($this->items) === 0) ? 0 : 4;
     $this->prepareProjectType();
     $this->pathwayName = JText::_('COM_CROWDFUNDING_STEP_REWARDS');
 }