Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
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 | /** | |
38 | * various Date Formats | |
39 | */ | |
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; | |
41 | ||
42 | /** | |
43 | * This function is to build the date-format form | |
44 | * | |
45 | * @param Object $form the form object that we are operating on | |
46 | * | |
47 | * @static | |
48 | * @access public | |
49 | */ | |
50 | static function buildAllowedDateFormats(&$form) { | |
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 | * |
bc3f7f04 | 77 | * @param object $form - the form the dates should be added to |
78 | * @param string $fieldName | |
79 | * @param integer $count | |
80 | * @param string $from | |
81 | * @param string $to | |
82 | * @param string $fromLabel | |
83 | * @param boolean $required | |
84 | * @param array $operators Additional value pairs to add | |
85 | * @param string $dateFormat | |
77b97be7 | 86 | * @param bool|string $displayTime |
6a488035 | 87 | * |
6a488035 TO |
88 | * |
89 | * @static | |
90 | * @access public | |
91 | */ | |
bc3f7f04 | 92 | |
634e1a1a DL |
93 | static function buildDateRange( |
94 | &$form, $fieldName, $count = 1, | |
95 | $from = '_from', $to = '_to', $fromLabel = 'From:', | |
96 | $required = FALSE, $operators = array(), | |
97 | $dateFormat = 'searchDate', $displayTime = FALSE | |
98 | ) { | |
99 | $selector = | |
100 | CRM_Core_Form_Date::returnDateRangeSelector( | |
101 | $form, $fieldName, $count, | |
102 | $from, $to, $fromLabel, | |
103 | $required, $operators, | |
104 | $dateFormat, $displayTime | |
105 | ); | |
106 | CRM_Core_Form_Date::addDateRangeToForm( | |
107 | $form, $fieldName, $selector, | |
108 | $from, $to, $fromLabel, | |
109 | $required, $dateFormat, $displayTime | |
110 | ); | |
f119bedd | 111 | } |
112 | ||
113 | /** | |
114 | * This function is to build the date range array that will provide the form option values | |
115 | * It can be - relative or absolute | |
116 | * | |
117 | * @param Object $form the form object that we are operating on | |
118 | * @param string $fieldName | |
119 | * @param integer $count | |
120 | * @param String $from | |
121 | * @param String $to | |
122 | * @param String $fromLabel | |
123 | * @param Boolean $required | |
bc3f7f04 | 124 | * @param Array $operators Additional Operator Selections to add |
f119bedd | 125 | * @param String $dateFormat |
126 | * @param Boolean $displayTime | |
127 | * @return array Values for Selector | |
128 | */ | |
634e1a1a DL |
129 | static function returnDateRangeSelector( |
130 | &$form, $fieldName, $count = 1, | |
131 | $from = '_from', $to = '_to', $fromLabel = 'From:', | |
132 | $required = FALSE, $operators = array(), | |
133 | $dateFormat = 'searchDate', $displayTime = FALSE | |
134 | ) { | |
135 | $selector = | |
136 | array( | |
137 | '' => ts('- any -'), | |
138 | 0 => ts('Choose Date Range'), | |
139 | 'this.year' => ts('This Year'), | |
140 | 'this.fiscal_year' => ts('This Fiscal Year'), | |
141 | 'this.quarter' => ts('This Quarter'), | |
142 | 'this.month' => ts('This Month'), | |
143 | 'this.week' => ts('This Week'), | |
144 | 'this.day' => ts('This Day'), | |
145 | 'previous.year' => ts('Previous Year'), | |
146 | 'previous.fiscal_year' => ts('Previous Fiscal Year'), | |
147 | 'previous.quarter' => ts('Previous Quarter'), | |
148 | 'previous.month' => ts('Previous Month'), | |
149 | 'previous.week' => ts('Previous Week'), | |
150 | 'previous.day' => ts('Previous Day'), | |
151 | 'previous_before.year' => ts('Prior to Previous Year'), | |
152 | 'previous_before.quarter' => ts('Prior to Previous Quarter'), | |
153 | 'previous_before.month' => ts('Prior to Previous Month'), | |
154 | 'previous_before.week' => ts('Prior to Previous Week'), | |
155 | 'previous_before.day' => ts('Prior to Previous Day'), | |
156 | 'previous_2.year' => ts('Previous 2 Years'), | |
157 | 'previous_2.quarter' => ts('Previous 2 Quarters'), | |
158 | 'previous_2.month' => ts('Previous 2 Months'), | |
159 | 'previous_2.week' => ts('Previous 2 Weeks'), | |
160 | 'previous_2.day' => ts('Previous 2 Days'), | |
c239e583 | 161 | 'earlier.year' => ts('To End of Previous Year'), |
162 | 'earlier.quarter' => ts('To End of Previous Quarter'), | |
163 | 'earlier.month' => ts('To End of Previous Month'), | |
164 | 'earlier.week' => ts('To End of Previous Week'), | |
165 | 'earlier.day' => ts('To End of Previous Day'), | |
e902edd1 | 166 | 'greater.year' => ts('From Start of Current Year'), |
167 | 'greater.quarter' => ts('From Start of Current Quarter'), | |
168 | 'greater.month' => ts('From Start of Current Month'), | |
169 | 'greater.week' => ts('From Start of Current Week'), | |
170 | 'greater.day' => ts('From Start of Current Day'), | |
70db5f07 | 171 | 'greater_previous.year' => ts('From End of Previous Year'), |
172 | 'greater_previous.quarter' => ts('From End of Previous Quarter'), | |
173 | 'greater_previous.month' => ts('From End of Previous Month'), | |
174 | 'greater_previous.week' => ts('From End of Previous Week'), | |
e902edd1 | 175 | 'current.year' => ts('Current Year to-date'), |
176 | 'current.quarter' => ts('Current Quarter to-date'), | |
177 | 'current.month' => ts('Current Month to-date'), | |
178 | 'current.week' => ts('Current Week to-date'), | |
e2c3163d | 179 | 'ending_3.year' => ts('Last 3 Years'), |
180 | 'ending_2.year' => ts('Last 2 Years'), | |
e72fca81 | 181 | 'ending.year' => ts('Last 12 Months'), |
182 | 'ending.quarter' => ts('Last 3 Months'), | |
183 | 'ending.month' => ts('Last Month'), | |
184 | 'ending.week' => ts('Last 7 days'), | |
634e1a1a | 185 | ); |
180214e9 DL |
186 | |
187 | if (is_array($operators)) { | |
188 | $selector = array_merge($selector, $operators); | |
189 | } | |
bc3f7f04 | 190 | |
6a488035 TO |
191 | $config = CRM_Core_Config::singleton(); |
192 | //if fiscal year start on 1 jan then remove fiscal year task | |
193 | //form list | |
194 | if ($config->fiscalYearStart['d'] == 1 & $config->fiscalYearStart['M'] == 1) { | |
195 | unset($selector['this.fiscal_year']); | |
196 | unset($selector['previous.fiscal_year']); | |
197 | } | |
f119bedd | 198 | return $selector; |
199 | } | |
6a488035 | 200 | |
f119bedd | 201 | /** |
202 | * This function is to build the date range - relative or absolute | |
203 | * | |
da6b46f4 | 204 | * @param CRM_Core_Form $form the form object that we are operating on |
f119bedd | 205 | * @param string $fieldName |
206 | * @param Array $selector array of option values to add | |
f119bedd | 207 | * @param string $from Label |
da6b46f4 EM |
208 | * @param string|\stringe $to |
209 | * @param string $fromLabel | |
f119bedd | 210 | * @param boolean $required |
211 | * @param string $dateFormat | |
212 | * @param boolean $displayTime | |
da6b46f4 EM |
213 | * |
214 | * @internal param int $count | |
f119bedd | 215 | * @return null |
216 | */ | |
217 | static function addDateRangeToForm(&$form, $fieldName, $selector, $from = '_from', $to = '_to', $fromLabel = 'From:', $required = FALSE, $dateFormat = 'searchDate', $displayTime = FALSE) { | |
6a488035 TO |
218 | $form->add('select', |
219 | "{$fieldName}_relative", | |
220 | ts('Relative Date Range'), | |
1eef83c9 CW |
221 | $selector, |
222 | $required, | |
223 | array('class' => 'crm-select2') | |
f119bedd | 224 | ); |
6a488035 | 225 | |
f119bedd | 226 | $form->addDateRange($fieldName, $from, $to, $fromLabel, $dateFormat, FALSE, $displayTime); |
6a488035 | 227 | } |
f119bedd | 228 | |
6a488035 TO |
229 | } |
230 |