Skip to content

Commit

Permalink
Preliminary tidy up of MembershipType form (towards custom data support)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire authored and eileenmcnaughton committed May 14, 2018
1 parent 935ec26 commit 1322dc5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
1 change: 0 additions & 1 deletion CRM/Member/Form/MembershipConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public function preProcess() {
* Set default values for the form. MobileProvider that in edit/view mode
* the default values are retrieved from the database
*
*
* @return array
* defaults
*/
Expand Down
30 changes: 14 additions & 16 deletions CRM/Member/Form/MembershipType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2018
* $Id$
*
*/

Expand Down Expand Up @@ -61,8 +60,8 @@ public function preProcess() {
* Set default values for the form. MobileProvider that in edit/view mode
* the default values are retrieved from the database
*
*
* @return void
* @return array
* defaults
*/
public function setDefaultValues() {
$defaults = parent::setDefaultValues();
Expand Down Expand Up @@ -111,7 +110,6 @@ public function setDefaultValues() {
* @return void
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @throws \HTML_QuickForm_Error
*/
public function buildQuickForm() {
parent::buildQuickForm();
Expand Down Expand Up @@ -330,9 +328,9 @@ public function postProcess() {
'max_related',
);

$params = $ids = array();
$params = array();
foreach ($fields as $fld) {
$params[$fld] = CRM_Utils_Array::value($fld, $submitted, 'NULL');
$params[$fld] = CRM_Utils_Array::value($fld, $submitted, 'null');
}

if ($params['minimum_fee']) {
Expand Down Expand Up @@ -360,7 +358,7 @@ public function postProcess() {
}
}
if (!$hasRelTypeVal) {
$params['relationship_type_id'] = $params['relationship_direction'] = $params['max_related'] = 'NULL';
$params['relationship_type_id'] = $params['relationship_direction'] = $params['max_related'] = 'null';
}

if ($params['duration_unit'] == 'lifetime' &&
Expand All @@ -370,20 +368,20 @@ public function postProcess() {
}

$periods = array('fixed_period_start_day', 'fixed_period_rollover_day');
foreach ($periods as $per) {
if (!empty($params[$per]['M']) && !empty($params[$per]['d'])) {
$mon = $params[$per]['M'];
$dat = $params[$per]['d'];
foreach ($periods as $period) {
if (!empty($params[$period]['M']) && !empty($params[$period]['d'])) {
$mon = $params[$period]['M'];
$dat = $params[$period]['d'];
$mon = ($mon < 10) ? '0' . $mon : $mon;
$dat = ($dat < 10) ? '0' . $dat : $dat;
$params[$per] = $mon . $dat;
$params[$period] = $mon . $dat;
}
elseif ($per == 'fixed_period_rollover_day' && !empty($params['month_fixed_period_rollover_day'])) {
elseif ($period == 'fixed_period_rollover_day' && !empty($params['month_fixed_period_rollover_day'])) {
$params['fixed_period_rollover_day'] = $params['month_fixed_period_rollover_day']['d'];
unset($params['month_fixed_period_rollover_day']);
}
else {
$params[$per] = 'NULL';
$params[$period] = 'null';
}
}
$oldWeight = NULL;
Expand All @@ -398,10 +396,10 @@ public function postProcess() {
);

if ($this->_action & CRM_Core_Action::UPDATE) {
$ids['membershipType'] = $this->_id;
$params['id'] = $this->_id;
}

$membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
$membershipType = CRM_Member_BAO_MembershipType::add($params);

CRM_Core_Session::setStatus(ts('The membership type \'%1\' has been saved.',
array(1 => $membershipType->name)
Expand Down

0 comments on commit 1322dc5

Please sign in to comment.