Пример #1
0
 /**
  * Test case for resolveDefaults( ).
  *
  * Test all pseudoConstant, stateProvince, country.
  */
 public function testResolveDefaults()
 {
     $params = array('prefix_id' => 3, 'suffix_id' => 2, 'gender_id' => 2, 'birth_date' => '1983-12-13');
     $params['address'][1] = array('location_type_id' => 1, 'is_primary' => 1, 'country_id' => 1228, 'state_province_id' => 1004);
     CRM_Contact_BAO_Contact::resolveDefaults($params);
     //check the resolve values.
     $genders = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
     $this->assertEquals($genders[$params['gender_id']], $params['gender'], 'Check for gender.');
     $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
     $this->assertEquals($prefix[$params['prefix_id']], $params['prefix'], 'Check for prefix.');
     $suffix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id');
     $this->assertEquals($suffix[$params['suffix_id']], $params['suffix'], 'Check for suffix.');
     $this->assertEquals(CRM_Core_PseudoConstant::stateProvince($params['address'][1]['state_province_id']), $params['address'][1]['state_province'], 'Check for state province.');
     $this->assertEquals(CRM_Core_PseudoConstant::country($params['address'][1]['country_id']), $params['address'][1]['country'], 'Check for country.');
 }
Пример #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;
 }
Пример #3
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;
 }
Пример #4
0
/**
 *
 * @param <type> $params
 * @param <type> $locationArray
 * @return <type>
 */
