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


PHP CRM_Contact_BAO_GroupContact::create方法代码示例

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


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

示例1: createProfileContact

 /**
  * Add/edit/register contacts through profile.
  *
  * @param array $params
  *   Array of profile fields to be edited/added.
  * @param array $fields
  *   Array of fields from UFGroup.
  * @param int $contactID
  *   Id of the contact to be edited/added.
  * @param int $addToGroupID
  *   Specifies the default group to which contact is added.
  * @param int $ufGroupId
  *   Uf group id (profile id).
  * @param string $ctype
  * @param bool $visibility
  *   Basically lets us know where this request is coming from.
  *                                if via a profile from web, we restrict what groups are changed
  *
  * @return int
  *   contact id created/edited
  */
 public static function createProfileContact(&$params, &$fields, $contactID = NULL, $addToGroupID = NULL, $ufGroupId = NULL, $ctype = NULL, $visibility = FALSE)
 {
     // add ufGroupID to params array ( CRM-2012 )
     if ($ufGroupId) {
         $params['uf_group_id'] = $ufGroupId;
     }
     self::addBillingNameFieldsIfOtherwiseNotSet($params);
     // If a user has logged in, or accessed via a checksum
     // Then deliberately 'blanking' a value in the profile should remove it from their record
     $session = CRM_Core_Session::singleton();
     $params['updateBlankLocInfo'] = TRUE;
     if (($session->get('authSrc') & CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN) == 0) {
         $params['updateBlankLocInfo'] = FALSE;
     }
     if ($contactID) {
         $editHook = TRUE;
         CRM_Utils_Hook::pre('edit', 'Profile', $contactID, $params);
     } else {
         $editHook = FALSE;
         CRM_Utils_Hook::pre('create', 'Profile', NULL, $params);
     }
     list($data, $contactDetails) = self::formatProfileContactParams($params, $fields, $contactID, $ufGroupId, $ctype);
     // manage is_opt_out
     if (array_key_exists('is_opt_out', $fields) && array_key_exists('is_opt_out', $params)) {
         $wasOptOut = CRM_Utils_Array::value('is_opt_out', $contactDetails, FALSE);
         $isOptOut = CRM_Utils_Array::value('is_opt_out', $params, FALSE);
         $data['is_opt_out'] = $isOptOut;
         // on change, create new civicrm_subscription_history entry
         if ($wasOptOut != $isOptOut && !empty($contactDetails['contact_id'])) {
             $shParams = array('contact_id' => $contactDetails['contact_id'], 'status' => $isOptOut ? 'Removed' : 'Added', 'method' => 'Web');
             CRM_Contact_BAO_SubscriptionHistory::create($shParams);
         }
     }
     $contact = self::create($data);
     // contact is null if the profile does not have any contact fields
     if ($contact) {
         $contactID = $contact->id;
     }
     if (empty($contactID)) {
         CRM_Core_Error::fatal('Cannot proceed without a valid contact id');
     }
     // Process group and tag
     if (!empty($fields['group'])) {
         $method = 'Admin';
         // this for sure means we are coming in via profile since i added it to fix
         // removing contacts from user groups -- lobo
         if ($visibility) {
             $method = 'Web';
         }
         CRM_Contact_BAO_GroupContact::create($params['group'], $contactID, $visibility, $method);
     }
     if (!empty($fields['tag'])) {
         CRM_Core_BAO_EntityTag::create($params['tag'], 'civicrm_contact', $contactID);
     }
     //to add profile in default group
     if (is_array($addToGroupID)) {
         $contactIds = array($contactID);
         foreach ($addToGroupID as $groupId) {
             CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId);
         }
     } elseif ($addToGroupID) {
         $contactIds = array($contactID);
         CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $addToGroupID);
     }
     // reset the group contact cache for this group
     CRM_Contact_BAO_GroupContactCache::remove();
     if ($editHook) {
         CRM_Utils_Hook::post('edit', 'Profile', $contactID, $params);
     } else {
         CRM_Utils_Hook::post('create', 'Profile', $contactID, $params);
     }
     return $contactID;
 }
开发者ID:hyebahi,项目名称:civicrm-core,代码行数:94,代码来源:Contact.php

