Skip to content

Commit

Permalink
Convert relationship_start_date & relationship_end_date to datepicker
Browse files Browse the repository at this point in the history
This seems to work OK - look forwards to seeing you kick the tyres on it & see if you find any issues
  • Loading branch information
eileenmcnaughton committed Oct 28, 2019
1 parent 5756d96 commit 1cbe1bf
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
25 changes: 12 additions & 13 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ public function __construct(
foreach (array_keys($this->legacyHackedFields) as $fieldName) {
$this->_fields[$fieldName]['type'] = CRM_Utils_Type::T_STRING;
}
$relationMetadata = CRM_Contact_BAO_Relationship::fields();
$relationFields = array_intersect_key($relationMetadata, array_fill_keys(['relationship_start_date', 'relationship_end_date'], 1));
$this->_fields = array_merge($relationFields, $this->_fields);

$fields = CRM_Core_Component::getQueryFields(!$this->_skipPermission);
unset($fields['note']);
Expand Down Expand Up @@ -1595,6 +1598,8 @@ public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals
'pledge_create_date_relative',
'pledge_start_date_relative',
'pledge_payment_scheduled_date_relative',
'relationship_start_date_relative',
'relationship_end_date_relative',
'membership_join_date_relative',
'membership_start_date_relative',
'membership_end_date_relative',
Expand Down Expand Up @@ -2020,10 +2025,10 @@ public function whereClauseSingle(&$values, $isForcePrimaryOnly = FALSE) {
return;

case 'relation_type_id':
case 'relation_start_date_high':
case 'relation_start_date_low':
case 'relation_end_date_high':
case 'relation_end_date_low':
case 'relationship_start_date_high':
case 'relationship_start_date_low':
case 'relationship_end_date_high':
case 'relationship_end_date_low':
case 'relation_active_period_date_high':
case 'relation_active_period_date_low':
case 'relation_target_name':
Expand Down Expand Up @@ -4377,15 +4382,9 @@ public function addRelationshipPermissionClauses($grouping, &$where) {
* not the main query.
*/
public function addRelationshipDateClauses($grouping, &$where) {
$dateValues = [];
$dateTypes = [
'start_date',
'end_date',
];

foreach ($dateTypes as $dateField) {
$dateValueLow = $this->getWhereValues('relation_' . $dateField . '_low', $grouping);
$dateValueHigh = $this->getWhereValues('relation_' . $dateField . '_high', $grouping);
foreach (['start_date', 'end_date'] as $dateField) {
$dateValueLow = $this->getWhereValues('relationship_' . $dateField . '_low', $grouping);
$dateValueHigh = $this->getWhereValues('relationship_' . $dateField . '_high', $grouping);
if (!empty($dateValueLow)) {
$date = date('Ymd', strtotime($dateValueLow[2]));
$where[$grouping][] = "civicrm_relationship.$dateField >= $date";
Expand Down
2 changes: 0 additions & 2 deletions CRM/Contact/BAO/SavedSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,6 @@ public static function saveRelativeDates(&$queryParams, $formValues) {
'birth_date_relative',
'deceased_date_relative',
'relation_date_relative',
'relation_start_date_relative',
'relation_end_date_relative',
'relation_action_date_relative',
];
foreach ($formValues as $id => $value) {
Expand Down
13 changes: 8 additions & 5 deletions CRM/Contact/Form/Search/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,11 @@ public static function getSearchFieldMetadata() {
'contact_tags' => ['name' => 'contact_tags', 'type' => CRM_Utils_Type::T_INT, 'is_pseudofield' => TRUE, 'template_grouping' => 'basic'],
'birth_date' => ['name' => 'birth_date', 'template_grouping' => 'demographic'],
'deceased_date' => ['name' => 'deceased_date', 'template_grouping' => 'demographic'],
'relationship_start_date' => ['name' => 'relationship_start_date', 'template_grouping' => 'relationship'],
'relationship_end_date' => ['name' => 'relationship_end_date', 'template_grouping' => 'relationship'],
];
$metadata = civicrm_api3('Contact', 'getfields', [])['values'];
$metadata = civicrm_api3('Relationship', 'getfields', [])['values'];
$metadata = array_merge($metadata, civicrm_api3('Contact', 'getfields', [])['values']);
foreach ($fields as $fieldName => $field) {
$fields[$fieldName] = array_merge(CRM_Utils_Array::value($fieldName, $metadata, []), $field);
}
Expand Down Expand Up @@ -509,10 +512,13 @@ public static function task(&$form) {

/**
* @param CRM_Core_Form_Search $form
*
* @throws \CiviCRM_API3_Exception
*/
public static function relationship(&$form) {
$form->add('hidden', 'hidden_relationship', 1);

$form->addSearchFieldMetadata(['Relationship' => self::getFilteredSearchFieldMetadata('relationship')]);
$form->addFormFieldsFromMetadata();
$form->add('text', 'relation_description', ts('Description'), ['class' => 'twenty']);
$allRelationshipType = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE);
$form->add('select', 'relation_type_id', ts('Relationship Type'), ['' => ts('- select -')] + $allRelationshipType, FALSE, ['multiple' => TRUE, 'class' => 'crm-select2']);
Expand All @@ -532,9 +538,6 @@ public static function relationship(&$form) {
['id' => 'relation_target_group', 'multiple' => 'multiple', 'class' => 'crm-select2']
);
}
CRM_Core_Form_Date::buildDateRange($form, 'relation_start_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);
CRM_Core_Form_Date::buildDateRange($form, 'relation_end_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);

CRM_Core_Form_Date::buildDateRange($form, 'relation_active_period_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);

// Add reltionship dates
Expand Down
8 changes: 8 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveTwenty.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ public function upgrade_5_20_alpha1($rev) {
['old' => 'mailing_date_relative', 'new' => 'mailing_job_start_date_relative'],
['old' => 'mailing_date_high', 'new' => 'mailing_job_start_date_high'],
['old' => 'mailing_date_low', 'new' => 'mailing_job_start_date_low'],
['old' => 'relation_start_date_low', 'new' => 'relationship_start_date_low'],
['old' => 'relation_start_date_high', 'new' => 'relationship_start_date_high'],
['old' => 'relation_start_date_relative', 'new' => 'relationship_start_date_relative'],
['old' => 'relation_end_date_low', 'new' => 'relationship_end_date_low'],
['old' => 'relation_end_date_high', 'new' => 'relationship_end_date_high'],
['old' => 'relation_end_date_relative', 'new' => 'relationship_end_date_relative'],
],
]);
$this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', [
Expand All @@ -115,6 +121,8 @@ public function upgrade_5_20_alpha1($rev) {
'case_start_date',
'case_end_date',
'mailing_job_start_date',
'relationship_start_date',
'relationship_end_date',
],
]);
}
Expand Down
10 changes: 2 additions & 8 deletions templates/CRM/Contact/Form/Search/Criteria/Relationship.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,10 @@
</td>
</tr>
<tr>
<td colspan="2"><label>{ts}Start Date{/ts}</label></td>
{include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="relationship_start_date"}
</tr>
<tr>
{include file="CRM/Core/DateRange.tpl" fieldName="relation_start_date" from='_low' to='_high'}
</tr>
<tr>
<td colspan="2"><label>{ts}End Date{/ts}</label></td>
</tr>
<tr>
{include file="CRM/Core/DateRange.tpl" fieldName="relation_end_date" from='_low' to='_high'}
{include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="relationship_end_date"}
</tr>
<tr>
<td colspan="2"><label>{ts}Active Period{/ts}</label> {help id="id-relationship-active-period" file="CRM/Contact/Form/Search/Advanced.hlp"}<br /></td>
Expand Down

0 comments on commit 1cbe1bf

Please sign in to comment.