本文整理汇总了PHP中CRM_Utils_Rule::integer方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Rule::integer方法的具体用法?PHP CRM_Utils_Rule::integer怎么用?PHP CRM_Utils_Rule::integer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Utils_Rule
的用法示例。
在下文中一共展示了CRM_Utils_Rule::integer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param string $name
* Symbolic name for the check.
* @param string $message
* Printable message (short or long).
* @param string $title
* Printable message (short).
* @param string $level
* The severity of the message. Use PSR-3 log levels.
*
* @see Psr\Log\LogLevel
*/
public function __construct($name, $message, $title, $level = \Psr\Log\LogLevel::WARNING)
{
$this->name = $name;
$this->message = $message;
$this->title = $title;
// Handle non-integer severity levels.
if (!CRM_Utils_Rule::integer($level)) {
$level = CRM_Utils_Check::severityMap($level);
}
$this->level = $level;
}
示例2: civicrm_api3_relationship_delete
/**
* Delete a relationship.
*
* @param array $params
*
* @return array
* API Result Array
*/
function civicrm_api3_relationship_delete($params)
{
if (!CRM_Utils_Rule::integer($params['id'])) {
return civicrm_api3_create_error('Invalid value for relationship ID');
}
$relationBAO = new CRM_Contact_BAO_Relationship();
$relationBAO->id = $params['id'];
if (!$relationBAO->find(TRUE)) {
return civicrm_api3_create_error('Relationship id is not valid');
} else {
$relationBAO->del($params['id']);
return civicrm_api3_create_success('Deleted relationship successfully');
}
}
示例3: 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;
}
示例4: civicrm_api3_action_schedule_create
/**
* Create a new Action Schedule
*
* @param array $params
*
* @return array
*
* {@getfields action_schedule_create}
*/
function civicrm_api3_action_schedule_create($params)
{
if (empty($params['id'])) {
// an update does not require any mandatory parameters
civicrm_api3_verify_one_mandatory($params, NULL, array('title', 'mapping_id', 'entity_status', 'entity_value'));
}
$ids = array();
if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) {
return civicrm_api3_create_error('Invalid value for ID');
}
if (!array_key_exists('name', $params) && !array_key_exists('id', $params)) {
$params['name'] = CRM_Utils_String::munge($params['title']);
}
$actionSchedule = new CRM_Core_BAO_ActionSchedule();
$actionSchedule = CRM_Core_BAO_ActionSchedule::add($params, $ids);
$actSchedule = array();
_civicrm_api3_object_to_array($actionSchedule, $actSchedule[$actionSchedule->id]);
return civicrm_api3_create_success($actSchedule, $params, 'action_schedule', 'create', $actionSchedule);
}
示例5: civicrm_api3_relationship_type_create
/**
* Create relationship type.
*
* @param array $params
* Array per getfields metadata.
*
* @return array
*/
function civicrm_api3_relationship_type_create($params)
{
if (!isset($params['label_a_b'])) {
$params['label_a_b'] = $params['name_a_b'];
}
if (!isset($params['label_b_a'])) {
$params['label_b_a'] = $params['name_b_a'];
}
$ids = array();
if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) {
return civicrm_api3_create_error('Invalid value for relationship type ID');
} else {
$ids['relationshipType'] = CRM_Utils_Array::value('id', $params);
}
$relationType = CRM_Contact_BAO_RelationshipType::add($params, $ids);
$relType = array();
_civicrm_api3_object_to_array($relationType, $relType[$relationType->id]);
return civicrm_api3_create_success($relType, $params, 'RelationshipType', 'create', $relationType);
}
示例6: create
/**
* Create or update a Status Preference entry.
*
* @param array $params
*
* @return array
*/
public static function create($params)
{
$statusPreference = new CRM_Core_BAO_StatusPreference();
// Default severity level to ignore is 0 (DEBUG).
if (!isset($params['ignore_severity'])) {
$params['ignore_severity'] = 0;
}
// Severity can be either text ('critical') or an integer <= 7.
// It's a magic number, but based on PSR-3 standards.
if (!CRM_Utils_Rule::integer($params['ignore_severity'])) {
$params['ignore_severity'] = CRM_Utils_Check::severityMap($params['ignore_severity']);
}
if ($params['ignore_severity'] > 7) {
CRM_Core_Error::fatal(ts('You can not pass a severity level higher than 7.'));
}
// If severity is now blank, you have an invalid severity string.
if (is_null($params['ignore_severity'])) {
CRM_Core_Error::fatal(ts('Invalid string passed as severity level.'));
}
// Check if this StatusPreference already exists.
if (empty($params['id']) && CRM_Utils_Array::value('name', $params)) {
$statusPreference->domain_id = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID());
$statusPreference->name = $params['name'];
$statusPreference->find(TRUE);
}
$statusPreference->copyValues($params);
$edit = $statusPreference->id ? TRUE : FALSE;
if ($edit) {
CRM_Utils_Hook::pre('edit', 'StatusPreference', $statusPreference->id, $statusPreference);
} else {
CRM_Utils_Hook::pre('create', 'StatusPreference', NULL, $statusPreference);
}
$statusPreference->save();
if ($edit) {
CRM_Utils_Hook::post('edit', 'StatusPreference', $statusPreference->id, $statusPreference);
} else {
CRM_Utils_Hook::post('create', 'StatusPreference', NULL, $statusPreference);
}
return $statusPreference;
}
示例7: groupTypeValues
/**
* Get group type values of the profile.
*
* @param int $profileId
* @param string $groupType
*
* @return array
* group type values
*/
public static function groupTypeValues($profileId, $groupType = NULL)
{
$groupTypeValue = array();
$groupTypes = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileId, 'group_type');
$groupTypeParts = explode(CRM_Core_DAO::VALUE_SEPARATOR, $groupTypes);
if (empty($groupTypeParts[1])) {
return $groupTypeValue;
}
$participantExtends = array('ParticipantRole', 'ParticipantEventName', 'ParticipantEventType');
foreach (explode(',', $groupTypeParts[1]) as $groupTypeValues) {
$values = array();
$valueParts = explode(':', $groupTypeValues);
if ($groupType && ($valueParts[0] != "{$groupType}Type" || $groupType == 'Participant' && !in_array($valueParts[0], $participantExtends))) {
continue;
}
foreach ($valueParts as $val) {
if (CRM_Utils_Rule::integer($val)) {
$values[$val] = $val;
}
}
if (!empty($values)) {
$typeName = substr($valueParts[0], 0, -4);
if (in_array($valueParts[0], $participantExtends)) {
$typeName = $valueParts[0];
}
$groupTypeValue[$typeName] = $values;
}
}
return $groupTypeValue;
}
示例8: civicrm_location_delete
/**
* Deletes a contact location.
*
* @param object $contact A valid Contact object (passed by reference).
* @param string $location_id A valid location ID.
*
* @return null, if successful. CRM error object, if 'contact' or 'location_id' is invalid, permissions are insufficient, etc.
*
* @access public
*
*/
function civicrm_location_delete(&$contact)
{
_civicrm_initialize();
if (!is_array($contact)) {
return civicrm_create_error('Params need to be of type array!');
}
if (!isset($contact['contact_id'])) {
return civicrm_create_error(ts('$contact is not valid contact datatype'));
}
require_once 'CRM/Utils/Rule.php';
$locationTypeID = CRM_Utils_Array::value('location_type', $contact);
if (!$locationTypeID || !CRM_Utils_Rule::integer($locationTypeID)) {
return civicrm_create_error(ts('missing or invalid location'));
}
$result =& _civicrm_location_delete($contact);
return $result;
}
示例9: extractGroupTypes
static function extractGroupTypes($groupType)
{
$returnGroupTypes = array();
if (!$groupType) {
return $returnGroupTypes;
}
$groupTypeParts = explode(CRM_Core_DAO::VALUE_SEPARATOR, $groupType);
foreach (explode(',', $groupTypeParts[0]) as $type) {
$returnGroupTypes[$type] = $type;
}
if (CRM_Utils_Array::value(1, $groupTypeParts)) {
foreach (explode(',', $groupTypeParts[1]) as $typeValue) {
$groupTypeValues = $valueLabels = array();
$valueParts = explode(':', $typeValue);
$typeName = NULL;
switch ($valueParts[0]) {
case 'ContributionType':
$typeName = 'Contribution';
$valueLabels = CRM_Contribute_PseudoConstant::financialType();
break;
case 'ParticipantRole':
$typeName = 'Participant';
$valueLabels = CRM_Event_PseudoConstant::participantRole();
break;
case 'ParticipantEventName':
$typeName = 'Participant';
$valueLabels = CRM_Event_PseudoConstant::event();
break;
case 'ParticipantEventType':
$typeName = 'Participant';
$valueLabels = CRM_Event_PseudoConstant::eventType();
break;
case 'MembershipType':
$typeName = 'Membership';
$valueLabels = CRM_Member_PseudoConstant::membershipType();
break;
case 'ActivityType':
$typeName = 'Activity';
$valueLabels = CRM_Core_PseudoConstant::ActivityType(TRUE, TRUE, FALSE, 'label', TRUE);
break;
}
foreach ($valueParts as $val) {
if (CRM_Utils_Rule::integer($val)) {
$groupTypeValues[$val] = CRM_Utils_Array::value($val, $valueLabels);
}
}
if (!is_array($returnGroupTypes[$typeName])) {
$returnGroupTypes[$typeName] = array();
}
$returnGroupTypes[$typeName][$valueParts[0]] = $groupTypeValues;
}
}
return $returnGroupTypes;
}
示例10: import
/**
* Handle the values in import mode.
*
* @param int $onDuplicate
* The code for what action to take on duplicates.
* @param array $values
* The array of values belonging to this line.
*
* @return bool
* the result of this processing
*/
public function import($onDuplicate, &$values)
{
// first make sure this is a valid line
$response = $this->summary($values);
if ($response != CRM_Import_Parser::VALID) {
return $response;
}
$params =& $this->getActiveFieldParams();
$session = CRM_Core_Session::singleton();
$dateType = $session->get('dateTypes');
$formatted = array('version' => 3);
$customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $params));
// don't add to recent items, CRM-4399
$formatted['skipRecentView'] = TRUE;
foreach ($params as $key => $val) {
if ($val) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
if ($customFields[$customFieldID]['data_type'] == 'Date') {
CRM_Contact_Import_Parser_Contact::formatCustomDate($params, $formatted, $dateType, $key);
unset($params[$key]);
} elseif ($customFields[$customFieldID]['data_type'] == 'Boolean') {
$params[$key] = CRM_Utils_String::strtoboolstr($val);
}
}
if ($key == 'participant_register_date') {
CRM_Utils_Date::convertToDefaultDate($params, $dateType, 'participant_register_date');
$formatted['participant_register_date'] = CRM_Utils_Date::processDate($params['participant_register_date']);
}
}
}
if (!(!empty($params['participant_role_id']) || !empty($params['participant_role']))) {
if (!empty($params['event_id'])) {
$params['participant_role_id'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'default_role_id');
} else {
$eventTitle = $params['event_title'];
$qParams = array();
$dao = new CRM_Core_DAO();
$params['participant_role_id'] = $dao->singleValueQuery("SELECT default_role_id FROM civicrm_event WHERE title = '{$eventTitle}' ", $qParams);
}
}
//date-Format part ends
static $indieFields = NULL;
if ($indieFields == NULL) {
$indieFields = CRM_Event_BAO_Participant::import();
}
$formatValues = array();
foreach ($params as $key => $field) {
if ($field == NULL || $field === '') {
continue;
}
$formatValues[$key] = $field;
}
$formatError = _civicrm_api3_deprecated_participant_formatted_param($formatValues, $formatted, TRUE);
if ($formatError) {
array_unshift($values, $formatError['error_message']);
return CRM_Import_Parser::ERROR;
}
if (!CRM_Utils_Rule::integer($formatted['event_id'])) {
array_unshift($values, ts('Invalid value for Event ID'));
return CRM_Import_Parser::ERROR;
}
if ($onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE) {
$formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, NULL, 'Participant');
} else {
if ($formatValues['participant_id']) {
$dao = new CRM_Event_BAO_Participant();
$dao->id = $formatValues['participant_id'];
$formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, $formatValues['participant_id'], 'Participant');
if ($dao->find(TRUE)) {
$ids = array('participant' => $formatValues['participant_id'], 'userId' => $session->get('userID'));
$participantValues = array();
//@todo calling api functions directly is not supported
$newParticipant = _civicrm_api3_deprecated_participant_check_params($formatted, $participantValues, FALSE);
if ($newParticipant['error_message']) {
array_unshift($values, $newParticipant['error_message']);
return CRM_Import_Parser::ERROR;
}
$newParticipant = CRM_Event_BAO_Participant::create($formatted, $ids);
if (!empty($formatted['fee_level'])) {
$otherParams = array('fee_label' => $formatted['fee_level'], 'event_id' => $newParticipant->event_id);
CRM_Price_BAO_LineItem::syncLineItems($newParticipant->id, 'civicrm_participant', $newParticipant->fee_amount, $otherParams);
}
$this->_newParticipant[] = $newParticipant->id;
return CRM_Import_Parser::VALID;
} else {
array_unshift($values, 'Matching Participant record not found for Participant ID ' . $formatValues['participant_id'] . '. Row was skipped.');
return CRM_Import_Parser::ERROR;
}
}
//.........这里部分代码省略.........
示例11: formRule
/**
* global validation rules for the form
*
* @param array $fields posted values of the form
*
* @return array list of errors to be posted back to the form
* @static
* @access public
*/
static function formRule(&$fields, &$files, &$form)
{
$optionLabel = CRM_Utils_Type::escape($fields['label'], 'String');
$optionValue = CRM_Utils_Type::escape($fields['value'], 'String');
$fieldId = $form->_fid;
$optionGroupId = $form->_optionGroupID;
$temp = array();
if (empty($form->_id)) {
$query = "\nSELECT count(*) \n FROM civicrm_option_value\n WHERE option_group_id = %1\n AND label = %2";
$params = array(1 => array($optionGroupId, 'Integer'), 2 => array($optionLabel, 'String'));
if (CRM_Core_DAO::singleValueQuery($query, $params) > 0) {
$errors['label'] = ts('There is an entry with the same label.');
}
$query = "\nSELECT count(*) \n FROM civicrm_option_value\n WHERE option_group_id = %1\n AND value = %2";
$params = array(1 => array($optionGroupId, 'Integer'), 2 => array($optionValue, 'String'));
if (CRM_Core_DAO::singleValueQuery($query, $params) > 0) {
$errors['value'] = ts('There is an entry with the same value.');
}
} else {
//capture duplicate entries while updating Custom Options
$optionId = CRM_Utils_Type::escape($fields['optionId'], 'Integer');
//check label duplicates within a custom field
$query = "\nSELECT count(*) \n FROM civicrm_option_value\n WHERE option_group_id = %1\n AND id != %2\n AND label = %3";
$params = array(1 => array($optionGroupId, 'Integer'), 2 => array($optionId, 'Integer'), 3 => array($optionLabel, 'String'));
if (CRM_Core_DAO::singleValueQuery($query, $params) > 0) {
$errors['label'] = ts('There is an entry with the same label.');
}
//check value duplicates within a custom field
$query = "\nSELECT count(*) \n FROM civicrm_option_value\n WHERE option_group_id = %1\n AND id != %2\n AND value = %3";
$params = array(1 => array($optionGroupId, 'Integer'), 2 => array($optionId, 'Integer'), 3 => array($optionValue, 'String'));
if (CRM_Core_DAO::singleValueQuery($query, $params) > 0) {
$errors['value'] = ts('There is an entry with the same value.');
}
}
$query = "\nSELECT data_type \n FROM civicrm_custom_field\n WHERE id = %1";
$params = array(1 => array($fieldId, 'Integer'));
$dao =& CRM_Core_DAO::executeQuery($query, $params);
if ($dao->fetch()) {
switch ($dao->data_type) {
case 'Int':
if (!CRM_Utils_Rule::integer($fields["value"])) {
$errors['value'] = ts('Please enter a valid integer value.');
}
break;
case 'Float':
// case 'Money':
if (!CRM_Utils_Rule::numeric($fields["value"])) {
$errors['value'] = ts('Please enter a valid number value.');
}
break;
case 'Money':
if (!CRM_Utils_Rule::money($fields["value"])) {
$errors['value'] = ts('Please enter a valid value.');
}
break;
case 'Date':
if (!CRM_Utils_Rule::date($fields["value"])) {
$errors['value'] = ts('Please enter a valid date using YYYY-MM-DD format. Example: 2004-12-31.');
}
break;
case 'Boolean':
if (!CRM_Utils_Rule::integer($fields["value"]) && ($fields["value"] != '1' || $fields["value"] != '0')) {
$errors['value'] = ts('Please enter 1 or 0 as value.');
}
break;
case 'Country':
if (!empty($fields["value"])) {
$params = array(1 => array($fields['value'], 'String'));
$query = "SELECT count(*) FROM civicrm_country WHERE name = %1 OR iso_code = %1";
if (CRM_Core_DAO::singleValueQuery($query, $params) <= 0) {
$errors['value'] = ts('Invalid default value for country.');
}
}
break;
case 'StateProvince':
if (!empty($fields["value"])) {
$params = array(1 => array($fields['value'], 'String'));
$query = "\nSELECT count(*) \n FROM civicrm_state_province\n WHERE name = %1\n OR abbreviation = %1";
if (CRM_Core_DAO::singleValueQuery($query, $params) <= 0) {
$errors['value'] = ts('The invalid value for State/Province data type');
}
}
break;
}
}
return empty($errors) ? true : $errors;
}
示例12: _civicrm_api3_deprecated_activity_formatted_param
/**
* 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.
*
* @param array|bool $create Is the formatted Values array going to
* be used for CRM_Activity_BAO_Activity::create()
*
* @return array|CRM_Error
*/
function _civicrm_api3_deprecated_activity_formatted_param(&$params, &$values, $create = FALSE)
{
// copy all the activity fields as is
$fields = CRM_Activity_DAO_Activity::fields();
_civicrm_api3_store_values($fields, $params, $values);
require_once 'CRM/Core/OptionGroup.php';
$customFields = CRM_Core_BAO_CustomField::getFields('Activity');
foreach ($params as $key => $value) {
// ignore empty values or empty arrays etc
if (CRM_Utils_System::isNull($value)) {
continue;
}
//Handling Custom Data
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
$values[$key] = $value;
$type = $customFields[$customFieldID]['html_type'];
if ($type == 'CheckBox' || $type == 'Multi-Select') {
$mulValues = explode(',', $value);
$customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
$values[$key] = array();
foreach ($mulValues as $v1) {
foreach ($customOption as $customValueID => $customLabel) {
$customValue = $customLabel['value'];
if (strtolower(trim($customLabel['label'])) == strtolower(trim($v1)) || strtolower(trim($customValue)) == strtolower(trim($v1))) {
if ($type == 'CheckBox') {
$values[$key][$customValue] = 1;
} else {
$values[$key][] = $customValue;
}
}
}
}
} elseif ($type == 'Select' || $type == 'Radio') {
$customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
foreach ($customOption as $customFldID => $customValue) {
$val = CRM_Utils_Array::value('value', $customValue);
$label = CRM_Utils_Array::value('label', $customValue);
$label = strtolower($label);
$value = strtolower(trim($value));
if ($value == $label || $value == strtolower($val)) {
$values[$key] = $val;
}
}
}
}
if ($key == 'target_contact_id') {
if (!CRM_Utils_Rule::integer($value)) {
return civicrm_api3_create_error("contact_id not valid: {$value}");
}
$contactID = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_contact WHERE id = {$value}");
if (!$contactID) {
return civicrm_api3_create_error("Invalid Contact ID: There is no contact record with contact_id = {$value}.");
}
}
}
return NULL;
}
示例13: _civicrm_api3_get_options_from_params
/**
* Get sort, limit etc options from the params - supporting old & new formats.
*
* Get returnProperties for legacy
*
* @param array $params
* Params array as passed into civicrm_api.
* @param bool $queryObject
* Is this supporting a queryObject api (e.g contact) - if so we support more options.
* for legacy report & return a unique fields array
*
* @param string $entity
* @param string $action
*
* @throws API_Exception
* @return array
* options extracted from params
*/
function _civicrm_api3_get_options_from_params(&$params, $queryObject = FALSE, $entity = '', $action = '')
{
$lowercase_entity = _civicrm_api_get_entity_name_from_camel($entity);
$is_count = FALSE;
$sort = CRM_Utils_Array::value('sort', $params, 0);
$sort = CRM_Utils_Array::value('option.sort', $params, $sort);
$sort = CRM_Utils_Array::value('option_sort', $params, $sort);
$offset = CRM_Utils_Array::value('offset', $params, 0);
$offset = CRM_Utils_Array::value('option.offset', $params, $offset);
// dear PHP thought it would be a good idea to transform a.b into a_b in the get/post
$offset = CRM_Utils_Array::value('option_offset', $params, $offset);
$limit = CRM_Utils_Array::value('rowCount', $params, 25);
$limit = CRM_Utils_Array::value('option.limit', $params, $limit);
$limit = CRM_Utils_Array::value('option_limit', $params, $limit);
if (is_array(CRM_Utils_Array::value('options', $params))) {
// is count is set by generic getcount not user
$is_count = CRM_Utils_Array::value('is_count', $params['options']);
$offset = CRM_Utils_Array::value('offset', $params['options'], $offset);
$limit = CRM_Utils_Array::value('limit', $params['options'], $limit);
$sort = CRM_Utils_Array::value('sort', $params['options'], $sort);
}
$returnProperties = array();
// handle the format return =sort_name,display_name...
if (array_key_exists('return', $params)) {
if (is_array($params['return'])) {
$returnProperties = array_fill_keys($params['return'], 1);
} else {
$returnProperties = explode(',', str_replace(' ', '', $params['return']));
$returnProperties = array_fill_keys($returnProperties, 1);
}
}
if ($entity && $action == 'get') {
if (!empty($returnProperties['id'])) {
$returnProperties[$lowercase_entity . '_id'] = 1;
unset($returnProperties['id']);
}
switch (trim(strtolower($sort))) {
case 'id':
case 'id desc':
case 'id asc':
$sort = str_replace('id', $lowercase_entity . '_id', $sort);
}
}
$options = array('offset' => CRM_Utils_Rule::integer($offset) ? $offset : NULL, 'sort' => CRM_Utils_Rule::string($sort) ? $sort : NULL, 'limit' => CRM_Utils_Rule::integer($limit) ? $limit : NULL, 'is_count' => $is_count, 'return' => !empty($returnProperties) ? $returnProperties : array());
if ($options['sort'] && stristr($options['sort'], 'SELECT')) {
throw new API_Exception('invalid string in sort options');
}
if (!$queryObject) {
return $options;
}
//here comes the legacy support for $returnProperties, $inputParams e.g for contat_get
// if the queryobject is being used this should be used
$inputParams = array();
$legacyreturnProperties = array();
$otherVars = array('sort', 'offset', 'rowCount', 'options', 'return', 'version', 'prettyprint', 'check_permissions', 'sequential');
foreach ($params as $n => $v) {
if (substr($n, 0, 7) == 'return.') {
$legacyreturnProperties[substr($n, 7)] = $v;
} elseif ($n == 'id') {
$inputParams[$lowercase_entity . '_id'] = $v;
} elseif (in_array($n, $otherVars)) {
} else {
$inputParams[$n] = $v;
if ($v && !is_array($v) && stristr($v, 'SELECT')) {
throw new API_Exception('invalid string');
}
}
}
$options['return'] = array_merge($returnProperties, $legacyreturnProperties);
$options['input_params'] = $inputParams;
return $options;
}
示例14: sendMail
/**
* Process that send e-mails
*
* @param int $contactID
* @param $values
* @param int $participantId
* @param bool $isTest
* @param bool $returnMessageText
*
* @return void
*/
public static function sendMail($contactID, &$values, $participantId, $isTest = FALSE, $returnMessageText = FALSE)
{
$template = CRM_Core_Smarty::singleton();
$gIds = array('custom_pre_id' => $values['custom_pre_id'], 'custom_post_id' => $values['custom_post_id']);
//get the params submitted by participant.
$participantParams = CRM_Utils_Array::value($participantId, $values['params'], array());
if (!$returnMessageText) {
//send notification email if field values are set (CRM-1941)
foreach ($gIds as $key => $gIdValues) {
if ($gIdValues) {
if (!is_array($gIdValues)) {
$gIdValues = array($gIdValues);
}
foreach ($gIdValues as $gId) {
$email = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify');
if ($email) {
//get values of corresponding profile fields for notification
list($profileValues) = self::buildCustomDisplay($gId, NULL, $contactID, $template, $participantId, $isTest, TRUE, $participantParams);
list($profileValues) = $profileValues;
$val = array('id' => $gId, 'values' => $profileValues, 'email' => $email);
CRM_Core_BAO_UFGroup::commonSendMail($contactID, $val);
}
}
}
}
}
if ($values['event']['is_email_confirm'] || $returnMessageText) {
list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
//send email only when email is present
if (isset($email) || $returnMessageText) {
$preProfileID = CRM_Utils_Array::value('custom_pre_id', $values);
$postProfileID = CRM_Utils_Array::value('custom_post_id', $values);
if (!empty($values['params']['additionalParticipant'])) {
$preProfileID = CRM_Utils_Array::value('additional_custom_pre_id', $values, $preProfileID);
$postProfileID = CRM_Utils_Array::value('additional_custom_post_id', $values, $postProfileID);
}
self::buildCustomDisplay($preProfileID, 'customPre', $contactID, $template, $participantId, $isTest, NULL, $participantParams);
self::buildCustomDisplay($postProfileID, 'customPost', $contactID, $template, $participantId, $isTest, NULL, $participantParams);
$sessions = CRM_Event_Cart_BAO_Conference::get_participant_sessions($participantId);
$tplParams = array_merge($values, $participantParams, array('email' => $email, 'confirm_email_text' => CRM_Utils_Array::value('confirm_email_text', $values['event']), 'isShowLocation' => CRM_Utils_Array::value('is_show_location', $values['event']), 'contributeMode' => CRM_Utils_Array::value('contributeMode', $template->_tpl_vars), 'participantID' => $participantId, 'conference_sessions' => $sessions, 'credit_card_number' => CRM_Utils_System::mungeCreditCard(CRM_Utils_Array::value('credit_card_number', $participantParams)), 'credit_card_exp_date' => CRM_Utils_Date::mysqlToIso(CRM_Utils_Date::format(CRM_Utils_Array::value('credit_card_exp_date', $participantParams)))));
// CRM-13890 : NOTE wait list condition need to be given so that
// wait list message is shown properly in email i.e. WRT online event registration template
if (empty($tplParams['participant_status']) && empty($values['params']['isOnWaitlist'])) {
$statusId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $participantId, 'status_id', 'id', TRUE);
$tplParams['participant_status'] = CRM_Event_PseudoConstant::participantStatus($statusId, NULL, 'label');
} elseif (!empty($tplParams['participant_status']) && CRM_Utils_Rule::integer($tplParams['participant_status'])) {
$tplParams['participant_status'] = CRM_Event_PseudoConstant::participantStatus($tplParams['participant_status'], NULL, 'label');
}
$sendTemplateParams = array('groupName' => 'msg_tpl_workflow_event', 'valueName' => 'event_online_receipt', 'contactId' => $contactID, 'isTest' => $isTest, 'tplParams' => $tplParams, 'PDFFilename' => ts('confirmation') . '.pdf');
// address required during receipt processing (pdf and email receipt)
if ($displayAddress = CRM_Utils_Array::value('address', $values)) {
$sendTemplateParams['tplParams']['address'] = $displayAddress;
$sendTemplateParams['tplParams']['contributeMode'] = NULL;
}
// set lineItem details
if ($lineItem = CRM_Utils_Array::value('lineItem', $values)) {
// check if additional prticipant, if so filter only to relevant ones
// CRM-9902
if (!empty($values['params']['additionalParticipant'])) {
$ownLineItems = array();
foreach ($lineItem as $liKey => $liValue) {
$firstElement = array_pop($liValue);
if ($firstElement['entity_id'] == $participantId) {
$ownLineItems[0] = $lineItem[$liKey];
break;
}
}
if (!empty($ownLineItems)) {
$sendTemplateParams['tplParams']['lineItem'] = $ownLineItems;
}
} else {
$sendTemplateParams['tplParams']['lineItem'] = $lineItem;
}
}
if ($returnMessageText) {
list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
return array('subject' => $subject, 'body' => $message, 'to' => $displayName, 'html' => $html);
} else {
$sendTemplateParams['from'] = CRM_Utils_Array::value('confirm_from_name', $values['event']) . " <" . CRM_Utils_Array::value('confirm_from_email', $values['event']) . ">";
$sendTemplateParams['toName'] = $displayName;
$sendTemplateParams['toEmail'] = $email;
$sendTemplateParams['autoSubmitted'] = TRUE;
$sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_confirm', $values['event']);
$sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc_confirm', $values['event']);
// append invoice pdf to email
$template = CRM_Core_Smarty::singleton();
$taxAmt = $template->get_template_vars('totalTaxAmount');
$prefixValue = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
$invoicing = CRM_Utils_Array::value('invoicing', $prefixValue);
//.........这里部分代码省略.........
示例15: formatCustomField
//.........这里部分代码省略.........
$value = CRM_Utils_Array::implodePadded($value);
} else {
$value = '';
}
}
if (($customFields[$customFieldId]['html_type'] == 'Multi-Select' || $customFields[$customFieldId]['html_type'] == 'AdvMulti-Select' || $customFields[$customFieldId]['html_type'] == 'CheckBox') && $customFields[$customFieldId]['data_type'] == 'String' && !empty($customFields[$customFieldId]['text_length']) && !empty($value)) {
// lets make sure that value is less than the length, else we'll
// be losing some data, CRM-7481
if (strlen($value) >= $customFields[$customFieldId]['text_length']) {
// need to do a few things here
// 1. lets find a new length
$newLength = $customFields[$customFieldId]['text_length'];
$minLength = strlen($value);
while ($newLength < $minLength) {
$newLength = $newLength * 2;
}
// set the custom field meta data to have a length larger than value
// alter the custom value table column to match this length
CRM_Core_BAO_SchemaHandler::alterFieldLength($customFieldId, $tableName, $columnName, $newLength);
}
}
$date = NULL;
if ($customFields[$customFieldId]['data_type'] == 'Date') {
if (!CRM_Utils_System::isNull($value)) {
$format = $customFields[$customFieldId]['date_format'];
$date = CRM_Utils_Date::processDate($value, NULL, FALSE, 'YmdHis', $format);
}
$value = $date;
}
if ($customFields[$customFieldId]['data_type'] == 'Float' || $customFields[$customFieldId]['data_type'] == 'Money') {
if (!$value) {
$value = 0;
}
if ($customFields[$customFieldId]['data_type'] == 'Money') {
$value = CRM_Utils_Rule::cleanMoney($value);
}
}
if (($customFields[$customFieldId]['data_type'] == 'StateProvince' || $customFields[$customFieldId]['data_type'] == 'Country') && empty($value)) {
// CRM-3415
$value = 0;
}
$fileId = NULL;
if ($customFields[$customFieldId]['data_type'] == 'File') {
if (empty($value)) {
return;
}
$config = CRM_Core_Config::singleton();
$fName = $value['name'];
$mimeType = $value['type'];
// If we are already passing the file id as a value then retrieve and set the file data
if (CRM_Utils_Rule::integer($value)) {
$fileDAO = new CRM_Core_DAO_File();
$fileDAO->id = $value;
$fileDAO->find(TRUE);
if ($fileDAO->N) {
$fileID = $value;
$fName = $fileDAO->uri;
$mimeType = $fileDAO->mime_type;
}
}
$filename = pathinfo($fName, PATHINFO_BASENAME);
// rename this file to go into the secure directory only if
// user has uploaded new file not existing verfied on the basis of $fileID
if (empty($fileID) && !rename($fName, $config->customFileUploadDir . $filename)) {
CRM_Core_Error::statusBounce(ts('Could not move custom file to custom upload directory'));
}
if ($customValueId && empty($fileID)) {
$query = "\nSELECT {$columnName}\n FROM {$tableName}\n WHERE id = %1";
$params = array(1 => array($customValueId, 'Integer'));
$fileId = CRM_Core_DAO::singleValueQuery($query, $params);
}
$fileDAO = new CRM_Core_DAO_File();
if ($fileId) {
$fileDAO->id = $fileId;
}
$fileDAO->uri = $filename;
$fileDAO->mime_type = $mimeType;
$fileDAO->upload_date = date('Ymdhis');
$fileDAO->save();
$fileId = $fileDAO->id;
$value = $filename;
}
if (!is_array($customFormatted)) {
$customFormatted = array();
}
if (!array_key_exists($customFieldId, $customFormatted)) {
$customFormatted[$customFieldId] = array();
}
$index = -1;
if ($customValueId) {
$index = $customValueId;
}
if (!array_key_exists($index, $customFormatted[$customFieldId])) {
$customFormatted[$customFieldId][$index] = array();
}
$customFormatted[$customFieldId][$index] = array('id' => $customValueId > 0 ? $customValueId : NULL, 'value' => $value, 'type' => $customFields[$customFieldId]['data_type'], 'custom_field_id' => $customFieldId, 'custom_group_id' => $groupID, 'table_name' => $tableName, 'column_name' => $columnName, 'file_id' => $fileId, 'is_multiple' => $customFields[$customFieldId]['is_multiple']);
//we need to sort so that custom fields are created in the order of entry
krsort($customFormatted[$customFieldId]);
return $customFormatted;
}