当前位置: 首页>>代码示例>>PHP>>正文


PHP CrowdfundingHelper::parseAmount方法代码示例

本文整理汇总了PHP中CrowdfundingHelper::parseAmount方法的典型用法代码示例。如果您正苦于以下问题:PHP CrowdfundingHelper::parseAmount方法的具体用法?PHP CrowdfundingHelper::parseAmount怎么用?PHP CrowdfundingHelper::parseAmount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CrowdfundingHelper的用法示例。


在下文中一共展示了CrowdfundingHelper::parseAmount方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

 public function save($key = null, $urlVar = null)
 {
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $data = $this->input->post->get('jform', array(), 'array');
     $itemId = JArrayHelper::getValue($data, "id");
     $dataFile = $this->input->files->get('jform', array(), 'array');
     $image = JArrayHelper::getValue($dataFile, "image", array(), "array");
     $imageName = Joomla\String\String::trim(JArrayHelper::getValue($image, 'name'));
     $redirectOptions = array("task" => $this->getTask(), "id" => $itemId);
     // Parse formatted amount.
     $data["amount"] = CrowdfundingHelper::parseAmount($data["amount"]);
     $model = $this->getModel();
     /** @var $model CrowdfundingModelReward */
     $form = $model->getForm($data, false);
     /** @var $form JForm */
     if (!$form) {
         throw new Exception(JText::_("COM_Crowdfunding_ERROR_FORM_CANNOT_BE_LOADED"), 500);
     }
     // Validate the form
     $validData = $model->validate($form, $data);
     // Check for errors.
     if ($validData === false) {
         $this->displayNotice($form->getErrors(), $redirectOptions);
         return;
     }
     $params = JComponentHelper::getParams("com_crowdfunding");
     /** @var  $params Joomla\Registry\Registry */
     try {
         $itemId = $model->save($validData);
         $redirectOptions["id"] = $itemId;
         // Upload an image
         $imagesAllowed = $params->get("rewards_images", 0);
         // Upload images.
         if ($imagesAllowed and !empty($imageName) and !empty($itemId)) {
             $reward = new Crowdfunding\Reward(JFactory::getDbo());
             $reward->load($itemId);
             // Get the folder where the images will be stored
             $imagesFolder = CrowdfundingHelper::getImagesFolder($reward->getUserId());
             jimport("joomla.filesystem.folder");
             if (!JFolder::exists($imagesFolder)) {
                 CrowdfundingHelper::createFolder($imagesFolder);
             }
             $images = $model->uploadImage($image, $imagesFolder);
             if (!empty($images)) {
                 $model->storeImage($images, $imagesFolder, $itemId);
             }
         }
     } catch (RuntimeException $e) {
         $this->displayError($e->getMessage(), $redirectOptions);
         return;
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_Crowdfunding_ERROR_SYSTEM'));
     }
     $this->displayMessage(JText::_('COM_Crowdfunding_REWARD_SAVED'), $redirectOptions);
 }
开发者ID:pashakiz,项目名称:crowdf,代码行数:56,代码来源:reward.php

示例2: save

 public function save($key = null, $urlVar = null)
 {
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $data = $this->input->post->get('jform', array(), 'array');
     $itemId = JArrayHelper::getValue($data, "id");
     $redirectOptions = array("task" => $this->getTask(), "id" => $itemId);
     // Parse formatted goal and funded amounts.
     $data["goal"] = CrowdfundingHelper::parseAmount($data["goal"]);
     $data["funded"] = CrowdfundingHelper::parseAmount($data["funded"]);
     $model = $this->getModel();
     /** @var $model CrowdfundingModelProject */
     $form = $model->getForm($data, false);
     /** @var $form JForm */
     if (!$form) {
         throw new Exception(JText::_("COM_Crowdfunding_ERROR_FORM_CANNOT_BE_LOADED"), 500);
     }
     // Validate the form
     $validData = $model->validate($form, $data);
     $validData["duration_type"] = JArrayHelper::getValue($data, "funding_duration_type");
     // Check for errors.
     if ($validData === false) {
         $this->displayNotice($form->getErrors(), $redirectOptions);
         return;
     }
     try {
         // Get image
         $files = $this->input->files->get('jform', array(), 'array');
         $image = JArrayHelper::getValue($files, "image");
         $pitchImage = JArrayHelper::getValue($files, "pitch_image");
         // Upload image
         if (!empty($image['name'])) {
             $imageNames = $model->uploadImage($image);
             if (!empty($imageNames["image"])) {
                 $validData = array_merge($validData, $imageNames);
             }
         }
         // Upload pitch image
         if (!empty($pitchImage['name'])) {
             $pitchImageName = $model->uploadPitchImage($pitchImage);
             if (!empty($pitchImageName)) {
                 $validData["pitch_image"] = $pitchImageName;
             }
         }
         $itemId = $model->save($validData);
         $redirectOptions["id"] = $itemId;
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_Crowdfunding_ERROR_SYSTEM'));
     }
     $this->displayMessage(JText::_('COM_Crowdfunding_PROJECT_SAVED'), $redirectOptions);
 }
