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


PHP CRM_Utils_Rule::money方法代码示例

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


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

示例1: validate

 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);
             break;
         case 'receive_date':
         case 'cancel_date':
         case 'receipt_date':
         case 'thankyou_date':
             return CRM_Utils_Rule::date($this->_value);
             break;
         case 'non_deductible_amount':
         case 'total_amount':
         case 'fee_amount':
         case 'net_amount':
             return CRM_Utils_Rule::money($this->_value);
             break;
         case 'trxn_id':
             static $seenTrxnIds = array();
             if (in_array($this->_value, $seenTrxnIds)) {
                 return false;
             } elseif ($this->_value) {
                 $seenTrxnIds[] = $this->_value;
                 return true;
             } else {
                 $this->_value = null;
                 return true;
             }
             break;
         case 'currency':
             return CRM_Utils_Rule::currencyCode($this->_value);
             break;
         case 'contribution_type':
             static $contributionTypes = null;
             if (!$contributionTypes) {
                 $contributionTypes =& CRM_Contribute_PseudoConstant::contributionType();
             }
             if (in_array($this->_value, $contributionTypes)) {
                 return true;
             } else {
                 return false;
             }
             break;
         case 'payment_instrument':
             static $paymentInstruments = null;
             if (!$paymentInstruments) {
                 $paymentInstruments =& CRM_Contribute_PseudoConstant::paymentInstrument();
             }
             if (in_array($this->_value, $paymentInstruments)) {
                 return true;
             } else {
                 return false;
             }
             break;
         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('Contribution');
         }
         if (!array_key_exists($customFieldID, $customFields)) {
             return false;
         }
         return CRM_Core_BAO_CustomValue::typecheck($customFields[$customFieldID]['data_type'], $this->_value);
     }
     return true;
 }
开发者ID:bhirsch,项目名称:voipdev,代码行数:77,代码来源:Field.php

