Example #1
0
 public function display($tpl = null)
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     // Get user ID.
     $this->userId = JFactory::getUser()->get("id");
     // Get reward ID.
     $rewardId = $app->input->getInt("id");
     // Validate reward owner
     jimport("crowdfunding.validator.reward.owner");
     $validator = new CrowdFundingValidatorRewardOwner(JFactory::getDbo(), $rewardId, $this->userId);
     if (!$validator->isValid()) {
         $app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_INVALID_REWARD"), "notice");
         $app->redirect(JRoute::_(CrowdFundingHelperRoute::getDiscoverRoute()));
         return;
     }
     $this->items = $this->get('Items');
     $this->state = $this->get('State');
     $this->pagination = $this->get('Pagination');
     // Get params
     /** @var  $params Joomla\Registry\Registry */
     $params = $this->state->get("params");
     $this->params = $params;
     // Prepare an URL where user will be redirected when change the state of a reward.
     $this->redirectUrl = "index.php?option=com_crowdfunding&view=reward&id=" . $rewardId;
     // Prepare filters
     $this->listOrder = $this->escape($this->state->get('list.ordering'));
     $this->listDirn = $this->escape($this->state->get('list.direction'));
     $this->saveOrder = strcmp($this->listOrder, 'a.ordering') != 0 ? false : true;
     // Load reward data.
     jimport("crowdfunding.reward");
     $this->reward = new CrowdFundingReward(JFactory::getDbo());
     $this->reward->load($rewardId);
     // Prepare reward delivery date.
     $dateValidator = new ITPrismValidatorDate($this->reward->getDeliveryDate());
     $this->deliveryDate = $dateValidator->isValid() ? JHtml::_('date', $this->reward->getDeliveryDate(), JText::_('DATE_FORMAT_LC3')) : "--";
     // Get images folder.
     $this->imagesFolder = CrowdFundingHelper::getImagesFolderUri($this->userId);
     // Get social profile
     $socialPlatform = $this->params->get("integration_social_platform");
     if (!empty($socialPlatform)) {
         $this->prepareSocialIntegration($socialPlatform);
     }
     $this->prepareDocument();
     $this->version = new CrowdFundingVersion();
     parent::display($tpl);
 }
Example #2
0
 /**
  * Method to remove image via AJAX.
  *
  * @throws  Exception
  *
  * @return  void
  */
 public function removeImage()
 {
     // Get the input
     $rewardId = $this->input->post->get('rid', 0, 'int');
     $userId = JFactory::getUser()->get("id");
     jimport("itprism.response.json");
     $response = new ITPrismResponseJson();
     // Validate user
     if (!$userId) {
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     $params = JComponentHelper::getParams("com_crowdfunding");
     /** @var  $params Joomla\Registry\Registry */
     if (!$params->get("rewards_images", 0)) {
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_REWARD'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     // Validate reward owner.
     jimport("crowdfunding.validator.reward.owner");
     $validator = new CrowdFundingValidatorRewardOwner(JFactory::getDbo(), $rewardId, $userId);
     if (!$rewardId or !$validator->isValid()) {
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_REWARD'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     // Get the model
     $model = $this->getModel();
     try {
         // Get the folder where the images will be stored
         $imagesFolder = CrowdFundingHelper::getImagesFolder($userId);
         $model->removeImage($rewardId, $imagesFolder);
     } catch (RuntimeException $e) {
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText($e->getMessage())->failure();
         echo $response;
         JFactory::getApplication()->close();
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     $response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::_('COM_CROWDFUNDING_REWARD_IMAGE_REMOVED_SUCCESSFULLY'))->success();
     echo $response;
     JFactory::getApplication()->close();
 }