示例2: createProfileContact

 /**
  * Add/edit/register contacts through profile.
  *
  * @param array $params
  *   Array of profile fields to be edited/added.
  * @param array $fields
  *   Array of fields from UFGroup.
  * @param int $contactID
  *   Id of the contact to be edited/added.
  * @param int $addToGroupID
  *   Specifies the default group to which contact is added.
  * @param int $ufGroupId
  *   Uf group id (profile id).
  * @param string $ctype
  * @param bool $visibility
  *   Basically lets us know where this request is coming from.
  *                                if via a profile from web, we restrict what groups are changed
  *
  * @return int
  *   contact id created/edited
  */
 public static function createProfileContact(&$params, &$fields, $contactID = NULL, $addToGroupID = NULL, $ufGroupId = NULL, $ctype = NULL, $visibility = FALSE)
 {
     // add ufGroupID to params array ( CRM-2012 )
     if ($ufGroupId) {
         $params['uf_group_id'] = $ufGroupId;
     }
     if ($contactID) {
         $editHook = TRUE;
         CRM_Utils_Hook::pre('edit', 'Profile', $contactID, $params);
     } else {
         $editHook = FALSE;
         CRM_Utils_Hook::pre('create', 'Profile', NULL, $params);
     }
     list($data, $contactDetails) = self::formatProfileContactParams($params, $fields, $contactID, $ufGroupId, $ctype);
     // manage is_opt_out
     if (array_key_exists('is_opt_out', $fields) && array_key_exists('is_opt_out', $params)) {
         $wasOptOut = CRM_Utils_Array::value('is_opt_out', $contactDetails, FALSE);
         $isOptOut = CRM_Utils_Array::value('is_opt_out', $params, FALSE);
         $data['is_opt_out'] = $isOptOut;
         // on change, create new civicrm_subscription_history entry
         if ($wasOptOut != $isOptOut && !empty($contactDetails['contact_id'])) {
             $shParams = array('contact_id' => $contactDetails['contact_id'], 'status' => $isOptOut ? 'Removed' : 'Added', 'method' => 'Web');
             CRM_Contact_BAO_SubscriptionHistory::create($shParams);
         }
     }
     $contact = self::create($data);
     // contact is null if the profile does not have any contact fields
     if ($contact) {
         $contactID = $contact->id;
     }
     if (empty($contactID)) {
         CRM_Core_Error::fatal('Cannot proceed without a valid contact id');
     }
     // Process group and tag
     if (!empty($fields['group'])) {
         $method = 'Admin';
         // this for sure means we are coming in via profile since i added it to fix
         // removing contacts from user groups -- lobo
         if ($visibility) {
             $method = 'Web';
         }
         CRM_Contact_BAO_GroupContact::create($params['group'], $contactID, $visibility, $method);
     }
     if (!empty($fields['tag'])) {
         CRM_Core_BAO_EntityTag::create($params['tag'], 'civicrm_contact', $contactID);
     }
     //to add profile in default group
     if (is_array($addToGroupID)) {
         $contactIds = array($contactID);
         foreach ($addToGroupID as $groupId) {
             CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId);
         }
     } elseif ($addToGroupID) {
         $contactIds = array($contactID);
         CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $addToGroupID);
     }
     // reset the group contact cache for this group
     CRM_Contact_BAO_GroupContactCache::remove();
     if ($editHook) {
         CRM_Utils_Hook::post('edit', 'Profile', $contactID, $params);
     } else {
         CRM_Utils_Hook::post('create', 'Profile', $contactID, $params);
     }
     return $contactID;
 }
开发者ID:JSProffitt,项目名称:civicrm-website-org,代码行数:86,代码来源:Contact.php

示例3: civicrm_api3_profile_submit

/**
 * Submit a set of fields against a profile.
 * Note choice of submit versus create is discussed CRM-13234 & related to the fact
 * 'profile' is being treated as a data-entry entity
 *
 * @param array $params
 *
 * @throws API_Exception
 * @return array API result array
 */