示例2: formRule

 /**
  * global validation rules for the form
  *
  * @param array $fields posted values of the form
  *
  * @return array list of errors to be posted back to the form
  * @static
  * @access public
  */
 static function formRule(&$fields, &$files, &$form)
 {
     $optionLabel = CRM_Utils_Type::escape($fields['label'], 'String');
     $optionValue = CRM_Utils_Type::escape($fields['value'], 'String');
     $fieldId = $form->_fid;
     $optionGroupId = $form->_optionGroupID;
     $temp = array();
     if (empty($form->_id)) {
         $query = "\nSELECT count(*) \n  FROM civicrm_option_value\n WHERE option_group_id = %1\n   AND label = %2";
         $params = array(1 => array($optionGroupId, 'Integer'), 2 => array($optionLabel, 'String'));
         if (CRM_Core_DAO::singleValueQuery($query, $params) > 0) {
             $errors['label'] = ts('There is an entry with the same label.');
         }
         $query = "\nSELECT count(*) \n  FROM civicrm_option_value\n WHERE option_group_id = %1\n   AND value = %2";
         $params = array(1 => array($optionGroupId, 'Integer'), 2 => array($optionValue, 'String'));
         if (CRM_Core_DAO::singleValueQuery($query, $params) > 0) {
             $errors['value'] = ts('There is an entry with the same value.');
         }
     } else {
         //capture duplicate entries while updating Custom Options
         $optionId = CRM_Utils_Type::escape($fields['optionId'], 'Integer');
         //check label duplicates within a custom field
         $query = "\nSELECT count(*) \n  FROM civicrm_option_value\n WHERE option_group_id = %1\n   AND id != %2\n   AND label = %3";
         $params = array(1 => array($optionGroupId, 'Integer'), 2 => array($optionId, 'Integer'), 3 => array($optionLabel, 'String'));
         if (CRM_Core_DAO::singleValueQuery($query, $params) > 0) {
             $errors['label'] = ts('There is an entry with the same label.');
         }
         //check value duplicates within a custom field
         $query = "\nSELECT count(*) \n  FROM civicrm_option_value\n WHERE option_group_id = %1\n   AND id != %2\n   AND value = %3";
         $params = array(1 => array($optionGroupId, 'Integer'), 2 => array($optionId, 'Integer'), 3 => array($optionValue, 'String'));
         if (CRM_Core_DAO::singleValueQuery($query, $params) > 0) {
             $errors['value'] = ts('There is an entry with the same value.');
         }
     }
     $query = "\nSELECT data_type \n  FROM civicrm_custom_field\n WHERE id = %1";
     $params = array(1 => array($fieldId, 'Integer'));
     $dao =& CRM_Core_DAO::executeQuery($query, $params);
     if ($dao->fetch()) {
         switch ($dao->data_type) {
             case 'Int':
                 if (!CRM_Utils_Rule::integer($fields["value"])) {
                     $errors['value'] = ts('Please enter a valid integer value.');
                 }
                 break;
             case 'Float':
                 //     case 'Money':
                 if (!CRM_Utils_Rule::numeric($fields["value"])) {
                     $errors['value'] = ts('Please enter a valid number value.');
                 }
                 break;
             case 'Money':
                 if (!CRM_Utils_Rule::money($fields["value"])) {
                     $errors['value'] = ts('Please enter a valid value.');
                 }
                 break;
             case 'Date':
                 if (!CRM_Utils_Rule::date($fields["value"])) {
                     $errors['value'] = ts('Please enter a valid date using YYYY-MM-DD format. Example: 2004-12-31.');
                 }
                 break;
             case 'Boolean':
                 if (!CRM_Utils_Rule::integer($fields["value"]) && ($fields["value"] != '1' || $fields["value"] != '0')) {
                     $errors['value'] = ts('Please enter 1 or 0 as value.');
                 }
                 break;
             case 'Country':
                 if (!empty($fields["value"])) {
                     $params = array(1 => array($fields['value'], 'String'));
                     $query = "SELECT count(*) FROM civicrm_country WHERE name = %1 OR iso_code = %1";
                     if (CRM_Core_DAO::singleValueQuery($query, $params) <= 0) {
                         $errors['value'] = ts('Invalid default value for country.');
                     }
                 }
                 break;
             case 'StateProvince':
                 if (!empty($fields["value"])) {
                     $params = array(1 => array($fields['value'], 'String'));
                     $query = "\nSELECT count(*) \n  FROM civicrm_state_province\n WHERE name = %1\n    OR abbreviation = %1";
                     if (CRM_Core_DAO::singleValueQuery($query, $params) <= 0) {
                         $errors['value'] = ts('The invalid value for State/Province data type');
                     }
                 }
                 break;
         }
     }
     return empty($errors) ? true : $errors;
 }
开发者ID:bhirsch,项目名称:voipdev,代码行数:96,代码来源:Option.php

示例3: 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

示例4: _civicrm_api3_deprecated_formatted_param


