),
'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,
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',
),
}
}
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)
+ );
+ }
}
}
}
}
}
+ /**
+ * @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;
+ }
+
}