function civicrm_api3_profile_submit($params)
{
    $profileID = _civicrm_api3_profile_getProfileID($params['profile_id']);
    if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_active')) {
        //@todo declare pseudoconstant & let api do this
        throw new API_Exception('Invalid value for profile_id');
    }
    $isContactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($profileID);
    if (!empty($params['id']) && CRM_Core_BAO_UFField::checkProfileType($profileID) && !$isContactActivityProfile) {
        throw new API_Exception('Update profiles including more than one entity not currently supported');
    }
    $contactParams = $activityParams = $missingParams = array();
    $profileFields = civicrm_api3('profile', 'getfields', array('action' => 'submit', 'profile_id' => $profileID));
    $profileFields = $profileFields['values'];
    if ($isContactActivityProfile) {
        civicrm_api3_verify_mandatory($params, NULL, array('activity_id'));
        $errors = CRM_Profile_Form::validateContactActivityProfile($params['activity_id'], $params['contact_id'], $profileID);
        if (!empty($errors)) {
            throw new API_Exception(array_pop($errors));
        }
    }
    foreach ($profileFields as $fieldName => $field) {
        if (!isset($params[$fieldName])) {
            continue;
        }
        $value = $params[$fieldName];
        if ($params[$fieldName] && isset($params[$fieldName . '_id'])) {
            $value = $params[$fieldName . '_id'];
        }
        $contactEntities = array('contact', 'individual', 'organization', 'household');
        $locationEntities = array('email', 'address', 'phone', 'website', 'im');
        $entity = strtolower(CRM_Utils_Array::value('entity', $field));
        if ($entity && !in_array($entity, array_merge($contactEntities, $locationEntities))) {
            $contactParams['api.' . $entity . '.create'][$fieldName] = $value;
            //@todo we are not currently declaring this option
            if (isset($params['batch_id']) && strtolower($entity) == 'contribution') {
                $contactParams['api.' . $entity . '.create']['batch_id'] = $params['batch_id'];
            }
            if (isset($params[$entity . '_id'])) {
                //todo possibly declare $entity_id in getfields ?
                $contactParams['api.' . $entity . '.create']['id'] = $params[$entity . '_id'];
            }
        } else {
            $contactParams[_civicrm_api3_profile_translate_fieldnames_for_bao($fieldName)] = $value;
        }
    }
    if (isset($contactParams['api.contribution.create']) && isset($contactParams['api.membership.create'])) {
        $contactParams['api.membership_payment.create'] = array('contribution_id' => '$value.api.contribution.create.id', 'membership_id' => '$value.api.membership.create.id');
    }
    if (isset($contactParams['api.contribution.create']) && isset($contactParams['api.participant.create'])) {
        $contactParams['api.participant_payment.create'] = array('contribution_id' => '$value.api.contribution.create.id', 'participant_id' => '$value.api.participant.create.id');
    }
    $contactParams['contact_id'] = CRM_Utils_Array::value('contact_id', $params);
    $contactParams['profile_id'] = $profileID;
    $contactParams['skip_custom'] = 1;
    $contactProfileParams = civicrm_api3_profile_apply($contactParams);
    // Contact profile fields
    $profileParams = $contactProfileParams['values'];
    // If profile having activity fields
    if ($isContactActivityProfile && !empty($activityParams)) {
        $activityParams['id'] = $params['activity_id'];
        $profileParams['api.activity.create'] = $activityParams;
    }
    $groups = $tags = array();
    if (isset($profileParams['group'])) {
        $groups = $profileParams['group'];
        unset($profileParams['group']);
    }
    if (isset($profileParams['tag'])) {
        $tags = $profileParams['tag'];
        unset($profileParams['tag']);
    }
    return civicrm_api3('contact', 'create', $profileParams);
    $ufGroupDetails = array();
    $ufGroupParams = array('id' => $profileID);
    CRM_Core_BAO_UFGroup::retrieve($ufGroupParams, $ufGroupDetails);
    if (isset($profileFields['group'])) {
        CRM_Contact_BAO_GroupContact::create($groups, $params['contact_id'], FALSE, 'Admin');
    }
    if (isset($profileFields['tag'])) {
        CRM_Core_BAO_EntityTag::create($tags, 'civicrm_contact', $params['contact_id']);
    }
    if (!empty($ufGroupDetails['add_to_group_id'])) {
        $contactIds = array($params['contact_id']);
        CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $ufGroupDetails['add_to_group_id']);
    }
    return $result;
}
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:98,代码来源:Profile.php