//.........这里部分代码省略.........
                    } elseif (!empty($params['trxn_id'])) {
                        $contactId->trxn_id = $params['trxn_id'];
                    } elseif (!empty($params['invoice_id'])) {
                        $contactId->invoice_id = $params['invoice_id'];
                    }
                    if ($contactId->find(TRUE)) {
                        $contactType->id = $contactId->contact_id;
                        if ($contactType->find(TRUE)) {
                            if ($params['contact_type'] != $contactType->contact_type) {
                                return civicrm_api3_create_error("Contact Type is wrong: {$contactType->contact_type}");
                            }
                        }
                    }
                } else {
                    if ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) {
                        return civicrm_api3_create_error("Empty Contribution and Invoice and Transaction ID. Row was skipped.");
                    } else {
                        return civicrm_api3_create_error("Empty Contact and External ID. Row was skipped.");
                    }
                }
                break;
            case 'receive_date':
            case 'cancel_date':
            case 'receipt_date':
            case 'thankyou_date':
                if (!CRM_Utils_Rule::dateTime($value)) {
                    return civicrm_api3_create_error("{$key} not a valid date: {$value}");
                }
                break;
            case 'non_deductible_amount':
            case 'total_amount':
            case 'fee_amount':
            case 'net_amount':
                if (!CRM_Utils_Rule::money($value)) {
                    return civicrm_api3_create_error("{$key} not a valid amount: {$value}");
                }
                break;
            case 'currency':
                if (!CRM_Utils_Rule::currencyCode($value)) {
                    return civicrm_api3_create_error("currency not a valid code: {$value}");
                }
                break;
            case 'financial_type':
                require_once 'CRM/Contribute/PseudoConstant.php';
                $contriTypes = CRM_Contribute_PseudoConstant::financialType();
                foreach ($contriTypes as $val => $type) {
                    if (strtolower($value) == strtolower($type)) {
                        $values['financial_type_id'] = $val;
                        break;
                    }
                }
                if (empty($values['financial_type_id'])) {
                    return civicrm_api3_create_error("Financial Type is not valid: {$value}");
                }
                break;
            case 'payment_instrument':
                require_once 'CRM/Core/OptionGroup.php';
                $values['payment_instrument_id'] = CRM_Core_OptionGroup::getValue('payment_instrument', $value);
                if (empty($values['payment_instrument_id'])) {
                    return civicrm_api3_create_error("Payment Instrument is not valid: {$value}");
                }
                break;
            case 'contribution_status_id':
                require_once 'CRM/Core/OptionGroup.php';
                if (!($values['contribution_status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', $value))) {
                    return civicrm_api3_create_error("Contribution Status is not valid: {$value}");
开发者ID:rameshrr99,项目名称:civicrm-core,代码行数:67,代码来源:DeprecatedUtils.php

示例5: _civicrm_api3_custom_field_validate_field

/**
 * Helper function to validate custom field value
 *
 * @params String $fieldName    Custom field name (eg: custom_8 )
 * @params Mixed  $value        Field value to be validate
 * @params Array  $fieldDetails Field Details
 * @params Array  $errors       Collect validation  errors
 *
 * @param $fieldName
 * @param $value
 * @param $fieldDetails
 * @param array $errors
 *
 * @return Array  Validation errors
 * @todo remove this function - not in use but need to review functionality before
 * removing as it might be useful in wrapper layer
 */
function _civicrm_api3_custom_field_validate_field($fieldName, $value, $fieldDetails, &$errors = array())
{
    return;
    //see comment block
    if (!$value) {
        return $errors;
    }
    $dataType = $fieldDetails['data_type'];
    $htmlType = $fieldDetails['html_type'];
    switch ($dataType) {
        case 'Int':
            if (!CRM_Utils_Rule::integer($value)) {
                $errors[$fieldName] = 'Invalid integer value for ' . $fieldName;
            }
            break;
        case 'Float':
            if (!CRM_Utils_Rule::numeric($value)) {
                $errors[$fieldName] = 'Invalid numeric value for ' . $fieldName;
            }
            break;
        case 'Money':
            if (!CRM_Utils_Rule::money($value)) {
                $errors[$fieldName] = 'Invalid numeric value for ' . $fieldName;
            }
            break;
        case 'Link':
            if (!CRM_Utils_Rule::url($value)) {
                $errors[$fieldName] = 'Invalid link for ' . $fieldName;
            }
            break;
        case 'Boolean':
            if ($value != '1' && $value != '0') {
                $errors[$fieldName] = 'Invalid boolean (use 1 or 0) value for ' . $fieldName;
            }
            break;
        case 'Country':
            if (empty($value)) {
                break;
            }
            if ($htmlType != 'Multi-Select Country' && is_array($value)) {
                $errors[$fieldName] = 'Invalid country for ' . $fieldName;
                break;
            }
            if (!is_array($value)) {
                $value = array($value);
            }
            $query = "SELECT count(*) FROM civicrm_country WHERE id IN (" . implode(',', $value) . ")";
            if (CRM_Core_DAO::singleValueQuery($query) < count($value)) {
                $errors[$fieldName] = 'Invalid country(s) for ' . $fieldName;
            }
            break;
        case 'StateProvince':
            if (empty($value)) {
                break;
            }
            if ($htmlType != 'Multi-Select State/Province' && is_array($value)) {
                $errors[$fieldName] = 'Invalid State/Province for ' . $fieldName;
                break;
            }
            if (!is_array($value)) {
                $value = array($value);
            }
            $query = "\nSELECT count(*)\n  FROM civicrm_state_province\n WHERE id IN ('" . implode("','", $value) . "')";
            if (CRM_Core_DAO::singleValueQuery($query) < count($value)) {
                $errors[$fieldName] = 'Invalid State/Province for ' . $fieldName;
            }
            break;
        case 'ContactReference':
            //FIX ME
            break;
    }
    if (in_array($htmlType, array('Select', 'Multi-Select', 'CheckBox', 'Radio', 'AdvMulti-Select')) && !isset($errors[$fieldName])) {
        $options = CRM_Core_OptionGroup::valuesByID($fieldDetails['option_group_id']);
        if (!is_array($value)) {
            $value = array($value);
        }
        $invalidOptions = array_diff($value, array_keys($options));
        if (!empty($invalidOptions)) {
            $errors[$fieldName] = "Invalid option(s) for field '{$fieldName}': " . implode(',', $invalidOptions);
        }
    }
    return $errors;
}
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:100,代码来源:CustomField.php

示例6: _civicrm_api3_validate_fields

/**
 * Validate fields being passed into API.
 *
 * This function relies on the getFields function working accurately
 * for the given API. If error mode is set to TRUE then it will also check
 * foreign keys
 *
 * As of writing only date was implemented.
 *
 * @param string $entity
 * @param string $action
 * @param array $params
 *   -.
 * @param array $fields
 *   Response from getfields all variables are the same as per civicrm_api.
 * @param bool $errorMode
 *   ErrorMode do intensive post fail checks?.
 *
 * @throws Exception
 */
function _civicrm_api3_validate_fields($entity, $action, &$params, $fields, $errorMode = FALSE)
{
    //CRM-15792 handle datetime for custom fields below code handles chain api call
    $chainApikeys = array_flip(preg_grep("/^api./", array_keys($params)));
    if (!empty($chainApikeys) && is_array($chainApikeys)) {
        foreach ($chainApikeys as $key => $value) {
            if (is_array($params[$key])) {
                $chainApiParams = array_intersect_key($fields, $params[$key]);
                $customFields = array_fill_keys(array_keys($params[$key]), $key);
            }
        }
    }
    $fields = array_intersect_key($fields, $params);
    if (!empty($chainApiParams)) {
        $fields = array_merge($fields, $chainApiParams);
    }
    foreach ($fields as $fieldName => $fieldInfo) {
        switch (CRM_Utils_Array::value('type', $fieldInfo)) {
            case CRM_Utils_Type::T_INT:
                //field is of type integer
                _civicrm_api3_validate_integer($params, $fieldName, $fieldInfo, $entity);
                break;
            case CRM_Utils_Type::T_DATE:
            case CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME:
            case CRM_Utils_Type::T_TIMESTAMP:
                //field is of type date or datetime
                if (!empty($customFields) && array_key_exists($fieldName, $customFields)) {
                    $dateParams =& $params[$customFields[$fieldName]];
                } else {
                    $dateParams =& $params;
                }
                _civicrm_api3_validate_date($dateParams, $fieldName, $fieldInfo);
                break;
            case 32:
                //blob
                _civicrm_api3_validate_html($params, $fieldName, $fieldInfo);
                break;
            case CRM_Utils_Type::T_STRING:
                _civicrm_api3_validate_string($params, $fieldName, $fieldInfo, $entity);
                break;
            case CRM_Utils_Type::T_MONEY:
                list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName);
                if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) {
                    break;
                }
                foreach ((array) $fieldValue as $fieldvalue) {
                    if (!CRM_Utils_Rule::money($fieldvalue) && !empty($fieldvalue)) {
                        throw new Exception($fieldName . " is  not a valid amount: " . $params[$fieldName]);
                    }
                }
                break;
        }
        // intensive checks - usually only called after DB level fail
        if (!empty($errorMode) && strtolower($action) == 'create') {
            if (!empty($fieldInfo['FKClassName'])) {
                if (!empty($fieldValue)) {
                    _civicrm_api3_validate_constraint($params, $fieldName, $fieldInfo);
                } elseif (!empty($fieldInfo['required'])) {
                    throw new Exception("DB Constraint Violation - possibly {$fieldName} should possibly be marked as mandatory for this API. If so, please raise a bug report");
                }
            }
            if (!empty($fieldInfo['api.unique'])) {
                $params['entity'] = $entity;
                _civicrm_api3_validate_unique_key($params, $fieldName);
            }
        }
    }
}
开发者ID:sugan2111,项目名称:Drupal_code,代码行数:88,代码来源:utils.php

