当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Utils_Array::explodePadded方法代码示例

本文整理汇总了PHP中CRM_Utils_Array::explodePadded方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Array::explodePadded方法的具体用法?PHP CRM_Utils_Array::explodePadded怎么用?PHP CRM_Utils_Array::explodePadded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Utils_Array的用法示例。


在下文中一共展示了CRM_Utils_Array::explodePadded方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createQuery

 /**
  * Generate a query to locate recipients who match the given
  * schedule.
  *
  * @param \CRM_Core_DAO_ActionSchedule $schedule
  *   The schedule as configured by the administrator.
  * @param string $phase
  *   See, e.g., RecipientBuilder::PHASE_RELATION_FIRST.
  * @return \CRM_Utils_SQL_Select
  * @see RecipientBuilder
  * @throws \CRM_Core_Exception
  */
 public function createQuery($schedule, $phase, $defaultParams)
 {
     $selectedValues = (array) \CRM_Utils_Array::explodePadded($schedule->entity_value);
     $selectedStatuses = (array) \CRM_Utils_Array::explodePadded($schedule->entity_status);
     $query = \CRM_Utils_SQL_Select::from("{$this->entity} e")->param($defaultParams);
     $query['casAddlCheckFrom'] = 'civicrm_activity e';
     $query['casContactIdField'] = 'r.contact_id';
     $query['casEntityIdField'] = 'e.id';
     $query['casContactTableAlias'] = NULL;
     $query['casDateField'] = 'e.activity_date_time';
     if (!is_null($schedule->limit_to)) {
         $activityContacts = \CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
         if ($schedule->limit_to == 0 || !isset($activityContacts[$schedule->recipient])) {
             $recipientTypeId = \CRM_Utils_Array::key('Activity Targets', $activityContacts);
         } else {
             $recipientTypeId = $schedule->recipient;
         }
         $query->join('r', "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id = {$recipientTypeId}");
     }
     // build where clause
     if (!empty($selectedValues)) {
         $query->where("e.activity_type_id IN (#selectedValues)")->param('selectedValues', $selectedValues);
     } else {
         $query->where("e.activity_type_id IS NULL");
     }
     if (!empty($selectedStatuses)) {
         $query->where("e.status_id IN (#selectedStatuss)")->param('selectedStatuss', $selectedStatuses);
     }
     $query->where('e.is_current_revision = 1 AND e.is_deleted = 0');
     return $query;
 }
开发者ID:rameshrr99,项目名称:civicrm-core,代码行数:43,代码来源:ActionMapping.php

示例2: _civicrm_api3_participant_createlineitem

/**
 * Create a default participant line item.
 *
 * @todo this should be done in the BAO not the api
 *
 * @param array $params
 * @param $participant
 *
 * @throws \CiviCRM_API3_Exception
 */
function _civicrm_api3_participant_createlineitem(&$params, $participant)
{
    // it is possible that a fee level contains information about multiple
    // price field values.
    $priceFieldValueDetails = CRM_Utils_Array::explodePadded($params["fee_level"]);
    foreach ($priceFieldValueDetails as $detail) {
        if (preg_match('/- ([0-9]+)$/', $detail, $matches)) {
            // it is possible that a price field value is payd for multiple times.
            // (FIXME: if the price field value ends in minus followed by whitespace
            // and a number, things will go wrong.)
            $qty = $matches[1];
            preg_match('/^(.*) - [0-9]+$/', $detail, $matches);
            $label = $matches[1];
        } else {
            $label = $detail;
            $qty = 1;
        }
        $sql = "\n      SELECT      ps.id AS setID, pf.id AS priceFieldID, pfv.id AS priceFieldValueID, pfv.amount AS amount\n      FROM  civicrm_price_set_entity cpse\n      LEFT JOIN civicrm_price_set ps ON cpse.price_set_id = ps.id AND cpse.entity_id = %1 AND cpse.entity_table = 'civicrm_event'\n      LEFT JOIN   civicrm_price_field pf ON pf.`price_set_id` = ps.id\n      LEFT JOIN   civicrm_price_field_value pfv ON pfv.price_field_id = pf.id\n      where ps.id is not null and pfv.label = %2\n    ";
        $qParams = array(1 => array($params['event_id'], 'Integer'), 2 => array($label, 'String'));
        $dao = CRM_Core_DAO::executeQuery($sql, $qParams);
        if ($dao->fetch()) {
            $lineItemParams = array('price_field_id' => $dao->priceFieldID, 'price_field_value_id' => $dao->priceFieldValueID, 'entity_table' => 'civicrm_participant', 'entity_id' => $participant->id, 'label' => $label, 'qty' => $qty, 'participant_count' => 0, 'unit_price' => $dao->amount, 'line_total' => $qty * $dao->amount);
            civicrm_api3('line_item', 'create', $lineItemParams);
        }
    }
}
开发者ID:FundingWorks,项目名称:civicrm-core,代码行数:36,代码来源:Participant.php

