From: Coleman Watts Date: Mon, 2 Mar 2015 21:17:04 +0000 (-0500) Subject: CRM-15932 - Decouple frequency units of contributions and recurring entities X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=8fe4b69f00fe00bbd430f3db5e57790335730001;p=civicrm-core.git CRM-15932 - Decouple frequency units of contributions and recurring entities --- diff --git a/CRM/Admin/Form/ScheduleReminders.php b/CRM/Admin/Form/ScheduleReminders.php index 0cba27518f..fc6f7dce2d 100644 --- a/CRM/Admin/Form/ScheduleReminders.php +++ b/CRM/Admin/Form/ScheduleReminders.php @@ -145,7 +145,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { } //get the frequency units. - $this->_freqUnits = CRM_Core_SelectValues::getScheduleReminderFrequencyUnits(); + $this->_freqUnits = CRM_Core_SelectValues::getRecurringFrequencyUnits(); //pass the mapping ID in UPDATE mode $mappings = CRM_Core_BAO_ActionSchedule::getMapping($mappingID); diff --git a/CRM/Core/Form/RecurringEntity.php b/CRM/Core/Form/RecurringEntity.php index 7df05aa487..ab9a3f466c 100644 --- a/CRM/Core/Form/RecurringEntity.php +++ b/CRM/Core/Form/RecurringEntity.php @@ -170,9 +170,6 @@ class CRM_Core_Form_RecurringEntity { * @param CRM_Core_Form $form */ public static function buildQuickForm(&$form) { - - $freqUnitsDisplay = array('hour' => ts('hour')) + CRM_Core_OptionGroup::values('recur_frequency_units'); - // For some reason this is using the following as keys rather than the standard numeric keys returned by CRM_Utils_Date $dayOfTheWeek = array( 'sunday', @@ -184,7 +181,7 @@ class CRM_Core_Form_RecurringEntity { 'saturday', ); $dayOfTheWeek = array_combine($dayOfTheWeek, CRM_Utils_Date::getAbbrWeekdayNames()); - $form->add('select', 'repetition_frequency_unit', ts('Repeats every'), $freqUnitsDisplay, FALSE, array('class' => 'required')); + $form->add('select', 'repetition_frequency_unit', ts('Repeats every'), CRM_Core_SelectValues::getRecurringFrequencyUnits(), FALSE, array('class' => 'required')); $numericOptions = CRM_Core_SelectValues::getNumericOptions(1, 30); $form->add('select', 'repetition_frequency_interval', NULL, $numericOptions, FALSE, array('class' => 'required')); $form->addDateTime('repetition_start_date', ts('Repetition Start Date'), FALSE, array('formatType' => 'activityDateTime')); @@ -231,6 +228,11 @@ class CRM_Core_Form_RecurringEntity { ), ) ); + // For client-side pluralization + $form->assign('recurringFrequencyOptions', array( + 'single' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::getRecurringFrequencyUnits()), + 'plural' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::getRecurringFrequencyUnits(2)), + )); } /** diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index b7273e4350..fff91f8274 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -968,18 +968,21 @@ class CRM_Core_SelectValues { /** * Frequency unit for schedule reminders. * + * @param int $count + * For pluralization * @return array */ - public static function getScheduleReminderFrequencyUnits() { - //@todo update schema to refer to option group direct & remove this - static $scheduleReminderFrequencyUnits = NULL; - if (!$scheduleReminderFrequencyUnits) { - $scheduleReminderFrequencyUnits = array( - 'hour' => ts('hour'), - ) + CRM_Core_OptionGroup::values('recur_frequency_units'); - } - - return $scheduleReminderFrequencyUnits; + public static function getRecurringFrequencyUnits($count = 1) { + // @todo this used to refer to the 'recur_frequency_unit' option_values which + // is for recurring payments and probably not good to re-use for recurring entities. + // If something other than a hard-coded list is desired, add a new option_group. + return array( + 'hour' => ts('hour', array('plural' => 'hours', 'count' => $count)), + 'day' => ts('day', array('plural' => 'days', 'count' => $count)), + 'week' => ts('week', array('plural' => 'weeks', 'count' => $count)), + 'month' => ts('month', array('plural' => 'months', 'count' => $count)), + 'year' => ts('year', array('plural' => 'years', 'count' => $count)), + ); } } diff --git a/templates/CRM/Core/Form/RecurringEntity.tpl b/templates/CRM/Core/Form/RecurringEntity.tpl index 8623cfaa2f..52f5a6aa88 100644 --- a/templates/CRM/Core/Form/RecurringEntity.tpl +++ b/templates/CRM/Core/Form/RecurringEntity.tpl @@ -196,6 +196,14 @@ } }); + // Pluralize frequency options + var recurringFrequencyOptions = {/literal}{$recurringFrequencyOptions|@json_encode}{literal}; + function pluralizeUnits() { + CRM.utils.setOptions($('[name=repetition_frequency_unit]', $form), + $(this).val() === '1' ? recurringFrequencyOptions.single : recurringFrequencyOptions.plural); + } + $('[name=repetition_frequency_interval]', $form).each(pluralizeUnits).change(pluralizeUnits); + });