/** * Method to change state of reward. * * @throws Exception * @return void */ public function changeState() { // Check for request forgeries. JSession::checkToken('get') or jexit(JText::_('JINVALID_TOKEN')); $userId = JFactory::getUser()->get('id'); if (!$userId) { $redirectOptions = array('force_direction' => JRoute::_('index.php?option=com_users&view=login', false)); $this->displayNotice(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'), $redirectOptions); return; } $redirect = base64_decode($this->input->get('redirect')); $redirectOptions = array('force_direction' => JRoute::_($redirect, false)); $txnId = $this->input->get->getInt('txn_id'); $state = $this->input->get->getInt('state'); $state = !$state ? 0 : 1; if (!$txnId) { $this->displayWarning(JText::_('COM_CROWDFUNDING_ERROR_INVALID_TRANSACTION'), $redirectOptions); return; } $keys = array('id' => $txnId, 'receiver_id' => $userId); /** @var $transaction Crowdfunding\Transaction */ $transaction = new Crowdfunding\Transaction(JFactory::getDbo()); $transaction->load($keys); if (!$transaction->getId()) { $this->displayWarning(JText::_('COM_CROWDFUNDING_ERROR_INVALID_TRANSACTION'), $redirectOptions); return; } try { $transaction->updateRewardState($state); } catch (Exception $e) { JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding'); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } if (!$state) { $msg = JText::_('COM_CROWDFUNDING_REWARD_HAS_BEEN_SET_AS_NOT_SENT'); } else { $msg = JText::_('COM_CROWDFUNDING_REWARD_HAS_BEEN_SET_AS_SENT'); } $this->displayMessage($msg, $redirectOptions); }