From: Eileen McNaughton Date: Wed, 9 Apr 2014 05:22:43 +0000 (+1200) Subject: CRM-14446 contact api.getfields declare birth_date & deceased_date high low filters... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9f60788a7cb96b14f55d35677e0146f4792e059f;p=civicrm-core.git CRM-14446 contact api.getfields declare birth_date & deceased_date high low filters so they will accept strtotime strings ---------------------------------------- * CRM-14446: https://issues.civicrm.org/jira/browse/CRM-14446 --- diff --git a/api/v3/Contact.php b/api/v3/Contact.php index 15bd089958..1efb42a13d 100644 --- a/api/v3/Contact.php +++ b/api/v3/Contact.php @@ -201,6 +201,10 @@ function _civicrm_api3_contact_get_spec(&$params) { $params['group_id']['title'] = 'Group Memberships (filter)'; $params['group']['title'] = 'Group Memberships (filter, array)'; $params['tag']['title'] = 'Assigned tags (filter, array)'; + $params['birth_date_low'] = array('name' => 'birth_date_low', 'type' => CRM_Utils_Type::T_DATE, 'title' => ts('Birthdate is equal to or greater than')); + $params['birth_date_high'] = array('name' => 'birth_date_high', 'type' => CRM_Utils_Type::T_DATE, 'title' => ts('Birthdate is equal to or less than')); + $params['deceased_date_low'] = array('name' => 'deceased_date_low','type' => CRM_Utils_Type::T_DATE, 'title' => ts('Deceased Date is equal to or greater than')); + $params['deceased_date_high'] = array('name' => 'deceased_date_high', 'type' => CRM_Utils_Type::T_DATE, 'title' => ts('Deceased Date is equal to or less than')); } /** diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index e7ca3fd241..88d40f1aa6 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -1229,6 +1229,9 @@ class api_v3_ContactTest extends CiviUnitTestCase { $result = $this->callAPISuccess('contact', 'get', array('birth_date_low' => date('Y-m-d', strtotime('-6 years')), 'birth_date_high' => date('Y-m-d', strtotime('- 3 years')))); $this->assertEquals(1, $result['count']); $this->assertEquals(date('Y-m-d', strtotime('first day of next month -5 years')), $result['values'][$contact2['id']]['birth_date']); + $result = $this->callAPISuccess('contact', 'get', array('birth_date_low' => '-6 years', 'birth_date_high' => '- 3 years')); + $this->assertEquals(1, $result['count']); + $this->assertEquals(date('Y-m-d', strtotime('first day of next month -5 years')), $result['values'][$contact2['id']]['birth_date']); } /** @@ -1249,7 +1252,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { $result = $this->callAPISuccess('contact', 'get', array('deceased_date_high' => date('Y-m-d', strtotime('-6 years')))); $this->assertEquals(1, $result['count']); $this->assertEquals(date('Y-m-d', strtotime('first day of next month -20 years')), $result['values'][$contact3['id']]['deceased_date']); - $result = $this->callAPISuccess('contact', 'get', array('deceased_date_low' => date('Y-m-d', strtotime('-6 years')), 'deceased_date_high' => date('Y-m-d', strtotime('- 3 years')))); + $result = $this->callAPISuccess('contact', 'get', array('deceased_date_low' => '-6 years', 'deceased_date_high' => date('Y-m-d', strtotime('- 3 years')))); $this->assertEquals(1, $result['count']); $this->assertEquals(date('Y-m-d', strtotime('first day of next month -5 years')), $result['values'][$contact2['id']]['deceased_date']); }