本文整理匯總了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);
}
示例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);
}
示例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");
//.........這裏部分代碼省略.........
示例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);
}