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 | */ | |
2aa397bc | 35 | class CRM_Core_Form_Date { |
6a488035 TO |
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 | /** | |
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 | * |
6a488035 | 90 | */ |
bc3f7f04 | 91 | |
634e1a1a DL |
92 | static function buildDateRange( |
93 | &$form, $fieldName, $count = 1, | |
94 | $from = '_from', $to = '_to', $fromLabel = 'From:', | |
95 | $required = FALSE, $operators = array(), | |
96 | $dateFormat = 'searchDate', $displayTime = FALSE | |
97 | ) { | |
98 | $selector = | |
99 | CRM_Core_Form_Date::returnDateRangeSelector( | |
100 | $form, $fieldName, $count, | |
101 | $from, $to, $fromLabel, | |
102 | $required, $operators, | |
103 | $dateFormat, $displayTime | |
104 | ); | |
105 | CRM_Core_Form_Date::addDateRangeToForm( | |
106 | $form, $fieldName, $selector, | |
107 | $from, $to, $fromLabel, | |
108 | $required, $dateFormat, $displayTime | |
109 | ); | |
f119bedd | 110 | } |
111 | ||
112 | /** | |
dc195289 | 113 | * build the date range array that will provide the form option values |
f119bedd | 114 | * It can be - relative or absolute |
115 | * | |
6a0b768e TO |
116 | * @param CRM_Core_Form $form |
117 | * The form object that we are operating on. | |
f119bedd | 118 | * @param string $fieldName |
6a0b768e TO |
119 | * @param int $count |
120 | * @param string $from | |
121 | * @param string $to | |
122 | * @param string $fromLabel | |
123 | * @param bool $required | |
124 | * @param array $operators | |
125 | * Additional Operator Selections to add. | |
126 | * @param string $dateFormat | |
127 | * @param bool $displayTime | |
a6c01b45 CW |
128 | * @return array |
129 | * Values for Selector | |
f119bedd | 130 | */ |
634e1a1a DL |
131 | static function returnDateRangeSelector( |
132 | &$form, $fieldName, $count = 1, | |
133 | $from = '_from', $to = '_to', $fromLabel = 'From:', | |
134 | $required = FALSE, $operators = array(), | |
135 | $dateFormat = 'searchDate', $displayTime = FALSE | |
136 | ) { | |
137 | $selector = | |
138 | array( | |
139 | '' => ts('- any -'), | |
140 | 0 => ts('Choose Date Range'), | |
634e1a1a DL |
141 | 'previous_2.year' => ts('Previous 2 Years'), |
142 | 'previous_2.quarter' => ts('Previous 2 Quarters'), | |
143 | 'previous_2.month' => ts('Previous 2 Months'), | |
144 | 'previous_2.week' => ts('Previous 2 Weeks'), | |
145 | 'previous_2.day' => ts('Previous 2 Days'), | |
c5670e9e | 146 | 'previous_before.year' => ts('Prior to Previous Year'), |
147 | 'previous_before.quarter' => ts('Prior to Previous Quarter'), | |
148 | 'previous_before.month' => ts('Prior to Previous Month'), | |
149 | 'previous_before.week' => ts('Prior to Previous Week'), | |
150 | 'previous_before.day' => ts('Prior to Previous Day'), | |
c5670e9e | 151 | 'previous.year' => ts('Previous Year'), |
152 | 'previous.fiscal_year' => ts('Previous Fiscal Year'), | |
153 | 'previous.quarter' => ts('Previous Quarter'), | |
154 | 'previous.month' => ts('Previous Month'), | |
155 | 'previous.week' => ts('Previous Week'), | |
c239e583 | 156 | 'earlier.year' => ts('To End of Previous Year'), |
157 | 'earlier.quarter' => ts('To End of Previous Quarter'), | |
158 | 'earlier.month' => ts('To End of Previous Month'), | |
159 | 'earlier.week' => ts('To End of Previous Week'), | |
160 | 'earlier.day' => ts('To End of Previous Day'), | |
c5670e9e | 161 | 'greater_previous.year' => ts('From End of Previous Year'), |
162 | 'greater_previous.quarter' => ts('From End of Previous Quarter'), | |
163 | 'greater_previous.month' => ts('From End of Previous Month'), | |
164 | 'greater_previous.week' => ts('From End of Previous Week'), | |
e902edd1 | 165 | 'greater.year' => ts('From Start of Current Year'), |
166 | 'greater.quarter' => ts('From Start of Current Quarter'), | |
167 | 'greater.month' => ts('From Start of Current Month'), | |
168 | 'greater.week' => ts('From Start of Current Week'), | |
169 | 'greater.day' => ts('From Start of Current Day'), | |
170 | 'current.year' => ts('Current Year to-date'), | |
171 | 'current.quarter' => ts('Current Quarter to-date'), | |
172 | 'current.month' => ts('Current Month to-date'), | |
173 | 'current.week' => ts('Current Week to-date'), | |
e2c3163d | 174 | 'ending_3.year' => ts('Last 3 Years'), |
175 | 'ending_2.year' => ts('Last 2 Years'), | |
e72fca81 | 176 | 'ending.year' => ts('Last 12 Months'), |
177 | 'ending.quarter' => ts('Last 3 Months'), | |
178 | 'ending.month' => ts('Last Month'), | |
179 | 'ending.week' => ts('Last 7 days'), | |
c5670e9e | 180 | 'previous.day' => ts('Yesterday'), |
c5670e9e | 181 | 'this.year' => ts('This Year'), |
182 | 'this.fiscal_year' => ts('This Fiscal Year'), | |
183 | 'this.quarter' => ts('This Quarter'), | |
184 | 'this.month' => ts('This Month'), | |
185 | 'this.week' => ts('This Week'), | |
186 | 'this.day' => ts('Today'), | |
c5670e9e | 187 | 'starting.day' => ts('Tomorrow'), |
188 | 'starting.week' => ts('Upcoming 7 days'), | |
189 | 'starting.month' => ts('Upcoming Month'), | |
190 | 'starting.year' => ts('Upcoming 12 Months'), | |
c5670e9e | 191 | 'less.year' => ts('To End of Current Year'), |
192 | 'less.quarter' => ts('To End of Current Quarter'), | |
193 | 'less.month' => ts('To End of Current Month'), | |
194 | 'less.week' => ts('To End of Current Week'), | |
c5670e9e | 195 | 'next.week' => ts('Next Week'), |
196 | 'next.month' => ts('Next Month'), | |
197 | 'next.quarter' => ts('Next Quarter'), | |
198 | 'next.fiscal_year' => ts('Next Fiscal Year'), | |
199 | 'next.year' => ts('Next Year'), | |
200 | ||
634e1a1a | 201 | ); |
180214e9 DL |
202 | |
203 | if (is_array($operators)) { | |
204 | $selector = array_merge($selector, $operators); | |
205 | } | |
bc3f7f04 | 206 | |
6a488035 TO |
207 | $config = CRM_Core_Config::singleton(); |
208 | //if fiscal year start on 1 jan then remove fiscal year task | |
209 | //form list | |
210 | if ($config->fiscalYearStart['d'] == 1 & $config->fiscalYearStart['M'] == 1) { | |
211 | unset($selector['this.fiscal_year']); | |
212 | unset($selector['previous.fiscal_year']); | |
213 | } | |
f119bedd | 214 | return $selector; |
215 | } | |
6a488035 | 216 | |
f119bedd | 217 | /** |
dc195289 | 218 | * build the date range - relative or absolute |
f119bedd | 219 | * |
6a0b768e TO |
220 | * @param CRM_Core_Form $form |
221 | * The form object that we are operating on. | |
f119bedd | 222 | * @param string $fieldName |
6a0b768e TO |
223 | * @param array $selector |
224 | * Array of option values to add. | |
225 | * @param string $from | |
226 | * Label. | |
da6b46f4 EM |
227 | * @param string|\stringe $to |
228 | * @param string $fromLabel | |
6a0b768e | 229 | * @param bool $required |
f119bedd | 230 | * @param string $dateFormat |
6a0b768e | 231 | * @param bool $displayTime |
da6b46f4 | 232 | * |
f119bedd | 233 | * @return null |
234 | */ | |
00be9182 | 235 | public static function addDateRangeToForm(&$form, $fieldName, $selector, $from = '_from', $to = '_to', $fromLabel = 'From:', $required = FALSE, $dateFormat = 'searchDate', $displayTime = FALSE) { |
6a488035 TO |
236 | $form->add('select', |
237 | "{$fieldName}_relative", | |
238 | ts('Relative Date Range'), | |
1eef83c9 CW |
239 | $selector, |
240 | $required, | |
241 | array('class' => 'crm-select2') | |
353ffa53 | 242 | ); |
6a488035 | 243 | |
2aa397bc | 244 | $form->addDateRange($fieldName, $from, $to, $fromLabel, $dateFormat, FALSE, $displayTime); |
6a488035 | 245 | } |
f119bedd | 246 | |
6a488035 | 247 | } |