示例3: createQuery

 /**
  * Generate a query to locate recipients who match the given
  * schedule.
  *
  * @param \CRM_Core_DAO_ActionSchedule $schedule
  *   The schedule as configured by the administrator.
  * @param string $phase
  *   See, e.g., RecipientBuilder::PHASE_RELATION_FIRST.
  * @param array $defaultParams
  *
  * @return \CRM_Utils_SQL_Select
  * @see RecipientBuilder
  */
 public function createQuery($schedule, $phase, $defaultParams)
 {
     $selectedValues = (array) \CRM_Utils_Array::explodePadded($schedule->entity_value);
     $selectedStatuses = (array) \CRM_Utils_Array::explodePadded($schedule->entity_status);
     $query = \CRM_Utils_SQL_Select::from("{$this->entity} e")->param($defaultParams);
     $query['casAddlCheckFrom'] = 'civicrm_membership e';
     $query['casContactIdField'] = 'e.contact_id';
     $query['casEntityIdField'] = 'e.id';
     $query['casContactTableAlias'] = NULL;
     $query['casDateField'] = str_replace('membership_', 'e.', $schedule->start_action_date);
     // FIXME: Numbers should be constants.
     if (in_array(2, $selectedStatuses)) {
         //auto-renew memberships
         $query->where("e.contribution_recur_id IS NOT NULL");
     } elseif (in_array(1, $selectedStatuses)) {
         $query->where("e.contribution_recur_id IS NULL");
     }
     if (!empty($selectedValues)) {
         $query->where("e.membership_type_id IN (@memberTypeValues)")->param('memberTypeValues', $selectedValues);
     } else {
         $query->where("e.membership_type_id IS NULL");
     }
     $query->where("( e.is_override IS NULL OR e.is_override = 0 )");
     $query->merge($this->prepareMembershipPermissionsFilter());
     $query->where("e.status_id IN (#memberStatus)")->param('memberStatus', \CRM_Member_PseudoConstant::membershipStatus(NULL, "(is_current_member = 1 OR name = 'Expired')", 'id'));
     // Why is this only for civicrm_membership?
     if ($schedule->start_action_date && $schedule->is_repeat == FALSE) {
         $query['casUseReferenceDate'] = TRUE;
     }
     return $query;
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:44,代码来源:ActionMapping.php

示例4: civicrm_api3_custom_group_create

/**
 * Use this API to create a new group.
 *
 * The 'extends' value accepts an array or a comma separated string.
 * e.g array(
 * 'Individual','Contact') or 'Individual,Contact'
 * See the CRM Data Model for custom_group property definitions
 * $params['class_name'] is a required field, class being extended.
 *
 * @param array $params
 *   Array per getfields metadata.
 *
 * @return array
 * @todo $params['extends'] is array format - is that std compatible
 */
function civicrm_api3_custom_group_create($params)
{
    if (isset($params['extends']) && is_string($params['extends'])) {
        $extends = explode(",", $params['extends']);
        unset($params['extends']);
        $params['extends'] = $extends;
    }
    if (!isset($params['extends'][0]) || !trim($params['extends'][0])) {
        return civicrm_api3_create_error("First item in params['extends'] must be a class name (e.g. 'Contact').");
    }
    if (isset($params['extends_entity_column_value']) && !is_array($params['extends_entity_column_value'])) {
        // BAO fails if this is a string, but API getFields says this must be a string, so we'll do a double backflip
        $params['extends_entity_column_value'] = CRM_Utils_Array::explodePadded($params['extends_entity_column_value']);
    }
    return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:31,代码来源:CustomGroup.php

示例5: civicrm_api3_custom_group_create

/**
* Use this API to create a new group.  The 'extends' value accepts an array or a comma separated string.
* e.g array(
  'Individual','Contact') or 'Individual,Contact'
* See the CRM Data Model for custom_group property definitions
* $params['class_name'] is a required field, class being extended.
*
* @param $params     array   Associative array of property name/value pairs to insert in group.
* {@getfields CustomGroup_create}
*
* @return   Newly create custom_group object
* @todo $params['extends'] is array format - is that std compatible
* @access public
*/
function civicrm_api3_custom_group_create($params)
{
    if (isset($params['extends']) && is_string($params['extends'])) {
        $extends = explode(",", $params['extends']);
        unset($params['extends']);
        $params['extends'] = $extends;
    }
    if (!isset($params['extends'][0]) || !trim($params['extends'][0])) {
        return civicrm_api3_create_error("First item in params['extends'] must be a class name (e.g. 'Contact').");
    }
    if (isset($params['extends_entity_column_value']) && !is_array($params['extends_entity_column_value'])) {
        // BAO fails if this is a string, but API getFields says this must be a string, so we'll do a double backflip
        $params['extends_entity_column_value'] = CRM_Utils_Array::explodePadded($params['extends_entity_column_value']);
    }
    $customGroup = CRM_Core_BAO_CustomGroup::create($params);
    _civicrm_api3_object_to_array($customGroup, $values[$customGroup->id]);
    return civicrm_api3_create_success($values, $params, 'custom_group', $customGroup);
}
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:32,代码来源:CustomGroup.php

示例6: createQuery

 /**
  * Generate a query to locate recipients who match the given
  * schedule.
  *
  * @param \CRM_Core_DAO_ActionSchedule $schedule
  *   The schedule as configured by the administrator.
  * @param string $phase
  *   See, e.g., RecipientBuilder::PHASE_RELATION_FIRST.
  * @param array $defaultParams
  *
  * @return \CRM_Utils_SQL_Select
  * @see RecipientBuilder
  */
 public function createQuery($schedule, $phase, $defaultParams)
 {
     $selectedValues = (array) \CRM_Utils_Array::explodePadded($schedule->entity_value);
     $selectedStatuses = (array) \CRM_Utils_Array::explodePadded($schedule->entity_status);
     $query = \CRM_Utils_SQL_Select::from("{$this->entity} e")->param($defaultParams);
     $query['casAddlCheckFrom'] = 'civicrm_event r';
     $query['casContactIdField'] = 'e.contact_id';
     $query['casEntityIdField'] = 'e.id';
     $query['casContactTableAlias'] = NULL;
     $query['casDateField'] = str_replace('event_', 'r.', $schedule->start_action_date);
     $query->join('r', 'INNER JOIN civicrm_event r ON e.event_id = r.id');
     if ($schedule->recipient_listing && $schedule->limit_to) {
         switch ($schedule->recipient) {
             case 'participant_role':
                 $query->where("e.role_id IN (#recipList)")->param('recipList', \CRM_Utils_Array::explodePadded($schedule->recipient_listing));
                 break;
             default:
                 break;
         }
     }
     // build where clause
     if (!empty($selectedValues)) {
         $valueField = $this->id == \CRM_Event_ActionMapping::EVENT_TYPE_MAPPING_ID ? 'event_type_id' : 'id';
         $query->where("r.{$valueField} IN (@selectedValues)")->param('selectedValues', $selectedValues);
     } else {
         $query->where($this->id == \CRM_Event_ActionMapping::EVENT_TYPE_MAPPING_ID ? "r.event_type_id IS NULL" : "r.id IS NULL");
     }
     $query->where('r.is_active = 1');
     $query->where('r.is_template = 0');
     // participant status criteria not to be implemented for additional recipients
     // ... why not?
     if (!empty($selectedStatuses)) {
         switch ($phase) {
             case RecipientBuilder::PHASE_RELATION_FIRST:
             case RecipientBuilder::PHASE_RELATION_REPEAT:
                 $query->where("e.status_id IN (#selectedStatuses)")->param('selectedStatuses', $selectedStatuses);
                 break;
         }
     }
     return $query;
 }
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:54,代码来源:ActionMapping.php

示例7: preProcessEntityRef

 /**
  * Convert IDs to values and format for display.
  *
  * @param HTML_QuickForm_element $field
  */
 public static function preProcessEntityRef($field)
 {
     $val = $field->getValue();
     // Temporarily convert string values to an array
     if (!is_array($val)) {
         // Try to auto-detect method of serialization
         $val = strpos($val, ',') ? explode(',', str_replace(', ', ',', $val)) : (array) CRM_Utils_Array::explodePadded($val);
     }
     if ($val) {
         $entity = $field->getAttribute('data-api-entity');
         // Get api params, ensure it is an array
         $params = $field->getAttribute('data-api-params');
         $params = $params ? json_decode($params, TRUE) : array();
         $result = civicrm_api3($entity, 'getlist', array('id' => $val) + $params);
         if ($field->isFrozen()) {
             // Prevent js from treating frozen entityRef as a "live" field
             $field->removeAttribute('class');
         }
         if (!empty($result['values'])) {
             $field->setAttribute('data-entity-value', json_encode($result['values']));
         }
         // CRM-15803 - Remove invalid values
         $val = array_intersect($val, CRM_Utils_Array::collect('id', $result['values']));
     }
     // Convert array values back to a string
     $field->setValue(implode(',', $val));
 }
开发者ID:kidaa30,项目名称:yes,代码行数:32,代码来源:Renderer.php

示例8: array

 /**
  * Store and return an array of all active custom fields.
  *
  * @param string $customDataType
  *   Type of Custom Data; empty is a synonym for "all contact data types".
  * @param bool $showAll
  *   If true returns all fields (includes disabled fields).
  * @param bool $inline
  *   If true returns all inline fields (includes disabled fields).
  * @param int $customDataSubType
  *   Custom Data sub type value.
  * @param int $customDataSubName
  *   Custom Data sub name value.
  * @param bool $onlyParent
  *   Return only top level custom data, for eg, only Participant and ignore subname and subtype.
  * @param bool $onlySubType
  *   Return only custom data for subtype.
  * @param bool $checkPermission
  *   If false, do not include permissioning clause.
  *
  * @return array
  *   an array of active custom fields.
  *
  */
 public static function &getFields($customDataType = 'Individual', $showAll = FALSE, $inline = FALSE, $customDataSubType = NULL, $customDataSubName = NULL, $onlyParent = FALSE, $onlySubType = FALSE, $checkPermission = TRUE)
 {
     if (empty($customDataType)) {
         $customDataType = array('Contact', 'Individual', 'Organization', 'Household');
     }
     if ($customDataType && !is_array($customDataType)) {
         if (in_array($customDataType, CRM_Contact_BAO_ContactType::subTypes())) {
             // This is the case when getFieldsForImport() requires fields
             // limited strictly to a subtype.
             $customDataSubType = $customDataType;
             $customDataType = CRM_Contact_BAO_ContactType::getBasicType($customDataType);
             $onlySubType = TRUE;
         }
         if (in_array($customDataType, array_keys(CRM_Core_SelectValues::customGroupExtends()))) {
             // this makes the method flexible to support retrieving fields
             // for multiple extends value.
             $customDataType = array($customDataType);
         }
     }
     $customDataSubType = CRM_Utils_Array::explodePadded($customDataSubType);
     if (is_array($customDataType)) {
         $cacheKey = implode('_', $customDataType);
     } else {
         $cacheKey = $customDataType;
     }
     $cacheKey .= !empty($customDataSubType) ? '_' . implode('_', $customDataSubType) : '_0';
     $cacheKey .= $customDataSubName ? "{$customDataSubName}_" : '_0';
     $cacheKey .= $showAll ? '_1' : '_0';
     $cacheKey .= $inline ? '_1_' : '_0_';
     $cacheKey .= $onlyParent ? '_1_' : '_0_';
     $cacheKey .= $onlySubType ? '_1_' : '_0_';
     $cacheKey .= $checkPermission ? '_1_' : '_0_';
     $cgTable = CRM_Core_DAO_CustomGroup::getTableName();
     // also get the permission stuff here
     if ($checkPermission) {
         $permissionClause = CRM_Core_Permission::customGroupClause(CRM_Core_Permission::VIEW, "{$cgTable}.");
     } else {
         $permissionClause = '(1)';
     }
     // lets md5 permission clause and take first 8 characters
     $cacheKey .= substr(md5($permissionClause), 0, 8);
     if (strlen($cacheKey) > 40) {
         $cacheKey = md5($cacheKey);
     }
     if (!self::$_importFields || CRM_Utils_Array::value($cacheKey, self::$_importFields) === NULL) {
         if (!self::$_importFields) {
             self::$_importFields = array();
         }
         // check if we can retrieve from database cache
         $fields = CRM_Core_BAO_Cache::getItem('contact fields', "custom importableFields {$cacheKey}");
         if ($fields === NULL) {
             $cfTable = self::getTableName();
             $extends = '';
             if (is_array($customDataType)) {
                 $value = NULL;
                 foreach ($customDataType as $dataType) {
                     if (in_array($dataType, array_keys(CRM_Core_SelectValues::customGroupExtends()))) {
                         if (in_array($dataType, array('Individual', 'Household', 'Organization'))) {
                             $val = "'" . CRM_Utils_Type::escape($dataType, 'String') . "', 'Contact' ";
                         } else {
                             $val = "'" . CRM_Utils_Type::escape($dataType, 'String') . "'";
                         }
                         $value = $value ? $value . ", {$val}" : $val;
                     }
                 }
                 if ($value) {
                     $extends = "AND   {$cgTable}.extends IN ( {$value} ) ";
                 }
             }
             if (!empty($customDataType) && empty($extends)) {
                 // $customDataType specified a filter, but there is no corresponding SQL ($extends)
                 self::$_importFields[$cacheKey] = array();
                 return self::$_importFields[$cacheKey];
             }
             if ($onlyParent) {
                 $extends .= " AND {$cgTable}.extends_entity_column_value IS NULL AND {$cgTable}.extends_entity_column_id IS NULL ";
//.........这里部分代码省略.........
开发者ID:Hack4Eugene,项目名称:Hack4Cause2016,代码行数:101,代码来源:CustomField.php

示例9: convertCiviModelToBackboneModel

 /**
  * FIXME: Move to somewhere more useful
  * FIXME: Do real mapping of "types"
  *
  * @param string $extends
  *   Entity type; note: "Individual" means "Individual|Contact"; "Household" means "Household|Contact".
  * @param string $title
  *   A string to use in section headers.
  * @param array $availableFields
  *   List of fields that are allowed in profiles, e.g. $availableFields['my_field']['field_type'].
  * @return array
  *   with keys 'sections' and 'schema'
  * @see js/model/crm.core.js
  * @see js/model/crm.mappedcore.js
  */
 public static function convertCiviModelToBackboneModel($extends, $title, $availableFields)
 {
     $locationFields = CRM_Core_BAO_UFGroup::getLocationFields();
     $result = array('schema' => array(), 'sections' => array());
     // build field list
     foreach ($availableFields as $fieldName => $field) {
         switch ($extends) {
             case 'Individual':
             case 'Organization':
             case 'Household':
                 if ($field['field_type'] != $extends && $field['field_type'] != 'Contact' && !in_array($field['field_type'], CRM_Contact_BAO_ContactType::subTypes($extends))) {
                     continue 2;
                 }
                 break;
             default:
                 if ($field['field_type'] != $extends) {
                     continue 2;
                 }
         }
         $result['schema'][$fieldName] = array('type' => 'Text', 'title' => $field['title'], 'civiFieldType' => $field['field_type']);
         if (in_array($fieldName, $locationFields)) {
             $result['schema'][$fieldName]['civiIsLocation'] = TRUE;
         }
         if ($fieldName == 'url') {
             $result['schema'][$fieldName]['civiIsWebsite'] = TRUE;
         }
         if (in_array($fieldName, array('phone', 'phone_and_ext'))) {
             // FIXME what about phone_ext?
             $result['schema'][$fieldName]['civiIsPhone'] = TRUE;
         }
     }
     // build section list
     $result['sections']['default'] = array('title' => $title, 'is_addable' => FALSE);
     $customGroup = CRM_Core_BAO_CustomGroup::getAllCustomGroupsByBaseEntity($extends);
     $customGroup->orderBy('weight');
     $customGroup->is_active = 1;
     $customGroup->find();
     while ($customGroup->fetch()) {
         $sectionName = 'cg_' . $customGroup->id;
         $section = array('title' => ts('%1: %2', array(1 => $title, 2 => $customGroup->title)), 'is_addable' => $customGroup->is_reserved ? FALSE : TRUE, 'custom_group_id' => $customGroup->id, 'extends_entity_column_id' => $customGroup->extends_entity_column_id, 'extends_entity_column_value' => CRM_Utils_Array::explodePadded($customGroup->extends_entity_column_value), 'is_reserved' => $customGroup->is_reserved ? TRUE : FALSE);
         $result['sections'][$sectionName] = $section;
     }
     // put fields in their sections
     $fields = CRM_Core_BAO_CustomField::getFields($extends);
     foreach ($fields as $fieldId => $field) {
         $sectionName = 'cg_' . $field['custom_group_id'];
         $fieldName = 'custom_' . $fieldId;
         if (isset($result['schema'][$fieldName])) {
             $result['schema'][$fieldName]['section'] = $sectionName;
             $result['schema'][$fieldName]['civiIsMultiple'] = (bool) CRM_Core_BAO_CustomField::isMultiRecordField($fieldId);
         }
     }
     return $result;
 }
开发者ID:JSProffitt,项目名称:civicrm-website-org,代码行数:69,代码来源:ProfileEditor.php

示例10: _civicrm_api3_api_match_pseudoconstant

/**
 * Validate & swap out any pseudoconstants / options.
 *
 * @param mixed $fieldValue
 * @param string $entity : api entity name
 * @param string $fieldName : field name used in api call (not necessarily the canonical name)
 * @param array $fieldInfo : getfields meta-data
 *
 * @throws \API_Exception
 */
function _civicrm_api3_api_match_pseudoconstant(&$fieldValue, $entity, $fieldName, $fieldInfo)
{
    $options = CRM_Utils_Array::value('options', $fieldInfo);
    if (!$options) {
        if (strtolower($entity) == 'profile' && !empty($fieldInfo['entity'])) {
            // We need to get the options from the entity the field relates to.
            $entity = $fieldInfo['entity'];
        }
        $options = civicrm_api($entity, 'getoptions', array('version' => 3, 'field' => $fieldInfo['name'], 'context' => 'validate'));
        $options = CRM_Utils_Array::value('values', $options, array());
    }
    // If passed a value-separated string, explode to an array, then re-implode after matching values.
    $implode = FALSE;
    if (is_string($fieldValue) && strpos($fieldValue, CRM_Core_DAO::VALUE_SEPARATOR) !== FALSE) {
        $fieldValue = CRM_Utils_Array::explodePadded($fieldValue);
        $implode = TRUE;
    }
    // If passed multiple options, validate each.
    if (is_array($fieldValue)) {
        foreach ($fieldValue as &$value) {
            if (!is_array($value)) {
                _civicrm_api3_api_match_pseudoconstant_value($value, $options, $fieldName);
            }
        }
        // TODO: unwrap the call to implodePadded from the conditional and do it always
        // need to verify that this is safe and doesn't break anything though.
        // Better yet would be to leave it as an array and ensure that every dao/bao can handle array input
        if ($implode) {
            CRM_Utils_Array::implodePadded($fieldValue);
        }
    } else {
        _civicrm_api3_api_match_pseudoconstant_value($fieldValue, $options, $fieldName);
    }
}
开发者ID:sugan2111,项目名称:Drupal_code,代码行数:44,代码来源:utils.php

示例11: escape

 /**
  * Verify that a variable is of a given type, and apply a bit of processing.
  *
  * @param mixed $data
  *   The value to be verified/escaped.
  * @param string $type
  *   The type to verify against.
  * @param bool $abort
  *   If TRUE, the operation will CRM_Core_Error::fatal() on invalid data.
  *
  * @return mixed
  *   The data, escaped if necessary.
  */
 public static function escape($data, $type, $abort = TRUE)
 {
     switch ($type) {
         case 'Integer':
         case 'Int':
             if (CRM_Utils_Rule::integer($data)) {
                 return (int) $data;
             }
             break;
         case 'Positive':
             if (CRM_Utils_Rule::positiveInteger($data)) {
                 return (int) $data;
             }
             break;
             // CRM-8925 for custom fields of this type
         // CRM-8925 for custom fields of this type
         case 'Country':
         case 'StateProvince':
             // Handle multivalued data in delimited or array format
             if (is_array($data) || strpos($data, CRM_Core_DAO::VALUE_SEPARATOR) !== FALSE) {
                 $valid = TRUE;
                 foreach (CRM_Utils_Array::explodePadded($data) as $item) {
                     if (!CRM_Utils_Rule::positiveInteger($item)) {
                         $valid = FALSE;
                     }
                 }
                 if ($valid) {
                     return $data;
                 }
             } elseif (CRM_Utils_Rule::positiveInteger($data)) {
                 return (int) $data;
             }
             break;
         case 'File':
             if (CRM_Utils_Rule::positiveInteger($data)) {
                 return (int) $data;
             }
             break;
         case 'Link':
             if (CRM_Utils_Rule::url($data = trim($data))) {
                 return $data;
             }
             break;
         case 'Boolean':
             if (CRM_Utils_Rule::boolean($data)) {
                 return $data;
             }
             break;
         case 'Float':
         case 'Money':
             if (CRM_Utils_Rule::numeric($data)) {
                 return $data;
             }
             break;
         case 'String':
         case 'Memo':
         case 'Text':
             return CRM_Core_DAO::escapeString($data);
         case 'Date':
         case 'Timestamp':
             // a null date or timestamp is valid
             if (strlen(trim($data)) == 0) {
                 return trim($data);
             }
             if ((preg_match('/^\\d{8}$/', $data) || preg_match('/^\\d{14}$/', $data)) && CRM_Utils_Rule::mysqlDate($data)) {
                 return $data;
             }
             break;
         case 'ContactReference':
             if (strlen(trim($data)) == 0) {
                 return trim($data);
             }
             if (CRM_Utils_Rule::validContact($data)) {
                 return (int) $data;
             }
             break;
         case 'MysqlColumnNameOrAlias':
             if (CRM_Utils_Rule::mysqlColumnNameOrAlias($data)) {
                 $data = str_replace('`', '', $data);
                 $parts = explode('.', $data);
                 $data = '`' . implode('`.`', $parts) . '`';
                 return $data;
             }
             break;
         case 'MysqlOrderByDirection':
             if (CRM_Utils_Rule::mysqlOrderByDirection($data)) {
                 return strtolower($data);
//.........这里部分代码省略.........
开发者ID:nielosz,项目名称:civicrm-core,代码行数:101,代码来源:Type.php

示例12: createQuery

 /**
  * Generate a query to locate contacts who match the given
  * schedule.
  *
  * @param \CRM_Core_DAO_ActionSchedule $schedule
  * @param string $phase
  *   See, e.g., RecipientBuilder::PHASE_RELATION_FIRST.
  * @param array $defaultParams
  *   Default parameters that should be included with query.
  * @return \CRM_Utils_SQL_Select
  * @see RecipientBuilder
  * @throws CRM_Core_Exception
  */
 public function createQuery($schedule, $phase, $defaultParams)
 {
     $selectedValues = (array) \CRM_Utils_Array::explodePadded($schedule->entity_value);
     $selectedStatuses = (array) \CRM_Utils_Array::explodePadded($schedule->entity_status);
     $query = \CRM_Utils_SQL_Select::from("civicrm_contribution e")->param($defaultParams);
     $query['casAddlCheckFrom'] = 'civicrm_contribution e';
     $query['casContactIdField'] = 'e.contact_id';
     $query['casEntityIdField'] = 'e.id';
     $query['casContactTableAlias'] = NULL;
     // $schedule->start_action_date is user-supplied data. validate.
     if (!array_key_exists($schedule->start_action_date, $this->getDateFields())) {
         throw new CRM_Core_Exception("Invalid date field");
     }
     $query['casDateField'] = $schedule->start_action_date;
     // build where clause
     if (!empty($selectedValues)) {
         $query->where("e.contribution_page_id IN (@selectedValues)")->param('selectedValues', $selectedValues);
     }
     if (!empty($selectedStatuses)) {
         $query->where("e.contribution_status_id IN (#selectedStatuses)")->param('selectedStatuses', $selectedStatuses);
     }
     return $query;
 }
开发者ID:FundingWorks,项目名称:civicrm-core,代码行数:36,代码来源:ByPage.php

示例13: formatDisplayValue

 /**
  * Lower-level logic for rendering a custom field value
  *
  * @param string|array $value
  * @param array $field
  * @param int|null $entityId
  *
  * @return string
  */
 private static function formatDisplayValue($value, $field, $entityId = NULL)
 {
     if (self::isSerialized($field) && !is_array($value)) {
         $value = CRM_Utils_Array::explodePadded($value);
     }
     // CRM-12989 fix
     if ($field['html_type'] == 'CheckBox') {
         CRM_Utils_Array::formatArrayKeys($value);
     }
     $display = is_array($value) ? implode(', ', $value) : (string) $value;
     switch ($field['html_type']) {
         case 'Select':
         case 'Autocomplete-Select':
         case 'Radio':
         case 'Select Country':
         case 'Select State/Province':
         case 'CheckBox':
         case 'AdvMulti-Select':
         case 'Multi-Select':
         case 'Multi-Select State/Province':
         case 'Multi-Select Country':
             if ($field['data_type'] == 'ContactReference' && $value) {
                 $display = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $value, 'display_name');
             } elseif (is_array($value)) {
                 $v = array();
                 foreach ($value as $key => $val) {
                     $v[] = CRM_Utils_Array::value($val, $field['options']);
                 }
                 $display = implode(', ', $v);
             } else {
                 $display = CRM_Utils_Array::value($value, $field['options'], '');
             }
             break;
         case 'Select Date':
             $customFormat = NULL;
             // FIXME: Are there any legitimate reasons why $value would be an array?
             // Or should we throw an exception here if it is?
             $value = is_array($value) ? CRM_Utils_Array::first($value) : $value;
             $actualPHPFormats = CRM_Core_SelectValues::datePluginToPHPFormats();
             $format = CRM_Utils_Array::value('date_format', $field);
             if ($format) {
                 if (array_key_exists($format, $actualPHPFormats)) {
                     $customTimeFormat = (array) $actualPHPFormats[$format];
                     switch (CRM_Utils_Array::value('time_format', $field)) {
                         case 1:
                             $customTimeFormat[] = 'g:iA';
                             break;
                         case 2:
                             $customTimeFormat[] = 'G:i';
                             break;
                         default:
                             // if time is not selected remove time from value
                             $value = substr($value, 0, 10);
                     }
                     $customFormat = implode(" ", $customTimeFormat);
                 }
             }
             $display = CRM_Utils_Date::processDate($value, NULL, FALSE, $customFormat);
             break;
         case 'File':
             // In the context of displaying a profile, show file/image
             if ($value) {
                 if ($entityId) {
                     $url = self::getFileURL($entityId, $field['id']);
                     if ($url) {
                         $display = $url['file_url'];
                     }
                 } else {
                     // In other contexts show a paperclip icon
                     if (CRM_Utils_Rule::integer($value)) {
                         $icons = CRM_Core_BAO_File::paperIconAttachment('*', $value);
                         $display = $icons[$value];
                     } else {
                         //CRM-18396, if filename is passed instead
                         $display = $value;
                     }
                 }
             }
             break;
         case 'TextArea':
             $display = nl2br($display);
             break;
         case 'Text':
             if ($field['data_type'] == 'Money' && isset($value)) {
                 //$value can also be an array(while using IN operator from search builder or api).
                 foreach ((array) $value as $val) {
                     $disp[] = CRM_Utils_Money::format($val);
                 }
                 $display = implode(', ', $disp);
             }
             break;
//.........这里部分代码省略.........
开发者ID:saurabhbatra96,项目名称:civicrm-core,代码行数:101,代码来源:CustomField.php

示例14: createQuery

 /**
  * Generate a query to locate contacts who match the given
  * schedule.
  *
  * @param \CRM_Core_DAO_ActionSchedule $schedule
  * @param string $phase
  *   See, e.g., RecipientBuilder::PHASE_RELATION_FIRST.
  * @param array $defaultParams
  *   Default parameters that should be included with query.
  * @return \CRM_Utils_SQL_Select
  * @see RecipientBuilder
  * @throws CRM_Core_Exception
  */
 public function createQuery($schedule, $phase, $defaultParams)
 {
     $selectedValues = (array) \CRM_Utils_Array::explodePadded($schedule->entity_value);
     $selectedStatuses = (array) \CRM_Utils_Array::explodePadded($schedule->entity_status);
     $query = \CRM_Utils_SQL_Select::from("civicrm_contribution e")->param($defaultParams);
     $query['casAddlCheckFrom'] = 'civicrm_contribution e';
     $query['casContactIdField'] = 'e.contact_id';
     $query['casEntityIdField'] = 'e.id';
     $query['casContactTableAlias'] = NULL;
     // $schedule->start_action_date is user-supplied data. validate.
     if (!array_key_exists($schedule->start_action_date, $this->getDateFields())) {
         throw new CRM_Core_Exception("Invalid date field");
     }
     $query['casDateField'] = $schedule->start_action_date;
     // build where clause
     if (!empty($selectedValues)) {
         $query->where("e.financial_type_id IN (@selectedValues)")->param('selectedValues', $selectedValues);
     }
     if (!empty($selectedStatuses)) {
         $query->where("e.contribution_status_id IN (#selectedStatuses)")->param('selectedStatuses', $selectedStatuses);
     }
     if ($schedule->recipient_listing && $schedule->limit_to) {
         switch ($schedule->recipient) {
             case 'soft_credit_type':
                 $query['casContactIdField'] = 'soft.contact_id';
                 $query->join('soft', 'INNER JOIN civicrm_contribution_soft soft ON soft.contribution_id = e.id')->where("soft.soft_credit_type_id IN (#recipList)")->param('recipList', \CRM_Utils_Array::explodePadded($schedule->recipient_listing));
                 break;
         }
     }
     return $query;
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:44,代码来源:ByType.php

示例15: escape

 /**
  * Verify that a variable is of a given type, and apply a bit of processing.
  *
  * @param mixed $data
  *   The value to be verified/escaped.
  * @param string $type
  *   The type to verify against.
  * @param bool $abort
  *   If TRUE, the operation will CRM_Core_Error::fatal() on invalid data.
  *
  * @return mixed
  *   The data, escaped if necessary.
  */
 public static function escape($data, $type, $abort = TRUE)
 {
     switch ($type) {
         case 'Integer':
         case 'Int':
             if (CRM_Utils_Rule::integer($data)) {
                 return (int) $data;
             }
             break;
         case 'Positive':
             if (CRM_Utils_Rule::positiveInteger($data)) {
                 return (int) $data;
             }
             break;
             // CRM-8925 for custom fields of this type
         // CRM-8925 for custom fields of this type
         case 'Country':
         case 'StateProvince':
             // Handle multivalued data in delimited or array format
             if (is_array($data) || strpos($data, CRM_Core_DAO::VALUE_SEPARATOR) !== FALSE) {
                 $valid = TRUE;
                 foreach (CRM_Utils_Array::explodePadded($data) as $item) {
                     if (!CRM_Utils_Rule::positiveInteger($item)) {
                         $valid = FALSE;
                     }
                 }
                 if ($valid) {
                     return $data;
                 }
             } elseif (CRM_Utils_Rule::positiveInteger($data)) {
                 return (int) $data;
             }
             break;
         case 'File':
             if (CRM_Utils_Rule::positiveInteger($data)) {
                 return (int) $data;
             }
             break;
         case 'Link':
             if (CRM_Utils_Rule::url($data = trim($data))) {
                 return $data;
             }
             break;
         case 'Boolean':
             if (CRM_Utils_Rule::boolean($data)) {
                 return $data;
             }
             break;
         case 'Float':
         case 'Money':
             if (CRM_Utils_Rule::numeric($data)) {
                 return $data;
             }
             break;
         case 'String':
         case 'Memo':
         case 'Text':
             return CRM_Core_DAO::escapeString($data);
         case 'Date':
         case 'Timestamp':
             // a null date or timestamp is valid
             if (strlen(trim($data)) == 0) {
                 return trim($data);
             }
             if ((preg_match('/^\\d{8}$/', $data) || preg_match('/^\\d{14}$/', $data)) && CRM_Utils_Rule::mysqlDate($data)) {
                 return $data;
             }
             break;
         case 'ContactReference':
             if (strlen(trim($data)) == 0) {
                 return trim($data);
             }
             if (CRM_Utils_Rule::validContact($data)) {
                 return (int) $data;
             }
             break;
         default:
             CRM_Core_Error::fatal($type . " is not a recognised (camel cased) data type.");
             break;
     }
     // @todo Use exceptions instead of CRM_Core_Error::fatal().
     if ($abort) {
         $data = htmlentities($data);
         CRM_Core_Error::fatal("{$data} is not of the type {$type}");
     }
     return NULL;
 }
开发者ID:scardinius,项目名称:civicrm-core,代码行数:100,代码来源:Type.php


注:本文中的CRM_Utils_Array::explodePadded方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。