* @param CRM_Core_Form $form
*/
public static function buildQuickForm(&$form) {
- // For some reason this is using the following as keys rather than the standard numeric keys returned by CRM_Utils_Date
- $dayOfTheWeek = array(
+ // FIXME: this is using the following as keys rather than the standard numeric keys returned by CRM_Utils_Date
+ $dayOfTheWeek = array();
+ $dayKeys = array(
'sunday',
'monday',
'tuesday',
'friday',
'saturday',
);
- $dayOfTheWeek = array_combine($dayOfTheWeek, CRM_Utils_Date::getAbbrWeekdayNames());
+ foreach (CRM_Utils_Date::getAbbrWeekdayNames() as $k => $label) {
+ $dayOfTheWeek[$dayKeys[$k]] = $label;
+ }
$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'));
/**
* Return abbreviated weekday names according to the locale.
*
+ * Array will be in localized order according to 'weekBegins' setting,
+ * but array keys will always match to:
+ * 0 => Sun
+ * 1 => Mon
+ * etc.
+ *
* @return array
* 0-based array with abbreviated weekday names
*
*/
- public static function &getAbbrWeekdayNames() {
- static $abbrWeekdayNames;
- if (!isset($abbrWeekdayNames)) {
+ public static function getAbbrWeekdayNames() {
+ static $days = array();
+ if (!$days) {
+ // First day of the week
+ $firstDay = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME, 'weekBegins', NULL, 0);
// set LC_TIME and build the arrays from locale-provided names
// June 1st, 1970 was a Monday
CRM_Core_I18n::setLcTime();
- for ($i = 0; $i < 7; $i++) {
- $abbrWeekdayNames[$i] = strftime('%a', mktime(0, 0, 0, 6, $i, 1970));
+ for ($i = $firstDay; count($days) < 7; $i = $i > 6 ? 0 : $i + 1) {
+ $days[$i] = strftime('%a', mktime(0, 0, 0, 6, $i, 1970));
}
}
- return $abbrWeekdayNames;
+ return $days;
}
/**
* Return full weekday names according to the locale.
*
+ * Array will be in localized order according to 'weekBegins' setting,
+ * but array keys will always match to:
+ * 0 => Sunday
+ * 1 => Monday
+ * etc.
+ *
* @return array
* 0-based array with full weekday names
*
*/
- public static function &getFullWeekdayNames() {
- static $fullWeekdayNames;
- if (!isset($fullWeekdayNames)) {
+ public static function getFullWeekdayNames() {
+ static $days = array();
+ if (!$days) {
+ // First day of the week
+ $firstDay = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME, 'weekBegins', NULL, 0);
// set LC_TIME and build the arrays from locale-provided names
// June 1st, 1970 was a Monday
CRM_Core_I18n::setLcTime();
- for ($i = 0; $i < 7; $i++) {
- $fullWeekdayNames[$i] = strftime('%A', mktime(0, 0, 0, 6, $i, 1970));
+ for ($i = $firstDay; count($days) < 7; $i = $i > 6 ? 0 : $i + 1) {
+ $days[$i] = strftime('%A', mktime(0, 0, 0, 6, $i, 1970));
}
}
- return $fullWeekdayNames;
+ return $days;
}
/**