示例#1
0
 /**
  * Save an item
  */
 public function save($key = null, $urlVar = null)
 {
     $response = new Prism\Response\Json();
     $userId = JFactory::getUser()->get("id");
     if (!$userId) {
         // Send response to the browser
         $response->setTitle(JText::_("COM_CROWDFUNDINGFINANCE_FAIL"))->setText(JText::_("COM_CROWDFUNDINGFINANCE_ERROR_SYSTEM"))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     // Get project ID.
     $projectId = $this->input->post->get('project_id');
     // Validate project owner
     $validator = new Crowdfunding\Validator\Project\Owner(JFactory::getDbo(), $projectId, $userId);
     if (!$validator->isValid()) {
         // Send response to the browser
         $response->setTitle(JText::_("COM_CROWDFUNDINGFINANCE_FAIL"))->setText(JText::_("COM_CROWDFUNDINGFINANCE_INVALID_PROJECT"))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     $data = array("id" => $projectId, "paypal_email" => $this->input->post->get('paypal_email', null, "string"), "paypal_first_name" => $this->input->post->get('paypal_first_name'), "paypal_last_name" => $this->input->post->get('paypal_last_name'), "iban" => $this->input->post->get('iban'), "bank_account" => $this->input->post->get('bank_account', null, "string"));
     $model = $this->getModel();
     /** @var $model CrowdfundingFinanceModelPayout */
     try {
         $model->save($data);
     } catch (Exception $e) {
         $response->setTitle(JText::_("COM_CROWDFUNDINGFINANCE_FAIL"))->setText(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_SYSTEM'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     $response->setTitle(JText::_("COM_CROWDFUNDINGFINANCE_SUCCESS"))->setText(JText::_("COM_CROWDFUNDINGFINANCE_PAYOUT_DATA_SAVED_SUCCESSFULLY"))->success();
     echo $response;
     JFactory::getApplication()->close();
 }
示例#2
0
 public function upload()
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     $response = new Prism\Response\Json();
     $userId = JFactory::getUser()->get("id");
     if (!$userId) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGFILES_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFILES_ERROR_NOT_LOG_IN'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     $projectId = $this->input->post->get("project_id");
     // Get component parameters
     $params = $app->getParams("com_crowdfundingfiles");
     /** @var  $params Joomla\Registry\Registry */
     // Get the model
     $model = $this->getModel();
     /** @var $model CrowdfundingFilesModelFiles */
     // Validate project owner.
     $validator = new Crowdfunding\Validator\Project\Owner(JFactory::getDbo(), $projectId, $userId);
     if (!$projectId or !$validator->isValid()) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGFILES_FAIL'))->setText(JText::sprintf('COM_CROWDFUNDINGFILES_ERROR_INVALID_PROJECT_FILE_TOO_LARGE', $params->get("max_size")))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     $files = $this->input->files->get("files");
     if (!$files) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGFILES_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFILES_ERROR_FILE_CANT_BE_UPLOADED'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     // Get the folder where the images will be stored
     $mediaUri = CrowdfundingFilesHelper::getMediaFolderUri($userId);
     // Get the folder where the images will be stored
     $destination = CrowdfundingFilesHelper::getMediaFolder($userId);
     if (!JFolder::exists($destination)) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGFILES_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFILES_ERROR_FILE_CANT_BE_UPLOADED'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     $options = array("legal_extensions" => $params->get("legal_extensions"), "legal_types" => $params->get("legal_types"), "max_size" => (int) $params->get("max_size", 2), "destination" => $destination);
     try {
         $files = $model->uploadFiles($files, $options);
         $files = $model->storeFiles($files, $projectId, $userId, $mediaUri);
     } catch (RuntimeException $e) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGFILES_FAIL'))->setText($e->getMessage())->failure();
         echo $response;
         JFactory::getApplication()->close();
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         $response->setTitle(JText::_('COM_CROWDFUNDINGFILES_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFILES_ERROR_SYSTEM'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     $response->setTitle(JText::_('COM_CROWDFUNDINGFILES_SUCCESS'))->setText(JText::_('COM_CROWDFUNDINGFILES_FILES_UPLOADED'))->setData($files)->success();
     echo $response;
     JFactory::getApplication()->close();
 }
 public function save($key = null, $urlVar = null)
 {
     // Check for request forgeries.
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     $response = new Prism\Response\Json();
     $userId = JFactory::getUser()->get('id');
     if (!$userId) {
         // Send response to the browser
         $response->setTitle(JText::_('COM_CROWDFUNDINGFINANCE_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_SYSTEM'))->failure();
         echo $response;
         $app->close();
     }
     // Get project ID.
     $projectId = $this->input->post->get('project_id');
     // Validate project owner
     $validator = new Crowdfunding\Validator\Project\Owner(JFactory::getDbo(), $projectId, $userId);
     if (!$validator->isValid()) {
         // Send response to the browser
         $response->setTitle(JText::_('COM_CROWDFUNDINGFINANCE_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_INVALID_PROJECT'))->failure();
         echo $response;
         $app->close();
     }
     $data = array('id' => $projectId, 'paypal_email' => $this->input->post->get('paypal_email', null, 'string'), 'paypal_first_name' => $this->input->post->get('paypal_first_name'), 'paypal_last_name' => $this->input->post->get('paypal_last_name'), 'iban' => $this->input->post->get('iban'), 'bank_account' => $this->input->post->get('bank_account', null, 'string'));
     $model = $this->getModel();
     /** @var $model CrowdfundingFinanceModelPayout */
     try {
         $model->save($data);
     } catch (Exception $e) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGFINANCE_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_SYSTEM'))->failure();
         echo $response;
         $app->close();
     }
     $response->setTitle(JText::_('COM_CROWDFUNDINGFINANCE_SUCCESS'))->setText(JText::_('COM_CROWDFUNDINGFINANCE_PAYOUT_DATA_SAVED_SUCCESSFULLY'))->success();
     echo $response;
     $app->close();
 }
 public function save()
 {
     // Check for request forgeries.
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $userId = JFactory::getUser()->get('id');
     if (!$userId) {
         $redirectOptions = array('force_direction' => 'index.php?option=com_users&view=login');
         $this->displayNotice(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'), $redirectOptions);
         return;
     }
     $params = JComponentHelper::getParams('com_crowdfunding');
     /** @var  $params Joomla\Registry\Registry */
     // Get the data from the form POST
     $projectId = $this->input->post->get('id', 0, 'int');
     // Check if rewards are enabled.
     if (!$params->get('rewards_enabled', 1)) {
         $redirectOptions = array('view' => 'project', 'layout' => 'manager', 'id' => $projectId);
         $this->displayNotice(JText::_('COM_CROWDFUNDING_ERROR_REWARDS_DISABLED'), $redirectOptions);
         return;
     }
     $data_ = $this->input->post->get('rewards', array(), 'array');
     $actionSubmit = $this->input->post->getCmd('btn_submit', 'save');
     // Reorder items.
     $data = array();
     foreach ($data_ as $item) {
         $ordering = array_key_exists('ordering', $item) ? (int) abs($item['ordering']) : 0;
         if (!$ordering or $ordering > 30) {
             continue;
         }
         $data[$ordering] = $item;
     }
     unset($data_);
     $images = $this->input->files->get('images', array(), 'array');
     // Get wizard type
     $wizardType = $params->get('project_wizard_type', 'five_steps');
     $fiveStepsWizard = strcmp($wizardType, 'five_steps') === 0;
     // If it is five steps wizard type, redirect to manager.
     // If it is six steps wizard type, redirect to extras.
     if (!$fiveStepsWizard) {
         $layout = strcmp($actionSubmit, 'save_continue') === 0 ? 'extras' : 'rewards';
     } else {
         $layout = strcmp($actionSubmit, 'save_continue') === 0 ? 'manager' : 'rewards';
     }
     $redirectOptions = array('view' => 'project', 'layout' => $layout, 'id' => $projectId);
     // Validate project owner.
     $validator = new Crowdfunding\Validator\Project\Owner(JFactory::getDbo(), $projectId, $userId);
     if (!$projectId or !$validator->isValid()) {
         $this->displayWarning(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), $redirectOptions);
         return;
     }
     $model = $this->getModel();
     /** @var $model CrowdfundingModelRewards */
     try {
         $validData = $model->validate($data);
         $rewardsIds = $model->save($validData, $projectId);
         $imagesAllowed = $params->get('rewards_images', 0);
         // Upload images.
         if ($imagesAllowed and count($images) > 0 and count($rewardsIds) > 0) {
             // Get the folder where the images will be stored
             $imagesFolder = CrowdfundingHelper::getImagesFolder($userId, JPATH_ROOT);
             if (!JFolder::exists($imagesFolder)) {
                 CrowdfundingHelper::createFolder($imagesFolder);
             }
             $options = array('temporary_path' => JFactory::getApplication()->get('tmp_path'), 'destination_path' => $imagesFolder);
             $images = $model->uploadImages($images, $rewardsIds, $options, $params);
             if (count($images) > 0) {
                 $model->storeImages($images, $imagesFolder);
             }
         }
     } catch (InvalidArgumentException $e) {
         $this->displayWarning($e->getMessage(), $redirectOptions);
         return;
     } catch (RuntimeException $e) {
         $this->displayWarning($e->getMessage(), $redirectOptions);
         return;
     } catch (Exception $e) {
         JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding');
         throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'));
     }
     // Redirect to next page
     $this->displayMessage(JText::_('COM_CROWDFUNDING_REWARDS_SUCCESSFULLY_SAVED'), $redirectOptions);
 }
示例#5
0
 public function save($key = null, $urlVar = null)
 {
     // Check for request forgeries.
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $userId = JFactory::getUser()->get("id");
     if (!$userId) {
         $redirectOptions = array("force_direction" => "index.php?option=com_users&view=login");
         $this->displayNotice(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'), $redirectOptions);
         return;
     }
     // Get the data from the form POST
     $data = $this->input->post->get('jform', array(), 'array');
     $itemId = Joomla\Utilities\ArrayHelper::getValue($data, "id");
     $redirectOptions = array("view" => "project", "layout" => "funding", "id" => $itemId);
     // Parse formatted amount.
     $data["goal"] = CrowdfundingHelper::parseAmount($data["goal"]);
     $model = $this->getModel();
     /** @var $model CrowdfundingModelFunding */
     $form = $model->getForm($data, false);
     /** @var $form JForm */
     if (!$form) {
         throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_FORM_CANNOT_BE_LOADED"));
     }
     // Test if the data is valid.
     $validData = $model->validate($form, $data);
     // Check for validation errors.
     if ($validData === false) {
         $this->displayNotice($form->getErrors(), $redirectOptions);
         return;
     }
     // Validate project owner.
     $validator = new Crowdfunding\Validator\Project\Owner(JFactory::getDbo(), $itemId, $userId);
     if (!$itemId or !$validator->isValid()) {
         $this->displayWarning(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), $redirectOptions);
         return;
     }
     // Get component parameters.
     $params = JComponentHelper::getParams($this->option);
     /** @var $params Joomla\Registry\Registry */
     // Include plugins to validate content.
     $dispatcher = JEventDispatcher::getInstance();
     JPluginHelper::importPlugin('content');
     // Trigger onContentValidate event.
     $context = $this->option . ".funding";
     $results = $dispatcher->trigger("onContentValidate", array($context, &$validData, &$params));
     // If there is an error, redirect to current step.
     foreach ($results as $result) {
         if ($result["success"] == false) {
             $this->displayWarning(Joomla\Utilities\ArrayHelper::getValue($result, "message"), $redirectOptions);
             return;
         }
     }
     try {
         // Save data
         $itemId = $model->save($validData);
         $redirectOptions["id"] = $itemId;
     } catch (RuntimeException $e) {
         $this->displayWarning($e->getMessage(), $redirectOptions);
         return;
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'));
     }
     // Redirect to next page
     $redirectOptions = array("view" => "project", "layout" => "story", "id" => $itemId);
     $this->displayMessage(JText::_("COM_CROWDFUNDING_FUNDING_SUCCESSFULLY_SAVED"), $redirectOptions);
 }
示例#6
0
 /**
  * Delete image
  */
 public function removeImage()
 {
     // Check for request forgeries.
     JSession::checkToken("get") or jexit(JText::_('JINVALID_TOKEN'));
     // Check for registered user
     $userId = JFactory::getUser()->get("id");
     if (!$userId) {
         $redirectOptions = array("force_direction" => "index.php?option=com_users&view=login");
         $this->displayNotice(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'), $redirectOptions);
         return;
     }
     $itemId = $this->input->get->getInt("id");
     $redirectOptions = array("view" => "project", "layout" => "story");
     // Validate project owner.
     $validator = new Crowdfunding\Validator\Project\Owner(JFactory::getDbo(), $itemId, $userId);
     if (!$itemId or !$validator->isValid()) {
         $this->displayWarning(JText::_('COM_CROWDFUNDING_ERROR_INVALID_IMAGE'), $redirectOptions);
         return;
     }
     try {
         $model = $this->getModel();
         $model->removeImage($itemId, $userId);
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'));
     }
     $redirectOptions["id"] = $itemId;
     $this->displayMessage(JText::_('COM_CROWDFUNDING_IMAGE_DELETED'), $redirectOptions);
 }
示例#7
0
 public function cropImage()
 {
     // Check for request forgeries.
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     $response = new Prism\Response\Json();
     $userId = JFactory::getUser()->get("id");
     if (!$userId) {
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'))->failure();
         echo $response;
         $app->close();
     }
     // Get the model
     $model = $this->getModel();
     /** @var $model CrowdfundingModelProject */
     $projectId = $this->input->post->get("id");
     // If there is a project, validate the owner.
     if (!empty($projectId)) {
         // Validate project owner.
         $validator = new Crowdfunding\Validator\Project\Owner(JFactory::getDbo(), $projectId, $userId);
         if (!$validator->isValid()) {
             $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'))->failure();
             echo $response;
             $app->close();
         }
     }
     // Get the filename from the session.
     $fileName = basename($app->getUserState(Crowdfunding\Constants::TEMPORARY_IMAGE_CONTEXT));
     $temporaryFile = JPath::clean(CrowdfundingHelper::getTemporaryImagesFolder() . "/" . $fileName);
     if (!$fileName or !JFile::exists($temporaryFile)) {
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_FILE_DOES_NOT_EXIST'))->failure();
         echo $response;
         $app->close();
     }
     $imageUrl = "";
     try {
         // Get the folder where the images will be stored
         $destination = CrowdfundingHelper::getTemporaryImagesFolder();
         $params = JComponentHelper::getParams("com_crowdfunding");
         $options = array("width" => $this->input->getFloat("width"), "height" => $this->input->getFloat("height"), "x" => $this->input->getFloat("x"), "y" => $this->input->getFloat("y"), "destination" => $destination, "resize_width" => $params->get("image_width", 200), "resize_height" => $params->get("image_height", 200));
         // Resize the picture.
         $images = $model->cropImage($temporaryFile, $options);
         $imageName = basename(Joomla\Utilities\ArrayHelper::getValue($images, "image"));
         // Remove the temporary images if they exist.
         $temporaryImages = $app->getUserState(Crowdfunding\Constants::CROPPED_IMAGES_CONTEXT);
         if (!empty($temporaryImages)) {
             $model->removeTemporaryImages($temporaryImages, $destination);
         }
         // If there is a project, store the images to database.
         // If there is NO project, store the images in the session.
         if (!empty($projectId)) {
             $model->updateImages($projectId, $images, $destination);
             $app->setUserState(Crowdfunding\Constants::CROPPED_IMAGES_CONTEXT, null);
             // Get the folder of the images where the pictures will be stored.
             $imageUrl = JUri::base() . CrowdfundingHelper::getImagesFolderUri() . "/" . $imageName;
         } else {
             $app->setUserState(Crowdfunding\Constants::CROPPED_IMAGES_CONTEXT, $images);
             // Get the temporary folder where the images will be stored.
             $imageUrl = JUri::base() . CrowdfundingHelper::getTemporaryImagesFolderUri() . "/" . $imageName;
         }
     } catch (RuntimeException $e) {
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText($e->getMessage())->failure();
         echo $response;
         $app->close();
     } catch (Exception $e) {
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'))->failure();
         echo $response;
         $app->close();
     }
     $response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::_('COM_CROWDFUNDING_IMAGE_SAVED'))->setData($imageUrl)->success();
     echo $response;
     $app->close();
 }
示例#8
0
 public function save()
 {
     // Check for request forgeries.
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $userId = JFactory::getUser()->get("id");
     if (!$userId) {
         $redirectOptions = array("force_direction" => "index.php?option=com_users&view=login");
         $this->displayNotice(JText::_("COM_CROWDFUNDING_ERROR_NOT_LOG_IN"), $redirectOptions);
         return;
     }
     $params = JComponentHelper::getParams("com_crowdfunding");
     /** @var  $params Joomla\Registry\Registry */
     // Get the data from the form POST
     $projectId = $this->input->post->get('id', 0, 'int');
     // Check if rewards are enabled.
     if (!$params->get("rewards_enabled", 1)) {
         $redirectOptions = array("view" => "project", "layout" => "manager", "id" => $projectId);
         $this->displayNotice(JText::_("COM_CROWDFUNDING_ERROR_REWARDS_DISABLED"), $redirectOptions);
         return;
     }
     $data = $this->input->post->get('rewards', array(), 'array');
     $actionSubmit = $this->input->post->getCmd('btn_submit', 'save');
     $images = $this->input->files->get('images', array(), 'array');
     // Get wizard type
     $wizardType = $params->get("project_wizard_type", "five_steps");
     $fiveStepsWizard = strcmp($wizardType, "five_steps") == 0 ? true : false;
     // If it is five steps wizard type, redirect to manager.
     // If it is six steps wizard type, redirect to extras.
     if (!$fiveStepsWizard) {
         $layout = strcmp($actionSubmit, "save_continue") == 0 ? "extras" : "rewards";
     } else {
         $layout = strcmp($actionSubmit, "save_continue") == 0 ? "manager" : "rewards";
     }
     $redirectOptions = array("view" => "project", "layout" => $layout, "id" => $projectId);
     // Validate project owner.
     $validator = new Crowdfunding\Validator\Project\Owner(JFactory::getDbo(), $projectId, $userId);
     if (!$projectId or !$validator->isValid()) {
         $this->displayWarning(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), $redirectOptions);
         return;
     }
     $model = $this->getModel();
     /** @var $model CrowdfundingModelRewards */
     try {
         $validData = $model->validate($data);
         $rewardsIds = $model->save($validData, $projectId);
         $imagesAllowed = $params->get("rewards_images", 0);
         // Upload images.
         if ($imagesAllowed and !empty($images) and !empty($rewardsIds)) {
             // Get the folder where the images will be stored
             $imagesFolder = CrowdfundingHelper::getImagesFolder($userId);
             jimport("joomla.filesystem.folder");
             if (!JFolder::exists($imagesFolder)) {
                 CrowdfundingHelper::createFolder($imagesFolder);
             }
             $images = $model->uploadImages($images, $imagesFolder, $rewardsIds);
             if (!empty($images)) {
                 $model->storeImages($images, $imagesFolder);
             }
         }
     } catch (InvalidArgumentException $e) {
         $this->displayWarning($e->getMessage(), $redirectOptions);
         return;
     } catch (RuntimeException $e) {
         $this->displayWarning($e->getMessage(), $redirectOptions);
         return;
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'));
     }
     // Redirect to next page
     $this->displayMessage(JText::_("COM_CROWDFUNDING_REWARDS_SUCCESSFULLY_SAVED"), $redirectOptions);
 }
示例#9
0
 /**
  * Delete an item.
  */
 public function remove()
 {
     // Create response object
     $response = new Prism\Response\Json();
     $userId = JFactory::getUser()->get("id");
     if (!$userId) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGPARTNERS_FAIL'))->setText(JText::_('COM_CROWDFUNDINGPARTNERS_ERROR_NOT_LOG_IN'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     // Get file ID.
     $itemId = $this->input->post->get("id");
     // Get the model
     $model = $this->getModel();
     /** @var $model CrowdfundingPartnersModelPartners */
     // Create an partner object and load the data from database.
     $partner = new CrowdfundingPartners\Partner(JFactory::getDbo());
     $partner->load($itemId);
     // Validate owner of the project.
     $validator = new Crowdfunding\Validator\Project\Owner(JFactory::getDbo(), $partner->getProjectId(), $userId);
     if (!$validator->isValid()) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGPARTNERS_FAIL'))->setText(JText::_('COM_CROWDFUNDINGPARTNERS_ERROR_INVALID_PROJECT'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     try {
         $model->remove($itemId);
     } catch (RuntimeException $e) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGPARTNERS_FAIL'))->setText(JText::_('COM_CROWDFUNDINGPARTNERS_ERROR_INVALID_PROJECT'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception($e->getMessage());
     }
     $response->setTitle(JText::_('COM_CROWDFUNDINGPARTNERS_SUCCESS'))->setText(JText::_('COM_CROWDFUNDINGPARTNERS_PARTNER_DELETED'))->setData(array("id" => $itemId))->success();
     echo $response;
     JFactory::getApplication()->close();
 }
 public function save($key = null, $urlVar = null)
 {
     // Check for request forgeries.
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $userId = JFactory::getUser()->get('id');
     if (!$userId) {
         $redirectOptions = array('force_direction' => 'index.php?option=com_users&view=login');
         $this->displayNotice(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'), $redirectOptions);
         return;
     }
     // Get the data from the form POST
     $data = $this->input->post->get('jform', array(), 'array');
     $itemId = Joomla\Utilities\ArrayHelper::getValue($data, 'id');
     $redirectOptions = array('view' => 'project', 'layout' => 'funding', 'id' => $itemId);
     // Get component parameters.
     $params = JComponentHelper::getParams($this->option);
     /** @var $params Joomla\Registry\Registry */
     $money = $this->getMoneyFormatter($params);
     $data['goal'] = $money->setAmount($data['goal'])->parse();
     $model = $this->getModel();
     /** @var $model CrowdfundingModelFunding */
     $form = $model->getForm($data, false);
     /** @var $form JForm */
     if (!$form) {
         throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_FORM_CANNOT_BE_LOADED'));
     }
     // Test if the data is valid.
     $validData = $model->validate($form, $data);
     // Check for validation errors.
     if ($validData === false) {
         $this->displayNotice($form->getErrors(), $redirectOptions);
         return;
     }
     // Validate project owner.
     $validator = new Crowdfunding\Validator\Project\Owner(JFactory::getDbo(), $itemId, $userId);
     if (!$itemId or !$validator->isValid()) {
         $this->displayWarning(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), $redirectOptions);
         return;
     }
     // Include plugins to validate content.
     $dispatcher = JEventDispatcher::getInstance();
     JPluginHelper::importPlugin('content');
     // Trigger onContentValidate event.
     $context = $this->option . '.funding';
     $results = $dispatcher->trigger('onContentValidate', array($context, &$validData, &$params));
     // If there is an error, redirect to current step.
     foreach ($results as $result) {
         if ((bool) $result['success'] === false) {
             $this->displayWarning(Joomla\Utilities\ArrayHelper::getValue($result, 'message'), $redirectOptions);
             return;
         }
     }
     try {
         $redirectOptions['id'] = $model->save($validData);
         $redirectOptions['layout'] = 'story';
     } catch (RuntimeException $e) {
         $this->displayWarning($e->getMessage(), $redirectOptions);
         return;
     } catch (Exception $e) {
         JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding');
         throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'));
     }
     $this->displayMessage(JText::_('COM_CROWDFUNDING_FUNDING_SUCCESSFULLY_SAVED'), $redirectOptions);
 }