示例7: _crm_format_contrib_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 _crm_format_contrib_params(&$params, &$values, $create = false)
{
    // copy all the contribution fields as is
    $fields =& CRM_Contribute_DAO_Contribution::fields();
    _crm_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 _crm_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 _crm_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 _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;
            case 'contribution_type':
                require_once 'CRM/Contribute/PseudoConstant.php';
                $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;
            case 'contribution_status_id':
                require_once 'CRM/Core/OptionGroup.php';
                $values['contribution_status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', $value);
                break;
            default:
                break;
        }
    }
    if (array_key_exists('note', $params)) {
        $values['note'] = $params['note'];
    }
    _crm_format_custom_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 null;
}
开发者ID:ksecor,项目名称:civicrm,代码行数:89,代码来源:utils.php

示例8: _civicrm_pledge_format_params


//.........这里部分代码省略.........
    if (array_key_exists('pledge_original_installment_amount', $params)) {
        $values['installment_amount'] = $params['pledge_original_installment_amount'];
    }
    if (array_key_exists('status_id', $params)) {
        $values['pledge_status_id'] = $params['status_id'];
    }
    if ($params['contact_id']) {
        //this is validity checked further down to make sure the contact exists
        $values['pledge_contact_id'] = $params['contact_id'];
    }
    if (array_key_exists('id', $params)) {
        //retrieve the id key dropped from params. Note we can't use pledge_id because it
        //causes an error in CRM_Pledge_BAO_PledgePayment - approx line 302
        $values['id'] = $params['id'];
    }
    if (array_key_exists('pledge_id', $params)) {
        //retrieve the id key dropped from params. Note we can't use pledge_id because it
        //causes an error in CRM_Pledge_BAO_PledgePayment - approx line 302
        $values['id'] = $params['pledge_id'];
        unset($values['pledge_id']);
    }
    if (array_key_exists('status_id', $params)) {
        $values['pledge_status_id'] = $params['status_id'];
    }
    if (empty($values['id'])) {
        //at this point both should be the same so unset both if not set - passing in empty
        //value causes crash rather creating new - do it before next section as null values ignored in 'switch'
        unset($values['id']);
    }
    if (!empty($params['scheduled_date'])) {
        //scheduled date is required to set next payment date - defaults to start date
        $values['scheduled_date'] = $params['scheduled_date'];
    } elseif (array_key_exists('start_date', $params)) {
        $values['scheduled_date'] = $params['start_date'];
    }
    if (CRM_Utils_Array::value('contribution_type_id', $params)) {
        $values['contribution_type_id'] = $params['contribution_type_id'];
    }
    foreach ($values 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 'pledge_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_pledge WHERE id = {$value}", $qParams);
                if (!$svq) {
                    return civicrm_create_error("Invalid Contact ID: There is no contact record with contact_id = {$value}.");
                }
                break;
            case 'create_date':
            case 'scheduled_date':
            case 'start_date':
                if (!CRM_Utils_Rule::datetime($value)) {
                    return civicrm_create_error("{$key} not a valid date: {$value}");
                }
                break;
            case 'installment_amount':
            case 'amount':
                if (!CRM_Utils_Rule::money($value)) {
                    return civicrm_create_error("{$key} not a valid amount: {$value}");
                }
                break;
            case 'currency':
                if (!CRM_Utils_Rule::currencyCode($value)) {
                    return civicrm_create_error("currency not a valid code: {$value}");
                }
                break;
            case 'contribution_type_id':
                require_once 'CRM/Contribute/PseudoConstant.php';
                $typeId = CRM_Contribute_PseudoConstant::contributionType($value);
                if (!CRM_Utils_Rule::integer($value) || !$typeId) {
                    return civicrm_create_error("contribution type id is not valid: {$value}");
                }
            default:
                break;
        }
    }
    //format the parameters
    _civicrm_custom_format_params($params, $values, 'Pledge');
    return array();
}
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:101,代码来源:Pledge.php

