Skip to content

Commit

Permalink
Convert pledge date fields to use datepicker rather than jcalendar
Browse files Browse the repository at this point in the history
  • Loading branch information
seamuslee001 committed Aug 31, 2019
1 parent c199a32 commit 2e9af46
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 38 deletions.
29 changes: 23 additions & 6 deletions CRM/Pledge/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ public static function select(&$query) {
$query->_tables['civicrm_pledge'] = $query->_whereTables['civicrm_pledge'] = 1;
}

if (!empty($query->_returnProperties['pledge_end_date'])) {
$query->_select['pledge_end_date'] = 'civicrm_pledge.end_date as pledge_end_date';
$query->_element['pledge_end_date'] = 1;
$query->_tables['civicrm_pledge'] = $query->_whereTables['civicrm_pledge'] = 1;
}

if (!empty($query->_returnProperties['pledge_start_date'])) {
$query->_select['pledge_start_date'] = 'civicrm_pledge.start_date as pledge_start_date';
$query->_element['pledge_start_date'] = 1;
Expand Down Expand Up @@ -531,11 +537,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 @@ -547,13 +569,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
8 changes: 5 additions & 3 deletions CRM/Pledge/DAO/Pledge.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Pledge/Pledge.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:5e5bb725caa46ae10f0c5d039a03c675)
* (GenCodeChecksum:238d9af98168511a7e6694e3d30e533d)
*/

/**
Expand Down Expand Up @@ -420,7 +420,7 @@ public static function &fields() {
'type' => 'Text',
],
],
'start_date' => [
'pledge_start_date' => [
'name' => 'start_date',
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
'title' => ts('Pledge Start Date'),
Expand All @@ -431,6 +431,7 @@ public static function &fields() {
'entity' => 'Pledge',
'bao' => 'CRM_Pledge_BAO_Pledge',
'localizable' => 0,
'unique_title' => ts('Payments Start Date'),
'html' => [
'type' => 'Select Date',
],
Expand Down Expand Up @@ -491,7 +492,7 @@ public static function &fields() {
'type' => 'Select Date',
],
],
'end_date' => [
'pledge_end_date' => [
'name' => 'end_date',
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
'title' => ts('Pledge End Date'),
Expand All @@ -501,6 +502,7 @@ public static function &fields() {
'entity' => 'Pledge',
'bao' => 'CRM_Pledge_BAO_Pledge',
'localizable' => 0,
'unique_title' => ts('Payments Ended Date'),
'html' => [
'type' => 'Select Date',
],
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
13 changes: 0 additions & 13 deletions CRM/Pledge/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,19 +321,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
26 changes: 15 additions & 11 deletions xml/schema/Pledge/Pledge.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@
<comment>The date the first scheduled pledge occurs.</comment>
<add>2.1</add>
<html>
<type>Select Date</type>
</html>
<type>Select Date</type>
</html>
<uniqueName>pledge_start_date</uniqueName>
<uniqueTitle>Payments Start Date</uniqueTitle>
</field>
<field>
<name>create_date</name>
Expand All @@ -222,7 +224,7 @@
<comment>When a pledge acknowledgement message was sent to the contributor.</comment>
<add>2.1</add>
<html>
<type>Select Date</type>
<type>Select Date</type>
</html>
</field>
<field>
Expand All @@ -239,7 +241,7 @@
<comment>Date this pledge was cancelled by contributor.</comment>
<add>2.1</add>
<html>
<type>Select Date</type>
<type>Select Date</type>
</html>
</field>
<field>
Expand All @@ -249,8 +251,10 @@
<comment>Date this pledge finished successfully (total pledge payments equal to or greater than pledged amount).</comment>
<add>2.1</add>
<html>
<type>Select Date</type>
<type>Select Date</type>
</html>
<uniqueName>pledge_end_date</uniqueName>
<uniqueTitle>Payments Ended Date</uniqueTitle>
</field>
<field>
<name>max_reminders</name>
Expand All @@ -259,8 +263,8 @@
<default>1</default>
<comment>The maximum number of payment reminders to send for any given payment.</comment>
<html>
<type>Text</type>
</html>
<type>Text</type>
</html>
<add>2.1</add>
</field>
<field>
Expand All @@ -271,8 +275,8 @@
<comment>Send initial reminder this many days prior to the payment due date.</comment>
<add>2.1</add>
<html>
<type>Select</type>
</html>
<type>Select</type>
</html>
</field>
<field>
<name>additional_reminder_day</name>
Expand All @@ -282,8 +286,8 @@
<comment>Send additional reminder this many days after last one sent, up to maximum number of reminders.</comment>
<add>2.1</add>
<html>
<type>Text</type>
</html>
<type>Text</type>
</html>
</field>
<field>
<name>status_id</name>
Expand Down
1 change: 1 addition & 0 deletions xml/schema/Pledge/PledgePayment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<type>Select Date</type>
<formatType>activityDate</formatType>
</html>
<uniqueTitle>Payment Scheduled</uniqueTitle>
</field>
<field>
<name>reminder_date</name>
Expand Down

0 comments on commit 2e9af46

Please sign in to comment.