bulk comment fix
[civicrm-core.git] / CRM / Core / Form / Date.php
CommitLineData
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 */
35Class 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'),
161 'earlier.year' => ts('To End of Prior Year'),
162 'earlier.quarter' => ts('To End of Prior Quarter'),
163 'earlier.month' => ts('To End of Prior Month'),
164 'earlier.week' => ts('To End of Prior Week'),
165 'earlier.day' => ts('To End of Prior 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'),
171 'current.year' => ts('Current Year to-date'),
172 'current.quarter' => ts('Current Quarter to-date'),
173 'current.month' => ts('Current Month to-date'),
174 'current.week' => ts('Current Week to-date'),
e2c3163d 175 'ending_3.year' => ts('Last 3 Years'),
176 'ending_2.year' => ts('Last 2 Years'),
e72fca81 177 'ending.year' => ts('Last 12 Months'),
178 'ending.quarter' => ts('Last 3 Months'),
179 'ending.month' => ts('Last Month'),
180 'ending.week' => ts('Last 7 days'),
634e1a1a 181 );
180214e9
DL
182
183 if (is_array($operators)) {
184 $selector = array_merge($selector, $operators);
185 }
bc3f7f04 186
6a488035
TO
187 $config = CRM_Core_Config::singleton();
188 //if fiscal year start on 1 jan then remove fiscal year task
189 //form list
190 if ($config->fiscalYearStart['d'] == 1 & $config->fiscalYearStart['M'] == 1) {
191 unset($selector['this.fiscal_year']);
192 unset($selector['previous.fiscal_year']);
193 }
f119bedd 194 return $selector;
195 }
6a488035 196
f119bedd 197 /**
198 * This function is to build the date range - relative or absolute
199 *
da6b46f4 200 * @param CRM_Core_Form $form the form object that we are operating on
f119bedd 201 * @param string $fieldName
202 * @param Array $selector array of option values to add
f119bedd 203 * @param string $from Label
da6b46f4
EM
204 * @param string|\stringe $to
205 * @param string $fromLabel
f119bedd 206 * @param boolean $required
207 * @param string $dateFormat
208 * @param boolean $displayTime
da6b46f4
EM
209 *
210 * @internal param int $count
f119bedd 211 * @return null
212 */
213 static function addDateRangeToForm(&$form, $fieldName, $selector, $from = '_from', $to = '_to', $fromLabel = 'From:', $required = FALSE, $dateFormat = 'searchDate', $displayTime = FALSE) {
6a488035
TO
214 $form->add('select',
215 "{$fieldName}_relative",
216 ts('Relative Date Range'),
1eef83c9
CW
217 $selector,
218 $required,
219 array('class' => 'crm-select2')
f119bedd 220 );
6a488035 221
f119bedd 222 $form->addDateRange($fieldName, $from, $to, $fromLabel, $dateFormat, FALSE, $displayTime);
6a488035 223 }
f119bedd 224
6a488035
TO
225}
226