示例9: _civicrm_api3_validate_fields

function _civicrm_api3_validate_fields($entity, $action, &$params, $errorMode = NULL)
{
    //skip any entities without working getfields functions
    $skippedEntities = array('entity', 'mailinggroup', 'customvalue', 'custom_value', 'mailing_group');
    if (in_array(strtolower($entity), $skippedEntities) || strtolower($action) == 'getfields') {
        return;
    }
    $fields = civicrm_api($entity, 'getfields', array('version' => 3, 'action' => $action));
    $fields = array_intersect_key($fields['values'], $params);
    foreach ($fields as $fieldname => $fieldInfo) {
        switch (CRM_Utils_Array::value('type', $fieldInfo)) {
            case CRM_Utils_Type::T_INT:
                //field is of type integer
                _civicrm_api3_validate_integer($params, $fieldname, $fieldInfo);
                break;
            case 4:
            case 12:
                //field is of type date or datetime
                _civicrm_api3_validate_date($params, $fieldname, $fieldInfo);
                break;
            case 32:
                //blob
                _civicrm_api3_validate_html($params, $fieldname, $fieldInfo);
                break;
            case CRM_Utils_Type::T_STRING:
                _civicrm_api3_validate_string($params, $fieldname, $fieldInfo);
                break;
            case CRM_Utils_Type::T_MONEY:
                if (!CRM_Utils_Rule::money($params[$fieldname])) {
                    throw new Exception($fieldname . " is  not a valid amount: " . $params[$fieldname]);
                }
        }
        // intensive checks - usually only called after DB level fail
        if (!empty($errorMode) && strtolower($action) == 'create') {
            if (CRM_Utils_Array::value('FKClassName', $fieldInfo)) {
                if (CRM_Utils_Array::value($fieldname, $params)) {
                    _civicrm_api3_validate_constraint($params, $fieldname, $fieldInfo);
                } elseif (CRM_Utils_Array::value('required', $fieldInfo)) {
                    throw new Exception("DB Constraint Violation - possibly {$fieldname} should possibly be marked as mandatory for this API. If so, please raise a bug report");
                }
            }
            if (CRM_Utils_Array::value('api.unique', $fieldInfo)) {
                $params['entity'] = $entity;
                _civicrm_api3_validate_uniquekey($params, $fieldname, $fieldInfo);
            }
        }
    }
}
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:48,代码来源:utils.php

