Example #1
0
 /**
  * Delete the object records that are associated with this contact
  *
  * @param  int  $contactId id of the contact to delete
  *
  * @return void
  * @access public
  * @static
  */
 static function deleteContact($contactId)
 {
     $relationship =& new CRM_Contact_DAO_Relationship();
     $relationship->contact_id_a = $contactId;
     $relationship->delete();
     $relationship =& new CRM_Contact_DAO_Relationship();
     $relationship->contact_id_b = $contactId;
     $relationship->delete();
     require_once 'CRM/Contact/BAO/Household.php';
     CRM_Contact_BAO_Household::updatePrimaryContact(null, $contactId);
 }
Example #2
0
 /**
  * Delete the object records that are associated with this contact.
  *
  * @param int $contactId
  *   Id of the contact to delete.
  */
 public static function deleteContact($contactId)
 {
     $relationship = new CRM_Contact_DAO_Relationship();
     $relationship->contact_id_a = $contactId;
     $relationship->delete();
     $relationship = new CRM_Contact_DAO_Relationship();
     $relationship->contact_id_b = $contactId;
     $relationship->delete();
     CRM_Contact_BAO_Household::updatePrimaryContact(NULL, $contactId);
 }
 /**
  * This is the function that check/add if the relationship created is valid
  *
  * @param array  $params      (reference ) an assoc array of name/value pairs
  * @param integer $contactId  this is contact id for adding relationship
  * @param array $ids          the array that holds all the db ids  
  * 
  * @return object CRM_Contact_BAO_Relationship 
  * @access public
  * @static
  */
 function add(&$params, &$ids, $contactId)
 {
     require_once 'CRM/Utils/Hook.php';
     if (CRM_Utils_Array::value('relationship', $ids)) {
         CRM_Utils_Hook::pre('edit', 'Relationship', $ids['relationship'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Relationship', null, $params);
     }
     require_once 'CRM/Contact/BAO/Household.php';
     $relationshipTypes = CRM_Utils_Array::value('relationship_type_id', $params);
     // expolode the string with _ to get the relationship type id and to know which contact has to be inserted in
     // contact_id_a and which one in contact_id_b
     list($type, $first, $second) = explode('_', $relationshipTypes);
     ${'contact_' . $first} = CRM_Utils_Array::value('contact', $ids);
     ${'contact_' . $second} = $contactId;
     //check if the relationship type is Head of Household then update the household's primary contact with this contact.
     if ($type == 6) {
         CRM_Contact_BAO_Household::updatePrimaryContact($contact_b, $contact_a);
     }
     $relationship =& new CRM_Contact_BAO_Relationship();
     $relationship->contact_id_b = $contact_b;
     $relationship->contact_id_a = $contact_a;
     $relationship->relationship_type_id = $type;
     $relationship->is_active = 1;
     $relationship->start_date = CRM_Utils_Date::format(CRM_Utils_Array::value('start_date', $params));
     if (!$relationship->start_date) {
         $relationship->start_date = 'NULL';
     }
     $relationship->end_date = CRM_Utils_Date::format(CRM_Utils_Array::value('end_date', $params));
     if (!$relationship->end_date) {
         $relationship->end_date = 'NULL';
     }
     $relationship->id = CRM_Utils_Array::value('relationship', $ids);
     if (CRM_Utils_Array::value('relationship', $ids)) {
         CRM_Utils_Hook::post('edit', 'Relationship', $relationship->id, $relationship);
     } else {
         CRM_Utils_Hook::post('create', 'Contribution', $relationship->id, $relationship);
     }
     return $relationship->save();
 }