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
49 public static function buildAllowedDateFormats(&$form) {
51 $dateOptions = array();
53 if (CRM_Utils_System
::getClassName($form) == 'CRM_Activity_Import_Form_DataSource') {
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)');
57 $dateText = ts('yyyy-mm-dd OR yyyymmdd (1998-12-25 OR 19981225) OR (2008-9-1 OR 20080901)');
60 $dateOptions[] = $form->createElement('radio', NULL, NULL, $dateText, self
::DATE_yyyy_mm_dd
);
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
));
73 * This function is to retrieve the date range - relative or absolute
74 * and assign it to the form
76 * @param CRM_Core_Form $form - the form the dates should be added to
77 * @param string $fieldName
78 * @param integer $count
81 * @param string $fromLabel
82 * @param boolean $required
83 * @param array $operators Additional value pairs to add
84 * @param string $dateFormat
85 * @param bool|string $displayTime
91 static function buildDateRange(
92 &$form, $fieldName, $count = 1,
93 $from = '_from', $to = '_to', $fromLabel = 'From:',
94 $required = FALSE, $operators = array(),
95 $dateFormat = 'searchDate', $displayTime = FALSE
98 CRM_Core_Form_Date
::returnDateRangeSelector(
99 $form, $fieldName, $count,
100 $from, $to, $fromLabel,
101 $required, $operators,
102 $dateFormat, $displayTime
104 CRM_Core_Form_Date
::addDateRangeToForm(
105 $form, $fieldName, $selector,
106 $from, $to, $fromLabel,
107 $required, $dateFormat, $displayTime
112 * This function is to build the date range array that will provide the form option values
113 * It can be - relative or absolute
115 * @param CRM_Core_Form $form the form object that we are operating on
116 * @param string $fieldName
117 * @param integer $count
118 * @param String $from
120 * @param String $fromLabel
121 * @param Boolean $required
122 * @param Array $operators Additional Operator Selections to add
123 * @param String $dateFormat
124 * @param Boolean $displayTime
125 * @return array Values for Selector
127 static function returnDateRangeSelector(
128 &$form, $fieldName, $count = 1,
129 $from = '_from', $to = '_to', $fromLabel = 'From:',
130 $required = FALSE, $operators = array(),
131 $dateFormat = 'searchDate', $displayTime = FALSE
136 0 => ts('Choose Date Range'),
137 'previous_2.year' => ts('Previous 2 Years'),
138 'previous_2.quarter' => ts('Previous 2 Quarters'),
139 'previous_2.month' => ts('Previous 2 Months'),
140 'previous_2.week' => ts('Previous 2 Weeks'),
141 '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'),
149 'previous.year' => ts('Previous Year'),
150 'previous.fiscal_year' => ts('Previous Fiscal Year'),
151 'previous.quarter' => ts('Previous Quarter'),
152 'previous.month' => ts('Previous Month'),
153 'previous.week' => ts('Previous Week'),
155 'earlier.year' => ts('To End of Previous Year'),
156 'earlier.quarter' => ts('To End of Previous Quarter'),
157 'earlier.month' => ts('To End of Previous Month'),
158 'earlier.week' => ts('To End of Previous Week'),
159 'earlier.day' => ts('To End of Previous Day'),
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'),
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'),
172 'current.year' => ts('Current Year to-date'),
173 'current.quarter' => ts('Current Quarter to-date'),
174 'current.month' => ts('Current Month to-date'),
175 'current.week' => ts('Current Week to-date'),
177 'ending_3.year' => ts('Last 3 Years'),
178 'ending_2.year' => ts('Last 2 Years'),
179 'ending.year' => ts('Last 12 Months'),
180 'ending.quarter' => ts('Last 3 Months'),
181 'ending.month' => ts('Last Month'),
182 'ending.week' => ts('Last 7 days'),
183 'previous.day' => ts('Yesterday'),
185 'this.year' => ts('This Year'),
186 'this.fiscal_year' => ts('This Fiscal Year'),
187 'this.quarter' => ts('This Quarter'),
188 'this.month' => ts('This Month'),
189 'this.week' => ts('This Week'),
190 'this.day' => ts('Today'),
192 'starting.day' => ts('Tomorrow'),
193 'starting.week' => ts('Upcoming 7 days'),
194 'starting.month' => ts('Upcoming Month'),
195 'starting.year' => ts('Upcoming 12 Months'),
197 'less.year' => ts('To End of Current Year'),
198 'less.quarter' => ts('To End of Current Quarter'),
199 'less.month' => ts('To End of Current Month'),
200 'less.week' => ts('To End of Current Week'),
202 'next.week' => ts('Next Week'),
203 'next.month' => ts('Next Month'),
204 'next.quarter' => ts('Next Quarter'),
205 'next.fiscal_year' => ts('Next Fiscal Year'),
206 'next.year' => ts('Next Year'),
210 if (is_array($operators)) {
211 $selector = array_merge($selector, $operators);
214 $config = CRM_Core_Config
::singleton();
215 //if fiscal year start on 1 jan then remove fiscal year task
217 if ($config->fiscalYearStart
['d'] == 1 & $config->fiscalYearStart
['M'] == 1) {
218 unset($selector['this.fiscal_year']);
219 unset($selector['previous.fiscal_year']);
225 * This function is to build the date range - relative or absolute
227 * @param CRM_Core_Form $form the form object that we are operating on
228 * @param string $fieldName
229 * @param Array $selector array of option values to add
230 * @param string $from Label
231 * @param string|\stringe $to
232 * @param string $fromLabel
233 * @param boolean $required
234 * @param string $dateFormat
235 * @param boolean $displayTime
239 public static function addDateRangeToForm(&$form, $fieldName, $selector, $from = '_from', $to = '_to', $fromLabel = 'From:', $required = FALSE, $dateFormat = 'searchDate', $displayTime = FALSE) {
241 "{$fieldName}_relative",
242 ts('Relative Date Range'),
245 array('class' => 'crm-select2')
248 $form->addDateRange($fieldName, $from, $to, $fromLabel, $dateFormat, FALSE, $displayTime);