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


PHP CRM_Utils_Rule::date方法代码示例

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


在下文中一共展示了CRM_Utils_Rule::date方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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_membership_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
 *
 * @param array  $create       Is the formatted Values array going to
 *                             be used for CRM_Member_BAO_Membership:create()
 *
 * @return array|error
 * @access public
 */
function _civicrm_membership_format_params(&$params, &$values, $create = false)
{
    require_once "CRM/Member/DAO/Membership.php";
    $fields =& CRM_Member_DAO_Membership::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 'membership_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['membership_contact_id'];
                unset($values['membership_contact_id']);
                break;
            case 'join_date':
            case 'membership_start_date':
            case 'membership_end_date':
                if (!CRM_Utils_Rule::date($value)) {
                    return civicrm_create_error("{$key} not a valid date: {$value}");
                }
                break;
            case 'membership_type_id':
                $id = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_MembershipType", $value, 'id', 'name');
                $values[$key] = $id;
                break;
            case 'status_id':
                $id = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_MembershipStatus", $value, 'id', 'name');
                $values[$key] = $id;
                break;
            default:
                break;
        }
    }
    _civicrm_custom_format_params($params, $values, 'Membership');
    if ($create) {
        // CRM_Member_BAO_Membership::create() handles membership_start_date,
        // membership_end_date and membership_source. So, if $values contains
        // membership_start_date, membership_end_date  or membership_source,
        // convert it to start_date, end_date or source
        $changes = array('membership_start_date' => 'start_date', 'membership_end_date' => 'end_date', 'membership_source' => 'source');
        foreach ($changes as $orgVal => $changeVal) {
            if (isset($values[$orgVal])) {
                $values[$changeVal] = $values[$orgVal];
                unset($values[$orgVal]);
            }
        }
    }
    return null;
}
开发者ID:bhirsch,项目名称:voipdev,代码行数:73,代码来源:MembershipContact.php

示例4: _civicrm_membership_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
 *
 * @param array  $create       Is the formatted Values array going to
 *                             be used for CRM_Member_BAO_Membership:create()
 *
 * @return array|error
 * @access public
 */
function _civicrm_membership_format_params(&$params, &$values, $create = FALSE)
{
    require_once "CRM/Member/DAO/Membership.php";
    require_once "CRM/Member/PseudoConstant.php";
    $fields = CRM_Member_DAO_Membership::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 'membership_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['membership_contact_id'];
                unset($values['membership_contact_id']);
                break;
            case 'join_date':
            case 'start_date':
            case 'end_date':
            case 'reminder_date':
            case 'membership_start_date':
            case 'membership_end_date':
                if (!CRM_Utils_Rule::date($value)) {
                    return civicrm_create_error("{$key} not a valid date: {$value}");
                }
                // make sure we format dates to mysql friendly format
                $values[$key] = CRM_Utils_Date::processDate($value, NULL, FALSE, 'Ymd');
                break;
            case 'membership_type_id':
                if (!CRM_Utils_Array::value($value, CRM_Member_PseudoConstant::membershipType())) {
                    return civicrm_create_error('Invalid Membership Type Id');
                }
                $values[$key] = $value;
                break;
            case 'membership_type':
                $membershipTypeId = CRM_Utils_Array::key(ucfirst($value), CRM_Member_PseudoConstant::membershipType());
                if ($membershipTypeId) {
                    if (CRM_Utils_Array::value('membership_type_id', $values) && $membershipTypeId != $values['membership_type_id']) {
                        return civicrm_create_error('Mismatched membership Type and Membership Type Id');
                    }
                } else {
                    return civicrm_create_error('Invalid Membership Type');
                }
                $values['membership_type_id'] = $membershipTypeId;
                break;
            case 'status_id':
                if (!CRM_Utils_Array::value($value, CRM_Member_PseudoConstant::membershipStatus())) {
                    return civicrm_create_error('Invalid Membership Status Id');
                }
                $values[$key] = $value;
                break;
            default:
                break;
        }
    }
    _civicrm_custom_format_params($params, $values, 'Membership');
    if ($create) {
        // CRM_Member_BAO_Membership::create() handles membership_start_date,
        // membership_end_date and membership_source. So, if $values contains
        // membership_start_date, membership_end_date  or membership_source,
        // convert it to start_date, end_date or source
        $changes = array('membership_start_date' => 'start_date', 'membership_end_date' => 'end_date', 'membership_source' => 'source');
        foreach ($changes as $orgVal => $changeVal) {
            if (isset($values[$orgVal])) {
                $values[$changeVal] = $values[$orgVal];
                unset($values[$orgVal]);
            }
        }
    }
    return NULL;
}
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:94,代码来源:MembershipContact.php

