Exemplo n.º 1
0
 /**
  * method for creating contact
  * 
  * 
  */
 function createContact(&$formatted, &$contactFields, $onDuplicate, $contactId = null, $requiredCheck = true)
 {
     $dupeCheck = false;
     $newContact = null;
     if (is_null($contactId) && $onDuplicate != CRM_Import_Parser::DUPLICATE_NOCHECK) {
         $dupeCheck = (bool) $onDuplicate;
     }
     //get the prefix id etc if exists
     CRM_Contact_BAO_Contact::resolveDefaults($formatted, true);
     require_once 'api/v2/Contact.php';
     // setting required check to false, CRM-2839
     // plus we do our own required check in import
     $error = civicrm_contact_check_params($formatted, $dupeCheck, true, false);
     if (is_null($error) && civicrm_error(_civicrm_validate_formatted_contact($formatted))) {
         $error = _civicrm_validate_formatted_contact($formatted);
     }
     $newContact = $error;
     if (is_null($error)) {
         if ($contactId) {
             $this->formatParams($formatted, $onDuplicate, (int) $contactId);
         }
         $cid = CRM_Contact_BAO_Contact::createProfileContact($formatted, $contactFields, $contactId, null, null, $formatted['contact_type']);
         $contact = array('contact_id' => $cid);
         $defaults = array();
         $newContact = CRM_Contact_BAO_Contact::retrieve($contact, $defaults);
     }
     return $newContact;
 }
Exemplo n.º 2
0
 /**
  * method for creating contact
  * 
  * 
  */
 function createContact(&$formatted, &$contactFields, $onDuplicate, $contactId = null, $requiredCheck = true)
 {
     $dupeCheck = false;
     $newContact = null;
     if (is_null($contactId) && $onDuplicate != CRM_Import_Parser::DUPLICATE_NOCHECK) {
         $dupeCheck = (bool) $onDuplicate;
     }
     //get the prefix id etc if exists
     CRM_Contact_BAO_Contact::resolveDefaults($formatted, true);
     require_once 'api/v2/Contact.php';
     // setting required check to false, CRM-2839
     // plus we do our own required check in import
     $error = civicrm_contact_check_params($formatted, $dupeCheck, true, false);
     if (is_null($error) && civicrm_error(_civicrm_validate_formatted_contact($formatted))) {
         $error = _civicrm_validate_formatted_contact($formatted);
     }
     $newContact = $error;
     if (is_null($error)) {
         if ($contactId) {
             $this->formatParams($formatted, $onDuplicate, (int) $contactId);
         }
         // pass doNotResetCache flag since resetting and rebuilding cache could be expensive.
         $config =& CRM_Core_Config::singleton();
         $config->doNotResetCache = 1;
         $cid = CRM_Contact_BAO_Contact::createProfileContact($formatted, $contactFields, $contactId, null, null, $formatted['contact_type']);
         $config->doNotResetCache = 0;
         $contact = array('contact_id' => $cid);
         $defaults = array();
         $newContact = CRM_Contact_BAO_Contact::retrieve($contact, $defaults);
     }
     //get the id of the contact whose street address is not parsable, CRM-5886
     if ($this->_parseStreetAddress && $newContact->address) {
         foreach ($newContact->address as $address) {
             if ($address['street_address'] && (!CRM_Utils_Array::value('street_number', $address) || !CRM_Utils_Array::value('street_name', $address))) {
                 $this->_unparsedStreetAddressContacts[] = array('id' => $newContact->id, 'streetAddress' => $address['street_address']);
             }
         }
     }
     return $newContact;
 }
/**
 * @todo Move this to ContactFormat.php
 * @deprecated
 */
function civicrm_contact_format_create(&$params)
{
    _civicrm_initialize();
    CRM_Core_DAO::freeResult();
    // return error if we have no params
    if (empty($params)) {
        return civicrm_create_error('Input Parameters empty');
    }
    $error = _civicrm_required_formatted_contact($params);
    if (civicrm_error($error)) {
        return $error;
    }
    $error = _civicrm_validate_formatted_contact($params);
    if (civicrm_error($error)) {
        return $error;
    }
    //get the prefix id etc if exists
    require_once 'CRM/Contact/BAO/Contact.php';
    CRM_Contact_BAO_Contact::resolveDefaults($params, TRUE);
    require_once 'CRM/Import/Parser.php';
    if (CRM_Utils_Array::value('onDuplicate', $params) != CRM_Import_Parser::DUPLICATE_NOCHECK) {
        CRM_Core_Error::reset();
        $error = _civicrm_duplicate_formatted_contact($params);
        if (civicrm_error($error)) {
            return $error;
        }
    }
    $contact = CRM_Contact_BAO_Contact::create($params, CRM_Utils_Array::value('fixAddress', $params));
    _civicrm_object_to_array($contact, $contactArray);
    return $contactArray;
}