function _civicrm_location_update($params, $locations)
{
    // convert api params to 3.0 format.
    if ('3.0' != CRM_Utils_Array::value('version', $params)) {
        _civicrm_format_params_v2_to_v3($params);
    }
    $contact = array('contact_id' => $params['contact_id']);
    $primary = $billing = array();
    // copy params value in contact array.
    foreach (array('email', 'phone', 'im', 'openid') as $name) {
        if (CRM_Utils_Array::value($name, $params) && is_array($params[$name])) {
            $blockCount = 0;
            $contact[$name] = array();
            foreach ($params[$name] as $val) {
                $contact[$name][++$blockCount] = $val;
                // check for primary and billing.
                if (CRM_Utils_Array::value('is_primary', $val)) {
                    $primary[$name][$blockCount] = true;
                }
                if (CRM_Utils_Array::value('is_billing', $val)) {
                    $primary[$name][$blockCount] = true;
                }
            }
        } else {
            // get values from db blocks so we dont lose them.
            if (!CRM_Utils_Array::value($name, $locations) || !is_array($locations[$name])) {
                continue;
            }
            $contact[$name] = $locations[$name];
        }
    }
    $addressCount = 1;
    if (CRM_Utils_Array::value(1, $params['address']) && !empty($params['address'][1])) {
        $contact['address'][$addressCount] = $params['address'][1];
        // check for primary and billing address.
        if (CRM_Utils_Array::value('is_primary', $params['address'][1])) {
            $primary['address'][$addressCount] = true;
        }
        if (CRM_Utils_Array::value('is_billing', $params['address'][1])) {
            $billing['address'][$addressCount] = true;
        }
        // format state and country.
        foreach (array('state_province', 'country') as $field) {
            $fName = $field == 'state_province' ? 'stateProvinceAbbreviation' : 'countryIsoCode';
            if (CRM_Utils_Array::value($field, $contact['address'][$addressCount]) && is_numeric($contact['address'][$addressCount][$field])) {
                $fValue =& $contact['address'][$addressCount][$field];
                eval('$fValue = CRM_Core_PseudoConstant::' . $fName . '( $fValue );');
                //kill the reference.
                unset($fValue);
            }
        }
    }
    //handle primary and billing reset.
    foreach (array('email', 'phone', 'im', 'address', 'openid') as $name) {
        if (!array_key_exists($name, $contact) || CRM_Utils_System::isNull($contact[$name])) {
            continue;
        }
        $errorMsg = null;
        $primaryBlockIndex = $billingBlockIndex = 0;
        if (array_key_exists($name, $primary)) {
            if (count($primary[$name]) > 1) {
                $errorMsg .= ts("<br />Multiple Primary %1.", array(1 => $name));
            } else {
                $primaryBlockIndex = key($primary[$name]);
            }
        }
        if (array_key_exists($name, $billing)) {
            if (count($billing[$name]) > 1) {
                $errorMsg .= ts("<br />Multiple Billing %1.", array(1 => $name));
            } else {
                $billingBlockIndex = key($billing[$name]);
            }
        }
        if ($errorMsg) {
            return civicrm_create_error($errorMsg);
        }
        foreach ($contact[$name] as $count => &$values) {
            if ($primaryBlockIndex && $count != $primaryBlockIndex) {
                $values['is_primary'] = false;
            }
            if ($billingBlockIndex && $count != $billingBlockIndex) {
                $values['is_billing'] = false;
            }
            // kill the reference.
            unset($values);
        }
    }
    // get all ids if not present.
    require_once 'CRM/Contact/BAO/Contact.php';
    CRM_Contact_BAO_Contact::resolveDefaults($contact, true);
    $location = CRM_Core_BAO_Location::create($contact);
    if (empty($location)) {
        return civicrm_create_error(ts("Location not created"));
    }
    $locArray = array();
    $blocks = array('address', 'phone', 'email', 'im', 'openid');
    $locationTypeId = null;
    foreach ($blocks as $block) {
        for ($i = 0; $i < count($location[$block]); $i++) {
            $locArray[$block][$i] = $location[$block][$i]->id;
            $locationTypeId = $location[$block][$i]->location_type_id;
        }
    }
    // CRM-4800
    if (3.0 != CRM_Utils_Array::value('version', $params)) {
        $locArray['location_type_id'] = $locationTypeId;
    }
    return civicrm_create_success($locArray);
}
Пример #5
0
 /**
  * Method for creating contact.
  */
 public function createContact(&$formatted, &$contactFields, $onDuplicate, $contactId = NULL, $requiredCheck = TRUE, $dedupeRuleGroupID = NULL)
 {
     $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 'CRM/Utils/DeprecatedUtils.php';
     //@todo direct call to API function not supported.
     // setting required check to false, CRM-2839
     // plus we do our own required check in import
     $error = _civicrm_api3_deprecated_contact_check_params($formatted, $dupeCheck, TRUE, FALSE, $dedupeRuleGroupID);
     if (is_null($error) && civicrm_error(_civicrm_api3_deprecated_validate_formatted_contact($formatted))) {
         $error = _civicrm_api3_deprecated_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 && is_object($newContact) && property_exists($newContact, 'address') && $newContact->address) {
         foreach ($newContact->address as $address) {
             if (!empty($address['street_address']) && (empty($address['street_number']) || empty($address['street_name']))) {
                 $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;
}
Пример #7
0
 /**
  * Heart of the viewing process. The runner gets all the meta data for
  * the contact and calls the appropriate type of page to view.
  *
  * @return void
  * @access public
  *
  */
 function preProcess()
 {
     parent::preProcess();
     // we need to retrieve privacy preferences
     // to (un)display the 'Send an Email' link
     $params = array();
     $defaults = array();
     $ids = array();
     $params['id'] = $params['contact_id'] = $this->_contactId;
     CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids);
     CRM_Contact_BAO_Contact::resolveDefaults($defaults);
     $this->assign($defaults);
 }
Пример #8
0
 /**
  * Heart of the viewing process. The runner gets all the meta data for
  * the contact and calls the appropriate type of page to view.
  *
  * @return void
  * @access public
  *
  */
 function preProcess()
 {
     parent::preProcess();
     // we need to retrieve privacy preferences
     // to (un)display the 'Send an Email' link
     $params = array();
     $defaults = array();
     $ids = array();
     $params['id'] = $params['contact_id'] = $this->_contactId;
     CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids);
     CRM_Contact_BAO_Contact::resolveDefaults($defaults);
     $this->assign($defaults);
     // also create the form element for the activity links box
     $controller =& new CRM_Core_Controller_Simple('CRM_Activity_Form_ActivityLinks', ts('Activity Links'), null);
     $controller->setEmbedded(true);
     $controller->run();
 }
Пример #9
0
/**
 * 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_params(&$params, &$values)
{
    // copy all the contact and contact_type fields as is
    $fields =& CRM_Contact_DAO_Contact::fields();
    _crm_store_values($fields, $params, $values);
    require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_DAO_" . $values['contact_type']) . ".php";
    eval('$fields =& CRM_Contact_DAO_' . $values['contact_type'] . '::fields( );');
    _crm_store_values($fields, $params, $values);
    $ids = array("prefix", "suffix", "gender");
    foreach ($ids as $id) {
        if (array_key_exists($id, $params)) {
            $values[$id] = $params[$id];
        }
    }
    $locationTypeNeeded = false;
    $values['location'] = array();
    $values['location'][1] = array();
    $fields =& CRM_Core_DAO_Location::fields();
    if (_crm_store_values($fields, $params, $values['location'][1])) {
        $locationTypeNeeded = true;
    }
    if (array_key_exists('location_type', $params)) {
        $locationTypes = CRM_Core_PseudoConstant::locationType();
        $locationType = $locationTypeId = '';
        //fix for CRM-707
        if (!is_numeric($params['location_type'])) {
            $locationTypeName = $params['location_type'];
            $locationTypeId = CRM_Utils_Array::value($params['location_type'], $locationTypes);
        } else {
            $locationTypeName = CRM_Utils_Array::value($params['location_type'], $locationTypes);
            $locationTypeId = $params['location_type'];
        }
        $values['location'][1]['location_type'] = $locationTypeName;
        $values['location'][1]['location_type_id'] = $locationTypeId;
    }
    $values['location'][1]['address'] = array();
    $fields =& CRM_Core_DAO_Address::fields();
    // ignore the note field in address for now
    unset($fields['note']);
    if (_crm_store_values($fields, $params, $values['location'][1]['address'])) {
        $locationTypeNeeded = true;
    }
    $ids = array('county', 'country', 'state_province', 'supplemental_address_1', 'supplemental_address_2', 'StateProvince.name');
    foreach ($ids as $id) {
        if (array_key_exists($id, $params)) {
            $values['location'][1]['address'][$id] = $params[$id];
            $locationTypeNeeded = true;
        }
    }
    $blocks = array('Email', 'Phone', 'IM');
    foreach ($blocks as $block) {
        $name = strtolower($block);
        $values['location'][1][$name] = array();
        $values['location'][1][$name][1] = array();
        require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Core_DAO_" . $block) . ".php";
        eval('$fields =& CRM_Core_DAO_' . $block . '::fields( );');
        if (_crm_store_values($fields, $params, $values['location'][1][$name][1])) {
            $locationTypeNeeded = true;
            $values['location'][1][$name][1]['is_primary'] = 1;
        }
    }
    if (!array_key_exists('first_name', $params) || !array_key_exists('last_name', $params)) {
        // make sure phone and email are valid strings
        if (array_key_exists('email', $params) && !CRM_Utils_Rule::email($params['email'])) {
            return _crm_error("Email not valid " . $params['email']);
        }
    }
    if (array_key_exists('im', $params)) {
        $values['location'][1]['im'][1]['name'] = $params['im'];
        $locationTypeNeeded = true;
    }
    if (array_key_exists('im_provider', $params)) {
        $values['location'][1]['im'][1]['provider'] = $params['im_provider'];
        $locationTypeNeeded = true;
    }
    if ($locationTypeNeeded) {
        if (!array_key_exists('location_type_id', $values['location'][1])) {
            require_once 'CRM/Core/BAO/LocationType.php';
            $locationType =& CRM_Core_BAO_LocationType::getDefault();
            $values['location'][1]['location_type_id'] = $locationType->id;
            $values['location'][1]['location_type'] = $locationType->name;
        }
        $values['location'][1]['is_primary'] = true;
    } else {
        unset($values['location']);
    }
    if (array_key_exists('note', $params)) {
        $values['note'] = $params['note'];
    }
    $values['custom'] = array();
    $customFields = CRM_Core_BAO_CustomField::getFields($values['contact_type']);
    foreach ($params as $key => $value) {
        if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
            /* check if it's a valid custom field id */
            if (!array_key_exists($customFieldID, $customFields)) {
                return _crm_error('Invalid custom field ID');
            }
            /* validate the data against the CF type */
            //CRM_Core_Error::debug( $value, $customFields[$customFieldID] );
            $valid = CRM_Core_BAO_CustomValue::typecheck($customFields[$customFieldID][2], $value);
            if (!$valid) {
                return _crm_error('Invalid value for custom field ' . $customFields[$customFieldID][0]);
            }
            // fix the date field if so
            if ($customFields[$customFieldID][2] == 'Date') {
                $value = str_replace('-', '', $value);
            }
            $newMulValues = array();
            if ($customFields[$customFieldID][3] == 'CheckBox' || $customFields[$customFieldID][3] == 'Multi-Select') {
                $value = str_replace("|", ",", $value);
                $mulValues = explode(',', $value);
                $custuomOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                foreach ($mulValues as $v1) {
                    foreach ($custuomOption as $v2) {
                        if (strtolower($v2['label']) == strtolower(trim($v1))) {
                            $newMulValues[] = $v2['value'];
                        }
                    }
                }
                $value = implode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, $newMulValues);
            } else {
                if ($customFields[$customFieldID][3] == 'Select' || $customFields[$customFieldID][3] == 'Radio') {
                    $custuomOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                    foreach ($custuomOption as $v2) {
                        if (strtolower($v2['label']) == strtolower(trim($value))) {
                            $value = $v2['value'];
                            break;
                        }
                    }
                }
            }
            $values['custom'][$customFieldID] = array('value' => $value, 'extends' => $customFields[$customFieldID][3], 'type' => $customFields[$customFieldID][2], 'custom_field_id' => $customFieldID);
        }
    }
    CRM_Contact_BAO_Contact::resolveDefaults($values, true);
    return null;
}
Пример #10
0
function &crm_create_contact_formatted(&$params, $onDuplicate)
{
    _crm_initialize();
    // return error if we have no params
    if (empty($params)) {
        return _crm_error('Input Parameters empty');
    }
    $error = _crm_required_formatted_contact($params);
    if (is_a($error, 'CRM_Core_Error')) {
        return $error;
    }
    $error = _crm_validate_formatted_contact($params);
    if (is_a($error, 'CRM_Core_Error')) {
        return $error;
    }
    require_once 'CRM/Import/Parser.php';
    if ($onDuplicate != CRM_IMPORT_PARSER_DUPLICATE_NOCHECK) {
        $error = _crm_duplicate_formatted_contact($params);
        if (is_a($error, 'CRM_Core_Error')) {
            return $error;
        }
    }
    $ids = array();
    CRM_Contact_BAO_Contact::resolveDefaults($params, true);
    $contact = CRM_Contact_BAO_Contact::create($params, $ids, count($params['location']));
    return $contact;
}
Пример #11
0
/**
 *  Update a specified location with the provided property values.
 * 
 *  @param  object  $contact        A valid Contact object (passed by reference).
 *  @param  string  $location_id    Valid (db-level) id for location to be updated. 
 *  @param  Array   $params         Associative array of property name/value pairs to be updated
 *
 *  @return Location object with updated property values
 * 
 *  @access public
 *
 */
