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


PHP CRM_Core_BAO_CustomValue::create方法代码示例

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


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

示例1: crm_create_custom_value

/**
 *  Defines 'custom value' within a field for a specific entity table/id combination.
 *
 * @param $entity_table String  Name of the table that this value is attached to
 * 
 * @param $entity_id    int     ID of the object in the relevant table
 * 
 * @param $custom_field object  field type of the value
 *
 * @param $data         Array         data appropriate value for the above custom field
 *
 * @param $separator    String        separator for values for ckeckbox.
 *
 * @return newly created custom_value object
 *
 * @access public 
 *
 *
 */
function crm_create_custom_value($entity_table, $entity_id, &$custom_field, &$data, $separator = null)
{
    _crm_initialize();
    if (!isset($entity_table)) {
        return _crm_error("parameter entity_table is not set ");
    }
    if (!isset($entity_id)) {
        return _crm_error("parameter entity_id is not set ");
    }
    if (!isset($custom_field->id) && !isset($custom_field->type)) {
        return _crm_error("field id ot type is not set in custom_field object");
    }
    if ($separator) {
        $values = explode($separator, $data['value']);
        require_once 'CRM/Core/BAO/CustomOption.php';
        $data['value'] = implode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, $values);
    }
    $data['type'] = $custom_field->data_type;
    $data['custom_field_id'] = $custom_field->id;
    $data['entity_table'] = $entity_table;
    $data['entity_id'] = $entity_id;
    require_once 'CRM/Core/BAO/CustomValue.php';
    return CRM_Core_BAO_CustomValue::create($data);
}
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:43,代码来源:CustomGroup.php

示例2: _crm_update_contact


//.........这里部分代码省略.........
                        require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Core_BAO_" . $block) . ".php";
                        eval('$contact->location[$contactLocationBlock]->{$name}[$propertyBlock] =& new CRM_Core_BAO_' . $block . '( );');
                    }
                    $property['location_id'] = $contact->location[$contactLocationBlock]->id;
                    if (!$overwrite) {
                        _crm_update_from_object($contact->location[$contactLocationBlock]->{$name}[$propertyBlock], $property, true);
                    }
                    if ($primary == null && $property['is_primary']) {
                        $primary = $propertyBlock;
                    } else {
                        if ($primary != $propertyBlock) {
                            $property['is_primary'] = false;
                        }
                    }
                    _crm_update_object($contact->location[$contactLocationBlock]->{$name}[$propertyBlock], $property);
                    $propertyBlock++;
                }
            }
            /* handle multiple phones */
            if (is_array($updateLocation['phone'])) {
                if (!isset($contact->location[$contactLocationBlock]->phone)) {
                    $contact->location[$contactLocationBlock]->phone = array();
                }
                $primary_phone = null;
                foreach ($contact->location[$contactLocationBlock]->phone as $key => $value) {
                    if ($value->is_primary) {
                        $primary_phone = $key;
                        break;
                    }
                }
                foreach ($updateLocation['phone'] as $phone) {
                    /* scan through the contact record for matching phone type at this location */
                    $contactPhoneBlock = null;
                    foreach ($contact->location[$contactLocationBlock]->phone as $key => $contactPhoneBlock) {
                        if ($contactPhoneBlock->phone_type_id == $phone['phone_type_id']) {
                            $contactPhoneBlock = $key;
                            break;
                        }
                    }
                    if ($contactPhoneBlock == null) {
                        if (empty($contact->location[$contactLocationBlock]->phone)) {
                            $contactPhoneBlock = 1;
                        } else {
                            $contactPhoneBlock = count($contact->location[$contactLocationBlock]->phone) + 1;
                        }
                        $contact->location[$contactLocationBlock]->phone[$contactPhoneBlock] =& new CRM_Core_BAO_Phone();
                    }
                    $phone['location_id'] = $contact->location[$contactLocationBlock]->id;
                    if (!$overwrite) {
                        _crm_update_from_object($contact->location[$contactLocationBlock]->phone[$contactPhoneBlock], $phone, true);
                    }
                    if ($primary_phone == null && $phone['is_primary']) {
                        $primary_phone = $contactPhoneBlock;
                    } else {
                        if ($primary_phone != $contactPhoneBlock) {
                            $phone['is_primary'] = false;
                        }
                    }
                    _crm_update_object($contact->location[$contactLocationBlock]->phone[$contactPhoneBlock], $phone);
                }
            }
        }
    }
    /* Custom data */
    if (is_array($values['custom'])) {
        foreach ($values['custom'] as $customValue) {
            /* get the field for the data type */
            $field = CRM_Core_BAO_CustomValue::typeToField($customValue['type']);
            if (!$field) {
                /* FIXME failure! */
                continue;
            }
            /* adjust the value if it's boolean */
            if ($customValue['type'] == 'Boolean') {
                $value = CRM_Utils_String::strtobool($customValue['value']);
            } else {
                $value = $customValue['value'];
            }
            /* look for a matching existing custom value */
            $match = false;
            foreach ($contact->custom_values as $cv) {
                if ($cv->custom_field_id == $customValue['custom_field_id']) {
                    /* match */
                    $match = true;
                    if ($overwrite) {
                        $cv->{$field} = $value;
                        $cv->save();
                        break;
                    }
                }
            }
            if (!$match) {
                /* no match, so create a new CustomValue */
                $cvParams = array('entity_table' => 'civicrm_contact', 'entity_id' => $contact->id, 'value' => $value, 'type' => $customValue['type'], 'custom_field_id' => $customValue['custom_field_id']);
                CRM_Core_BAO_CustomValue::create($cvParams);
            }
        }
    }
    return $contact;
}
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:101,代码来源:utils.php

