CRM-17654 Allow for multiple relationship types to be used in the relationship report
authorSeamus Lee <seamuslee001@gmail.com>
Thu, 3 Dec 2015 05:58:54 +0000 (05:58 +0000)
committerSeamus Lee <seamuslee001@gmail.com>
Thu, 3 Dec 2015 06:07:10 +0000 (06:07 +0000)
CRM/Report/Form/Contact/Relationship.php

index 23bff4e533f97e6caa490b1730645000e073c0c0..615f77320b73b556c8155be0aa00117e0879eb55 100644 (file)
@@ -234,11 +234,8 @@ class CRM_Report_Form_Contact_Relationship extends CRM_Report_Form {
           ),
           'relationship_type_id' => array(
             'title' => ts('Relationship'),
-            'operatorType' => CRM_Report_Form::OP_SELECT,
-            'options' => array(
-              '' => '- any relationship type -',
-            ) +
-            CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, NULL, TRUE),
+            'operatorType' => CRM_Report_Form::OP_MULTISELECT,
+            'options' => CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, NULL, TRUE),
             'type' => CRM_Utils_Type::T_INT,
           ),
           'start_date' => array(
@@ -507,9 +504,13 @@ class CRM_Report_Form_Contact_Relationship extends CRM_Report_Form {
         //for displaying relationship type filter
         if ($value['title'] == 'Relationship') {
           $relTypes = CRM_Core_PseudoConstant::relationshipType();
-          $statistics['filters'][$id]['value'] = 'Is equal to ' .
-            $relTypes[$this->_params['relationship_type_id_value']]['label_' .
-            $this->relationType];
+          $op = 'Is one of ';
+          $relationshipTypes = array();
+          foreach ($this->_params['relationship_type_id_value'] as $relationship) {
+            $relationshipTypes[] = $relTypes[$relationship]['label_' . $this->relationType];
+          }
+          $statistics['filters'][$id]['value'] = $op .
+            implode(', ', $relationshipTypes);
         }
 
         //for displaying relationship status
@@ -558,10 +559,17 @@ class CRM_Report_Form_Contact_Relationship extends CRM_Report_Form {
     $this->relationType = NULL;
     $relType = array();
     if (!empty($this->_params['relationship_type_id_value'])) {
-      $relType = explode('_', $this->_params['relationship_type_id_value']);
-
-      $this->relationType = $relType[1] . '_' . $relType[2];
-      $this->_params['relationship_type_id_value'] = intval($relType[0]);
+      $relationshipTypes = array();
+      $direction = array();
+      foreach ($this->_params['relationship_type_id_value'] as $relationship_type) {
+        $relType = explode('_', $relationship_type);
+        $direction[] = $relType[1] . '_' . $relType[2];
+        $relationshipTypes[] = intval($relType[0]);
+      }
+      // Lets take the first relationship type to guide us in the relationship direction
+      // we should use.
+      $this->relationType = $direction[0];
+      $this->_params['relationship_type_id_value'] = $relationshipTypes;
     }
 
     $this->buildACLClause(array(