case 'relation_active_period_date_low':
case 'relation_target_name':
case 'relation_status':
+ case 'relation_description':
case 'relation_date_low':
case 'relation_date_high':
$this->relationship($values);
// also get values array for relation_target_name
// for relationship search we always do wildcard
$relationType = $this->getWhereValues('relation_type_id', $grouping);
+ $description = $this->getWhereValues('relation_description', $grouping);
$targetName = $this->getWhereValues('relation_target_name', $grouping);
$relStatus = $this->getWhereValues('relation_status', $grouping);
$targetGroup = $this->getWhereValues('relation_target_group', $grouping);
}
}
+ // Description
+ if (!empty($description[2]) && trim($description[2])) {
+ $this->_qill[$grouping][] = ts('Relationship description - ' . $description[2]);
+ $description = CRM_Core_DAO::escapeString(trim($description[2]));
+ $where[$grouping][] = "civicrm_relationship.description LIKE '%{$description}%'";
+ }
+
// Note we do not currently set mySql to handle timezones, so doing this the old-fashioned way
$today = date('Ymd');
//check for active, inactive and all relation status
}
/**
- * @param $form
+ * @param CRM_Core_Form_Search $form
*/
public static function relationship(&$form) {
$form->add('hidden', 'hidden_relationship', 1);
- $allRelationshipType = [];
+ $form->add('text', 'relation_description', ts('Description'), ['class' => 'twenty']);
$allRelationshipType = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE);
$form->add('select', 'relation_type_id', ts('Relationship Type'), ['' => ts('- select -')] + $allRelationshipType, FALSE, ['multiple' => TRUE, 'class' => 'crm-select2']);
$form->addElement('text', 'relation_target_name', ts('Target Contact'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
}
+ public function testRelationshipDescription() {
+ $relType = $this->callAPISuccess('RelationshipType', 'create', [
+ 'name_a_b' => uniqid('a'),
+ 'name_b_a' => uniqid('b'),
+ ]);
+ $contactID_a = $this->individualCreate([], 1);
+ $contactID_b = $this->individualCreate([], 2);
+ $contactID_c = $this->individualCreate([], 3);
+ $contactID_d = $this->individualCreate([], 4);
+ $desc = uniqid('rel', TRUE);
+ $this->callAPISuccess('Relationship', 'create', [
+ 'contact_id_a' => $contactID_a,
+ 'contact_id_b' => $contactID_b,
+ 'relationship_type_id' => $relType['id'],
+ 'is_active' => 1,
+ 'description' => $desc,
+ ]);
+ $this->callAPISuccess('Relationship', 'create', [
+ 'contact_id_a' => $contactID_c,
+ 'contact_id_b' => $contactID_d,
+ 'relationship_type_id' => $relType['id'],
+ 'is_active' => 1,
+ 'description' => 'nothing of interest',
+ ]);
+ $params = [
+ ['relation_description', '=', substr($desc, 3, 18), 0, 0],
+ ];
+
+ $query = new CRM_Contact_BAO_Query($params);
+ $dao = $query->searchQuery();
+ // This is a little weird but seems consistent with the behavior of the search form in general.
+ // Technically there are 2 contacts who share a relationship with the description searched for,
+ // so one might expect the search form to return both of them instead of just Contact A... but it doesn't.
+ $this->assertEquals('1', $dao->N, "Search query returns exactly 1 result?");
+ $this->assertTrue($dao->fetch(), "Search query returns success?");
+ $this->assertEquals($contactID_a, $dao->contact_id, "Search query returns contact A?");
+ }
+
public function testNonReciprocalRelationshipTargetGroupIsCorrectResults() {
$contactID_a = $this->individualCreate();
$contactID_b = $this->individualCreate();