示例3: array

 /**
  * takes an associative array and creates a contribution object
  *
  * @param array $params (reference ) an assoc array of name/value pairs
  * @param array $ids    the array that holds all the db ids
  *
  * @return object CRM_Contribute_BAO_Contribution object 
  * @access public
  * @static
  */
 function &create(&$params, &$ids)
 {
     require_once 'CRM/Utils/Money.php';
     require_once 'CRM/Utils/Date.php';
     // FIXME: a cludgy hack to fix the dates to MySQL format
     $dateFields = array('receive_date', 'cancel_date', 'receipt_date', 'thankyou_date');
     foreach ($dateFields as $df) {
         if (isset($params[$df])) {
             $params[$df] = CRM_Utils_Date::isoToMysql($params[$df]);
         }
     }
     CRM_Core_DAO::transaction('BEGIN');
     $contribution = CRM_Contribute_BAO_Contribution::add($params, $ids);
     if (is_a($contribution, 'CRM_Core_Error')) {
         CRM_Core_DAO::transaction('ROLLBACK');
         return $contribution;
     }
     $params['contribution_id'] = $contribution->id;
     // add custom field values
     if (CRM_Utils_Array::value('custom', $params)) {
         foreach ($params['custom'] as $customValue) {
             $cvParams = array('entity_table' => 'civicrm_contribution', 'entity_id' => $contribution->id, 'value' => $customValue['value'], 'type' => $customValue['type'], 'custom_field_id' => $customValue['custom_field_id']);
             if ($customValue['id']) {
                 $cvParams['id'] = $customValue['id'];
             }
             CRM_Core_BAO_CustomValue::create($cvParams);
         }
     }
     // let's create an (or update the relevant) Acitivity History record
     $contributionType = CRM_Contribute_PseudoConstant::contributionType($contribution->contribution_type_id);
     if (!$contributionType) {
         $contributionType = ts('Contribution');
     }
     if (!$GLOBALS['_CRM_CONTRIBUTE_BAO_CONTRIBUTION']['insertDate']) {
         $GLOBALS['_CRM_CONTRIBUTE_BAO_CONTRIBUTION']['insertDate'] = CRM_Utils_Date::customFormat(date('Y-m-d H:i'));
     }
     $activitySummary = ts('%1 - %2 (updated on %3)', array(1 => CRM_Utils_Money::format($contribution->total_amount, $contribution->currency), 2 => $contributionType, 3 => $GLOBALS['_CRM_CONTRIBUTE_BAO_CONTRIBUTION']['insertDate']));
     $historyParams = array('entity_table' => 'civicrm_contact', 'entity_id' => $contribution->contact_id, 'activity_type' => $contributionType, 'module' => 'CiviContribute', 'callback' => 'CRM_Contribute_Page_Contribution::details', 'activity_id' => $contribution->id, 'activity_summary' => $activitySummary, 'activity_date' => $contribution->receive_date);
     if (CRM_Utils_Array::value('contribution', $ids)) {
         // this contribution should have an Activity History record already
         $getHistoryParams = array('module' => 'CiviContribute', 'activity_id' => $contribution->id);
         $getHistoryValues =& CRM_Core_BAO_History::getHistory($getHistoryParams, 0, 1, null, 'Activity');
         if (!empty($getHistoryValues)) {
             $tmp = array_keys($getHistoryValues);
             $ids['activity_history'] = $tmp[0];
         }
     }
     $historyDAO =& CRM_Core_BAO_History::create($historyParams, $ids, 'Activity');
     if (is_a($historyDAO, 'CRM_Core_Error')) {
         CRM_Core_Error::fatal("Failed creating Activity History for contribution of id {$contribution->id}");
     }
     CRM_Core_DAO::transaction('COMMIT');
     return $contribution;
 }
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:64,代码来源:Contribution.php

