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


PHP CRM_Utils_Rule::string方法代码示例

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


在下文中一共展示了CRM_Utils_Rule::string方法的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;
 }
开发者ID:rajeshrhino,项目名称:civicrm-core,代码行数:60,代码来源:CustomValue.php

示例2: 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 boolean True if the value is of the specified type
  * @access 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':
             return CRM_Utils_Rule::date($value);
         case 'Boolean':
             return CRM_Utils_Rule::boolean($value);
         case 'StateProvince':
             return array_key_exists(strtolower($value), array_change_key_case(array_flip(CRM_Core_PseudoConstant::stateProvinceAbbreviation()), CASE_LOWER)) || array_key_exists(strtolower($value), array_change_key_case(array_flip(CRM_Core_PseudoConstant::stateProvince()), CASE_LOWER));
         case 'Country':
             return array_key_exists(strtolower($value), array_change_key_case(array_flip(CRM_Core_PseudoConstant::countryIsoCode()), CASE_LOWER)) || array_key_exists(strtolower($value), array_change_key_case(array_flip(CRM_Core_PseudoConstant::country()), CASE_LOWER));
     }
     return false;
 }
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:33,代码来源:CustomValue.php

示例3: _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;
}
开发者ID:sugan2111,项目名称:Drupal_code,代码行数:90,代码来源:utils.php


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