Ejemplo n.º 1
0
 /**
  * Add() method (create and update modes)
  */
 public function testAdd()
 {
     $contactId = $this->individualCreate();
     $params = array();
     $params = array('name' => 'jane.doe', 'provider_id' => 1, 'is_primary' => 1, 'location_type_id' => 1, 'contact_id' => $contactId);
     CRM_Core_BAO_IM::add($params);
     $imId = $this->assertDBNotNull('CRM_Core_DAO_IM', 'jane.doe', 'id', 'name', 'Database check for created IM name.');
     // Now call add() to modify an existing IM
     $params = array();
     $params = array('id' => $imId, 'contact_id' => $contactId, 'provider_id' => 3, 'name' => 'doe.jane');
     CRM_Core_BAO_IM::add($params);
     $isEditIM = $this->assertDBNotNull('CRM_Core_DAO_IM', $imId, 'provider_id', 'id', 'Database check on updated IM provider_name record.');
     $this->assertEquals($isEditIM, 3, 'Verify IM provider_id value is 3.');
     $isEditIM = $this->assertDBNotNull('CRM_Core_DAO_IM', $imId, 'name', 'id', 'Database check on updated IM name record.');
     $this->assertEquals($isEditIM, 'doe.jane', 'Verify IM provider_id value is doe.jane.');
     $this->contactDelete($contactId);
 }
Ejemplo n.º 2
0
 /**
  * takes an associative array and creates a contact object
  *
  * the function extract all the params it needs to initialize the create a
  * contact object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array  $params         (reference ) an assoc array of name/value pairs
  * @param array  $ids            the array that holds all the db ids
  * @param array  $locationId     
  *
  * @return object   CRM_Core_BAO_Location object on success, null otherwise
  * @access public
  * @static
  */
 function add(&$params, &$ids, $locationId)
 {
     if (!CRM_Core_BAO_Location::dataExists($params, $locationId, $ids)) {
         return null;
     }
     $location =& new CRM_Core_BAO_Location();
     if (!isset($params['contact_id'])) {
         require_once 'CRM/Core/BAO/Domain.php';
         $location->entity_table = CRM_Core_BAO_Domain::getTableName();
         $location->entity_id = $params['domain_id'];
     } else {
         $location->entity_table = CRM_Contact_BAO_Contact::getTableName();
         $location->entity_id = $params['contact_id'];
     }
     $location->location_type_id = CRM_Utils_Array::value('location_type_id', $params['location'][$locationId]);
     $location->name = CRM_Utils_Array::value('name', $params['location'][$locationId]);
     $location->is_primary = CRM_Utils_Array::value('is_primary', $params['location'][$locationId], false);
     // check if there exists another location has is_primary set, and if so reset that
     // if no location has is_primary, make this one is_primart
     if ($location->is_primary) {
         // reset all other locations with the same entity table entity id
         $sql = "UPDATE " . CRM_Core_BAO_Location::getTableName() . "\n SET is_primary = 0 WHERE \n entity_table = '{$location->entity_table}' AND\n entity_id    = '{$location->entity_id}' ";
         CRM_Core_DAO::executeQuery($sql);
     } else {
         // make sure there is at once location with is_primary set
         $sql = "SELECT count( " . CRM_Core_BAO_Location::getTableName() . ".id )\n FROM " . CRM_Core_BAO_Location::getTableName() . " WHERE\n entity_table = '{$location->entity_table}' AND\n entity_id    = '{$location->entity_id}'    AND\n is_primary   = 1";
         $count = CRM_Core_DAO::singleValueQuery($sql);
         if ($count == 0) {
             $location->is_primary = true;
         }
     }
     $location->id = CRM_Utils_Array::value('id', $ids['location'][$locationId]);
     $location->save();
     $params['location'][$locationId]['id'] = $location->id;
     $address_object = CRM_Core_BAO_Address::add($params, $ids, $locationId);
     $location->address = $address_object;
     // set this to true if this has been made the primary IM.
     // the rule is the first entered value is the primary object
     $isPrimaryPhone = $isPrimaryEmail = $isPrimaryIM = true;
     $location->phone = array();
     $location->email = array();
     $location->im = array();
     for ($i = 1; $i <= CRM_CONTACT_FORM_LOCATION_BLOCKS; $i++) {
         $location->phone[$i] = CRM_Core_BAO_Phone::add($params, $ids, $locationId, $i, $isPrimaryPhone);
         $location->email[$i] = CRM_Core_BAO_Email::add($params, $ids, $locationId, $i, $isPrimaryEmail);
         $location->im[$i] = CRM_Core_BAO_IM::add($params, $ids, $locationId, $i, $isPrimaryIM);
     }
     return $location;
 }