示例4: createProfileContact

 /**
  * function to add/edit/register contacts through profile.
  *
  * @params  array  $params        Array of profile fields to be edited/added.
  * @params  int    $contactID     contact_id of the contact to be edited/added.
  * @params  array  $fields        array of fields from UFGroup
  * @params  int    $addToGroupID  specifies the default group to which contact is added.
  * @params  int    $ufGroupId     uf group id (profile id)
  * @param   string $ctype         contact type
  *
  * @return  int                   contact id created/edited
  * @static
  * @access public
  */
 static function createProfileContact(&$params, &$fields, $contactID = null, $addToGroupID = null, $ufGroupId = null, $ctype = null, $visibility = false)
 {
     // add ufGroupID to params array ( CRM-2012 )
     if ($ufGroupId) {
         $params['uf_group_id'] = $ufGroupId;
     }
     require_once 'CRM/Utils/Hook.php';
     if ($contactID) {
         $editHook = true;
         CRM_Utils_Hook::pre('edit', 'Profile', $contactID, $params);
     } else {
         $editHook = false;
         CRM_Utils_Hook::pre('create', 'Profile', null, $params);
     }
     $data = $contactDetails = array();
     // get the contact details (hier)
     if ($contactID) {
         list($details, $options) = self::getHierContactDetails($contactID, $fields);
         $contactDetails = $details[$contactID];
         $data['contact_type'] = CRM_Utils_Array::value('contact_type', $contactDetails);
     } else {
         //we should get contact type only if contact
         if ($ufGroupId) {
             require_once "CRM/Core/BAO/UFField.php";
             $data['contact_type'] = CRM_Core_BAO_UFField::getProfileType($ufGroupId);
             //special case to handle profile with only contact fields
             if ($data['contact_type'] == 'Contact') {
                 $data['contact_type'] = 'Individual';
             } else {
                 if (CRM_Contact_BAO_ContactType::isaSubType($data['contact_type'])) {
                     $data['contact_type'] = CRM_Contact_BAO_ContactType::getBasicType($data['contact_type']);
                 }
             }
         } else {
             if ($ctype) {
                 $data['contact_type'] = $ctype;
             } else {
                 $data['contact_type'] = 'Individual';
             }
         }
     }
     //fix contact sub type CRM-5125
     if ($subType = CRM_Utils_Array::value('contact_sub_type', $params)) {
         $data['contact_sub_type'] = $subType;
     } else {
         if ($ufGroupId) {
             $data['contact_sub_type'] = CRM_Core_BAO_UFField::getProfileSubType($ufGroupId, $data['contact_type']);
         }
     }
     if ($ctype == "Organization") {
         $data["organization_name"] = $contactDetails["organization_name"];
     } else {
         if ($ctype == "Household") {
             $data["household_name"] = $contactDetails["household_name"];
         }
     }
     $locationType = array();
     $count = 1;
     if ($contactID) {
         //add contact id
         $data['contact_id'] = $contactID;
         $primaryLocationType = self::getPrimaryLocationType($contactID);
     } else {
         require_once "CRM/Core/BAO/LocationType.php";
         $defaultLocation =& CRM_Core_BAO_LocationType::getDefault();
         $defaultLocationId = $defaultLocation->id;
     }
     // get the billing location type
     $locationTypes =& CRM_Core_PseudoConstant::locationType();
     $billingLocationTypeId = array_search('Billing', $locationTypes);
     $blocks = array('email', 'phone', 'im', 'openid');
     // prevent overwritten of formatted array, reset all block from
     // params if it is not in valid format (since import pass valid format)
     foreach ($blocks as $blk) {
         if (array_key_exists($blk, $params) && !is_array($params[$blk])) {
             unset($params[$blk]);
         }
     }
     $primaryPhoneLoc = null;
     foreach ($params as $key => $value) {
         $fieldName = $locTypeId = $typeId = null;
         list($fieldName, $locTypeId, $typeId) = CRM_Utils_System::explode('-', $key, 3);
         //store original location type id
         $actualLocTypeId = $locTypeId;
         if ($locTypeId == 'Primary') {
             if ($contactID) {
//.........这里部分代码省略.........
开发者ID:ksecor,项目名称:civicrm,代码行数:101,代码来源:Contact.php

示例5: postProcess

 /**
  * Form submission of new/edit contact is processed.
  *
  * @access public
  * @return None
  */
 function postProcess()
 {
     // check if dedupe button, if so return.
     $buttonName = $this->controller->getButtonName();
     if ($buttonName == $this->_dedupeButtonName) {
         return;
     }
     // store the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     // action is taken depending upon the mode
     $ids = array();
     if ($this->_action & CRM_CORE_ACTION_UPDATE) {
         // if update get all the valid database ids
         // from the session
         $ids = $this->get('ids');
     }
     $params['contact_type'] = $this->_contactType;
     $contact = CRM_Contact_BAO_Contact::create($params, $ids, CRM_CONTACT_FORM_EDIT_LOCATION_BLOCKS);
     //add contact to gruoup
     CRM_Contact_BAO_GroupContact::create($params['group'], $params['contact_id']);
     //add contact to tags
     CRM_Core_BAO_EntityTag::create($params['tag'], $params['contact_id']);
     // here we replace the user context with the url to view this contact
     $config =& CRM_Core_Config::singleton();
     $session =& CRM_Core_Session::singleton();
     CRM_Core_Session::setStatus(ts('Your %1 contact record has been saved.', array(1 => $contact->contact_type_display)));
     $buttonName = $this->controller->getButtonName();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         // add the recently viewed contact
         list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($contact->id);
         CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $contact->id), $contactImage, $contact->id);
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/add' . $contact->contact_type[0], 'reset=1&c_type=' . $contact->contact_type));
     } else {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $contact->id));
     }
     CRM_Core_BAO_CustomGroup::postProcess($this->_groupTree, $params);
     // do the updates/inserts
     CRM_Core_BAO_CustomGroup::updateCustomData($this->_groupTree, $this->_contactType, $contact->id);
 }
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:45,代码来源:Edit.php

