}
/**
- * @param $form
+ * @param CRM_Core_Form_Search $form
*/
public static function demographics(&$form) {
$form->add('hidden', 'hidden_demographics', 1);
}
$form->addGroup($genderOptions, 'gender_id', ts('Gender'))->setAttribute('allowClear', TRUE);
- $form->add('text', 'age_low', ts('Min Age'), array('size' => 6));
+ $form->add('number', 'age_low', ts('Min Age'), ['class' => 'four', 'min' => 0]);
$form->addRule('age_low', ts('Please enter a positive integer'), 'positiveInteger');
- $form->add('text', 'age_high', ts('Max Age'), array('size' => 6));
+ $form->add('number', 'age_high', ts('Max Age'), ['class' => 'four', 'min' => 0]);
$form->addRule('age_high', ts('Please enter a positive integer'), 'positiveInteger');
- $form->addDate('age_asof_date', ts('Age as of Date'), FALSE, array('formatType' => 'searchDate'));
+ $form->add('datepicker', 'age_asof_date', ts('As of'), NULL, FALSE, ['time' => FALSE]);
CRM_Core_Form_Date::buildDateRange($form, 'birth_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth');
* Do any relevant smart group updates.
*
* @param CRM_Queue_TaskContext $ctx
- * @param string $version
+ * @param array $actions
*
* @return bool
*/
- public function updateSmartGroups($ctx, $version) {
- $groupUpdateObject = new CRM_Upgrade_Incremental_SmartGroups($version);
- $groupUpdateObject->updateGroups();
+ public function updateSmartGroups($ctx, $actions) {
+ $groupUpdateObject = new CRM_Upgrade_Incremental_SmartGroups();
+ $groupUpdateObject->updateGroups($actions);
return TRUE;
}
class CRM_Upgrade_Incremental_SmartGroups {
/**
- * Version we are upgrading to.
- *
- * @var string
- */
- protected $upgradeVersion;
-
- /**
- * @return string
- */
- public function getUpgradeVersion() {
- return $this->upgradeVersion;
- }
-
- /**
- * @param string $upgradeVersion
- */
- public function setUpgradeVersion($upgradeVersion) {
- $this->upgradeVersion = $upgradeVersion;
- }
-
- /**
- * CRM_Upgrade_Incremental_MessageTemplates constructor.
- *
- * @param string $upgradeVersion
- */
- public function __construct($upgradeVersion) {
- $this->setUpgradeVersion($upgradeVersion);
- }
-
- /**
- * Get any conversions required for saved smart groups.
- *
- * @return array
+ * Perform updates specified by upgrade function.
*/
- public function getSmartGroupConversions() {
- return [
- [
- 'version' => '5.11.alpha1',
- 'upgrade_descriptors' => [ts('Upgrade grant smart groups to datepicker format')],
- 'actions' => [
- 'function' => 'datepickerConversion',
- 'fields' => [
- 'grant_application_received_date',
- 'grant_decision_date',
- 'grant_money_transfer_date',
- 'grant_due_date'
- ]
- ]
- ]
- ];
+ public function updateGroups($actions) {
+ foreach ($actions as $func => $fields) {
+ $this->{$func}($fields);
+ }
}
/**
}
}
- /**
- * Update message templates.
- */
- public function updateGroups() {
- $conversions = $this->getSmartGroupConversionsToApply();
- foreach ($conversions as $conversion) {
- $function = $conversion['function'];
- $this->{$function}($conversion['fields']);
- }
- }
-
- /**
- * Get any required template updates.
- *
- * @return array
- */
- public function getSmartGroupConversionsToApply() {
- $conversions = $this->getSmartGroupConversions();
- $return = [];
- foreach ($conversions as $conversion) {
- if ($conversion['version'] === $this->getUpgradeVersion()) {
- $return[] = $conversion['actions'];
- }
- }
- return $return;
- }
-
/**
* Get converted date value.
*
*/
public function upgrade_5_11_alpha1($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
- $this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', $rev);
+ $this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', [
+ 'datepickerConversion' => [
+ 'grant_application_received_date',
+ 'grant_decision_date',
+ 'grant_money_transfer_date',
+ 'grant_due_date'
+ ]
+ ]);
}
}
* (change the x in the function name):
*/
- // /**
- // * Upgrade function.
- // *
- // * @param string $rev
- // */
- // public function upgrade_5_0_x($rev) {
- // $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
- // $this->addTask('Do the foo change', 'taskFoo', ...);
- // // Additional tasks here...
- // // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex.
- // // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable.
- // }
-
- // public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) {
- // return TRUE;
- // }
+ /**
+ * Upgrade function.
+ *
+ * @param string $rev
+ */
+ public function upgrade_5_12_alpha1($rev) {
+ $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
+ $this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', [
+ 'datepickerConversion' => [
+ 'age_asof_date',
+ ]
+ ]);
+ }
}
{$form.$maxName.html}
</span>
</span>
-</td>
-<td>
<span class="crm-age-range-asofdate">
- {assign var=dateName value=$fieldName|cat:$date}
- {$form.$dateName.label}
- {include file="CRM/common/jcalendar.tpl" elementName=$dateName}
+ {assign var=dateName value=$fieldName|cat:$date}
+ {$form.$dateName.label}
+ {$form.$dateName.html}
</span>
{literal}
<script type="text/javascript">
- cj(".crm-age-range").change(function() {
- if (cj('.crm-age-range-min :text').val() || cj('.crm-age-range-max :text').val()) {
- cj(".crm-age-range-asofdate").show();
- } else {
- cj(".crm-age-range-asofdate").hide();
+ CRM.$(function($) {
+ var $form = $('form.{/literal}{$form.formClass}{literal}');
+ function toggleDate() {
+ $(".crm-age-range-asofdate").toggle(!!($('.crm-age-range-min input', $form).val() || $('.crm-age-range-max input', $form).val()));
}
- }).change();
+ $('.crm-age-range input', $form).on('keyup change', toggleDate);
+ toggleDate();
+ });
+
</script>
{/literal}
</td>
['grant_due_date_low', '=', '01/22/2019'],
]
]);
- $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups('5.11.alpha1');
- $smartGroupConversionObject->updateGroups();
+ $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups();
+ $smartGroupConversionObject->updateGroups([
+ 'datepickerConversion' => [
+ 'grant_application_received_date',
+ 'grant_decision_date',
+ 'grant_money_transfer_date',
+ 'grant_due_date'
+ ]
+ ]);
$savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []);
$this->assertEquals('grant_application_received_date_high', $savedSearch['form_values'][0][0]);
$this->assertEquals('2019-01-20 00:00:00', $savedSearch['form_values'][0][2]);