本文整理汇总了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;
}
}