示例6: civicrm_api3_profile_set

/**
 * Update Profile field values.
 *
 * @param array  $params       Associative array of property name/value
 *                             pairs to update profile field values
 *
 * @return Updated Contact/ Activity object|CRM_Error
 *
 * @todo add example
 * @todo add test cases
 *
 */
function civicrm_api3_profile_set($params)
{
    civicrm_api3_verify_mandatory($params, NULL, array('profile_id'));
    if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $params['profile_id'], 'is_active')) {
        return civicrm_api3_create_error('Invalid value for profile_id');
    }
    $isContactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($params['profile_id']);
    if (CRM_Core_BAO_UFField::checkProfileType($params['profile_id']) && !$isContactActivityProfile) {
        return civicrm_api3_create_error('Can not retrieve values for profiles include fields for more than one record type.');
    }
    $contactParams = $activityParams = $missingParams = array();
    $profileFields = CRM_Core_BAO_UFGroup::getFields($params['profile_id'], FALSE, NULL, NULL, NULL, FALSE, NULL, TRUE, NULL, CRM_Core_Permission::EDIT);
    if ($isContactActivityProfile) {
        civicrm_api3_verify_mandatory($params, NULL, array('activity_id'));
        require_once 'CRM/Profile/Form.php';
        $errors = CRM_Profile_Form::validateContactActivityProfile($params['activity_id'], $params['contact_id'], $params['profile_id']);
        if (!empty($errors)) {
            return civicrm_api3_create_error(array_pop($errors));
        }
    }
    foreach ($profileFields as $fieldName => $field) {
        if (CRM_Utils_Array::value('is_required', $field)) {
            if (!CRM_Utils_Array::value($fieldName, $params) || empty($params[$fieldName])) {
                $missingParams[] = $fieldName;
            }
        }
        if (!isset($params[$fieldName])) {
            continue;
        }
        $value = $params[$fieldName];
        if ($params[$fieldName] && isset($params[$fieldName . '_id'])) {
            $value = $params[$fieldName . '_id'];
        }
        if ($isContactActivityProfile && CRM_Utils_Array::value('field_type', $field) == 'Activity') {
            $activityParams[$fieldName] = $value;
        } else {
            $contactParams[$fieldName] = $value;
        }
    }
    if (!empty($missingParams)) {
        return civicrm_api3_create_error("Missing required parameters for profile id {$params['profile_id']}: " . implode(', ', $missingParams));
    }
    $contactParams['version'] = 3;
    $contactParams['contact_id'] = CRM_Utils_Array::value('contact_id', $params);
    $contactParams['profile_id'] = $params['profile_id'];
    $contactParams['skip_custom'] = 1;
    $contactProfileParams = civicrm_api3_profile_apply($contactParams);
    if (CRM_Utils_Array::value('is_error', $contactProfileParams)) {
        return $contactProfileParams;
    }
    // Contact profile fields
    $profileParams = $contactProfileParams['values'];
    // If profile having activity fields
    if ($isContactActivityProfile && !empty($activityParams)) {
        $activityParams['id'] = $params['activity_id'];
        $profileParams['api.activity.create'] = $activityParams;
    }
    $groups = $tags = array();
    if (isset($profileParams['group'])) {
        $groups = $profileParams['group'];
        unset($profileParams['group']);
    }
    if (isset($profileParams['tag'])) {
        $tags = $profileParams['tag'];
        unset($profileParams['tag']);
    }
    $result = civicrm_api('contact', 'create', $profileParams);
    if (CRM_Utils_Array::value('is_error', $result)) {
        return $result;
    }
    $ufGroupDetails = array();
    $ufGroupParams = array('id' => $params['profile_id']);
    CRM_Core_BAO_UFGroup::retrieve($ufGroupParams, $ufGroupDetails);
    if (isset($profileFields['group'])) {
        CRM_Contact_BAO_GroupContact::create($groups, $params['contact_id'], FALSE, 'Admin');
    }
    if (isset($profileFields['tag'])) {
        require_once 'CRM/Core/BAO/EntityTag.php';
        CRM_Core_BAO_EntityTag::create($tags, 'civicrm_contact', $params['contact_id']);
    }
    if (CRM_Utils_Array::value('add_to_group_id', $ufGroupDetails)) {
        $contactIds = array($params['contact_id']);
        CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $ufGroupDetails['add_to_group_id']);
    }
    return $result;
}
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:98,代码来源:Profile.php