function crm_update_location(&$contact, $location_id, $params)
{
    _crm_initialize();
    if (!isset($contact->id)) {
        return _crm_error('$contact is not valid contact datatype');
    }
    $locationId = (int) $location_id;
    if ($locationId == 0) {
        return _crm_error('missing or invalid $location_id');
    }
    // $locationNumber is the contact-level number of the location (1, 2, 3, etc.)
    $locationNumber = null;
    $locations =& crm_get_locations($contact);
    foreach ($locations as $locNumber => $locValue) {
        if ($locValue->id == $locationId) {
            $locationNumber = $locNumber;
            break;
        }
    }
    if (!$locationNumber) {
        return _crm_error('invalid $location_id');
    }
    $values = array('contact_id' => $contact->id, 'location' => array($locationNumber => array()));
    $loc =& $values['location'][$locationNumber];
    $loc['address'] = array();
    require_once 'CRM/Core/DAO/Address.php';
    $fields =& CRM_Core_DAO_Address::fields();
    _crm_store_values($fields, $params, $loc['address']);
    //$ids = array( 'county', 'country_id', 'state_province_id', 'supplemental_address_1', 'supplemental_address_2', 'StateProvince.name' );
    $ids = array('county', 'country_id', 'country', 'state_province_id', 'state_province', 'supplemental_address_1', 'supplemental_address_2', 'StateProvince.name', 'street_address');
    foreach ($ids as $id) {
        if (array_key_exists($id, $params)) {
            $loc['address'][$id] = $params[$id];
        }
    }
    if (is_numeric($loc['address']['state_province'])) {
        $loc['address']['state_province'] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($loc['address']['state_province']);
    }
    if (is_numeric($loc['address']['country'])) {
        $loc['address']['country'] = CRM_Core_PseudoConstant::countryIsoCode($loc['address']['country']);
    }
    if (array_key_exists('location_type_id', $params)) {
        $loc['location_type_id'] = $params['location_type_id'];
    }
    if (array_key_exists('location_type', $params)) {
        $locTypes =& CRM_Core_PseudoConstant::locationType();
        $loc['location_type_id'] = CRM_Utils_Array::key($params['location_type'], $locTypes);
    }
    if (array_key_exists('name', $params)) {
        $loc['name'] = $params['name'];
    }
    if (array_key_exists('is_primary', $params)) {
        $loc['is_primary'] = (int) $params['is_primary'];
    }
    $loc['id'] = $locationId;
    $blocks = array('Email', 'Phone', 'IM');
    foreach ($blocks as $block) {
        $name = strtolower($block);
        $loc[$name] = array();
        if ($params[$name]) {
            $count = 1;
            foreach ($params[$name] as $val) {
                CRM_Core_DAO::storeValues($val, $loc[$name][$count++]);
            }
        }
    }
    $par = array('id' => $contact->id, 'contact_id' => $contact->id);
    $contact = CRM_Contact_BAO_Contact::retrieve($par, $defaults, $ids);
    CRM_Contact_BAO_Contact::resolveDefaults($values, true);
    $location = CRM_Core_BAO_Location::add($values, $ids, $locationNumber);
    return $location;
}
Пример #12
0
 /**
  * View summary details of a contact
  *
  * @return void
  * @access public
  */
 function view()
 {
     $params = array();
     $defaults = array();
     $ids = array();
     $params['id'] = $params['contact_id'] = $this->_contactId;
     $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids);
     CRM_Contact_BAO_Contact::resolveDefaults($defaults);
     if (CRM_Utils_Array::value('gender_id', $defaults)) {
         $gender = CRM_Core_PseudoConstant::gender();
         $defaults['gender_display'] = $gender[CRM_Utils_Array::value('gender_id', $defaults)];
     }
     // get the list of all the categories
     $tag =& CRM_Core_PseudoConstant::tag();
     // get categories for the contact id
     require_once 'CRM/Core/BAO/EntityTag.php';
     $entityTag =& CRM_Core_BAO_EntityTag::getTag('civicrm_contact', $this->_contactId);
     if ($entityTag) {
         $categories = array();
         foreach ($entityTag as $key) {
             $categories[] = $tag[$key];
         }
         $defaults['contactTag'] = implode(', ', $categories);
     }
     $defaults['privacy_values'] = CRM_Core_SelectValues::privacy();
     $this->assign($defaults);
     $this->setShowHide($defaults);
     // get the contributions, new style of doing stuff
     // do the below only if the person has access to contributions
     $config =& CRM_Core_Config::singleton();
     if (CRM_Utils_System::accessCiviContribute()) {
         $this->assign('accessContribution', true);
         $controller =& new CRM_Core_Controller_Simple('CRM_Contribute_Form_Search', ts('Contributions'), $this->_action);
         $controller->setEmbedded(true);
         $controller->reset();
         $controller->set('limit', 3);
         $controller->set('force', 1);
         $controller->set('cid', $this->_contactId);
         $controller->set('context', 'basic');
         $controller->process();
         $controller->run();
     } else {
         $this->assign('accessContribution', false);
     }
     //add link to CMS user
     if ($uid = CRM_Core_BAO_UFMatch::getUFId($this->_contactId)) {
         if ($config->userFramework == 'Drupal') {
             $url = CRM_Utils_System::url('user/' . $uid);
         } else {
             //$url = CRM_Utils_System::url( 'option=com_users&task=editA&hidemainmenu=1&id=' . $uid );
             $url = $config->userFrameworkBaseURL . 'index2.php?option=com_users&task=editA&hidemainmenu=1&id=' . $uid;
         }
         $this->assign('url', $url);
     }
 }