示例10: _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

示例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: _civicrm_api3_validate_fields

/**
 * Validate fields being passed into API. This function relies on the getFields function working accurately
 * for the given API. If error mode is set to TRUE then it will also check
 * foreign keys
 *
 * As of writing only date was implemented.
 * @param string $entity
 * @param string $action
 * @param array $params -
 * @param array $fields response from getfields all variables are the same as per civicrm_api
 * @param bool $errorMode errorMode do intensive post fail checks?
 * @throws Exception
 */
function _civicrm_api3_validate_fields($entity, $action, &$params, $fields, $errorMode = False)
{
    $fields = array_intersect_key($fields, $params);
    foreach ($fields as $fieldName => $fieldInfo) {
        switch (CRM_Utils_Array::value('type', $fieldInfo)) {
            case CRM_Utils_Type::T_INT:
                //field is of type integer
                _civicrm_api3_validate_integer($params, $fieldName, $fieldInfo, $entity);
                break;
            case 4:
            case 12:
            case CRM_Utils_Type::T_TIMESTAMP:
                //field is of type date or datetime
                _civicrm_api3_validate_date($params, $fieldName, $fieldInfo);
                break;
            case 32:
                //blob
                _civicrm_api3_validate_html($params, $fieldName, $fieldInfo);
                break;
            case CRM_Utils_Type::T_STRING:
                _civicrm_api3_validate_string($params, $fieldName, $fieldInfo, $entity);
                break;
            case CRM_Utils_Type::T_MONEY:
                if (!CRM_Utils_Rule::money($params[$fieldName]) && !empty($params[$fieldName])) {
                    throw new Exception($fieldName . " is  not a valid amount: " . $params[$fieldName]);
                }
        }
        // intensive checks - usually only called after DB level fail
        if (!empty($errorMode) && strtolower($action) == 'create') {
            if (!empty($fieldInfo['FKClassName'])) {
                if (!empty($params[$fieldName])) {
                    _civicrm_api3_validate_constraint($params, $fieldName, $fieldInfo);
                } elseif (!empty($fieldInfo['required'])) {
                    throw new Exception("DB Constraint Violation - possibly {$fieldName} should possibly be marked as mandatory for this API. If so, please raise a bug report");
                }
            }
            if (!empty($fieldInfo['api.unique'])) {
                $params['entity'] = $entity;
                _civicrm_api3_validate_uniquekey($params, $fieldName, $fieldInfo);
            }
        }
    }
}
开发者ID:ruchirapingale,项目名称:civicrm-core,代码行数:56,代码来源:utils.php

