Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | Class CRM_Core_Form_Date { | |
36 | ||
37 | /** | |
100fef9d | 38 | * Various Date Formats |
6a488035 | 39 | */ |
7da04cde | 40 | 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 |
41 | |
42 | /** | |
43 | * This function is to build the date-format form | |
44 | * | |
6a0b768e TO |
45 | * @param CRM_Core_Form $form |
46 | * The form object that we are operating on. | |
6a488035 TO |
47 | * |
48 | * @static | |
6a488035 | 49 | */ |
00be9182 | 50 | public static function buildAllowedDateFormats(&$form) { |
6a488035 TO |
51 | |
52 | $dateOptions = array(); | |
53 | ||
ac4410cd | 54 | if (CRM_Utils_System::getClassName($form) == 'CRM_Activity_Import_Form_DataSource') { |
6a488035 TO |
55 | $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)'); |
56 | } | |
57 | else { | |
58 | $dateText = ts('yyyy-mm-dd OR yyyymmdd (1998-12-25 OR 19981225) OR (2008-9-1 OR 20080901)'); | |
59 | } | |
60 | ||
61 | $dateOptions[] = $form->createElement('radio', NULL, NULL, $dateText, self::DATE_yyyy_mm_dd); | |
62 | ||
63 | $dateOptions[] = $form->createElement('radio', NULL, NULL, ts('mm/dd/yy OR mm-dd-yy (12/25/98 OR 12-25-98) OR (9/1/08 OR 9-1-08)'), self::DATE_mm_dd_yy); | |
64 | $dateOptions[] = $form->createElement('radio', NULL, NULL, ts('mm/dd/yyyy OR mm-dd-yyyy (12/25/1998 OR 12-25-1998) OR (9/1/2008 OR 9-1-2008)'), self::DATE_mm_dd_yyyy); | |
65 | $dateOptions[] = $form->createElement('radio', NULL, NULL, ts('Month dd, yyyy (December 12, 1998)'), self::DATE_Month_dd_yyyy); | |
66 | $dateOptions[] = $form->createElement('radio', NULL, NULL, ts('dd-mon-yy OR dd/mm/yy (25-Dec-98 OR 25/12/98)'), self::DATE_dd_mon_yy); | |
67 | $dateOptions[] = $form->createElement('radio', NULL, NULL, ts('dd/mm/yyyy (25/12/1998) OR (1/9/2008)'), self::DATE_dd_mm_yyyy); | |
68 | $form->addGroup($dateOptions, 'dateFormats', ts('Date Format'), '<br/>'); | |
69 | $form->setDefaults(array('dateFormats' => self::DATE_yyyy_mm_dd)); | |
70 | } | |
71 | ||
bc3f7f04 | 72 | |
6a488035 | 73 | /** |
f119bedd | 74 | * This function is to retrieve the date range - relative or absolute |
75 | * and assign it to the form | |
77b97be7 | 76 | * |
6a0b768e TO |
77 | * @param CRM_Core_Form $form |
78 | * The form the dates should be added to. | |
bc3f7f04 | 79 | * @param string $fieldName |
6a0b768e | 80 | * @param int $count |
bc3f7f04 | 81 | * @param string $from |
82 | * @param string $to | |
83 | * @param string $fromLabel | |
6a0b768e TO |
84 | * @param bool $required |
85 | * @param array $operators | |
86 | * Additional value pairs to add. | |
bc3f7f04 | 87 | * @param string $dateFormat |
77b97be7 | 88 | * @param bool|string $displayTime |
6a488035 | 89 | * |
6a488035 TO |
90 | * |
91 | * @static | |
6a488035 | 92 | */ |
bc3f7f04 | 93 | |
634e1a1a DL |
94 | static function buildDateRange( |
95 | &$form, $fieldName, $count = 1, | |
96 | $from = '_from', $to = '_to', $fromLabel = 'From:', | |
97 | $required = FALSE, $operators = array(), | |
98 | $dateFormat = 'searchDate', $displayTime = FALSE | |
99 | ) { | |
100 | $selector = | |
101 | CRM_Core_Form_Date::returnDateRangeSelector( | |
102 | $form, $fieldName, $count, | |
103 | $from, $to, $fromLabel, | |
104 | $required, $operators, | |
105 | $dateFormat, $displayTime | |
106 | ); | |
107 | CRM_Core_Form_Date::addDateRangeToForm( | |
108 | $form, $fieldName, $selector, | |
109 | $from, $to, $fromLabel, | |
110 | $required, $dateFormat, $displayTime | |
111 | ); | |
f119bedd | 112 | } |
113 | ||
114 | /** | |
115 | * This function is to build the date range array that will provide the form option values | |
116 | * It can be - relative or absolute | |
117 | * | |
6a0b768e TO |
118 | * @param CRM_Core_Form $form |
119 | * The form object that we are operating on. | |
f119bedd | 120 | * @param string $fieldName |
6a0b768e TO |
121 | * @param int $count |
122 | * @param string $from | |
123 | * @param string $to | |
124 | * @param string $fromLabel | |
125 | * @param bool $required | |
126 | * @param array $operators | |
127 | * Additional Operator Selections to add. | |
128 | * @param string $dateFormat | |
129 | * @param bool $displayTime | |
f119bedd | 130 | * @return array Values for Selector |
131 | */ | |
634e1a1a DL |
132 | static function returnDateRangeSelector( |
133 | &$form, $fieldName, $count = 1, | |
134 | $from = '_from', $to = '_to', $fromLabel = 'From:', | |
135 | $required = FALSE, $operators = array(), | |
136 | $dateFormat = 'searchDate', $displayTime = FALSE | |
137 | ) { | |
138 | $selector = | |
139 | array( | |
140 | '' => ts('- any -'), | |
141 | 0 => ts('Choose Date Range'), | |
634e1a1a DL |
142 | 'previous_2.year' => ts('Previous 2 Years'), |
143 | 'previous_2.quarter' => ts('Previous 2 Quarters'), | |
144 | 'previous_2.month' => ts('Previous 2 Months'), | |
145 | 'previous_2.week' => ts('Previous 2 Weeks'), | |
146 | 'previous_2.day' => ts('Previous 2 Days'), | |
c5670e9e | 147 | |
148 | 'previous_before.year' => ts('Prior to Previous Year'), | |
149 | 'previous_before.quarter' => ts('Prior to Previous Quarter'), | |
150 | 'previous_before.month' => ts('Prior to Previous Month'), | |
151 | 'previous_before.week' => ts('Prior to Previous Week'), | |
152 | 'previous_before.day' => ts('Prior to Previous Day'), | |
153 | ||
154 | 'previous.year' => ts('Previous Year'), | |
155 | 'previous.fiscal_year' => ts('Previous Fiscal Year'), | |
156 | 'previous.quarter' => ts('Previous Quarter'), | |
157 | 'previous.month' => ts('Previous Month'), | |
158 | 'previous.week' => ts('Previous Week'), | |
159 | ||
c239e583 | 160 | 'earlier.year' => ts('To End of Previous Year'), |
161 | 'earlier.quarter' => ts('To End of Previous Quarter'), | |
162 | 'earlier.month' => ts('To End of Previous Month'), | |
163 | 'earlier.week' => ts('To End of Previous Week'), | |
164 | 'earlier.day' => ts('To End of Previous Day'), | |
c5670e9e | 165 | |
166 | 'greater_previous.year' => ts('From End of Previous Year'), | |
167 | 'greater_previous.quarter' => ts('From End of Previous Quarter'), | |
168 | 'greater_previous.month' => ts('From End of Previous Month'), | |
169 | 'greater_previous.week' => ts('From End of Previous Week'), | |
170 | ||
e902edd1 | 171 | 'greater.year' => ts('From Start of Current Year'), |
172 | 'greater.quarter' => ts('From Start of Current Quarter'), | |
173 | 'greater.month' => ts('From Start of Current Month'), | |
174 | 'greater.week' => ts('From Start of Current Week'), | |
175 | 'greater.day' => ts('From Start of Current Day'), | |
c5670e9e | 176 | |
e902edd1 | 177 | 'current.year' => ts('Current Year to-date'), |
178 | 'current.quarter' => ts('Current Quarter to-date'), | |
179 | 'current.month' => ts('Current Month to-date'), | |
180 | 'current.week' => ts('Current Week to-date'), | |
c5670e9e | 181 | |
e2c3163d | 182 | 'ending_3.year' => ts('Last 3 Years'), |
183 | 'ending_2.year' => ts('Last 2 Years'), | |
e72fca81 | 184 | 'ending.year' => ts('Last 12 Months'), |
185 | 'ending.quarter' => ts('Last 3 Months'), | |
186 | 'ending.month' => ts('Last Month'), | |
187 | 'ending.week' => ts('Last 7 days'), | |
c5670e9e | 188 | 'previous.day' => ts('Yesterday'), |
189 | ||
190 | 'this.year' => ts('This Year'), | |
191 | 'this.fiscal_year' => ts('This Fiscal Year'), | |
192 | 'this.quarter' => ts('This Quarter'), | |
193 | 'this.month' => ts('This Month'), | |
194 | 'this.week' => ts('This Week'), | |
195 | 'this.day' => ts('Today'), | |
196 | ||
197 | 'starting.day' => ts('Tomorrow'), | |
198 | 'starting.week' => ts('Upcoming 7 days'), | |
199 | 'starting.month' => ts('Upcoming Month'), | |
200 | 'starting.year' => ts('Upcoming 12 Months'), | |
201 | ||
202 | 'less.year' => ts('To End of Current Year'), | |
203 | 'less.quarter' => ts('To End of Current Quarter'), | |
204 | 'less.month' => ts('To End of Current Month'), | |
205 | 'less.week' => ts('To End of Current Week'), | |
206 | ||
207 | 'next.week' => ts('Next Week'), | |
208 | 'next.month' => ts('Next Month'), | |
209 | 'next.quarter' => ts('Next Quarter'), | |
210 | 'next.fiscal_year' => ts('Next Fiscal Year'), | |
211 | 'next.year' => ts('Next Year'), | |
212 | ||
634e1a1a | 213 | ); |
180214e9 DL |
214 | |
215 | if (is_array($operators)) { | |
216 | $selector = array_merge($selector, $operators); | |
217 | } | |
bc3f7f04 | 218 | |
6a488035 TO |
219 | $config = CRM_Core_Config::singleton(); |
220 | //if fiscal year start on 1 jan then remove fiscal year task | |
221 | //form list | |
222 | if ($config->fiscalYearStart['d'] == 1 & $config->fiscalYearStart['M'] == 1) { | |
223 | unset($selector['this.fiscal_year']); | |
224 | unset($selector['previous.fiscal_year']); | |
225 | } | |
f119bedd | 226 | return $selector; |
227 | } | |
6a488035 | 228 | |
f119bedd | 229 | /** |
230 | * This function is to build the date range - relative or absolute | |
231 | * | |
6a0b768e TO |
232 | * @param CRM_Core_Form $form |
233 | * The form object that we are operating on. | |
f119bedd | 234 | * @param string $fieldName |
6a0b768e TO |
235 | * @param array $selector |
236 | * Array of option values to add. | |
237 | * @param string $from | |
238 | * Label. | |
da6b46f4 EM |
239 | * @param string|\stringe $to |
240 | * @param string $fromLabel | |
6a0b768e | 241 | * @param bool $required |
f119bedd | 242 | * @param string $dateFormat |
6a0b768e | 243 | * @param bool $displayTime |
da6b46f4 | 244 | * |
f119bedd | 245 | * @return null |
246 | */ | |
00be9182 | 247 | public static function addDateRangeToForm(&$form, $fieldName, $selector, $from = '_from', $to = '_to', $fromLabel = 'From:', $required = FALSE, $dateFormat = 'searchDate', $displayTime = FALSE) { |
6a488035 TO |
248 | $form->add('select', |
249 | "{$fieldName}_relative", | |
250 | ts('Relative Date Range'), | |
1eef83c9 CW |
251 | $selector, |
252 | $required, | |
253 | array('class' => 'crm-select2') | |
f119bedd | 254 | ); |
6a488035 | 255 | |
f119bedd | 256 | $form->addDateRange($fieldName, $from, $to, $fromLabel, $dateFormat, FALSE, $displayTime); |
6a488035 | 257 | } |
f119bedd | 258 | |
6a488035 | 259 | } |