示例4: str_replace

 /**
  * takes an associative array and creates a contact object and all the associated
  * derived objects (i.e. individual, location, email, phone etc)
  *
  * This function is invoked from within the web form layer and also from the api layer
  *
  * @param array $params (reference ) an assoc array of name/value pairs
  * @param array $ids    the array that holds all the db ids
  * @param int   $maxLocationBlocks the maximum number of location blocks to process
  *
  * @return object CRM_Contact_BAO_Contact object 
  * @access public
  * @static
  */
 function &create(&$params, &$ids, $maxLocationBlocks)
 {
     require_once 'CRM/Utils/Hook.php';
     if (CRM_Utils_Array::value('contact', $ids)) {
         CRM_Utils_Hook::pre('edit', $params['contact_type'], $ids['contact'], $params);
     } else {
         CRM_Utils_Hook::pre('create', $params['contact_type'], null, $params);
     }
     CRM_Core_DAO::transaction('BEGIN');
     $contact = CRM_Contact_BAO_Contact::add($params, $ids);
     $params['contact_id'] = $contact->id;
     // invoke the add operator on the contact_type class
     require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_BAO_" . $params['contact_type']) . ".php";
     eval('$contact->contact_type_object =& CRM_Contact_BAO_' . $params['contact_type'] . '::add($params, $ids);');
     $location = array();
     for ($locationId = 1; $locationId <= $maxLocationBlocks; $locationId++) {
         // start of for loop for location
         $location[$locationId] = CRM_Core_BAO_Location::add($params, $ids, $locationId);
     }
     $contact->location = $location;
     // add notes
     if (CRM_Utils_Array::value('note', $params)) {
         if (is_array($params['note'])) {
             foreach ($params['note'] as $note) {
                 $noteParams = array('entity_id' => $contact->id, 'entity_table' => 'civicrm_contact', 'note' => $note['note']);
                 CRM_Core_BAO_Note::add($noteParams);
             }
         } else {
             $noteParams = array('entity_id' => $contact->id, 'entity_table' => 'civicrm_contact', 'note' => $params['note']);
             CRM_Core_BAO_Note::add($noteParams);
         }
     }
     // update the UF email if that has changed
     require_once 'CRM/Core/BAO/UFMatch.php';
     CRM_Core_BAO_UFMatch::updateUFEmail($contact->id);
     // add custom field values
     if (CRM_Utils_Array::value('custom', $params)) {
         foreach ($params['custom'] as $customValue) {
             $cvParams = array('entity_table' => 'civicrm_contact', 'entity_id' => $contact->id, 'value' => $customValue['value'], 'type' => $customValue['type'], 'custom_field_id' => $customValue['custom_field_id']);
             if ($customValue['id']) {
                 $cvParams['id'] = $customValue['id'];
             }
             CRM_Core_BAO_CustomValue::create($cvParams);
         }
     }
     // make a civicrm_subscription_history entry only on contact create (CRM-777)
     if (!CRM_Utils_Array::value('contact', $ids)) {
         $subscriptionParams = array('contact_id' => $contact->id, 'status' => 'Added', 'method' => 'Admin');
         CRM_Contact_BAO_SubscriptionHistory::create($subscriptionParams);
     }
     CRM_Core_DAO::transaction('COMMIT');
     if (CRM_Utils_Array::value('contact', $ids)) {
         CRM_Utils_Hook::post('edit', $params['contact_type'], $contact->id, $contact);
     } else {
         CRM_Utils_Hook::post('create', $params['contact_type'], $contact->id, $contact);
     }
     $contact->contact_type_display = CRM_Contact_DAO_Contact::tsEnum('contact_type', $contact->contact_type);
     return $contact;
 }
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:73,代码来源:Contact.php


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