Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.3 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2013 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2013
* $Id$
*
*/
Class CRM_Core_Form_Date {
/**
* various Date Formats
*/
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;
/**
* This function is to build the date-format form
*
* @param Object $form the form object that we are operating on
*
* @static
* @access public
*/
static function buildAllowedDateFormats(&$form) {
$dateOptions = array();
if (CRM_Utils_System::getClassName($form) == 'CRM_Activity_Import_Form_UploadFile') {
$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)');
}
else {
$dateText = ts('yyyy-mm-dd OR yyyymmdd (1998-12-25 OR 19981225) OR (2008-9-1 OR 20080901)');
}
$dateOptions[] = $form->createElement('radio', NULL, NULL, $dateText, self::DATE_yyyy_mm_dd);
$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);
$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);
$dateOptions[] = $form->createElement('radio', NULL, NULL, ts('Month dd, yyyy (December 12, 1998)'), self::DATE_Month_dd_yyyy);
$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);
$dateOptions[] = $form->createElement('radio', NULL, NULL, ts('dd/mm/yyyy (25/12/1998) OR (1/9/2008)'), self::DATE_dd_mm_yyyy);
$form->addGroup($dateOptions, 'dateFormats', ts('Date Format'), '<br/>');
$form->setDefaults(array('dateFormats' => self::DATE_yyyy_mm_dd));
}
* This function is to retrieve the date range - relative or absolute
* and assign it to the form
* @param object $form - the form the dates should be added to
* @param string $fieldName
* @param integer $count
* @param string $from
* @param string $to
* @param string $fromLabel
* @param boolean $required
* @param array $operators Additional value pairs to add
* @param string $dateFormat
* @param string $displayTime
static function buildDateRange(
&$form, $fieldName, $count = 1,
$from = '_from', $to = '_to', $fromLabel = 'From:',
$required = FALSE, $operators = array(),
$dateFormat = 'searchDate', $displayTime = FALSE
) {
$selector =
CRM_Core_Form_Date::returnDateRangeSelector(
$form, $fieldName, $count,
$from, $to, $fromLabel,
$required, $operators,
$dateFormat, $displayTime
);
CRM_Core_Form_Date::addDateRangeToForm(
$form, $fieldName, $selector,
$from, $to, $fromLabel,
$required, $dateFormat, $displayTime
);
}
/**
* This function is to build the date range array that will provide the form option values
* It can be - relative or absolute
*
* @param Object $form the form object that we are operating on
* @param string $fieldName
* @param integer $count
* @param String $from
* @param String $to
* @param String $fromLabel
* @param Boolean $required
* @param Array $operators Additional Operator Selections to add
* @param String $dateFormat
* @param Boolean $displayTime
* @return array Values for Selector
*/
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
static function returnDateRangeSelector(
&$form, $fieldName, $count = 1,
$from = '_from', $to = '_to', $fromLabel = 'From:',
$required = FALSE, $operators = array(),
$dateFormat = 'searchDate', $displayTime = FALSE
) {
$selector =
array(
'' => ts('- any -'),
0 => ts('Choose Date Range'),
'this.year' => ts('This Year'),
'this.fiscal_year' => ts('This Fiscal Year'),
'this.quarter' => ts('This Quarter'),
'this.month' => ts('This Month'),
'this.week' => ts('This Week'),
'this.day' => ts('This Day'),
'previous.year' => ts('Previous Year'),
'previous.fiscal_year' => ts('Previous Fiscal Year'),
'previous.quarter' => ts('Previous Quarter'),
'previous.month' => ts('Previous Month'),
'previous.week' => ts('Previous Week'),
'previous.day' => ts('Previous Day'),
'previous_before.year' => ts('Prior to Previous Year'),
'previous_before.quarter' => ts('Prior to Previous Quarter'),
'previous_before.month' => ts('Prior to Previous Month'),
'previous_before.week' => ts('Prior to Previous Week'),
'previous_before.day' => ts('Prior to Previous Day'),
'previous_2.year' => ts('Previous 2 Years'),
'previous_2.quarter' => ts('Previous 2 Quarters'),
'previous_2.month' => ts('Previous 2 Months'),
'previous_2.week' => ts('Previous 2 Weeks'),
'previous_2.day' => ts('Previous 2 Days'),
'earlier.year' => ts('To End of Prior Year'),
'earlier.quarter' => ts('To End of Prior Quarter'),
'earlier.month' => ts('To End of Prior Month'),
'earlier.week' => ts('To End of Prior Week'),
'earlier.day' => ts('To End of Prior Day'),
'greater.year' => ts('Current Year to-date'),
'greater.quarter' => ts('Current Quarter to-date'),
'greater.month' => ts('Current Month to-date'),
'greater.week' => ts('Current Week to-date'),
'greater.day' => ts('Current Day'),
'ending.year' => ts('From 12 Months Ago'),
'ending.quarter' => ts('From 3 Months Ago'),
'ending.month' => ts('From 1 Month Ago'),
'ending.week' => ts('From 1 Week Ago'),
);
if (is_array($operators)) {
$selector = array_merge($selector, $operators);
}
$config = CRM_Core_Config::singleton();
//if fiscal year start on 1 jan then remove fiscal year task
//form list
if ($config->fiscalYearStart['d'] == 1 & $config->fiscalYearStart['M'] == 1) {
unset($selector['this.fiscal_year']);
unset($selector['previous.fiscal_year']);
}
return $selector;
}
/**
* This function is to build the date range - relative or absolute
*
* @param Object $form the form object that we are operating on
* @param string $fieldName
* @param Array $selector array of option values to add
* @param integer $count
* @param string $from
* @param stringe $to
* @param string $from Label
* @param boolean $required
* @param string $dateFormat
* @param boolean $displayTime
* @return null
*/
static function addDateRangeToForm(&$form, $fieldName, $selector, $from = '_from', $to = '_to', $fromLabel = 'From:', $required = FALSE, $dateFormat = 'searchDate', $displayTime = FALSE) {
$form->add('select',
"{$fieldName}_relative",
ts('Relative Date Range'),
$selector,
$required
);
$form->addDateRange($fieldName, $from, $to, $fromLabel, $dateFormat, FALSE, $displayTime);