开发者ID:pashakiz,项目名称:crowdf,代码行数:51,代码来源:project.php

示例3: process

 public function process()
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     // Check for request forgeries.
     $requestMethod = $app->input->getMethod();
     if (strcmp("POST", $requestMethod) == 0) {
         JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     } else {
         JSession::checkToken("get") or jexit(JText::_('JINVALID_TOKEN'));
     }
     // Get params
     $params = JComponentHelper::getParams("com_crowdfunding");
     /** @var  $params Joomla\Registry\Registry */
     // Get the data from the form
     $itemId = $this->input->getInt('id', 0);
     $rewardId = $this->input->getInt('rid', 0);
     // Get amount
     $amount = CrowdfundingHelper::parseAmount($this->input->getString("amount"));
     // Get user ID
     $user = JFactory::getUser();
     $userId = (int) $user->get("id");
     // Anonymous user ID
     $aUserId = "";
     $model = $this->getModel();
     /** @var $model CrowdfundingModelBacking */
     // Get the item
     $item = $model->getItem($itemId);
     $returnUrl = CrowdfundingHelperRoute::getBackingRoute($item->slug, $item->catslug);
     // Authorise the user
     if (!$user->authorise("crowdfunding.donate", "com_crowdfunding")) {
         $this->setRedirect(JRoute::_($returnUrl, false), JText::_('COM_CROWDFUNDING_ERROR_NO_PERMISSIONS'), "notice");
         return;
     }
     // Check for valid project
     if (empty($item->id)) {
         $this->setRedirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute()), JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), "notice");
         return;
     }
     // Check for maintenance (debug) state.
     if ($params->get("debug_payment_disabled", 0)) {
         $msg = Joomla\String\String::trim($params->get("debug_disabled_functionality_msg"));
         if (!$msg) {
             $msg = JText::_("COM_CROWDFUNDING_DEBUG_MODE_DEFAULT_MSG");
         }
         $this->setRedirect(JRoute::_($returnUrl, false), $msg, "notice");
         return;
     }
     // Check for agreed conditions from the user.
     if ($params->get("backing_terms", 0)) {
         $terms = $this->input->get("terms", 0, "int");
         if (!$terms) {
             $this->setRedirect(JRoute::_($returnUrl, false), JText::_("COM_CROWDFUNDING_ERROR_TERMS_NOT_ACCEPTED"), "notice");
             return;
         }
     }
     // Check for valid amount.
     if (!$amount) {
         $this->setRedirect(JRoute::_($returnUrl, false), JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT"), "notice");
         return;
     }
     // Store payment process data
     // Get the payment process object and
     // store the selected data from the user.
     $paymentSessionContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $item->id;
     $paymentSessionLocal = $app->getUserState($paymentSessionContext);
     $paymentSessionLocal->step1 = true;
     $paymentSessionLocal->amount = $amount;
     $paymentSessionLocal->rewardId = $rewardId;
     $app->setUserState($paymentSessionContext, $paymentSessionLocal);
     // Generate hash user ID used for anonymous payment.
     if (!$userId) {
         $aUserId = $app->getUserState("auser_id");
         if (!$aUserId) {
             // Generate a hash ID for anonymous user.
             $anonymousUserId = new Prism\String();
             $anonymousUserId->generateRandomString(32);
             $aUserId = (string) $anonymousUserId;
             $app->setUserState("auser_id", $aUserId);
         }
     }
     $date = new JDate();
     // Create an intention record.
     $intentionId = 0;
     if (!empty($userId)) {
         $intentionKeys = array("user_id" => $userId, "project_id" => $item->id);
         $intention = new Crowdfunding\Intention(JFactory::getDbo());
         $intention->load($intentionKeys);
         $intentionData = array("user_id" => $userId, "project_id" => $item->id, "reward_id" => $rewardId, "record_date" => $date->toSql());
         $intention->bind($intentionData);
         $intention->store();
         $intentionId = $intention->getId();
     }
     // Create a payment session.
     $paymentSessionDatabase = new Crowdfunding\Payment\Session(JFactory::getDbo());
     $paymentSessionData = array("user_id" => $userId, "auser_id" => $aUserId, "project_id" => $item->id, "reward_id" => $rewardId, "record_date" => $date->toSql(), "session_id" => $paymentSessionLocal->session_id, "intention_id" => $intentionId);
     $paymentSessionDatabase->bind($paymentSessionData);
     $paymentSessionDatabase->store();
     // Redirect to next page
     $link = CrowdfundingHelperRoute::getBackingRoute($item->slug, $item->catslug, "payment");
//.........这里部分代码省略.........
开发者ID:Eautentik,项目名称:CrowdFunding,代码行数:101,代码来源:backing.php

示例4: save

 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);
 }
开发者ID:Eautentik,项目名称:CrowdFunding,代码行数:67,代码来源:funding.php


注:本文中的CrowdfundingHelper::parseAmount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。