/** * Method to get the data that should be injected in the form. * * @return mixed The data for the form. * @since 1.6 */ protected function loadFormData() { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $data = $app->getUserState($this->option . '.edit.funding.data', array()); if (!$data) { $itemId = (int) $this->getState($this->getName() . '.id'); $userId = JFactory::getUser()->get("id"); $data = $this->getItem($itemId, $userId); // Prepare date format. $dateFormat = CrowdFundingHelper::getDateFormat(); $dateValidator = new ITPrismValidatorDate($data->funding_end); // Validate end date. If the date is not valid, generate a valid one. // Use minimum allowed days to generate end funding date. if (!$dateValidator->isValid()) { // Get minimum days. $params = $this->getState("params"); $minDays = $params->get("project_days_minimum", 30); // Generate end date. $today = new CrowdFundingDate(); $fundingEndDate = $today->calculateEndDate($minDays); $data->funding_end = $fundingEndDate->format("Y-m-d"); } $date = new JDate($data->funding_end); $data->funding_end = $date->format($dateFormat); } return $data; }
protected function prepareRewards() { $model = JModelLegacy::getInstance("Rewards", "CrowdFundingModel", $config = array('ignore_request' => false)); // Initialise variables // Get state /** @var $state Joomla\Registry\Registry */ $state = $model->getState(); $this->state = $state; // Get params /** @var $params Joomla\Registry\Registry */ $params = $this->state->get("params"); $this->params = $params; $this->projectId = $this->state->get("rewards.id"); $this->items = $model->getItems($this->projectId); // Get project and validate it jimport("crowdfunding.project"); $project = CrowdFundingProject::getInstance(JFactory::getDbo(), $this->projectId); $project = $project->getProperties(); $this->item = JArrayHelper::toObject($project); if (!$this->item->id or $this->item->user_id != $this->userId) { throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_INVALID_PROJECT")); } // Create a currency object. jimport("crowdfunding.currency"); $currencyId = $this->params->get("project_currency"); $this->currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $this->params); // Get date format $this->dateFormat = CrowdFundingHelper::getDateFormat(); $this->dateFormatCalendar = CrowdFundingHelper::getDateFormat(true); $js = ' // Rewards calendar date format. var projectWizard = { dateFormat: "' . $this->dateFormatCalendar . '" }; '; $this->document->addScriptDeclaration($js); // Prepare rewards images. $this->rewardsImagesEnabled = $this->params->get("rewards_images", 0); $this->rewardsImagesUri = CrowdFundingHelper::getImagesFolderUri($this->userId); $this->prepareProjectType(); $this->pathwayName = JText::_("COM_CROWDFUNDING_STEP_REWARDS"); }