*/
protected $_renderer;
+ /**
+ * An array to hold a list of datefields on the form
+ * so that they can be converted to ISO in a consistent manner
+ *
+ * @var array
+ *
+ * e.g on a form declare $_dateFields = array(
+ * 'receive_date' => array('default' => 'now'),
+ * );
+ * then in postProcess call $this->convertDateFieldsToMySQL($formValues)
+ * to have the time field re-incorporated into the field & 'now' set if
+ * no value has been passed in
+ */
+ protected $_dateFields = array();
+
/**
* cache the smarty template for efficiency reasons
*
$this->setDefaults(array($name => $defaultCurrency));
}
+ /**
+ * Convert all date fields within the params to mysql date ready for the
+ * BAO layer. In this case fields are checked against the $_datefields defined for the form
+ * and if time is defined it is incorporated
+ *
+ * @param array $params input params from the form
+ *
+ * @todo it would probably be better to work on $this->_params than a passed array
+ * @todo standardise the format which dates are passed to the BAO layer in & remove date
+ * handling from BAO
+ */
+ function convertDateFieldsToMySQL(&$params){
+ foreach ($this->_dateFields as $fieldName => $specs){
+ if(!empty($params[$fieldName])){
+ $params[$fieldName] = CRM_Utils_Date::isoToMysql(
+ CRM_Utils_Date::processDate(
+ $params[$fieldName],
+ CRM_Utils_Array::value("{$fieldName}_time", $params), TRUE)
+ );
+ }
+ else{
+ if(isset($specs['default'])){
+ $params[$fieldName] = date('YmdHis', strtotime($specs['default']));
+ }
+ }
+ }
+ }
+
function removeFileRequiredRules($elementName) {
$this->_required = array_diff($this->_required, array($elementName));
if (isset($this->_rules[$elementName])) {
*/
protected $_membershipIDs = array( );
+ /**
+ * An array to hold a list of datefields on the form
+ * so that they can be converted to ISO in a consistent manner
+ *
+ * @var array
+ */
+ protected $_dateFields = array(
+ 'receive_date' => array('default' => 'now'),
+ );
+
public function preProcess() {
//custom data related code
$this->_cdType = CRM_Utils_Array::value('type', $_GET);
$resources->addScriptFile('civicrm', 'templates/CRM/Member/Form/Membership.js');
}
}
- else {
+ else {
$resources = CRM_Core_Resources::singleton();
$resources->addScriptFile('civicrm', 'templates/CRM/Member/Form/MembershipStandalone.js');
$statuses = array();
$this->add('text', 'total_amount', ts('Amount'));
$this->addRule('total_amount', ts('Please enter a valid amount.'), 'money');
- $this->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDate'));
+ $this->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
$this->add('select', 'payment_instrument_id',
ts('Paid By'),
$config = CRM_Core_Config::singleton();
// get the submitted form values.
$this->_params = $formValues = $this->controller->exportValues($this->_name);
+ $this->convertDateFieldsToMySQL($formValues);
$params = $ids = array();
$$dateVariable = CRM_Utils_Date::processDate($formValues[$dateField]);
}
- $dates = array(
- 'join_date',
- 'start_date',
- 'end_date',
- );
-
$num_terms = CRM_Utils_Array::value('num_terms', $formValues, 1);
$calcDates = array();
}
foreach ($calcDates as $memType => $calcDate) {
- foreach ($dates as $d) {
+ foreach (array_keys($dateTypes) as $d) {
//first give priority to form values then calDates.
$date = CRM_Utils_Array::value($d, $formValues);
if (!$date) {
$this->assign('is_pay_later', 1);
}
- if (CRM_Utils_Array::value('receive_date', $params)) {
- $formValues['receive_date'] = $params['receive_date'] = CRM_Utils_Date::processDate($params['receive_date']);
- }
if (CRM_Utils_Array::value('send_receipt', $formValues)) {
- $params['receipt_date'] = CRM_Utils_Array::value('receive_date', $params);
+ $params['receipt_date'] = CRM_Utils_Array::value('receive_date', $formValues);
}
//insert financial type name in receipt.
*/
protected $_context;
+ /**
+ * An array to hold a list of datefields on the form
+ * so that they can be converted to ISO in a consistent manner
+ *
+ * @var array
+ */
+ protected $_dateFields = array(
+ 'receive_date' => array('default' => 'now'),
+ );
+
public function preProcess() {
//custom data related code
$this->_cdType = CRM_Utils_Array::value('type', $_GET);
$this->add('text', 'total_amount', ts('Amount'));
$this->addRule('total_amount', ts('Please enter a valid amount.'), 'money');
- $this->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDate'));
+ $this->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
$this->add('text', 'num_terms', ts('Extend Membership by'), array('onchange' => "setPaymentBlock();"), TRUE);
$this->addRule('num_terms', ts('Please enter a whole number for how many periods to renew.'), 'integer');
}
$now = CRM_Utils_Date::getToday( null, 'YmdHis');
- if (CRM_Utils_Array::value('receive_date', $this->_params)) {
- $formValues['receive_date'] = CRM_Utils_Date::processDate($this->_params['receive_date']);
- }
- else {
- $formValues['receive_date'] = $now;
- }
+ $this->convertDateFieldsToMySQL($formValues);
$this->assign('receive_date', $formValues['receive_date']);
if (CRM_Utils_Array::value('send_receipt', $this->_params)) {