Skip to content
Snippets Groups Projects
Commit f119bedd authored by eileen's avatar eileen
Browse files

extract the functionality that determines the select options away from the...

extract the functionality that determines the select options away from the adding of those to a form
parent 25aaa6fd
No related branches found
No related tags found
No related merge requests found
......@@ -70,7 +70,8 @@ Class CRM_Core_Form_Date {
}
/**
* This function is to build the date range - relative or absolute
* This function is to retrieve the date range - relative or absolute
* and assign it to the form
*
* @param Object $form the form object that we are operating on
*
......@@ -78,6 +79,27 @@ Class CRM_Core_Form_Date {
* @access public
*/
static function buildDateRange(&$form, $fieldName, $count = 1, $from = '_from', $to = '_to', $fromLabel = 'From:', $required = FALSE, $addReportFilters = TRUE, $dateFormat = 'searchDate', $displayTime = FALSE) {
$selector = CRM_Core_Form_Date::returnDateRangeSelector(&$form, $fieldName, $count = 1, $from = '_from', $to = '_to', $fromLabel = 'From:', $required = FALSE, $addReportFilters = TRUE, $dateFormat = 'searchDate', $displayTime = FALSE);
CRM_Core_Form_Date::addDateRangeToForm($form, $fieldName, $selector, $from = '_from', $to = '_to', $fromLabel = 'From:', $required = FALSE, $dateFormat = 'searchDate', $displayTime = FALSE);
}
/**
* 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 String $addReportFilters (this seems to be a bit of a hack for report class)
* @param String $dateFormat
* @param Boolean $displayTime
* @return array Values for Selector
*/
static function returnDateRangeSelector(&$form, $fieldName, $count = 1, $from = '_from', $to = '_to', $fromLabel = 'From:', $required = FALSE, $addReportFilters = TRUE, $dateFormat = 'searchDate', $displayTime = FALSE) {
$selector = array('' => ts('- any -'),
0 => ts('Choose Date Range'),
'this.year' => ts('This Year'),
......@@ -117,8 +139,9 @@ Class CRM_Core_Form_Date {
'ending.month' => ts('From 1 Month Ago'),
'ending.week' => ts('From 1 Week Ago'),
);
//@todo if method exists would be better
if ($addReportFilters) {
$selector += CRM_Report_Form::getOperationPair(CRM_Report_FORM::OP_DATE);
$selector += $form->getOperationPair(CRM_Report_FORM::OP_DATE);
}
$config = CRM_Core_Config::singleton();
//if fiscal year start on 1 jan then remove fiscal year task
......@@ -127,15 +150,34 @@ Class CRM_Core_Form_Date {
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
);
$selector,
$required
);
$form->addDateRange($fieldName, $from, $to, $fromLabel, $dateFormat, FALSE, $displayTime);
$form->addDateRange($fieldName, $from, $to, $fromLabel, $dateFormat, FALSE, $displayTime);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment