/** * investigates if the given household still complies * with all the requirements for a proper household entity * */ function checkHousehold($household_id) { $problems_identified = array(); // load household $household = civicrm_api3('Contact', 'getsingle', array('id' => $household_id)); // load members $members = $this->getMembers($household_id); // CHECK 1: number of members if (count($members) < CRM_Householdmerge_Logic_Configuration::getMinimumMemberCount()) { if (count($members) == 0) { $problems_identified[] = CRM_Householdmerge_Logic_Problem::createProblem('HOM0', $household_id); } else { $problems_identified[] = CRM_Householdmerge_Logic_Problem::createProblem('HOMX', $household_id, array('count' => count($members))); } } // HEAD related checks if ('hierarchy' == CRM_Householdmerge_Logic_Configuration::getHouseholdMode()) { $heads = array(); foreach ($members as $member) { if ($member['hh_relation'] == 'head') { $heads[] = $member; } } // CHECK 2: is there still a head? if (empty($heads)) { $problems_identified[] = CRM_Householdmerge_Logic_Problem::createProblem('HHN0', $household_id); } // CHECK 3: is there more than one head? if (count($heads) > 1) { $problems_identified[] = CRM_Householdmerge_Logic_Problem::createProblem('HHN2', $household_id); } // CHECK 4: does the head have a DO NOT mail/phone/sms/email $donts = CRM_Householdmerge_Logic_Configuration::getDontXXXChecks(); foreach ($heads as $head) { foreach ($donts as $field_name) { if (!empty($head[$field_name])) { $problems_identified[] = CRM_Householdmerge_Logic_Problem::createProblem('HHNC', $household_id); break; } } } // CHECK 5: does the head have certain tags $bad_tags = CRM_Householdmerge_Logic_Configuration::getBadHeadTags(); foreach ($heads as $head) { $tags = CRM_Core_BAO_EntityTag::getContactTags($head['id']); foreach ($tags as $tag) { if (in_array($tag, $bad_tags)) { $problems_identified[] = CRM_Householdmerge_Logic_Problem::createProblem('HHTG', $household_id, array('tag' => $tag)); } } } // CHECK 6: is the head also head of another household? foreach ($heads as $head) { $head_relation_id = CRM_Householdmerge_Logic_Configuration::getHeadRelationID(); $relationships_a = civicrm_api3('Relationship', 'get', array('contact_id_a' => $head['id'], 'relationship_type_id' => $head_relation_id, 'is_active' => 1)); $relationships_b = civicrm_api3('Relationship', 'get', array('contact_id_b' => $head['id'], 'relationship_type_id' => $head_relation_id, 'is_active' => 1)); if ($relationships_a['count'] + $relationships_b['count'] > 1) { $problems_identified[] = CRM_Householdmerge_Logic_Problem::createProblem('HHMM', $household_id); } } } // all member checks // CHECK 7: does one of the members not have the household address any more? $this->checkAddresses($household, $members, $problems_identified); // CHECK 8: Is there a potential new member for this household? $this->findNewMembers($household, $members, $problems_identified); // if (!empty($problems_identified)) { // $this->createActivity($household, $problems_identified, $members); // } foreach ($problems_identified as $problem) { $problem->createActivity(); } }