Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert pledge date fields to use datepicker rather than jcalendar #15170

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,14 @@ public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals

self::filterCountryFromValuesIfStateExists($formValues);
// We shouldn't have to whitelist fields to not hack but here we are, for now.
$nonLegacyDateFields = ['participant_register_date_relative', 'receive_date_relative'];
$nonLegacyDateFields = [
'participant_register_date_relative',
'receive_date_relative',
'pledge_end_date_relative',
'pledge_create_date_relative',
'pledge_start_date_relative',
'pledge_payment_scheduled_date_relative',
];
// Handle relative dates first
foreach (array_keys($formValues) as $id) {
if (
Expand Down
31 changes: 25 additions & 6 deletions CRM/Pledge/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ public static function whereClauseSingle(&$values, &$query) {
);
return;

case 'pledge_payment_scheduled_date_low':
case 'pledge_payment_scheduled_date_high':
// process to / from date
$query->dateQueryBuilder($values,
'civicrm_pledge_payment', 'pledge_payment_scheduled_date', 'scheduled_date', 'Payment Scheduled'
);
return;

case 'pledge_amount':
case 'pledge_amount_low':
case 'pledge_amount_high':
Expand Down Expand Up @@ -537,11 +545,27 @@ public static function extraReturnProperties($mode) {
public static function getSearchFieldMetadata() {
$fields = [
'pledge_status_id',
'pledge_start_date',
'pledge_end_date',
'pledge_create_date',
];
$metadata = civicrm_api3('Pledge', 'getfields', [])['values'];
return array_intersect_key($metadata, array_flip($fields));
}

/**
* Get the metadata for fields to be included on the grant search form.
*
* @throws \CiviCRM_API3_Exception
*/
public static function getPledgePaymentSearchFieldMetadata() {
$fields = [
'pledge_payment_scheduled_date',
];
$metadata = civicrm_api3('PledgePayment', 'getfields', [])['values'];
return array_intersect_key($metadata, array_flip($fields));
}

/**
* Build the search for for pledges.
*
Expand All @@ -553,13 +577,8 @@ public static function getSearchFieldMetadata() {
public static function buildSearchForm(&$form) {
// pledge related dates
$form->addSearchFieldMetadata(['Pledge' => self::getSearchFieldMetadata()]);
$form->addSearchFieldMetadata(['PledgePayment' => self::getPledgePaymentSearchFieldMetadata()]);
$form->addFormFieldsFromMetadata();
CRM_Core_Form_Date::buildDateRange($form, 'pledge_start_date', 1, '_low', '_high', ts('From'), FALSE);
CRM_Core_Form_Date::buildDateRange($form, 'pledge_end_date', 1, '_low', '_high', ts('From'), FALSE);
CRM_Core_Form_Date::buildDateRange($form, 'pledge_create_date', 1, '_low', '_high', ts('From'), FALSE);

// pledge payment related dates
CRM_Core_Form_Date::buildDateRange($form, 'pledge_payment_date', 1, '_low', '_high', ts('From'), FALSE);

$form->addYesNo('pledge_test', ts('Pledge is a Test?'), TRUE);
$form->add('text', 'pledge_amount_low', ts('From'), ['size' => 8, 'maxlength' => 8]);
Expand Down
3 changes: 2 additions & 1 deletion CRM/Pledge/DAO/PledgePayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Pledge/PledgePayment.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:7dfb4f8000b79fa8b1abab1de3712fc1)
* (GenCodeChecksum:563e2926d00b9fe0c4919bfd9a0a05e7)
*/

/**
Expand Down Expand Up @@ -236,6 +236,7 @@ public static function &fields() {
'entity' => 'PledgePayment',
'bao' => 'CRM_Pledge_BAO_PledgePayment',
'localizable' => 0,
'unique_title' => ts('Payment Scheduled'),
'html' => [
'type' => 'Select Date',
'formatType' => 'activityDate',
Expand Down
19 changes: 5 additions & 14 deletions CRM/Pledge/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public function preProcess() {
}

if ($this->_force) {
// pledge related dates
$this->addSearchFieldMetadata(['Pledge' => CRM_Pledge_BAO_Query::getSearchFieldMetadata()]);
$this->addSearchFieldMetadata(['PledgePayment' => CRM_Pledge_BAO_Query::getPledgePaymentSearchFieldMetadata()]);
$this->addFormFieldsFromMetadata();
$this->postProcess();
$this->set('force', 0);
}
Expand Down Expand Up @@ -230,7 +234,7 @@ public function postProcess() {

$this->_done = TRUE;

$this->_formValues = $this->controller->exportValues($this->_name);
$this->setFormValues();

$this->fixFormValues();

Expand Down Expand Up @@ -321,19 +325,6 @@ public function addRules() {
$this->addFormRule(['CRM_Pledge_Form_Search', 'formRule']);
}

/**
* Set the default form values.
*
*
* @return array
* the default array reference
*/
public function setDefaultValues() {
$defaults = [];
$defaults = $this->_formValues;
return $defaults;
}

public function fixFormValues() {
if (!$this->_force) {
return;
Expand Down
13 changes: 13 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveEighteen.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ public function upgrade_5_18_alpha1($rev) {
$this->addTask('Remove Foreign Key from civicrm_dashboard on domain_id if exists', 'removeDomainIDFK');
$this->addTask('Remove Index on domain_id that might have been randomly added in the same format as FK', 'dropIndex', 'civicrm_dashboard', 'FK_civicrm_dashboard_domain_id');
$this->addTask('Re-Create Foreign key between civicrm_dashboard and civicrm_domain correctly', 'recreateDashboardFK');
$this->addTask('Update smart groups to rename filters on pledge_payment_date to pledge_payment_scheduled_date', 'updateSmartGroups', [
'renameField' => [
['old' => 'pledge_payment_date', 'new' => 'pledge_payment_scheduled_date'],
],
]);
$this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', [
'datepickerConversion' => [
'pledge_payment_scheduled_date',
'pledge_create_date',
'pledge_end_date',
'pledge_start_date',
],
]);
}

public static function removeDomainIDFK() {
Expand Down
8 changes: 4 additions & 4 deletions templates/CRM/Pledge/Form/Search/Common.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*}

<tr>
{include file="CRM/Core/DateRange.tpl" fieldName="pledge_payment_date" from='_low' to='_high' label="<label>Payment Scheduled</label>"}
{include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="pledge_payment_scheduled_date" colspan="2"}
</tr>
<tr>
<td colspan="2">
Expand All @@ -45,13 +45,13 @@
</td>
</tr>
<tr>
{include file="CRM/Core/DateRange.tpl" fieldName="pledge_create_date" from='_low' to='_high' label="<label>Pledge Made</label>"}
{include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="pledge_create_date" colspan="2"}
</tr>
<tr>
{include file="CRM/Core/DateRange.tpl" fieldName="pledge_start_date" from='_low' to='_high' label="<label>Payments Start Date</label>"}
{include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="pledge_start_date" colspan="2"}
</tr>
<tr>
{include file="CRM/Core/DateRange.tpl" fieldName="pledge_end_date" from='_low' to='_high' label="<label>Payments Ended Date</label>"}
{include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="pledge_end_date" colspan="2"}
</tr>
<tr>
<td>
Expand Down
2 changes: 2 additions & 0 deletions xml/schema/Pledge/PledgePayment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<uniqueName>pledge_payment_scheduled_amount</uniqueName>
<title>Scheduled Amount</title>
<import>true</import>
<export>true</export>
<type>decimal</type>
<required>true</required>
<comment>Pledged amount for this payment (the actual contribution amount might be different).</comment>
Expand Down Expand Up @@ -107,6 +108,7 @@
<type>Select Date</type>
<formatType>activityDate</formatType>
</html>
<uniqueTitle>Payment Scheduled</uniqueTitle>
</field>
<field>
<name>reminder_date</name>
Expand Down