Skip to content

Commit 23d61bd

Browse files
Merge pull request civicrm#17 from seamuslee001/CRM-17727-4.6-fuzion
CRM-17727 Improve relationship report by adding in end_date check for active re…
2 parents 4596546 + a1f9702 commit 23d61bd

File tree

1 file changed

+47
-7
lines changed

1 file changed

+47
-7
lines changed

CRM/Report/Form/Contact/Relationship.php

+47-7
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,30 @@ public function __construct() {
219219
),
220220
'type' => CRM_Utils_Type::T_INT,
221221
),
222+
'is_valid' => array(
223+
'title' => ts('Relationship Dates Validity'),
224+
'operatorType' => CRM_Report_Form::OP_SELECT,
225+
'options' => array(
226+
NULL => ts('- Any -'),
227+
1 => ts('Not expired'),
228+
0 => ts('Expired'),
229+
),
230+
'type' => CRM_Utils_Type::T_INT,
231+
),
222232
'relationship_type_id' => array(
223233
'title' => ts('Relationship'),
224234
'operatorType' => CRM_Report_Form::OP_MULTISELECT,
225235
'options' => CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, NULL, TRUE),
226236
'type' => CRM_Utils_Type::T_INT,
227237
),
238+
'start_date' => array(
239+
'title' => ts('Start Date'),
240+
'type' => CRM_Utils_Type::T_DATE,
241+
),
242+
'end_date' => array(
243+
'title' => ts('End Date'),
244+
'type' => CRM_Utils_Type::T_DATE,
245+
),
228246
),
229247
'grouping' => 'relation-fields',
230248
),
@@ -417,13 +435,17 @@ public function where() {
417435
}
418436
}
419437
else {
420-
421-
$clause = $this->whereClause($field,
422-
$op,
423-
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
424-
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
425-
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
426-
);
438+
if ($fieldName == 'is_valid') {
439+
$clause = $this->buildValidityQuery(CRM_Utils_Array::value("{$fieldName}_value", $this->_params));
440+
}
441+
else {
442+
$clause = $this->whereClause($field,
443+
$op,
444+
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
445+
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
446+
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
447+
);
448+
}
427449
}
428450
}
429451
}
@@ -638,5 +660,23 @@ public function alterDisplay(&$rows) {
638660
}
639661
}
640662
}
663+
664+
/**
665+
* @param $valid bool - set to 1 if we are looking for a valid relationship, 0 if not
666+
*
667+
* @return array
668+
*/
669+
public function buildValidityQuery($valid) {
670+
$clause = NULL;
671+
if ($valid == '1') {
672+
// relationships dates are not expired
673+
$clause = "((start_date <= CURDATE() OR start_date is null) AND (end_date >= CURDATE() OR end_date is null))";
674+
}
675+
elseif ($valid == '0') {
676+
// relationships dates are expired or has not started yet
677+
$clause = "(start_date >= CURDATE() OR end_date < CURDATE())";
678+
}
679+
return $clause;
680+
}
641681

642682
}

0 commit comments

Comments
 (0)