@@ -219,12 +219,30 @@ public function __construct() {
219
219
),
220
220
'type ' => CRM_Utils_Type::T_INT ,
221
221
),
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
+ ),
222
232
'relationship_type_id ' => array (
223
233
'title ' => ts ('Relationship ' ),
224
234
'operatorType ' => CRM_Report_Form::OP_MULTISELECT ,
225
235
'options ' => CRM_Contact_BAO_Relationship::getContactRelationshipType (NULL , 'null ' , NULL , NULL , TRUE ),
226
236
'type ' => CRM_Utils_Type::T_INT ,
227
237
),
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
+ ),
228
246
),
229
247
'grouping ' => 'relation-fields ' ,
230
248
),
@@ -417,13 +435,17 @@ public function where() {
417
435
}
418
436
}
419
437
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
+ }
427
449
}
428
450
}
429
451
}
@@ -638,5 +660,23 @@ public function alterDisplay(&$rows) {
638
660
}
639
661
}
640
662
}
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
+ }
641
681
642
682
}
0 commit comments