示例7: createProfileContact

 /**
  * function to add/edit/register contacts through profile.
  *
  * @params  array  $params        Array of profile fields to be edited/added.
  * @params  int    $contactID     contact_id of the contact to be edited/added.
  * @params  array  $fields        array of fields from UFGroup
  * @params  int    $addToGroupID  specifies the default group to which contact is added.
  * @params  int    $ufGroupId     uf group id (profile id)
  * @param   string $ctype         contact type
  * @param   boolean $visibility   basically lets us know where this request is coming from
  *                                if via a profile from web, we restrict what groups are changed
  *
  * @return  int                   contact id created/edited
  * @static
  * @access public
  */
 static function createProfileContact(&$params, &$fields, $contactID = NULL, $addToGroupID = NULL, $ufGroupId = NULL, $ctype = NULL, $visibility = FALSE)
 {
     // add ufGroupID to params array ( CRM-2012 )
     if ($ufGroupId) {
         $params['uf_group_id'] = $ufGroupId;
     }
     if ($contactID) {
         $editHook = TRUE;
         CRM_Utils_Hook::pre('edit', 'Profile', $contactID, $params);
     } else {
         $editHook = FALSE;
         CRM_Utils_Hook::pre('create', 'Profile', NULL, $params);
     }
     list($data, $contactDetails) = self::formatProfileContactParams($params, $fields, $contactID, $ufGroupId, $ctype);
     // manage is_opt_out
     if (array_key_exists('is_opt_out', $fields) && array_key_exists('is_opt_out', $params)) {
         $wasOptOut = CRM_Utils_Array::value('is_opt_out', $contactDetails, FALSE);
         $isOptOut = CRM_Utils_Array::value('is_opt_out', $params, FALSE);
         $data['is_opt_out'] = $isOptOut;
         // on change, create new civicrm_subscription_history entry
         if ($wasOptOut != $isOptOut && CRM_Utils_Array::value('contact_id', $contactDetails)) {
             $shParams = array('contact_id' => $contactDetails['contact_id'], 'status' => $isOptOut ? 'Removed' : 'Added', 'method' => 'Web');
             CRM_Contact_BAO_SubscriptionHistory::create($shParams);
         }
     }
     if ($data['contact_type'] != 'Student') {
         $contact = self::create($data);
     }
     // contact is null if the profile does not have any contact fields
     if ($contact) {
         $contactID = $contact->id;
     }
     if (!$contactID) {
         CRM_Core_Error::fatal('Cannot proceed without a valid contact id');
     }
     // Process group and tag
     if (CRM_Utils_Array::value('group', $fields)) {
         $method = 'Admin';
         // this for sure means we are coming in via profile since i added it to fix
         // removing contacts from user groups -- lobo
         if ($visibility) {
             $method = 'Web';
         }
         CRM_Contact_BAO_GroupContact::create($params['group'], $contactID, $visibility, $method);
     }
     if (CRM_Utils_Array::value('tag', $fields)) {
         CRM_Core_BAO_EntityTag::create($params['tag'], 'civicrm_contact', $contactID);
     }
     //to add profile in default group
     if (is_array($addToGroupID)) {
         $contactIds = array($contactID);
         foreach ($addToGroupID as $groupId) {
             CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId);
         }
     } elseif ($addToGroupID) {
         $contactIds = array($contactID);
         CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $addToGroupID);
     }
     //to update student record
     if (CRM_Core_Permission::access('Quest') && $studentFieldPresent) {
         $ids = array();
         $dao = new CRM_Quest_DAO_Student();
         $dao->contact_id = $contactID;
         if ($dao->find(TRUE)) {
             $ids['id'] = $dao->id;
         }
         $ssids = array();
         $studentSummary = new CRM_Quest_DAO_StudentSummary();
         $studentSummary->contact_id = $contactID;
         if ($studentSummary->find(TRUE)) {
             $ssids['id'] = $studentSummary->id;
         }
         $params['contact_id'] = $contactID;
         //fixed for check boxes
         $specialFields = array('educational_interest', 'college_type', 'college_interest', 'test_tutoring');
         foreach ($specialFields as $field) {
             if ($params[$field]) {
                 $params[$field] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params[$field]));
             }
         }
         CRM_Quest_BAO_Student::create($params, $ids);
         CRM_Quest_BAO_Student::createStudentSummary($params, $ssids);
     }
     // reset the group contact cache for this group
