3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
35 Class CRM_Core_Form_Date
{
38 * Various Date Formats
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;
43 * This function is to build the date-format form
45 * @param CRM_Core_Form $form the form object that we are operating on
50 static function buildAllowedDateFormats(&$form) {
52 $dateOptions = array();
54 if (CRM_Utils_System
::getClassName($form) == 'CRM_Activity_Import_Form_DataSource') {
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)');
58 $dateText = ts('yyyy-mm-dd OR yyyymmdd (1998-12-25 OR 19981225) OR (2008-9-1 OR 20080901)');
61 $dateOptions[] = $form->createElement('radio', NULL, NULL, $dateText, self
::DATE_yyyy_mm_dd
);
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
));
74 * This function is to retrieve the date range - relative or absolute
75 * and assign it to the form
77 * @param CRM_Core_Form $form - the form the dates should be added to
78 * @param string $fieldName
79 * @param integer $count
82 * @param string $fromLabel
83 * @param boolean $required
84 * @param array $operators Additional value pairs to add
85 * @param string $dateFormat
86 * @param bool|string $displayTime
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
100 CRM_Core_Form_Date
::returnDateRangeSelector(
101 $form, $fieldName, $count,
102 $from, $to, $fromLabel,
103 $required, $operators,
104 $dateFormat, $displayTime
106 CRM_Core_Form_Date
::addDateRangeToForm(
107 $form, $fieldName, $selector,
108 $from, $to, $fromLabel,
109 $required, $dateFormat, $displayTime
114 * This function is to build the date range array that will provide the form option values
115 * It can be - relative or absolute
117 * @param CRM_Core_Form $form the form object that we are operating on
118 * @param string $fieldName
119 * @param integer $count
120 * @param String $from
122 * @param String $fromLabel
123 * @param Boolean $required
124 * @param Array $operators Additional Operator Selections to add
125 * @param String $dateFormat
126 * @param Boolean $displayTime
127 * @return array Values for Selector
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
138 0 => ts('Choose Date Range'),
139 'previous_2.year' => ts('Previous 2 Years'),
140 'previous_2.quarter' => ts('Previous 2 Quarters'),
141 'previous_2.month' => ts('Previous 2 Months'),
142 'previous_2.week' => ts('Previous 2 Weeks'),
143 'previous_2.day' => ts('Previous 2 Days'),
145 'previous_before.year' => ts('Prior to Previous Year'),
146 'previous_before.quarter' => ts('Prior to Previous Quarter'),
147 'previous_before.month' => ts('Prior to Previous Month'),
148 'previous_before.week' => ts('Prior to Previous Week'),
149 'previous_before.day' => ts('Prior to Previous Day'),
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'),
157 'earlier.year' => ts('To End of Previous Year'),
158 'earlier.quarter' => ts('To End of Previous Quarter'),
159 'earlier.month' => ts('To End of Previous Month'),
160 'earlier.week' => ts('To End of Previous Week'),
161 'earlier.day' => ts('To End of Previous Day'),
163 'greater_previous.year' => ts('From End of Previous Year'),
164 'greater_previous.quarter' => ts('From End of Previous Quarter'),
165 'greater_previous.month' => ts('From End of Previous Month'),
166 'greater_previous.week' => ts('From End of Previous Week'),
168 'greater.year' => ts('From Start of Current Year'),
169 'greater.quarter' => ts('From Start of Current Quarter'),
170 'greater.month' => ts('From Start of Current Month'),
171 'greater.week' => ts('From Start of Current Week'),
172 'greater.day' => ts('From Start of Current Day'),
174 'current.year' => ts('Current Year to-date'),
175 'current.quarter' => ts('Current Quarter to-date'),
176 'current.month' => ts('Current Month to-date'),
177 'current.week' => ts('Current Week to-date'),
179 'ending_3.year' => ts('Last 3 Years'),
180 'ending_2.year' => ts('Last 2 Years'),
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'),
185 'previous.day' => ts('Yesterday'),
187 'this.year' => ts('This Year'),
188 'this.fiscal_year' => ts('This Fiscal Year'),
189 'this.quarter' => ts('This Quarter'),
190 'this.month' => ts('This Month'),
191 'this.week' => ts('This Week'),
192 'this.day' => ts('Today'),
194 'starting.day' => ts('Tomorrow'),
195 'starting.week' => ts('Upcoming 7 days'),
196 'starting.month' => ts('Upcoming Month'),
197 'starting.year' => ts('Upcoming 12 Months'),
199 'less.year' => ts('To End of Current Year'),
200 'less.quarter' => ts('To End of Current Quarter'),
201 'less.month' => ts('To End of Current Month'),
202 'less.week' => ts('To End of Current Week'),
204 'next.week' => ts('Next Week'),
205 'next.month' => ts('Next Month'),
206 'next.quarter' => ts('Next Quarter'),
207 'next.fiscal_year' => ts('Next Fiscal Year'),
208 'next.year' => ts('Next Year'),
212 if (is_array($operators)) {
213 $selector = array_merge($selector, $operators);
216 $config = CRM_Core_Config
::singleton();
217 //if fiscal year start on 1 jan then remove fiscal year task
219 if ($config->fiscalYearStart
['d'] == 1 & $config->fiscalYearStart
['M'] == 1) {
220 unset($selector['this.fiscal_year']);
221 unset($selector['previous.fiscal_year']);
227 * This function is to build the date range - relative or absolute
229 * @param CRM_Core_Form $form the form object that we are operating on
230 * @param string $fieldName
231 * @param Array $selector array of option values to add
232 * @param string $from Label
233 * @param string|\stringe $to
234 * @param string $fromLabel
235 * @param boolean $required
236 * @param string $dateFormat
237 * @param boolean $displayTime
241 static function addDateRangeToForm(&$form, $fieldName, $selector, $from = '_from', $to = '_to', $fromLabel = 'From:', $required = FALSE, $dateFormat = 'searchDate', $displayTime = FALSE) {
243 "{$fieldName}_relative",
244 ts('Relative Date Range'),
247 array('class' => 'crm-select2')
250 $form->addDateRange($fieldName, $from, $to, $fromLabel, $dateFormat, FALSE, $displayTime);