Пример #13
0
 /**
  * Heart of the vCard data assignment process. The runner gets all the meta
  * data for the contact and calls the writeVcard method to output the vCard
  * to the user.
  *
  * @return void
  */
 function run()
 {
     $this->preProcess();
     $params = array();
     $defaults = array();
     $ids = array();
     $params['id'] = $params['contact_id'] = $this->_contactId;
     $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids);
     CRM_Contact_BAO_Contact::resolveDefaults($defaults);
     // now that we have the contact's data - let's build the vCard
     // TODO: non-US-ASCII support (requires changes to the Contact_Vcard_Build class)
     $vcard =& new Contact_Vcard_Build('2.1');
     if ($defaults['contact_type'] == 'Individual') {
         $vcard->setName($defaults['last_name'], $defaults['first_name'], $defaults['middle_name'], $defaults['prefix'], $defaults['suffix']);
     } elseif ($defaults['contact_type'] == 'Organization') {
         $vcard->setName($defaults['organization_name'], '', '', '', '');
     } elseif ($defaults['contact_type'] == 'Household') {
         $vcard->setName($defaults['household_name'], '', '', '', '');
     }
     $vcard->setFormattedName($defaults['display_name']);
     $vcard->setSortString($defaults['sort_name']);
     if ($defaults['nick_name']) {
         $vcard->addNickname($defaults['nick_name']);
     }
     if ($defaults['job_title']) {
         $vcard->setTitle($defaults['job_title']);
     }
     if ($defaults['birth_date']) {
         $vcard->setBirthday($defaults['birth_date']);
     }
     if ($defaults['home_URL']) {
         $vcard->setURL($defaults['home_URL']);
     }
     // TODO: $vcard->setGeo($lat, $lon);
     foreach ($defaults['location'] as $location) {
         // we don't keep PO boxes in separate fields
         $pob = '';
         $extend = $location['address']['supplemental_address_1'];
         if ($location['address']['supplemental_address_2']) {
             $extend .= ', ' . $location['address']['supplemental_address_2'];
         }
         $street = $location['address']['street_address'];
         $locality = $location['address']['city'];
         $region = $location['address']['state_province'];
         $postcode = $location['address']['postal_code'];
         if ($location['address']['postal_code_suffix']) {
             $postcode .= '-' . $location['address']['postal_code_suffix'];
         }
         $country = $location['address']['country'];
         $vcard->addAddress($pob, $extend, $street, $locality, $region, $postcode, $country);
         if ($location['vcard_name']) {
             $vcard->addParam('TYPE', $location['vcard_name']);
         }
         if ($location['is_primary']) {
             $vcard->addParam('TYPE', 'PREF');
         }
         foreach ($location['phone'] as $phone) {
             $vcard->addTelephone($phone['phone']);
             if ($location['vcard_name']) {
                 $vcard->addParam('TYPE', $location['vcard_name']);
             }
             if ($phone['is_primary']) {
                 $vcard->addParam('TYPE', 'PREF');
             }
         }
         foreach ($location['email'] as $email) {
             $vcard->addEmail($email['email']);
             if ($location['vcard_name']) {
                 $vcard->addParam('TYPE', $location['vcard_name']);
             }
             if ($email['is_primary']) {
                 $vcard->addParam('TYPE', 'PREF');
             }
         }
     }
     // all that's left is sending the vCard to the browser
     $filename = CRM_Utils_String::munge($defaults['display_name']);
     $vcard->send($filename . '.vcf', 'attachment', 'utf-8');
     exit;
 }