/** * Function to create various elements of location block * * @param array $params (reference ) an assoc array of name/value pairs * @param boolean $fixAddress true if you need to fix (format) address values * before inserting in db * * @param null $entity * * @return array $location * @access public * @static */ static function create(&$params, $fixAddress = TRUE, $entity = NULL) { $location = array(); if (!self::dataExists($params)) { return $location; } // create location blocks. foreach (self::$blocks as $block) { if ($block != 'address') { $location[$block] = CRM_Core_BAO_Block::create($block, $params, $entity); } else { $location[$block] = CRM_Core_BAO_Address::create($params, $fixAddress, $entity); } } if ($entity) { // this is a special case for adding values in location block table $entityElements = array('entity_table' => $params['entity_table'], 'entity_id' => $params['entity_id']); $location['id'] = self::createLocBlock($location, $entityElements); } else { // when we come from a form which displays all the location elements (like the edit form or the inline block // elements, we can skip the below check. The below check adds quite a feq queries to an already overloaded // form if (!CRM_Utils_Array::value('updateBlankLocInfo', $params, FALSE)) { // make sure contact should have only one primary block, CRM-5051 self::checkPrimaryBlocks(CRM_Utils_Array::value('contact_id', $params)); } } return $location; }
/** * Function to create various elements of location block * * @param array $params (reference ) an assoc array of name/value pairs * @param boolean $fixAddress true if you need to fix (format) address values * before inserting in db * * @return array $location * @access public * @static */ static function create(&$params, $fixAddress = true, $entity = null) { $location = array(); if (!self::dataExists($params)) { return $location; } // create location blocks. foreach (self::$blocks as $block) { if ($block != 'address') { eval('$location[$block] = CRM_Core_BAO_Block::create( $block, $params, $entity );'); } else { $location[$block] = CRM_Core_BAO_Address::create($params, $fixAddress, $entity); } } if ($entity) { // this is a special case for adding values in location block table $entityElements = array('entity_table' => $params['entity_table'], 'entity_id' => $params['entity_id']); $location['id'] = self::createLocBlock($location, $entityElements); } else { // make sure contact should have only one primary block, CRM-5051 self::checkPrimaryBlocks(CRM_Utils_Array::value('contact_id', $params)); } return $location; }
/** * Process the form. * * @return void */ public function postProcess() { $params = $this->exportValues(); // Process / save address $params['contact_id'] = $this->_contactId; $params['updateBlankLocInfo'] = TRUE; // process shared contact address. CRM_Contact_BAO_Contact_Utils::processSharedAddress($params['address']); if ($this->_parseStreetAddress) { CRM_Contact_Form_Contact::parseAddress($params); } if ($this->_addressId > 0) { $params['address'][$this->_locBlockNo]['id'] = $this->_addressId; } // save address changes $address = CRM_Core_BAO_Address::create($params, TRUE); $this->log(); $this->ajaxResponse['addressId'] = $address[0]->id; $this->response(); }
/** * process the form * * @return void * @access public */ public function postProcess() { $params = $this->exportValues(); // need to process / save address $params['contact_id'] = $this->_contactId; $params['updateBlankLocInfo'] = TRUE; // process shared contact address. CRM_Contact_BAO_Contact_Utils::processSharedAddress($params['address']); if ($this->_parseStreetAddress) { CRM_Contact_Form_Contact::parseAddress($params); } if ($this->_addressId > 0) { $params['address'][$this->_locBlockNo]['id'] = $this->_addressId; } // save address changes $address = CRM_Core_BAO_Address::create($params, TRUE); // make entry in log table CRM_Core_BAO_Log::register($this->_contactId, 'civicrm_contact', $this->_contactId); $response = array('status' => 'save', 'addressId' => $address[0]->id); $this->postProcessHook(); echo json_encode($response); CRM_Utils_System::civiExit(); }
/** * GetValues() method (get Address fields) */ public function testGetValues() { $contactId = Contact::createIndividual(); $params = array(); $params['address']['1'] = array('street_address' => 'Oberoi Garden', 'supplemental_address_1' => 'Attn: Accounting', 'supplemental_address_2' => 'Powai', 'city' => 'Athens', 'postal_code' => '01903', 'state_province_id' => '1000', 'country_id' => '1228', 'geo_code_1' => '18.219023', 'geo_code_2' => '-105.00973', 'location_type_id' => '1', 'is_primary' => '1', 'is_billing' => '0'); $params['contact_id'] = $contactId; $fixAddress = TRUE; CRM_Core_BAO_Address::create($params, $fixAddress, $entity = NULL); $addressId = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id', 'Database check for created address.'); $entityBlock = array('contact_id' => $contactId); $address = CRM_Core_BAO_Address::getValues($entityBlock); $this->assertEquals($address[1]['id'], $addressId); $this->assertEquals($address[1]['contact_id'], $contactId); $this->assertEquals($address[1]['street_address'], 'Oberoi Garden'); Contact::delete($contactId); }