示例13: _civicrm_api3_validate_fields

/**
 * Validate fields being passed into API.
 *
 * This function relies on the getFields function working accurately
 * for the given API.
 *
 * As of writing only date was implemented.
 *
 * @param string $entity
 * @param string $action
 * @param array $params
 *   -.
 * @param array $fields
 *   Response from getfields all variables are the same as per civicrm_api.
 *
 * @throws Exception
 */
function _civicrm_api3_validate_fields($entity, $action, &$params, $fields)
{
    //CRM-15792 handle datetime for custom fields below code handles chain api call
    $chainApikeys = array_flip(preg_grep("/^api./", array_keys($params)));
    if (!empty($chainApikeys) && is_array($chainApikeys)) {
        foreach ($chainApikeys as $key => $value) {
            if (is_array($params[$key])) {
                $chainApiParams = array_intersect_key($fields, $params[$key]);
                $customFields = array_fill_keys(array_keys($params[$key]), $key);
            }
        }
    }
    $fields = array_intersect_key($fields, $params);
    if (!empty($chainApiParams)) {
        $fields = array_merge($fields, $chainApiParams);
    }
    foreach ($fields as $fieldName => $fieldInfo) {
        switch (CRM_Utils_Array::value('type', $fieldInfo)) {
            case CRM_Utils_Type::T_INT:
                //field is of type integer
                _civicrm_api3_validate_integer($params, $fieldName, $fieldInfo, $entity);
                break;
            case CRM_Utils_Type::T_DATE:
            case CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME:
            case CRM_Utils_Type::T_TIMESTAMP:
                //field is of type date or datetime
                if (!empty($customFields) && array_key_exists($fieldName, $customFields)) {
                    $dateParams =& $params[$customFields[$fieldName]];
                } else {
                    $dateParams =& $params;
                }
                _civicrm_api3_validate_date($dateParams, $fieldName, $fieldInfo);
                break;
            case CRM_Utils_Type::T_TEXT:
                //blob
                _civicrm_api3_validate_html($params, $fieldName, $fieldInfo);
                break;
            case CRM_Utils_Type::T_STRING:
                _civicrm_api3_validate_string($params, $fieldName, $fieldInfo, $entity);
                break;
            case CRM_Utils_Type::T_MONEY:
                list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName);
                if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) {
                    break;
                }
                foreach ((array) $fieldValue as $fieldvalue) {
                    if (!CRM_Utils_Rule::money($fieldvalue) && !empty($fieldvalue)) {
                        throw new Exception($fieldName . " is  not a valid amount: " . $params[$fieldName]);
                    }
                }
                break;
        }
    }
}
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:71,代码来源:utils.php

