CRM-15932 - Decouple frequency units of contributions and recurring entities
authorColeman Watts <coleman@civicrm.org>
Mon, 2 Mar 2015 21:17:04 +0000 (16:17 -0500)
committerColeman Watts <coleman@civicrm.org>
Mon, 2 Mar 2015 21:17:04 +0000 (16:17 -0500)
CRM/Admin/Form/ScheduleReminders.php
CRM/Core/Form/RecurringEntity.php
CRM/Core/SelectValues.php
templates/CRM/Core/Form/RecurringEntity.tpl

index 0cba27518f24de0bd7d62c0e8a632d41bb722c0b..fc6f7dce2ddbb5e8e2c2b2e4745c44f136f6e3e2 100644 (file)
@@ -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);
index 7df05aa4872374075270fd6da2922264917df87a..ab9a3f466c88b6da8be23eab2dd6856bd1b7c4ee 100644 (file)
@@ -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)),
+    ));
   }
 
   /**
index b7273e435030d82b4649f2e8cfa72124451ba41a..fff91f827426df8df3bfd5a068047dd102920ab6 100644 (file)
@@ -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)),
+    );
   }
 
 }
index 8623cfaa2fbc778fbebed2d9285a2646aa05a1c7..52f5a6aa88acdaa03a169ca8d04c62665d6002f3 100644 (file)
       }\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