//.........这里部分代码省略.........
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:101,代码来源:Contact.php

示例8: postProcess


//.........这里部分代码省略.........
                                 continue;
                             } else {
                                 $data[$key] = $value;
                             }
                         }
                     }
                 }
             }
         }
     }
     // fix all the custom field checkboxes which are empty
     foreach ($this->_fields as $name => $field) {
         $cfID = CRM_Core_BAO_CustomField::getKeyID($name);
         // if there is a custom field of type checkbox and it has not been set
         // then set it to null, thanx to html protocol
         if ($cfID && $customFields[$cfID][3] == 'CheckBox' && CRM_Utils_Array::value('custom', $data) && !CRM_Utils_Array::value($cfID, $data['custom'])) {
             $str = 'custom_value_' . $cfID . '_id';
             if ($this->_contact[$str]) {
                 $id = $this->_contact[$str];
             }
             $data['custom'][$cfID] = array('id' => $id, 'value' => '', 'extends' => $customFields[$cfID][3], 'type' => $customFields[$cfID][2], 'custom_field_id' => $cfID);
         }
     }
     if ($this->_id) {
         $objects = array('contact_id', 'individual_id', 'location_id', 'address_id');
         $ids = array();
         $phoneLoc = 0;
         foreach ($this->_fields as $name => $field) {
             $nameValue = explode('-', $name);
             foreach ($this->_contact as $key => $value) {
                 if (in_array($key, $objects)) {
                     $ids[substr($key, 0, strlen($key) - 3)] = $value;
                 } else {
                     if (is_array($value)) {
                         //fixed for CRM-665
                         if ($nameValue[1] == $value['location_type_id']) {
                             $locations[$value['location_type_id']] = 1;
                             $loc_no = count($locations);
                             if ($nameValue[0] == 'phone') {
                                 $phoneLoc++;
                                 if (isset($nameValue[2])) {
                                     $ids['location'][$loc_no]['phone'][$phoneLoc] = $value['phone'][$nameValue[2] . '_id'];
                                 } else {
                                     $ids['location'][$loc_no]['phone'][$phoneLoc] = $value['phone']['1_id'];
                                 }
                             } else {
                                 if ($nameValue[0] == 'im') {
                                     $ids['location'][$loc_no]['im'][1] = $value['im']['1_id'];
                                 } else {
                                     if ($nameValue[0] == 'email') {
                                         $ids['location'][$loc_no]['email'][1] = $value['email']['1_id'];
                                     } else {
                                         $ids['location'][$loc_no]['address'] = $value['address_id'];
                                     }
                                 }
                             }
                             $ids['location'][$loc_no]['id'] = $value['location_id'];
                         }
                     }
                 }
             }
         }
     }
     //set the values for checkboxes (do_not_email, do_not_mail, do_not_trade, do_not_phone)
     $privacy = CRM_Core_SelectValues::privacy();
     foreach ($privacy as $key => $value) {
         if (array_key_exists($key, $this->_fields)) {
             if ($params[$key]) {
                 $data[$key] = $params[$key];
             } else {
                 $data[$key] = 0;
             }
         }
     }
     // manage is_opt_out
     if (array_key_exists('is_opt_out', $this->_fields)) {
         $wasOptOut = $this->_contact['is_opt_out'] ? true : false;
         $isOptOut = $params['is_opt_out'] ? true : false;
         $data['is_opt_out'] = $isOptOut;
         // on change, create new civicrm_subscription_history entry
         if ($wasOptOut != $isOptOut) {
             $shParams = array('contact_id' => $this->_contact['contact_id'], 'status' => $isOptOut ? 'Removed' : 'Added', 'method' => 'Web');
             CRM_Contact_BAO_SubscriptionHistory::create($shParams);
         }
     }
     if ($this->_mode == CRM_PROFILE_FORM_MODE_REGISTER) {
         require_once 'CRM/Core/BAO/Address.php';
         CRM_Core_BAO_Address::setOverwrite(false);
     }
     require_once 'CRM/Contact/BAO/Contact.php';
     $contact = CRM_Contact_BAO_Contact::create($data, $ids, count($data['location']));
     // Process group and tag
     if (CRM_Utils_Array::value('group', $this->_fields)) {
         CRM_Contact_BAO_GroupContact::create($params['group'], $contact->id);
     }
     if (CRM_Utils_Array::value('tag', $this->_fields)) {
         require_once 'CRM/Core/BAO/EntityTag.php';
         CRM_Core_BAO_EntityTag::create($params['tag'], $contact->id);
     }
 }
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:101,代码来源:Form.php