示例14: _civicrm_contribute_formatted_param

/**
 * take the input parameter list as specified in the data model and
 * convert it into the same format that we use in QF and BAO object
 *
 * @param array  $params       Associative array of property name/value
 *                             pairs to insert in new contact.
 * @param array  $values       The reformatted properties that we can use internally
 *                            '
 *
 * @return array|CRM_Error
 * @access public
 */
function _civicrm_contribute_formatted_param(&$params, &$values, $create = FALSE)
{
    // copy all the contribution fields as is
    $fields = CRM_Contribute_DAO_Contribution::fields();
    _civicrm_store_values($fields, $params, $values);
    require_once 'CRM/Core/OptionGroup.php';
    $customFields = CRM_Core_BAO_CustomField::getFields('Contribution');
    foreach ($params as $key => $value) {
        // ignore empty values or empty arrays etc
        if (CRM_Utils_System::isNull($value)) {
            continue;
        }
        //Handling Custom Data
        _civicrm_generic_handle_custom_data($key, $value, $values, $customFields);
        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 'contact_type':
                //import contribution record according to select contact type
                require_once 'CRM/Contact/DAO/Contact.php';
                $contactType = new CRM_Contact_DAO_Contact();
                //when insert mode check contact id or external identifire
                if ($params['contribution_contact_id'] || $params['external_identifier']) {
                    if ($params['contribution_contact_id']) {
                        $contactType->id = $params['contribution_contact_id'];
                    } elseif ($params['external_identifier']) {
                        $contactType->external_identifier = $params['external_identifier'];
                    }
                    if ($contactType->find(TRUE)) {
                        if ($params['contact_type'] != $contactType->contact_type) {
                            return civicrm_create_error("Contact Type is wrong: {$contactType->contact_type}");
                        }
                    }
                } elseif ($params['contribution_id'] || $params['trxn_id'] || $params['invoice_id']) {
                    //when update mode check contribution id or trxn id or
                    //invoice id
                    $contactId = new CRM_Contribute_DAO_Contribution();
                    if ($params['contribution_id']) {
                        $contactId->id = $params['contribution_id'];
                    } elseif ($params['trxn_id']) {
                        $contactId->trxn_id = $params['trxn_id'];
                    } elseif ($params['invoice_id']) {
                        $contactId->invoice_id = $params['invoice_id'];
                    }
                    if ($contactId->find(TRUE)) {
                        $contactType->id = $contactId->contact_id;
                        if ($contactType->find(TRUE)) {
                            if ($params['contact_type'] != $contactType->contact_type) {
                                return civicrm_create_error("Contact Type is wrong: {$contactType->contact_type}");
                            }
                        }
                    }
                }
                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':
                require_once 'CRM/Contribute/PseudoConstant.php';
//.........这里部分代码省略.........
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:101,代码来源:utils.v2.php


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