Skip to content

Commit

Permalink
Improve relationship report by adding in end_date check for active re…
Browse files Browse the repository at this point in the history
…lationships and also by adding in filters for relationship start and end dates

Switch to using is_valid test as per 4.7
  • Loading branch information
seamuslee001 committed Dec 17, 2015
1 parent 4596546 commit a1f9702
Showing 1 changed file with 47 additions and 7 deletions.
54 changes: 47 additions & 7 deletions CRM/Report/Form/Contact/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,30 @@ public function __construct() {
),
'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_MULTISELECT,
'options' => 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',
),
Expand Down Expand Up @@ -417,13 +435,17 @@ public function where() {
}
}
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)
);
}
}
}
}
Expand Down Expand Up @@ -638,5 +660,23 @@ public function alterDisplay(&$rows) {
}
}
}

/**
* @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;
}

}

0 comments on commit a1f9702

Please sign in to comment.