示例9: foreach

 /** 
  * 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
  * primarily from the profile / contribute forms where we dont have a nice hierarchy
  * and are too lazy to create one. This function should be obsoleted at some time
  * 
  * @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_Contact_BAO_Contact object  
  * @access public 
  * @static 
  */
 function &createFlat(&$params, &$ids)
 {
     require_once 'CRM/Utils/Hook.php';
     if (CRM_Utils_Array::value('contact', $ids)) {
         CRM_Utils_Hook::pre('edit', 'Individual', $ids['contact'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Individual', null, $params);
     }
     CRM_Core_DAO::transaction('BEGIN');
     $params['contact_type'] = 'Individual';
     $contact = CRM_Contact_BAO_Contact::add($params, $ids);
     $params['contact_id'] = $contact->id;
     require_once 'CRM/Contact/BAO/Individual.php';
     CRM_Contact_BAO_Individual::add($params, $ids);
     require_once 'CRM/Core/BAO/LocationType.php';
     $locationType =& CRM_Core_BAO_LocationType::getDefault();
     $locationTypeId = $locationType->id;
     $locationIds = CRM_Utils_Array::value('location', $ids);
     // extract the first location id
     if ($locationIds) {
         foreach ($locationIds as $dontCare => $locationId) {
             $locationIds = $locationId;
             break;
         }
     }
     $location =& new CRM_Core_DAO_Location();
     $location->location_type_id = $locationTypeId;
     $location->entity_table = 'civicrm_contact';
     $location->entity_id = $contact->id;
     $location->id = CRM_Utils_Array::value('id', $locationIds);
     if ($location->find(true)) {
         if (!$location->is_primary) {
             $location->is_primary = true;
         }
     } else {
         $location->is_primary = true;
     }
     $location->save();
     $address =& new CRM_Core_BAO_Address();
     CRM_Core_BAO_Address::fixAddress($params);
     if (!$address->copyValues($params)) {
         $address->id = CRM_Utils_Array::value('address', $locationIds);
         $address->location_id = $location->id;
         $address->save();
     }
     $phone =& new CRM_Core_BAO_Phone();
     if (!$phone->copyValues($params)) {
         $blockIds = CRM_Utils_Array::value('phone', $locationIds);
         $phone->id = CRM_Utils_Array::value(1, $blockIds);
         $phone->location_id = $location->id;
         $phone->is_primary = true;
         $phone->save();
     }
     $email =& new CRM_Core_BAO_Email();
     if (!$email->copyValues($params)) {
         $blockIds = CRM_Utils_Array::value('email', $locationIds);
         $email->id = CRM_Utils_Array::value(1, $blockIds);
         $email->location_id = $location->id;
         $email->is_primary = true;
         $email->save();
     }
     /* Process custom field values and other values */
     foreach ($params as $key => $value) {
         if ($key == 'group') {
             CRM_Contact_BAO_GroupContact::create($params['group'], $contact->id);
         } else {
             if ($key == 'tag') {
                 require_once 'CRM/Core/BAO/EntityTag.php';
                 CRM_Core_BAO_EntityTag::create($params['tag'], $contact->id);
             } else {
                 if ($cfID = CRM_Core_BAO_CustomField::getKeyID($key)) {
                     $custom_field_id = $cfID;
                     $cf =& new CRM_Core_BAO_CustomField();
                     $cf->id = $custom_field_id;
                     if ($cf->find(true)) {
                         switch ($cf->html_type) {
                             case 'Select Date':
                                 $date = CRM_Utils_Date::format($value);
                                 if (!$date) {
                                     $date = '';
                                 }
                                 $customValue = $date;
                                 break;
                             case 'CheckBox':
                                 $customValue = implode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, array_keys($value));
//.........这里部分代码省略.........
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:101,代码来源:Contact.php


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