3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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 Object $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_UploadFile') {
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
76 * @param object $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 string $displayTime
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
99 CRM_Core_Form_Date
::returnDateRangeSelector(
100 $form, $fieldName, $count,
101 $from, $to, $fromLabel,
102 $required, $operators,
103 $dateFormat, $displayTime
105 CRM_Core_Form_Date
::addDateRangeToForm(
106 $form, $fieldName, $selector,
107 $from, $to, $fromLabel,
108 $required, $dateFormat, $displayTime
113 * This function is to build the date range array that will provide the form option values
114 * It can be - relative or absolute
116 * @param Object $form the form object that we are operating on
117 * @param string $fieldName
118 * @param integer $count
119 * @param String $from
121 * @param String $fromLabel
122 * @param Boolean $required
123 * @param Array $operators Additional Operator Selections to add
124 * @param String $dateFormat
125 * @param Boolean $displayTime
126 * @return array Values for Selector
128 static function returnDateRangeSelector(
129 &$form, $fieldName, $count = 1,
130 $from = '_from', $to = '_to', $fromLabel = 'From:',
131 $required = FALSE, $operators = array(),
132 $dateFormat = 'searchDate', $displayTime = FALSE
137 0 => ts('Choose Date Range'),
138 'this.year' => ts('This Year'),
139 'this.fiscal_year' => ts('This Fiscal Year'),
140 'this.quarter' => ts('This Quarter'),
141 'this.month' => ts('This Month'),
142 'this.week' => ts('This Week'),
143 'this.day' => ts('This Day'),
144 'previous.year' => ts('Previous Year'),
145 'previous.fiscal_year' => ts('Previous Fiscal Year'),
146 'previous.quarter' => ts('Previous Quarter'),
147 'previous.month' => ts('Previous Month'),
148 'previous.week' => ts('Previous Week'),
149 'previous.day' => ts('Previous Day'),
150 'previous_before.year' => ts('Prior to Previous Year'),
151 'previous_before.quarter' => ts('Prior to Previous Quarter'),
152 'previous_before.month' => ts('Prior to Previous Month'),
153 'previous_before.week' => ts('Prior to Previous Week'),
154 'previous_before.day' => ts('Prior to Previous Day'),
155 'previous_2.year' => ts('Previous 2 Years'),
156 'previous_2.quarter' => ts('Previous 2 Quarters'),
157 'previous_2.month' => ts('Previous 2 Months'),
158 'previous_2.week' => ts('Previous 2 Weeks'),
159 'previous_2.day' => ts('Previous 2 Days'),
160 'earlier.year' => ts('To End of Prior Year'),
161 'earlier.quarter' => ts('To End of Prior Quarter'),
162 'earlier.month' => ts('To End of Prior Month'),
163 'earlier.week' => ts('To End of Prior Week'),
164 'earlier.day' => ts('To End of Prior Day'),
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'),
174 'ending.year' => ts('Last 12 Months'),
175 'ending.quarter' => ts('Last 3 Months'),
176 'ending.month' => ts('Last Month'),
177 'ending.week' => ts('Last 7 days'),
180 if (is_array($operators)) {
181 $selector = array_merge($selector, $operators);
184 $config = CRM_Core_Config
::singleton();
185 //if fiscal year start on 1 jan then remove fiscal year task
187 if ($config->fiscalYearStart
['d'] == 1 & $config->fiscalYearStart
['M'] == 1) {
188 unset($selector['this.fiscal_year']);
189 unset($selector['previous.fiscal_year']);
195 * This function is to build the date range - relative or absolute
197 * @param Object $form the form object that we are operating on
198 * @param string $fieldName
199 * @param Array $selector array of option values to add
200 * @param integer $count
201 * @param string $from
203 * @param string $from Label
204 * @param boolean $required
205 * @param string $dateFormat
206 * @param boolean $displayTime
209 static function addDateRangeToForm(&$form, $fieldName, $selector, $from = '_from', $to = '_to', $fromLabel = 'From:', $required = FALSE, $dateFormat = 'searchDate', $displayTime = FALSE) {
211 "{$fieldName}_relative",
212 ts('Relative Date Range'),
217 $form->addDateRange($fieldName, $from, $to, $fromLabel, $dateFormat, FALSE, $displayTime);