3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
33 class CRM_Core_Form_Date
{
36 * Various Date Formats.
38 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 * Build the date-format form.
43 * @param CRM_Core_Form $form
44 * The form object that we are operating on.
46 public static function buildAllowedDateFormats(&$form) {
48 $dateOptions = array();
50 if (CRM_Utils_System
::getClassName($form) == 'CRM_Activity_Import_Form_DataSource') {
51 $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)');
54 $dateText = ts('yyyy-mm-dd OR yyyymmdd (1998-12-25 OR 19981225) OR (2008-9-1 OR 20080901)');
57 $dateOptions[] = $form->createElement('radio', NULL, NULL, $dateText, self
::DATE_yyyy_mm_dd
);
59 $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
);
60 $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
);
61 $dateOptions[] = $form->createElement('radio', NULL, NULL, ts('Month dd, yyyy (December 12, 1998)'), self
::DATE_Month_dd_yyyy
);
62 $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
);
63 $dateOptions[] = $form->createElement('radio', NULL, NULL, ts('dd/mm/yyyy (25/12/1998) OR (1/9/2008)'), self
::DATE_dd_mm_yyyy
);
64 $form->addGroup($dateOptions, 'dateFormats', ts('Date Format'), '<br/>');
65 $form->setDefaults(array('dateFormats' => self
::DATE_yyyy_mm_dd
));
70 * Retrieve the date range - relative or absolute and assign it to the form.
72 * @param CRM_Core_Form $form
73 * The form the dates should be added to.
74 * @param string $fieldName
78 * @param string $fromLabel
79 * @param bool $required
80 * @param array $operators
81 * Additional value pairs to add.
82 * @param string $dateFormat
83 * @param bool|string $displayTime
84 * @param array $attributes
86 public static function buildDateRange(
87 &$form, $fieldName, $count = 1,
88 $from = '_from', $to = '_to', $fromLabel = 'From:',
89 $required = FALSE, $operators = array(),
90 $dateFormat = 'searchDate', $displayTime = FALSE,
91 $attributes = array('class' => 'crm-select2')
94 = CRM_Core_Form_Date
::returnDateRangeSelector(
95 $form, $fieldName, $count,
96 $from, $to, $fromLabel,
97 $required, $operators,
98 $dateFormat, $displayTime
100 CRM_Core_Form_Date
::addDateRangeToForm(
101 $form, $fieldName, $selector,
102 $from, $to, $fromLabel,
103 $required, $dateFormat, $displayTime,
109 * Build the date range array that will provide the form option values.
111 * It can be - relative or absolute.
113 * @param CRM_Core_Form $form
114 * The form object that we are operating on.
115 * @param string $fieldName
117 * @param string $from
119 * @param string $fromLabel
120 * @param bool $required
121 * @param array $operators
122 * Additional Operator Selections to add.
123 * @param string $dateFormat
124 * @param bool $displayTime
127 * Values for Selector
129 public 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
137 0 => ts('Choose Date Range'),
139 // CRM-16195 Pull relative date filters from an option group
140 $selector = $selector + CRM_Core_OptionGroup
::values('relative_date_filters');
142 if (is_array($operators)) {
143 $selector = array_merge($selector, $operators);
146 $config = CRM_Core_Config
::singleton();
147 //if fiscal year start on 1 jan then remove fiscal year task
149 if ($config->fiscalYearStart
['d'] == 1 & $config->fiscalYearStart
['M'] == 1) {
150 unset($selector['this.fiscal_year']);
151 unset($selector['previous.fiscal_year']);
157 * Build the date range - relative or absolute.
159 * @param CRM_Core_Form $form
160 * The form object that we are operating on.
161 * @param string $fieldName
162 * @param array $selector
163 * Array of option values to add.
164 * @param string $from
167 * @param string $fromLabel
168 * @param bool $required
169 * @param string $dateFormat
170 * @param bool $displayTime
171 * @param array $attributes
173 public static function addDateRangeToForm(
179 $fromLabel = 'From:',
181 $dateFormat = 'searchDate',
182 $displayTime = FALSE,
186 "{$fieldName}_relative",
187 ts('Relative Date Range'),
193 $form->addDateRange($fieldName, $from, $to, $fromLabel, $dateFormat, FALSE, $displayTime);