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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
2aa397bc | 35 | class CRM_Core_Form_Date { |
6a488035 TO |
36 | |
37 | /** | |
fe482240 | 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 | /** | |
dc195289 | 43 | * build the date-format form |
6a488035 | 44 | * |
6a0b768e TO |
45 | * @param CRM_Core_Form $form |
46 | * The form object that we are operating on. | |
6a488035 | 47 | * |
6a488035 | 48 | */ |
00be9182 | 49 | public static function buildAllowedDateFormats(&$form) { |
6a488035 TO |
50 | |
51 | $dateOptions = array(); | |
52 | ||
ac4410cd | 53 | if (CRM_Utils_System::getClassName($form) == 'CRM_Activity_Import_Form_DataSource') { |
6a488035 TO |
54 | $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)'); |
55 | } | |
56 | else { | |
57 | $dateText = ts('yyyy-mm-dd OR yyyymmdd (1998-12-25 OR 19981225) OR (2008-9-1 OR 20080901)'); | |
58 | } | |
59 | ||
60 | $dateOptions[] = $form->createElement('radio', NULL, NULL, $dateText, self::DATE_yyyy_mm_dd); | |
61 | ||
62 | $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); | |
63 | $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); | |
64 | $dateOptions[] = $form->createElement('radio', NULL, NULL, ts('Month dd, yyyy (December 12, 1998)'), self::DATE_Month_dd_yyyy); | |
65 | $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); | |
66 | $dateOptions[] = $form->createElement('radio', NULL, NULL, ts('dd/mm/yyyy (25/12/1998) OR (1/9/2008)'), self::DATE_dd_mm_yyyy); | |
67 | $form->addGroup($dateOptions, 'dateFormats', ts('Date Format'), '<br/>'); | |
68 | $form->setDefaults(array('dateFormats' => self::DATE_yyyy_mm_dd)); | |
69 | } | |
70 | ||
bc3f7f04 | 71 | |
6a488035 | 72 | /** |
dc195289 | 73 | * retrieve the date range - relative or absolute |
f119bedd | 74 | * and assign it to the form |
77b97be7 | 75 | * |
6a0b768e TO |
76 | * @param CRM_Core_Form $form |
77 | * The form the dates should be added to. | |
bc3f7f04 | 78 | * @param string $fieldName |
6a0b768e | 79 | * @param int $count |
bc3f7f04 | 80 | * @param string $from |
81 | * @param string $to | |
82 | * @param string $fromLabel | |
6a0b768e TO |
83 | * @param bool $required |
84 | * @param array $operators | |
85 | * Additional value pairs to add. | |
bc3f7f04 | 86 | * @param string $dateFormat |
77b97be7 | 87 | * @param bool|string $displayTime |
6a488035 | 88 | * |
6a488035 | 89 | */ |
8d7a9d07 | 90 | public static function buildDateRange( |
634e1a1a DL |
91 | &$form, $fieldName, $count = 1, |
92 | $from = '_from', $to = '_to', $fromLabel = 'From:', | |
93 | $required = FALSE, $operators = array(), | |
94 | $dateFormat = 'searchDate', $displayTime = FALSE | |
95 | ) { | |
8d7a9d07 CB |
96 | $selector |
97 | = CRM_Core_Form_Date::returnDateRangeSelector( | |
634e1a1a DL |
98 | $form, $fieldName, $count, |
99 | $from, $to, $fromLabel, | |
100 | $required, $operators, | |
101 | $dateFormat, $displayTime | |
102 | ); | |
103 | CRM_Core_Form_Date::addDateRangeToForm( | |
104 | $form, $fieldName, $selector, | |
105 | $from, $to, $fromLabel, | |
106 | $required, $dateFormat, $displayTime | |
107 | ); | |
f119bedd | 108 | } |
109 | ||
110 | /** | |
fe482240 | 111 | * build the date range array that will provide the form option values. |
f119bedd | 112 | * It can be - relative or absolute |
113 | * | |
6a0b768e TO |
114 | * @param CRM_Core_Form $form |
115 | * The form object that we are operating on. | |
f119bedd | 116 | * @param string $fieldName |
6a0b768e TO |
117 | * @param int $count |
118 | * @param string $from | |
119 | * @param string $to | |
120 | * @param string $fromLabel | |
121 | * @param bool $required | |
122 | * @param array $operators | |
123 | * Additional Operator Selections to add. | |
124 | * @param string $dateFormat | |
125 | * @param bool $displayTime | |
a6c01b45 CW |
126 | * @return array |
127 | * Values for Selector | |
f119bedd | 128 | */ |
8d7a9d07 | 129 | public static function returnDateRangeSelector( |
634e1a1a DL |
130 | &$form, $fieldName, $count = 1, |
131 | $from = '_from', $to = '_to', $fromLabel = 'From:', | |
132 | $required = FALSE, $operators = array(), | |
133 | $dateFormat = 'searchDate', $displayTime = FALSE | |
134 | ) { | |
8d7a9d07 CB |
135 | $selector = array( |
136 | '' => ts('- any -'), | |
137 | 0 => ts('Choose Date Range'), | |
138 | 'previous_2.year' => ts('Previous 2 Years'), | |
139 | 'previous_2.quarter' => ts('Previous 2 Quarters'), | |
140 | 'previous_2.month' => ts('Previous 2 Months'), | |
141 | 'previous_2.week' => ts('Previous 2 Weeks'), | |
142 | 'previous_2.day' => ts('Previous 2 Days'), | |
143 | 'previous_before.year' => ts('Prior to Previous Year'), | |
144 | 'previous_before.quarter' => ts('Prior to Previous Quarter'), | |
145 | 'previous_before.month' => ts('Prior to Previous Month'), | |
146 | 'previous_before.week' => ts('Prior to Previous Week'), | |
147 | 'previous_before.day' => ts('Prior to Previous Day'), | |
148 | 'previous.year' => ts('Previous Year'), | |
149 | 'previous.fiscal_year' => ts('Previous Fiscal Year'), | |
150 | 'previous.quarter' => ts('Previous Quarter'), | |
151 | 'previous.month' => ts('Previous Month'), | |
152 | 'previous.week' => ts('Previous Week'), | |
153 | 'earlier.year' => ts('To End of Previous Year'), | |
154 | 'earlier.quarter' => ts('To End of Previous Quarter'), | |
155 | 'earlier.month' => ts('To End of Previous Month'), | |
156 | 'earlier.week' => ts('To End of Previous Week'), | |
157 | 'earlier.day' => ts('To End of Previous Day'), | |
158 | 'greater_previous.year' => ts('From End of Previous Year'), | |
159 | 'greater_previous.quarter' => ts('From End of Previous Quarter'), | |
160 | 'greater_previous.month' => ts('From End of Previous Month'), | |
161 | 'greater_previous.week' => ts('From End of Previous Week'), | |
162 | 'greater.year' => ts('From Start of Current Year'), | |
163 | 'greater.quarter' => ts('From Start of Current Quarter'), | |
164 | 'greater.month' => ts('From Start of Current Month'), | |
165 | 'greater.week' => ts('From Start of Current Week'), | |
166 | 'greater.day' => ts('From Start of Current Day'), | |
167 | 'current.year' => ts('Current Year to-date'), | |
168 | 'current.quarter' => ts('Current Quarter to-date'), | |
169 | 'current.month' => ts('Current Month to-date'), | |
170 | 'current.week' => ts('Current Week to-date'), | |
171 | 'ending_3.year' => ts('Last 3 Years'), | |
172 | 'ending_2.year' => ts('Last 2 Years'), | |
173 | 'ending.year' => ts('Last 12 Months'), | |
174 | 'ending.quarter' => ts('Last 3 Months'), | |
175 | 'ending.month' => ts('Last Month'), | |
176 | 'ending.week' => ts('Last 7 days'), | |
177 | 'previous.day' => ts('Yesterday'), | |
178 | 'this.year' => ts('This Year'), | |
179 | 'this.fiscal_year' => ts('This Fiscal Year'), | |
180 | 'this.quarter' => ts('This Quarter'), | |
181 | 'this.month' => ts('This Month'), | |
182 | 'this.week' => ts('This Week'), | |
183 | 'this.day' => ts('Today'), | |
184 | 'starting.day' => ts('Tomorrow'), | |
185 | 'starting.week' => ts('Upcoming 7 days'), | |
186 | 'starting.month' => ts('Upcoming Month'), | |
187 | 'starting.year' => ts('Upcoming 12 Months'), | |
188 | 'less.year' => ts('To End of Current Year'), | |
189 | 'less.quarter' => ts('To End of Current Quarter'), | |
190 | 'less.month' => ts('To End of Current Month'), | |
191 | 'less.week' => ts('To End of Current Week'), | |
192 | 'next.week' => ts('Next Week'), | |
193 | 'next.month' => ts('Next Month'), | |
194 | 'next.quarter' => ts('Next Quarter'), | |
195 | 'next.fiscal_year' => ts('Next Fiscal Year'), | |
196 | 'next.year' => ts('Next Year'), | |
197 | ); | |
180214e9 DL |
198 | |
199 | if (is_array($operators)) { | |
200 | $selector = array_merge($selector, $operators); | |
201 | } | |
bc3f7f04 | 202 | |
6a488035 TO |
203 | $config = CRM_Core_Config::singleton(); |
204 | //if fiscal year start on 1 jan then remove fiscal year task | |
205 | //form list | |
206 | if ($config->fiscalYearStart['d'] == 1 & $config->fiscalYearStart['M'] == 1) { | |
207 | unset($selector['this.fiscal_year']); | |
208 | unset($selector['previous.fiscal_year']); | |
209 | } | |
f119bedd | 210 | return $selector; |
211 | } | |
6a488035 | 212 | |
f119bedd | 213 | /** |
dc195289 | 214 | * build the date range - relative or absolute |
f119bedd | 215 | * |
6a0b768e TO |
216 | * @param CRM_Core_Form $form |
217 | * The form object that we are operating on. | |
f119bedd | 218 | * @param string $fieldName |
6a0b768e TO |
219 | * @param array $selector |
220 | * Array of option values to add. | |
221 | * @param string $from | |
222 | * Label. | |
da6b46f4 EM |
223 | * @param string|\stringe $to |
224 | * @param string $fromLabel | |
6a0b768e | 225 | * @param bool $required |
f119bedd | 226 | * @param string $dateFormat |
6a0b768e | 227 | * @param bool $displayTime |
f119bedd | 228 | */ |
00be9182 | 229 | public static function addDateRangeToForm(&$form, $fieldName, $selector, $from = '_from', $to = '_to', $fromLabel = 'From:', $required = FALSE, $dateFormat = 'searchDate', $displayTime = FALSE) { |
6a488035 TO |
230 | $form->add('select', |
231 | "{$fieldName}_relative", | |
232 | ts('Relative Date Range'), | |
1eef83c9 CW |
233 | $selector, |
234 | $required, | |
235 | array('class' => 'crm-select2') | |
353ffa53 | 236 | ); |
6a488035 | 237 | |
2aa397bc | 238 | $form->addDateRange($fieldName, $from, $to, $fromLabel, $dateFormat, FALSE, $displayTime); |
6a488035 | 239 | } |
f119bedd | 240 | |
6a488035 | 241 | } |