From: Seamus Lee Date: Thu, 17 Dec 2015 19:57:50 +0000 (+0000) Subject: Improve relationship report by adding in end_date check for active relationships... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4e43a5c56a808eb131b2a1ec607b794a8dfbcd9e;p=civicrm-core.git Improve relationship report by adding in end_date check for active relationships and also by adding in filters for relationship start and end dates Switch to using is_valid test as per 4.7 --- diff --git a/CRM/Report/Form/Contact/Relationship.php b/CRM/Report/Form/Contact/Relationship.php index 97e49c6760..04b34278eb 100644 --- a/CRM/Report/Form/Contact/Relationship.php +++ b/CRM/Report/Form/Contact/Relationship.php @@ -219,6 +219,16 @@ class CRM_Report_Form_Contact_Relationship extends CRM_Report_Form { ), 'type' => CRM_Utils_Type::T_INT, ), + 'is_valid' => array( + 'title' => ts('Relationship Dates Validity'), + 'operatorType' => CRM_Report_Form::OP_SELECT, + 'options' => array( + NULL => ts('- Any -'), + 1 => ts('Not expired'), + 0 => ts('Expired'), + ), + 'type' => CRM_Utils_Type::T_INT, + ), 'relationship_type_id' => array( 'title' => ts('Relationship'), 'operatorType' => CRM_Report_Form::OP_SELECT, @@ -228,6 +238,14 @@ class CRM_Report_Form_Contact_Relationship extends CRM_Report_Form { CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, NULL, TRUE), 'type' => CRM_Utils_Type::T_INT, ), + 'start_date' => array( + 'title' => ts('Start Date'), + 'type' => CRM_Utils_Type::T_DATE, + ), + 'end_date' => array( + 'title' => ts('End Date'), + 'type' => CRM_Utils_Type::T_DATE, + ), ), 'grouping' => 'relation-fields', ), @@ -420,13 +438,17 @@ class CRM_Report_Form_Contact_Relationship extends CRM_Report_Form { } } else { - - $clause = $this->whereClause($field, - $op, - CRM_Utils_Array::value("{$fieldName}_value", $this->_params), - CRM_Utils_Array::value("{$fieldName}_min", $this->_params), - CRM_Utils_Array::value("{$fieldName}_max", $this->_params) - ); + if ($fieldName == 'is_valid') { + $clause = $this->buildValidityQuery(CRM_Utils_Array::value("{$fieldName}_value", $this->_params)); + } + else { + $clause = $this->whereClause($field, + $op, + CRM_Utils_Array::value("{$fieldName}_value", $this->_params), + CRM_Utils_Array::value("{$fieldName}_min", $this->_params), + CRM_Utils_Array::value("{$fieldName}_max", $this->_params) + ); + } } } } @@ -629,4 +651,22 @@ class CRM_Report_Form_Contact_Relationship extends CRM_Report_Form { } } + /** + * @param $valid bool - set to 1 if we are looking for a valid relationship, 0 if not + * + * @return array + */ + public function buildValidityQuery($valid) { + $clause = NULL; + if ($valid == '1') { + // relationships dates are not expired + $clause = "((start_date <= CURDATE() OR start_date is null) AND (end_date >= CURDATE() OR end_date is null))"; + } + elseif ($valid == '0') { + // relationships dates are expired or has not started yet + $clause = "(start_date >= CURDATE() OR end_date < CURDATE())"; + } + return $clause; + } + }