示例5: isErrorInCoreData

 /**
  * function to check if an error in Core( non-custom fields ) field
  *
  * @param String   $errorMessage   A string containing all the error-fields.
  *
  * @access public
  */
 function isErrorInCoreData($params, &$errorMessage)
 {
     require_once 'CRM/Core/OptionGroup.php';
     foreach ($params as $key => $value) {
         if ($value) {
             $session =& CRM_Core_Session::singleton();
             $dateType = $session->get("dateTypes");
             switch ($key) {
                 case 'birth_date':
                     if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         if (!CRM_Utils_Rule::date($params[$key])) {
                             self::addToErrorMsg(ts('Birth Date'), $errorMessage);
                         }
                     } else {
                         self::addToErrorMsg(ts('Birth-Date'), $errorMessage);
                     }
                     break;
                 case 'deceased_date':
                     if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         if (!CRM_Utils_Rule::date($params[$key])) {
                             self::addToErrorMsg(ts('Deceased Date'), $errorMessage);
                         }
                     } else {
                         self::addToErrorMsg(ts('Deceased Date'), $errorMessage);
                     }
                     break;
                 case 'is_deceased':
                     if (CRM_Utils_String::strtoboolstr($value) === false) {
                         self::addToErrorMsg(ts('Is Deceased'), $errorMessage);
                     }
                     break;
                 case 'gender':
                     if (!self::checkGender($value)) {
                         self::addToErrorMsg(ts('Gender'), $errorMessage);
                     }
                     break;
                 case 'preferred_communication_method':
                     $preffComm = array();
                     $preffComm = explode(',', $value);
                     foreach ($preffComm as $v) {
                         if (!self::in_value(trim($v), CRM_Core_PseudoConstant::pcm())) {
                             self::addToErrorMsg(ts('Preferred Communication Method'), $errorMessage);
                         }
                     }
                     break;
                 case 'preferred_mail_format':
                     if (!array_key_exists(strtolower($value), array_change_key_case(CRM_Core_SelectValues::pmf(), CASE_LOWER))) {
                         self::addToErrorMsg(ts('Preferred Mail Format'), $errorMessage);
                     }
                     break;
                 case 'individual_prefix':
                     if (!self::in_value($value, CRM_Core_PseudoConstant::individualPrefix())) {
                         self::addToErrorMsg(ts('Individual Prefix'), $errorMessage);
                     }
                     break;
                 case 'individual_suffix':
                     if (!self::in_value($value, CRM_Core_PseudoConstant::individualSuffix())) {
                         self::addToErrorMsg(ts('Individual Suffix'), $errorMessage);
                     }
                     break;
                 case 'state_province':
                     if (!empty($value)) {
                         foreach ($value as $stateValue) {
                             if ($stateValue['state_province']) {
                                 if (self::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvinceAbbreviation()) || self::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvince())) {
                                     continue;
                                 } else {
                                     self::addToErrorMsg(ts('State / Province'), $errorMessage);
                                 }
                             }
                         }
                     }
                     break;
                 case 'country':
                     if (!empty($value)) {
                         foreach ($value as $stateValue) {
                             if ($stateValue['country']) {
                                 CRM_Core_PseudoConstant::populate($countryNames, 'CRM_Core_DAO_Country', true, 'name', 'is_active');
                                 CRM_Core_PseudoConstant::populate($countryIsoCodes, 'CRM_Core_DAO_Country', true, 'iso_code');
                                 $config =& CRM_Core_Config::singleton();
                                 $limitCodes = $config->countryLimit();
                                 //If no country is selected in
                                 //localization then take all countries
                                 if (empty($limitCodes)) {
                                     $limitCodes = $countryIsoCodes;
                                 }
                                 if (self::in_value($stateValue['country'], $limitCodes) || self::in_value($stateValue['country'], CRM_Core_PseudoConstant::country())) {
                                     continue;
                                 } else {
                                     if (self::in_value($stateValue['country'], $countryIsoCodes) || self::in_value($stateValue['country'], $countryNames)) {
                                         self::addToErrorMsg(ts('Country input value is in table but not "available": "This Country is valid but is NOT in the list of Available Countries currently configured for your site. This can be viewed and modifed from Global Settings >> Localization." '), $errorMessage);
                                     } else {
                                         self::addToErrorMsg(ts('Country input value not in country table: "The Country value appears to be invalid. It does not match any value in CiviCRM table of countries."'), $errorMessage);
//.........这里部分代码省略.........
开发者ID:bhirsch,项目名称:voipdev,代码行数:101,代码来源:Contact.php

示例6: validate

 /**
  * @return bool
  */
 public function validate()
 {
     if (CRM_Utils_System::isNull($this->_value)) {
         return TRUE;
     }
     switch ($this->_name) {
         case 'contact_id':
             // note: we validate extistence of the contact in API, upon
             // insert (it would be too costlty to do a db call here)
             return CRM_Utils_Rule::integer($this->_value);
         case 'register_date':
             return CRM_Utils_Rule::date($this->_value);
             /* @codingStandardsIgnoreStart
                  case 'event_id':
                      static $events = null;
                      if (!$events) {
                          $events = CRM_Event_PseudoConstant::event();
                      }
                      if (in_array($this->_value, $events)) {
                          return true;
                      }
                      else {
                          return false;
                      }
                      break;
                @codingStandardsIgnoreEnd */
         /* @codingStandardsIgnoreStart
              case 'event_id':
                  static $events = null;
                  if (!$events) {
                      $events = CRM_Event_PseudoConstant::event();
                  }
                  if (in_array($this->_value, $events)) {
                      return true;
                  }
                  else {
                      return false;
                  }
                  break;
            @codingStandardsIgnoreEnd */
         default:
             break;
     }
     // check whether that's a valid custom field id
     // and if so, check the contents' validity
     if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($this->_name)) {
         static $customFields = NULL;
         if (!$customFields) {
             $customFields = CRM_Core_BAO_CustomField::getFields('Participant');
         }
         if (!array_key_exists($customFieldID, $customFields)) {
             return FALSE;
         }
         return CRM_Core_BAO_CustomValue::typecheck($customFields[$customFieldID]['data_type'], $this->_value);
     }
     return TRUE;
 }
开发者ID:nganivet,项目名称:civicrm-core,代码行数:60,代码来源:Field.php

示例7: _crm_validate_formatted_contribution

/**
 * Validate a formatted contribution parameter list.
 *
 * @param array $params  Structured parameter list (as in crm_format_params)
 *
 * @return bool|CRM_Core_Error
 * @access public
 */
function _crm_validate_formatted_contribution(&$params)
{
    static $domainID = null;
    if (!$domainID) {
        $config =& CRM_Core_Config::singleton();
        $domainID = $config->domainID();
    }
    foreach ($params as $key => $value) {
        switch ($key) {
            case 'contact_id':
                if (!CRM_Utils_Rule::integer($value)) {
                    return _crm_error("contact_id not valid: {$value}");
                }
                $dao =& new CRM_Core_DAO();
                $svq = $dao->singleValueQuery("SELECT id FROM civicrm_contact WHERE domain_id = {$domainID} AND id = {$value}");
                if (!$svq) {
                    return _crm_error("there's no contact with contact_id of {$value}");
                }
                break;
            case 'receive_date':
            case 'cancel_date':
            case 'receipt_date':
            case 'thankyou_date':
                if (!CRM_Utils_Rule::date($value)) {
                    return _crm_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 _crm_error("{$key} not a valid amount: {$value}");
                }
                break;
            case 'currency':
                if (!CRM_Utils_Rule::currencyCode($value)) {
                    return _crm_error("currency not a valid code: {$value}");
                }
                break;
            default:
                break;
        }
    }
    /* Validate custom data fields */
    if (is_array($params['custom'])) {
        foreach ($params['custom'] as $key => $custom) {
            if (is_array($custom)) {
                $valid = CRM_Core_BAO_CustomValue::typecheck($custom['type'], $custom['value']);
                if (!$valid) {
                    return _crm_error('Invalid value for custom field \'' . $custom['name'] . '\'');
                }
                if ($custom['type'] == 'Date') {
                    $params['custom'][$key]['value'] = str_replace('-', '', $params['custom'][$key]['value']);
                }
            }
        }
    }
    return true;
}
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:68,代码来源:utils.php

示例8: formRule

 /**
  * global validation rules for the form
  *
  * @param array  $fields   (referance) posted values of the form
  *
  * @return array    if errors then list of errors to be posted back to the form,
  *                  true otherwise
  * @static
  * @access public
  */
 static function formRule($fields, $files, $self)
 {
     $default = CRM_Utils_Array::value('default_value', $fields);
     $errors = array();
     //validate field label as well as name.
     $title = $fields['label'];
     $name = CRM_Utils_String::munge($title, '_', 64);
     $gId = $self->_gid;
     // CRM-7564
     $query = 'select count(*) from civicrm_custom_field where ( name like %1 OR label like %2 ) and id != %3 and custom_group_id = %4';
     $fldCnt = CRM_Core_DAO::singleValueQuery($query, array(1 => array($name, 'String'), 2 => array($title, 'String'), 3 => array((int) $self->_id, 'Integer'), 4 => array($gId, 'Integer')));
     if ($fldCnt) {
         $errors['label'] = ts('Custom field \'%1\' already exists in Database.', array(1 => $title));
     }
     //checks the given custom field name doesnot start with digit
     if (!empty($title)) {
         // gives the ascii value
         $asciiValue = ord($title[0]);
         if ($asciiValue >= 48 && $asciiValue <= 57) {
             $errors['label'] = ts("Field's Name should not start with digit");
         }
     }
     // ensure that the label is not 'id'
     if (strtolower($title) == 'id') {
         $errors['label'] = ts("You cannot use 'id' as a field label.");
     }
     if (!isset($fields['data_type'][0]) || !isset($fields['data_type'][1])) {
         $errors['_qf_default'] = ts('Please enter valid - Data and Input Field Type.');
     }
     $dataType = self::$_dataTypeKeys[$fields['data_type'][0]];
     if ($default || $dataType == 'ContactReference') {
         switch ($dataType) {
             case 'Int':
                 if (!CRM_Utils_Rule::integer($default)) {
                     $errors['default_value'] = ts('Please enter a valid integer as default value.');
                 }
                 break;
             case 'Float':
                 if (!CRM_Utils_Rule::numeric($default)) {
                     $errors['default_value'] = ts('Please enter a valid number as default value.');
                 }
                 break;
             case 'Money':
                 if (!CRM_Utils_Rule::money($default)) {
                     $errors['default_value'] = ts('Please enter a valid number value.');
                 }
                 break;
             case 'Link':
                 if (!CRM_Utils_Rule::url($default)) {
                     $errors['default_value'] = ts('Please enter a valid link.');
                 }
                 break;
             case 'Date':
                 if (!CRM_Utils_Rule::date($default)) {
                     $errors['default_value'] = ts('Please enter a valid date as default value using YYYY-MM-DD format. Example: 2004-12-31.');
                 }
                 break;
             case 'Boolean':
                 if ($default != '1' && $default != '0') {
                     $errors['default_value'] = ts('Please enter 1 (for Yes) or 0 (for No) if you want to set a default value.');
                 }
                 break;
             case 'Country':
                 if (!empty($default)) {
                     $query = "SELECT count(*) FROM civicrm_country WHERE name = %1 OR iso_code = %1";
                     $params = array(1 => array($fields['default_value'], 'String'));
                     if (CRM_Core_DAO::singleValueQuery($query, $params) <= 0) {
                         $errors['default_value'] = ts('Invalid default value for country.');
                     }
                 }
                 break;
             case 'StateProvince':
                 if (!empty($default)) {
                     $query = "\nSELECT count(*)\n  FROM civicrm_state_province\n WHERE name = %1\n    OR abbreviation = %1";
                     $params = array(1 => array($fields['default_value'], 'String'));
                     if (CRM_Core_DAO::singleValueQuery($query, $params) <= 0) {
                         $errors['default_value'] = ts('The invalid default value for State/Province data type');
                     }
                 }
                 break;
             case 'ContactReference':
                 if ($fields['filter_selected'] == 'Advance' && CRM_Utils_Array::value('filter', $fields)) {
                     if (strpos($fields['filter'], 'entity=') !== FALSE) {
                         $errors['filter'] = ts("Please do not include entity parameter (entity is always 'contact')");
                     } elseif (strpos($fields['filter'], 'action=') === FALSE) {
                         $errors['filter'] = ts("Please specify 'action' parameter, it should be 'lookup' or 'get'");
                     } elseif (strpos($fields['filter'], 'action=get') === FALSE && strpos($fields['filter'], 'action=lookup') === FALSE) {
                         $errors['filter'] = ts("Only 'get' and 'lookup' actions are supported.");
                     }
                 }
//.........这里部分代码省略.........
开发者ID:hguru,项目名称:224Civi,代码行数:101,代码来源:Field.php

示例9: summary

 /**
  * handle the values in summary mode
  *
  * @param array $values the array of values belonging to this line
  *
  * @return boolean      the result of this processing
  * @access public
  */
 function summary(&$values)
 {
     $erroneousField = null;
     $response = $this->setActiveFieldValues($values, $erroneousField);
     /*if ($response != CRM_Contribute_Import_Parser::VALID) {
           array_unshift($values, ts('Invalid field value: %1', array(1 => $this->_activeFields[$erroneousField]->_title)));
           return CRM_Contribute_Import_Parser::ERROR;
       }*/
     $errorRequired = false;
     if ($this->_totalAmountIndex < 0 or $this->_contributionTypeIndex < 0) {
         $errorRequired = true;
     } else {
         $errorRequired = !CRM_Utils_Array::value($this->_totalAmountIndex, $values) || !CRM_Utils_Array::value($this->_contributionTypeIndex, $values);
     }
     if ($errorRequired) {
         array_unshift($values, ts('Missing required fields'));
         return CRM_CONTRIBUTE_IMPORT_PARSER_ERROR;
     }
     $params =& $this->getActiveFieldParams();
     require_once 'CRM/Import/Parser/Contact.php';
     $errorMessage = null;
     //for date-Formats
     $session =& CRM_Core_Session::singleton();
     $dateType = $session->get("dateTypes");
     foreach ($params as $key => $val) {
         if ($val) {
             switch ($key) {
                 case 'receive_date':
                     CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
                     if (!CRM_Utils_Rule::date($params[$key])) {
                         //return _crm_error('Invalid value for field  : Receive Date');
                         CRM_Import_Parser_Contact::addToErrorMsg('Receive Date', $errorMessage);
                     }
                     break;
                 case 'cancel_date':
                     CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
                     if (!CRM_Utils_Rule::date($params[$key])) {
                         //return _crm_error('Invalid value for field  : Cancel Date');
                         CRM_Import_Parser_Contact::addToErrorMsg('Cancel Date', $errorMessage);
                     }
                     break;
                 case 'receipt_date':
                     CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
                     if (!CRM_Utils_Rule::date($params[$key])) {
                         //return _crm_error('Invalid value for field  : Activity Date');
                         CRM_Import_Parser_Contact::addToErrorMsg('Receipt date', $errorMessage);
                     }
                     break;
                 case 'thankyou_date':
                     CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
                     if (!CRM_Utils_Rule::date($params[$key])) {
                         //return _crm_error('Invalid value for field  : Thankyou Date');
                         CRM_Import_Parser_Contact::addToErrorMsg('Thankyou Date', $errorMessage);
                     }
                     break;
             }
         }
     }
     //date-Format part ends
     $params['contact_type'] = $this->_contactType;
     //checking error in custom data
     CRM_Import_Parser_Contact::isErrorInCustomData($params, $errorMessage);
     if ($errorMessage) {
         $tempMsg = "Invalid value for field(s) : {$errorMessage}";
         array_unshift($values, $tempMsg);
         $errorMessage = null;
         return CRM_IMPORT_PARSER_ERROR;
     }
     return CRM_CONTRIBUTE_IMPORT_PARSER_VALID;
 }
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:78,代码来源:Contribution.php

示例10: summary

 /**
  * handle the values in summary mode
  *
  * @param array $values the array of values belonging to this line
  *
  * @return boolean      the result of this processing
  * @access public
  */
 function summary(&$values)
 {
     $erroneousField = NULL;
     $response = $this->setActiveFieldValues($values, $erroneousField);
     $params =& $this->getActiveFieldParams();
     $errorMessage = NULL;
     //for date-Formats
     $session = CRM_Core_Session::singleton();
     $dateType = $session->get("dateTypes");
     foreach ($params as $key => $val) {
         if ($val) {
             switch ($key) {
                 case 'receive_date':
                     if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         if (!CRM_Utils_Rule::date($params[$key])) {
                             CRM_Import_Parser_Contact::addToErrorMsg('Receive Date', $errorMessage);
                         }
                     } else {
                         CRM_Import_Parser_Contact::addToErrorMsg('Receive Date', $errorMessage);
                     }
                     break;
                 case 'cancel_date':
                     if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         if (!CRM_Utils_Rule::date($params[$key])) {
                             CRM_Import_Parser_Contact::addToErrorMsg('Cancel Date', $errorMessage);
                         }
                     } else {
                         CRM_Import_Parser_Contact::addToErrorMsg('Cancel Date', $errorMessage);
                     }
                     break;
                 case 'receipt_date':
                     if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         if (!CRM_Utils_Rule::date($params[$key])) {
                             CRM_Import_Parser_Contact::addToErrorMsg('Receipt date', $errorMessage);
                         }
                     } else {
                         CRM_Import_Parser_Contact::addToErrorMsg('Receipt date', $errorMessage);
                     }
                     break;
                 case 'thankyou_date':
                     if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         if (!CRM_Utils_Rule::date($params[$key])) {
                             CRM_Import_Parser_Contact::addToErrorMsg('Thankyou Date', $errorMessage);
                         }
                     } else {
                         CRM_Import_Parser_Contact::addToErrorMsg('Thankyou Date', $errorMessage);
                     }
                     break;
             }
         }
     }
     //date-Format part ends
     $params['contact_type'] = 'Contribution';
     //checking error in custom data
     CRM_Import_Parser_Contact::isErrorInCustomData($params, $errorMessage);
     if ($errorMessage) {
         $tempMsg = "Invalid value for field(s) : {$errorMessage}";
         array_unshift($values, $tempMsg);
         $errorMessage = NULL;
         return CRM_Contribute_Import_Parser::ERROR;
     }
     return CRM_Contribute_Import_Parser::VALID;
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:71,代码来源:Contribution.php

示例11: _civicrm_pledgepayment_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_pledgepayment_format_params(&$params, &$values, $create = FALSE)
{
    // copy all the pledge fields as is
    require_once 'CRM/Pledge/BAO/PledgePayment.php';
    require_once 'CRM/Pledge/DAO/Pledge.php';
    $fields = CRM_Pledge_DAO_Pledge::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 'pledge_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['pledge_contact_id'];
                unset($values['pledge_contact_id']);
                break;
            case 'receive_date':
            case 'end_date':
            case 'pledge_create_date':
            case 'cancel_date':
            case 'receipt_date':
            case 'thankyou_date':
                if (!CRM_Utils_Rule::date($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 'pledge_type':
                $values['pledge_type_id'] = CRM_Utils_Array::key(ucfirst($value), CRM_Pledge_PseudoConstant::pledgeType());
                break;
            case 'payment_instrument':
                require_once 'CRM/Core/OptionGroup.php';
                $values['payment_instrument_id'] = CRM_Core_OptionGroup::getValue('payment_instrument', $value);
                break;
            default:
                break;
        }
    }
    if (array_key_exists('note', $params)) {
        $values['note'] = $params['note'];
    }
    if (array_key_exists('installment_amount', $params)) {
        $values['installment_amount'] = $params['installment_amount'];
    }
    // testing testing - how do I make it take a create_date? It needs $values['create_date'] set but doesn't seem to like it because $fields calls it $pledge_create_date
    //ditto scheduled date. I don't know why this is needs to be done because I don't fully understand the code above
    if (array_key_exists('pledge_create_date', $params)) {
        $values['create_date'] = $params['pledge_create_date'];
    }
    if (array_key_exists('pledge_scheduled_date', $params)) {
        $values['scheduled_date'] = $params['pledge_scheduled_date'];
    }
    if (array_key_exists('pledge_create_date', $params)) {
        $values['create_date'] = $params['pledge_create_date'];
    }
    if (array_key_exists('status_id', $params)) {
        $values['status_id'] = $params['status_id'];
        $values['pledge_status_id'] = $params['status_id'];
    }
    _civicrm_custom_format_params($params, $values, 'Pledge');
    if ($create) {
        // CRM_pledge_BAO_Pledge::add() handles Pledge_source
        // So, if $values contains Pledge_source, convert it to source
        $changes = array('pledge_source' => 'source');
        foreach ($changes as $orgVal => $changeVal) {
            if (isset($values[$orgVal])) {
//.........这里部分代码省略.........
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:101,代码来源:PledgePayment.php

示例12: isErrorInCoreData

 /**
  * function to check if an error in Core( non-custom fields ) field
  *
  * @param String   $errorMessage   A string containing all the error-fields.
  *
  * @access public
  */
 function isErrorInCoreData($params, &$errorMessage)
 {
     foreach ($params as $key => $value) {
         if ($value) {
             switch ($key) {
                 case 'birth_date':
                     if (!CRM_Utils_Rule::date($value)) {
                         //return _crm_error('Birth Date');
                         CRM_Import_Parser_Contact::addToErrorMsg('Birth Date', $errorMessage);
                     }
                     break;
                 case 'gender':
                     if (!CRM_Import_Parser_Contact::in_value($value, CRM_Core_PseudoConstant::gender(true))) {
                         //return _crm_error('Invalid value for field  : Gender');
                         CRM_Import_Parser_Contact::addToErrorMsg('Gender', $errorMessage);
                     }
                     break;
                 case 'preferred_communication_method':
                     if (!array_key_exists(strtolower($value), array_change_key_case(CRM_Core_SelectValues::pcm(), CASE_LOWER))) {
                         //return _crm_error('Invalid value for field  : Preferred Communication Method');
                         CRM_Import_Parser_Contact::addToErrorMsg('Preferred Communication Method', $errorMessage);
                     }
                     break;
                 case 'preferred_mail_format':
                     if (!array_key_exists(strtolower($value), array_change_key_case(CRM_Core_SelectValues::pmf(), CASE_LOWER))) {
                         //return _crm_error('Invalid value for field  : Preferred Communication Method');
                         CRM_Import_Parser_Contact::addToErrorMsg('Preferred Mail Format', $errorMessage);
                     }
                     break;
                 case 'individual_prefix':
                     if (!CRM_Import_Parser_Contact::in_value($value, CRM_Core_PseudoConstant::individualPrefix(true))) {
                         //return _crm_error('Invalid value for field  : Individual Prefix');
                         CRM_Import_Parser_Contact::addToErrorMsg('Individual Prefix', $errorMessage);
                     }
                     break;
                 case 'individual_suffix':
                     if (!CRM_Import_Parser_Contact::in_value($value, CRM_Core_PseudoConstant::individualSuffix(true))) {
                         //return _crm_error('Invalid value for field  : Individual Suffix');
                         CRM_Import_Parser_Contact::addToErrorMsg('Individual Suffix', $errorMessage);
                     }
                     break;
                 case 'state_province':
                     if (!empty($value)) {
                         foreach ($value as $stateValue) {
                             if ($stateValue['state_province']) {
                                 if (CRM_Import_Parser_Contact::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvinceAbbreviation()) || CRM_Import_Parser_Contact::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvince())) {
                                     continue;
                                 } else {
                                     //return _crm_error('Invalid value for field  : State Province ');
                                     CRM_Import_Parser_Contact::addToErrorMsg('State Province', $errorMessage);
                                 }
                             }
                         }
                     }
                     break;
                 case 'country':
                     if (!empty($value)) {
                         foreach ($value as $stateValue) {
                             if ($stateValue['country']) {
                                 if (CRM_Import_Parser_Contact::in_value($stateValue['country'], CRM_Core_PseudoConstant::countryIsoCode()) || CRM_Import_Parser_Contact::in_value($stateValue['country'], CRM_Core_PseudoConstant::country())) {
                                     continue;
                                 } else {
                                     //return _crm_error('Invalid value for field  : Country');
                                     CRM_Import_Parser_Contact::addToErrorMsg('Country', $errorMessage);
                                 }
                             }
                         }
                     }
                     break;
                 case 'geo_code_1':
                     if (!empty($value)) {
                         foreach ($value as $codeValue) {
                             if ($codeValue['geo_code_1']) {
                                 if (CRM_Utils_Rule::numeric($codeValue['geo_code_1'])) {
                                     continue;
                                 } else {
                                     //return _crm_error('Invalid value for field  : geo_code_1');
                                     CRM_Import_Parser_Contact::addToErrorMsg('geo_code_1', $errorMessage);
                                 }
                             }
                         }
                     }
                     break;
                 case 'geo_code_2':
                     if (!empty($value)) {
                         foreach ($value as $codeValue) {
                             if ($codeValue['geo_code_2']) {
                                 if (CRM_Utils_Rule::numeric($codeValue['geo_code_2'])) {
                                     continue;
                                 } else {
                                     //return _crm_error('Invalid value for field  : geo_code_2');
                                     CRM_Import_Parser_Contact::addToErrorMsg('geo_code_2', $errorMessage);
                                 }
//.........这里部分代码省略.........
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:101,代码来源:Contact.php

示例13: _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::date($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':
                $values['contribution_type_id'] = CRM_Utils_Array::key(ucfirst($value), CRM_Contribute_PseudoConstant::contributionType());
                break;
            case 'payment_instrument':
                require_once 'CRM/Core/OptionGroup.php';
                $values['payment_instrument_id'] = CRM_Core_OptionGroup::getValue('payment_instrument', $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]);
            }
        }
    }
    return array();
}
开发者ID:ksecor,项目名称:civicrm,代码行数:84,代码来源:Contribute.php

示例14: 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 boolean      the result of this processing
  * @access public
  */
 function import($onDuplicate, &$values)
 {
     // first make sure this is a valid line
     $response = $this->summary($values);
     if ($response != CRM_Member_Import_Parser::VALID) {
         return $response;
     }
     $params =& $this->getActiveFieldParams();
     //assign join date equal to start date if join date is not provided
     if (!$params['join_date'] && $params['membership_start_date']) {
         $params['join_date'] = $params['membership_start_date'];
     }
     $session =& CRM_Core_Session::singleton();
     $dateType = $session->get("dateTypes");
     $formatted = array();
     $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) {
             switch ($key) {
                 case 'join_date':
                     if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         if (!CRM_Utils_Rule::date($params[$key])) {
                             CRM_Import_Parser_Contact::addToErrorMsg('Join Date', $errorMessage);
                         }
                     } else {
                         CRM_Import_Parser_Contact::addToErrorMsg('Join Date', $errorMessage);
                     }
                     break;
                 case 'membership_start_date':
                     if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         if (!CRM_Utils_Rule::date($params[$key])) {
                             CRM_Import_Parser_Contact::addToErrorMsg('Start Date', $errorMessage);
                         }
                     } else {
                         CRM_Import_Parser_Contact::addToErrorMsg('Start Date', $errorMessage);
                     }
                     break;
                 case 'membership_end_date':
                     if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         if (!CRM_Utils_Rule::date($params[$key])) {
                             CRM_Import_Parser_Contact::addToErrorMsg('End Date', $errorMessage);
                         }
                     } else {
                         CRM_Import_Parser_Contact::addToErrorMsg('End Date', $errorMessage);
                     }
                     break;
                 case 'is_override':
                     $params[$key] = CRM_Utils_String::strtobool($val);
                     break;
             }
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
                 if ($customFields[$customFieldID][2] == 'Date') {
                     CRM_Import_Parser_Contact::formatCustomDate($params, $formatted, $dateType, $key);
                     unset($params[$key]);
                 } else {
                     if ($customFields[$customFieldID][2] == 'Boolean') {
                         $params[$key] = CRM_Utils_String::strtoboolstr($val);
                     }
                 }
             }
         }
     }
     //date-Format part ends
     static $indieFields = null;
     if ($indieFields == null) {
         require_once 'CRM/Member/DAO/Membership.php';
         $tempIndieFields =& CRM_Member_DAO_Membership::import();
         $indieFields = $tempIndieFields;
     }
     $formatValues = array();
     foreach ($params as $key => $field) {
         if ($field == null || $field === '') {
             continue;
         }
         $formatValues[$key] = $field;
     }
     $formatError = _civicrm_membership_formatted_param($formatValues, $formatted, true);
     if ($formatError) {
         array_unshift($values, $formatError['error_message']);
         return CRM_Member_Import_Parser::ERROR;
     }
     if ($onDuplicate != CRM_Member_Import_Parser::DUPLICATE_UPDATE) {
         $formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, CRM_Core_DAO::$_nullObject, null, 'Membership');
     } else {
         //fix for CRM-2219 Update Membership
         // onDuplicate == CRM_Member_Import_Parser::DUPLICATE_UPDATE
         if (CRM_Utils_Array::value('is_override', $formatted) && !CRM_Utils_Array::value('status_id', $formatted)) {
             array_unshift($values, "Required parameter missing: Status");
             return CRM_Member_Import_Parser::ERROR;
//.........这里部分代码省略.........
开发者ID:bhirsch,项目名称:voipdev,代码行数:101,代码来源:Membership.php

示例15: 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
  */
 function formRule(&$fields)
 {
     $optionLabel = CRM_Utils_Type::escape($fields['label'], 'String');
     $optionValue = CRM_Utils_Type::escape($fields['value'], 'String');
     if (empty($fields['optionId'])) {
         $fieldId = $fields['fieldId'];
         //check label duplicates within a custom field
         $query = "SELECT count(*) FROM civicrm_custom_option WHERE entity_id = '{$fieldId}' AND entity_table = 'civicrm_custom_field' AND label = '{$optionLabel}'";
         if (CRM_Core_DAO::singleValueQuery($query) > 0) {
             $errors['label'] = 'There is an entry with the same label.';
         }
         //check value duplicates within a custom field
         $query = "SELECT count(*) FROM civicrm_custom_option WHERE entity_id = '{$fieldId}' AND entity_table = 'civicrm_custom_field' AND value = '{$optionValue}'";
         if (CRM_Core_DAO::singleValueQuery($query) > 0) {
             $errors['value'] = 'There is an entry with the same value.';
         }
     } else {
         //capture duplicate entries while updating Custom Options
         $optionId = CRM_Utils_Type::escape($fields['optionId'], 'Integer');
         $fieldId = CRM_Utils_Type::escape($fields['fieldId'], 'Integer');
         //check label duplicates within a custom field
         $query = "SELECT count(*) FROM civicrm_custom_option WHERE entity_id = '{$fieldId}' AND entity_table = 'civicrm_custom_field' AND id != '{$optionId}' AND label = '{$optionLabel}'";
         if (CRM_Core_DAO::singleValueQuery($query) > 0) {
             $errors['label'] = 'There is an entry with same label.';
         }
         //check value duplicates within a custom field
         $query = "SELECT count(*) FROM civicrm_custom_option WHERE entity_id = '{$fieldId}' AND entity_table = 'civicrm_custom_field' AND id != '{$optionId}' AND value = '{$optionValue}'";
         if (CRM_Core_DAO::singleValueQuery($query) > 0) {
             $errors['value'] = 'There is an entry with same value';
         }
     }
     $query = "SELECT data_type FROM civicrm_custom_field WHERE id = '{$fieldId}'";
     $dao = new CRM_Core_DAO();
     $dao->query($query);
     $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 '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"])) {
                 $fieldCountry = addslashes($fields['value']);
                 $query = "SELECT count(*) FROM civicrm_country WHERE name = '{$fieldCountry}' OR iso_code = '{$fieldCountry}'";
                 if (CRM_Core_DAO::singleValueQuery($query) <= 0) {
                     $errors['value'] = ts('Invalid default value for country.');
                 }
             }
             break;
         case 'StateProvince':
             if (!empty($fields["value"])) {
                 $fieldStateProvince = addslashes($fields['value']);
                 $query = "SELECT count(*) FROM civicrm_state_province WHERE name = '{$fieldStateProvince}' OR abbreviation = '{$fieldStateProvince}'";
                 if (CRM_Core_DAO::singleValueQuery($query) <= 0) {
                     $errors['value'] = ts('The invalid value for State/Province data type');
                 }
             }
             break;
     }
     return empty($errors) ? true : $errors;
 }
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:87,代码来源:Option.php


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