From: eileen Date: Tue, 30 Apr 2013 04:32:28 +0000 (+1200) Subject: extract the functionality that determines the select options away from the adding... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f119bedd70bb7c93ad7084168c556641da201c6d;p=civicrm-core.git extract the functionality that determines the select options away from the adding of those to a form --- diff --git a/CRM/Core/Form/Date.php b/CRM/Core/Form/Date.php index 1f81daeacd..be3d11517d 100644 --- a/CRM/Core/Form/Date.php +++ b/CRM/Core/Form/Date.php @@ -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); } + }