}
//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);
* @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',
'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'));
),
)
);
+ // 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)),
+ ));
}
/**
/**
* 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)),
+ );
}
}
}\r
});\r
\r
+ // Pluralize frequency options\r
+ var recurringFrequencyOptions = {/literal}{$recurringFrequencyOptions|@json_encode}{literal};\r
+ function pluralizeUnits() {\r
+ CRM.utils.setOptions($('[name=repetition_frequency_unit]', $form),\r
+ $(this).val() === '1' ? recurringFrequencyOptions.single : recurringFrequencyOptions.plural);\r
+ }\r
+ $('[name=repetition_frequency_interval]', $form).each(pluralizeUnits).change(pluralizeUnits);\r
+\r
});\r
\r
</script>\r