本文整理匯總了PHP中CrowdfundingHelper::convertToSql方法的典型用法代碼示例。如果您正苦於以下問題:PHP CrowdfundingHelper::convertToSql方法的具體用法?PHP CrowdfundingHelper::convertToSql怎麽用?PHP CrowdfundingHelper::convertToSql使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CrowdfundingHelper
的用法示例。
在下文中一共展示了CrowdfundingHelper::convertToSql方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: validate
public function validate($data)
{
if (!is_array($data) or count($data) === 0) {
throw new InvalidArgumentException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_REWARDS'));
}
$filter = JFilterInput::getInstance();
$params = JComponentHelper::getParams('com_crowdfunding');
/** @var $params Joomla\Registry\Registry */
$money = $this->getMoneyFormatter($params);
foreach ($data as $key => &$item) {
$item['amount'] = $money->setAmount($item['amount'])->parse();
// Filter data
if (!is_numeric($item['amount'])) {
$item['amount'] = 0.0;
}
$item['title'] = $filter->clean($item['title'], 'string');
$item['title'] = JString::trim($item['title']);
$item['title'] = JString::substr($item['title'], 0, 128);
$item['description'] = $filter->clean($item['description'], 'string');
$item['description'] = JString::trim($item['description']);
$item['description'] = JString::substr($item['description'], 0, 500);
$item['number'] = (int) $item['number'];
$item['delivery'] = trim($item['delivery']);
$item['delivery'] = $filter->clean($item['delivery'], 'string');
if (!empty($item['delivery'])) {
$item['delivery'] = CrowdfundingHelper::convertToSql($item['delivery']);
$validatorDate = new Prism\Validator\Date($item['delivery']);
if (!$validatorDate->isValid()) {
$item['delivery'] = '';
}
}
if (!$item['title']) {
throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_TITLE'));
}
if (!$item['description']) {
throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_DESCRIPTION'));
}
if (!$item['amount']) {
throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_AMOUNT'));
}
}
unset($item);
return $data;
}
示例2: prepareTableData
/**
* Prepare and sanitise the table prior to saving.
*
* @param CrowdfundingTableProject $table
* @param array $data
*
* @throws \RuntimeException
* @throws \InvalidArgumentException
*
* @since 1.6
*/
protected function prepareTableData($table, $data)
{
$durationType = Joomla\Utilities\ArrayHelper::getValue($data, 'duration_type');
$fundingEnd = Joomla\Utilities\ArrayHelper::getValue($data, 'funding_end');
$fundingDays = Joomla\Utilities\ArrayHelper::getValue($data, 'funding_days', 0, 'int');
switch ($durationType) {
case 'days':
$fundingDays = $fundingDays < 0 ? 0 : (int) $fundingDays;
$table->set('funding_days', $fundingDays);
// Calculate end date
$startingDateValidator = new Prism\Validator\Date($table->get('funding_start'));
if ($startingDateValidator->isValid()) {
$fundingStartDate = new Crowdfunding\Date($table->get('funding_start'));
$fundingEndDate = $fundingStartDate->calculateEndDate($table->get('funding_days'));
$table->set('funding_end', $fundingEndDate->format(Prism\Constants::DATE_FORMAT_SQL_DATE));
} else {
$table->set('funding_end', Prism\Constants::DATE_DEFAULT_SQL_DATE);
}
break;
case 'date':
$fundingEnd = CrowdfundingHelper::convertToSql($fundingEnd);
$dateValidator = new Prism\Validator\Date($fundingEnd);
if (!$dateValidator->isValid()) {
throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_DATE'));
}
$date = new JDate($fundingEnd);
$table->set('funding_days', 0);
$table->set('funding_end', $date->toSql());
break;
default:
$table->set('funding_days', 0);
$table->set('funding_end', Prism\Constants::DATE_DEFAULT_SQL_DATE);
break;
}
}