本文整理汇总了PHP中CRM_Utils_Rule::dateTime方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Rule::dateTime方法的具体用法?PHP CRM_Utils_Rule::dateTime怎么用?PHP CRM_Utils_Rule::dateTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Utils_Rule
的用法示例。
在下文中一共展示了CRM_Utils_Rule::dateTime方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: typecheck
/**
* Validate a value against a CustomField type.
*
* @param string $type
* The type of the data.
* @param string $value
* The data to be validated.
*
* @return bool
* True if the value is of the specified type
*/
public static function typecheck($type, $value)
{
switch ($type) {
case 'Memo':
return TRUE;
case 'String':
return CRM_Utils_Rule::string($value);
case 'Int':
return CRM_Utils_Rule::integer($value);
case 'Float':
case 'Money':
return CRM_Utils_Rule::numeric($value);
case 'Date':
if (is_numeric($value)) {
return CRM_Utils_Rule::dateTime($value);
} else {
return CRM_Utils_Rule::date($value);
}
case 'Boolean':
return CRM_Utils_Rule::boolean($value);
case 'ContactReference':
return CRM_Utils_Rule::validContact($value);
case 'StateProvince':
//fix for multi select state, CRM-3437
$valid = FALSE;
$mulValues = explode(',', $value);
foreach ($mulValues as $key => $state) {
$valid = array_key_exists(strtolower(trim($state)), array_change_key_case(array_flip(CRM_Core_PseudoConstant::stateProvinceAbbreviation()), CASE_LOWER)) || array_key_exists(strtolower(trim($state)), array_change_key_case(array_flip(CRM_Core_PseudoConstant::stateProvince()), CASE_LOWER));
if (!$valid) {
break;
}
}
return $valid;
case 'Country':
//fix multi select country, CRM-3437
$valid = FALSE;
$mulValues = explode(',', $value);
foreach ($mulValues as $key => $country) {
$valid = array_key_exists(strtolower(trim($country)), array_change_key_case(array_flip(CRM_Core_PseudoConstant::countryIsoCode()), CASE_LOWER)) || array_key_exists(strtolower(trim($country)), array_change_key_case(array_flip(CRM_Core_PseudoConstant::country()), CASE_LOWER));
if (!$valid) {
break;
}
}
return $valid;
case 'Link':
return CRM_Utils_Rule::url($value);
}
return FALSE;
}
示例2: _civicrm_api3_deprecated_formatted_param
//.........这里部分代码省略.........
}
}
} elseif (!empty($params['contribution_id']) || !empty($params['trxn_id']) || !empty($params['invoice_id'])) {
// when update mode check contribution id or trxn id or
// invoice id
$contactId = new CRM_Contribute_DAO_Contribution();
if (!empty($params['contribution_id'])) {
$contactId->id = $params['contribution_id'];
} elseif (!empty($params['trxn_id'])) {
$contactId->trxn_id = $params['trxn_id'];
} elseif (!empty($params['invoice_id'])) {
$contactId->invoice_id = $params['invoice_id'];
}
if ($contactId->find(TRUE)) {
$contactType->id = $contactId->contact_id;
if ($contactType->find(TRUE)) {
if ($params['contact_type'] != $contactType->contact_type) {
return civicrm_api3_create_error("Contact Type is wrong: {$contactType->contact_type}");
}
}
}
} else {
if ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) {
return civicrm_api3_create_error("Empty Contribution and Invoice and Transaction ID. Row was skipped.");
} else {
return civicrm_api3_create_error("Empty Contact and External ID. Row was skipped.");
}
}
break;
case 'receive_date':
case 'cancel_date':
case 'receipt_date':
case 'thankyou_date':
if (!CRM_Utils_Rule::dateTime($value)) {
return civicrm_api3_create_error("{$key} not a valid date: {$value}");
}
break;
case 'non_deductible_amount':
case 'total_amount':
case 'fee_amount':
case 'net_amount':
if (!CRM_Utils_Rule::money($value)) {
return civicrm_api3_create_error("{$key} not a valid amount: {$value}");
}
break;
case 'currency':
if (!CRM_Utils_Rule::currencyCode($value)) {
return civicrm_api3_create_error("currency not a valid code: {$value}");
}
break;
case 'financial_type':
require_once 'CRM/Contribute/PseudoConstant.php';
$contriTypes = CRM_Contribute_PseudoConstant::financialType();
foreach ($contriTypes as $val => $type) {
if (strtolower($value) == strtolower($type)) {
$values['financial_type_id'] = $val;
break;
}
}
if (empty($values['financial_type_id'])) {
return civicrm_api3_create_error("Financial Type is not valid: {$value}");
}
break;
case 'payment_instrument':
require_once 'CRM/Core/OptionGroup.php';
$values['payment_instrument_id'] = CRM_Core_OptionGroup::getValue('payment_instrument', $value);
示例3: _civicrm_contribute_format_params
/**
* take the input parameter list as specified in the data model and
* convert it into the same format that we use in QF and BAO object
*
* @param array $params Associative array of property name/value
* pairs to insert in new contact.
* @param array $values The reformatted properties that we can use internally
* '
*
* @return array|CRM_Error
* @access public
*/
function _civicrm_contribute_format_params(&$params, &$values, $create = FALSE)
{
// copy all the contribution fields as is
$fields = CRM_Contribute_DAO_Contribution::fields();
_civicrm_store_values($fields, $params, $values);
foreach ($params as $key => $value) {
// ignore empty values or empty arrays etc
if (CRM_Utils_System::isNull($value)) {
continue;
}
switch ($key) {
case 'contribution_contact_id':
if (!CRM_Utils_Rule::integer($value)) {
return civicrm_create_error("contact_id not valid: {$value}");
}
$dao = new CRM_Core_DAO();
$qParams = array();
$svq = $dao->singleValueQuery("SELECT id FROM civicrm_contact WHERE id = {$value}", $qParams);
if (!$svq) {
return civicrm_create_error("Invalid Contact ID: There is no contact record with contact_id = {$value}.");
}
$values['contact_id'] = $values['contribution_contact_id'];
unset($values['contribution_contact_id']);
break;
case 'receive_date':
case 'cancel_date':
case 'receipt_date':
case 'thankyou_date':
if (!CRM_Utils_Rule::dateTime($value)) {
return civicrm_create_error("{$key} not a valid date: {$value}");
}
break;
case 'non_deductible_amount':
case 'total_amount':
case 'fee_amount':
case 'net_amount':
if (!CRM_Utils_Rule::money($value)) {
return civicrm_create_error("{$key} not a valid amount: {$value}");
}
break;
case 'currency':
if (!CRM_Utils_Rule::currencyCode($value)) {
return civicrm_create_error("currency not a valid code: {$value}");
}
break;
case 'contribution_type_id':
if (!CRM_Utils_Array::value($value, CRM_Contribute_PseudoConstant::contributionType())) {
return civicrm_create_error('Invalid Contribution Type Id');
}
break;
case 'contribution_type':
$contributionTypeId = CRM_Utils_Array::key(ucfirst($value), CRM_Contribute_PseudoConstant::contributionType());
if ($contributionTypeId) {
if (CRM_Utils_Array::value('contribution_type_id', $values) && $contributionTypeId != $values['contribution_type_id']) {
return civicrm_create_error('Mismatched Contribution Type and Contribution Type Id');
}
$values['contribution_type_id'] = $contributionTypeId;
} else {
return civicrm_create_error('Invalid Contribution Type');
}
break;
case 'payment_instrument':
require_once 'CRM/Core/OptionGroup.php';
$values['payment_instrument_id'] = CRM_Core_OptionGroup::getValue('payment_instrument', $value);
break;
case 'soft_credit_to':
if (!CRM_Utils_Rule::integer($value)) {
return civicrm_create_error("{$key} not a valid Id: {$value}");
}
$values['soft_credit_to'] = $value;
break;
default:
break;
}
}
if (array_key_exists('note', $params)) {
$values['note'] = $params['note'];
}
_civicrm_custom_format_params($params, $values, 'Contribution');
if ($create) {
// CRM_Contribute_BAO_Contribution::add() handles contribution_source
// So, if $values contains contribution_source, convert it to source
$changes = array('contribution_source' => 'source');
foreach ($changes as $orgVal => $changeVal) {
if (isset($values[$orgVal])) {
$values[$changeVal] = $values[$orgVal];
unset($values[$orgVal]);
}
//.........这里部分代码省略.........