Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 | 16 | */ |
2aa397bc | 17 | class CRM_Core_Form_Date { |
6a488035 TO |
18 | |
19 | /** | |
fe482240 | 20 | * Various Date Formats. |
6a488035 | 21 | */ |
7da04cde | 22 | const DATE_yyyy_mm_dd = 1, DATE_mm_dd_yy = 2, DATE_mm_dd_yyyy = 4, DATE_Month_dd_yyyy = 8, DATE_dd_mon_yy = 16, DATE_dd_mm_yyyy = 32; |
6a488035 TO |
23 | |
24 | /** | |
8eedd10a | 25 | * Build the date-format form. |
6a488035 | 26 | * |
6a0b768e TO |
27 | * @param CRM_Core_Form $form |
28 | * The form object that we are operating on. | |
6a488035 | 29 | */ |
00be9182 | 30 | public static function buildAllowedDateFormats(&$form) { |
6a488035 | 31 | |
be2fb01f | 32 | $dateOptions = []; |
6a488035 | 33 | |
ac4410cd | 34 | if (CRM_Utils_System::getClassName($form) == 'CRM_Activity_Import_Form_DataSource') { |
6a488035 TO |
35 | $dateText = ts('yyyy-mm-dd OR yyyy-mm-dd HH:mm OR yyyymmdd OR yyyymmdd HH:mm (1998-12-25 OR 1998-12-25 15:33 OR 19981225 OR 19981225 10:30 OR ( 2008-9-1 OR 2008-9-1 15:33 OR 20080901 15:33)'); |
36 | } | |
37 | else { | |
38 | $dateText = ts('yyyy-mm-dd OR yyyymmdd (1998-12-25 OR 19981225) OR (2008-9-1 OR 20080901)'); | |
39 | } | |
40 | ||
39405208 SL |
41 | $form->addRadio('dateFormats', ts('Date Format'), [ |
42 | self::DATE_yyyy_mm_dd => $dateText, | |
43 | self::DATE_mm_dd_yy => ts('mm/dd/yy OR mm-dd-yy (12/25/98 OR 12-25-98) OR (9/1/08 OR 9-1-08)'), | |
44 | self::DATE_mm_dd_yyyy => ts('mm/dd/yyyy OR mm-dd-yyyy (12/25/1998 OR 12-25-1998) OR (9/1/2008 OR 9-1-2008)'), | |
45 | self::DATE_Month_dd_yyyy => ts('Month dd, yyyy (December 12, 1998)'), | |
46 | self::DATE_dd_mon_yy => ts('dd-mon-yy OR dd/mm/yy (25-Dec-98 OR 25/12/98)'), | |
47 | self::DATE_dd_mm_yyyy => ts('dd/mm/yyyy (25/12/1998) OR (1/9/2008)'), | |
48 | ], [], '<br/>'); | |
be2fb01f | 49 | $form->setDefaults(['dateFormats' => self::DATE_yyyy_mm_dd]); |
6a488035 TO |
50 | } |
51 | ||
52 | /** | |
8eedd10a | 53 | * Retrieve the date range - relative or absolute and assign it to the form. |
77b97be7 | 54 | * |
b2753d44 | 55 | * @deprecated |
56 | * | |
6a0b768e TO |
57 | * @param CRM_Core_Form $form |
58 | * The form the dates should be added to. | |
bc3f7f04 | 59 | * @param string $fieldName |
6a0b768e | 60 | * @param int $count |
bc3f7f04 | 61 | * @param string $from |
62 | * @param string $to | |
63 | * @param string $fromLabel | |
6a0b768e TO |
64 | * @param bool $required |
65 | * @param array $operators | |
66 | * Additional value pairs to add. | |
bc3f7f04 | 67 | * @param string $dateFormat |
77b97be7 | 68 | * @param bool|string $displayTime |
49d4d222 | 69 | * @param array $attributes |
6a488035 | 70 | */ |
8d7a9d07 | 71 | public static function buildDateRange( |
634e1a1a DL |
72 | &$form, $fieldName, $count = 1, |
73 | $from = '_from', $to = '_to', $fromLabel = 'From:', | |
be2fb01f | 74 | $required = FALSE, $operators = [], |
49d4d222 | 75 | $dateFormat = 'searchDate', $displayTime = FALSE, |
be2fb01f | 76 | $attributes = ['class' => 'crm-select2'] |
634e1a1a | 77 | ) { |
b2753d44 | 78 | CRM_Core_Error::deprecatedFunctionWarning('function will be removed'); |
8d7a9d07 CB |
79 | $selector |
80 | = CRM_Core_Form_Date::returnDateRangeSelector( | |
634e1a1a DL |
81 | $form, $fieldName, $count, |
82 | $from, $to, $fromLabel, | |
83 | $required, $operators, | |
84 | $dateFormat, $displayTime | |
85 | ); | |
86 | CRM_Core_Form_Date::addDateRangeToForm( | |
87 | $form, $fieldName, $selector, | |
88 | $from, $to, $fromLabel, | |
49d4d222 | 89 | $required, $dateFormat, $displayTime, |
90 | $attributes | |
634e1a1a | 91 | ); |
f119bedd | 92 | } |
93 | ||
94 | /** | |
8eedd10a | 95 | * Build the date range array that will provide the form option values. |
96 | * | |
b2753d44 | 97 | * @deprecated |
98 | * | |
8eedd10a | 99 | * It can be - relative or absolute. |
f119bedd | 100 | * |
6a0b768e TO |
101 | * @param CRM_Core_Form $form |
102 | * The form object that we are operating on. | |
f119bedd | 103 | * @param string $fieldName |
6a0b768e TO |
104 | * @param int $count |
105 | * @param string $from | |
106 | * @param string $to | |
107 | * @param string $fromLabel | |
108 | * @param bool $required | |
109 | * @param array $operators | |
110 | * Additional Operator Selections to add. | |
111 | * @param string $dateFormat | |
112 | * @param bool $displayTime | |
8eedd10a | 113 | * |
a6c01b45 CW |
114 | * @return array |
115 | * Values for Selector | |
f119bedd | 116 | */ |
8d7a9d07 | 117 | public static function returnDateRangeSelector( |
634e1a1a DL |
118 | &$form, $fieldName, $count = 1, |
119 | $from = '_from', $to = '_to', $fromLabel = 'From:', | |
be2fb01f | 120 | $required = FALSE, $operators = [], |
634e1a1a DL |
121 | $dateFormat = 'searchDate', $displayTime = FALSE |
122 | ) { | |
b2753d44 | 123 | CRM_Core_Error::deprecatedFunctionWarning('function will be removed'); |
be2fb01f | 124 | $selector = [ |
8d7a9d07 CB |
125 | '' => ts('- any -'), |
126 | 0 => ts('Choose Date Range'), | |
be2fb01f | 127 | ]; |
7537a84b J |
128 | // CRM-16195 Pull relative date filters from an option group |
129 | $selector = $selector + CRM_Core_OptionGroup::values('relative_date_filters'); | |
180214e9 DL |
130 | |
131 | if (is_array($operators)) { | |
132 | $selector = array_merge($selector, $operators); | |
133 | } | |
bc3f7f04 | 134 | |
6a488035 TO |
135 | $config = CRM_Core_Config::singleton(); |
136 | //if fiscal year start on 1 jan then remove fiscal year task | |
137 | //form list | |
138 | if ($config->fiscalYearStart['d'] == 1 & $config->fiscalYearStart['M'] == 1) { | |
139 | unset($selector['this.fiscal_year']); | |
140 | unset($selector['previous.fiscal_year']); | |
141 | } | |
f119bedd | 142 | return $selector; |
143 | } | |
6a488035 | 144 | |
f119bedd | 145 | /** |
8eedd10a | 146 | * Build the date range - relative or absolute. |
f119bedd | 147 | * |
b2753d44 | 148 | * @deprecated |
149 | * | |
6a0b768e TO |
150 | * @param CRM_Core_Form $form |
151 | * The form object that we are operating on. | |
f119bedd | 152 | * @param string $fieldName |
6a0b768e TO |
153 | * @param array $selector |
154 | * Array of option values to add. | |
155 | * @param string $from | |
156 | * Label. | |
8eedd10a | 157 | * @param string $to |
da6b46f4 | 158 | * @param string $fromLabel |
6a0b768e | 159 | * @param bool $required |
f119bedd | 160 | * @param string $dateFormat |
6a0b768e | 161 | * @param bool $displayTime |
49d4d222 | 162 | * @param array $attributes |
f119bedd | 163 | */ |
49d4d222 | 164 | public static function addDateRangeToForm( |
165 | &$form, | |
166 | $fieldName, | |
167 | $selector, | |
4a167d97 SL |
168 | $from, |
169 | $to, | |
170 | $fromLabel, | |
171 | $required, | |
172 | $dateFormat, | |
173 | $displayTime, | |
49d4d222 | 174 | $attributes |
175 | ) { | |
b2753d44 | 176 | CRM_Core_Error::deprecatedFunctionWarning('function will be removed'); |
6a488035 TO |
177 | $form->add('select', |
178 | "{$fieldName}_relative", | |
179 | ts('Relative Date Range'), | |
1eef83c9 CW |
180 | $selector, |
181 | $required, | |
49d4d222 | 182 | $attributes |
353ffa53 | 183 | ); |
6a488035 | 184 | |
2aa397bc | 185 | $form->addDateRange($fieldName, $from, $to, $fromLabel, $dateFormat, FALSE, $displayTime); |
6a488035 | 186 | } |
f119bedd | 187 | |
6a488035 | 188 | } |