//set defaults in create mode
if (!$contributionID) {
- self::setDefaults($params);
+ CRM_Core_DAO::setCreateDefaults($params, self::getDefaults());
self::calculateMissingAmountParams($params);
}
),
'contribution_status_id' => CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'),
);
-
}
- /**
- * Set defaults when creating new entity
- * @param $params
- */
- static function setDefaults(&$params) {
- foreach (self::getDefaults() as $key => $value) {
- if (empty($params[$key])) {
- $params[$key] = $value;
- }
- }
- }
/**
* Given the list of params in the params array, fetch the object
* and store the values in the values array
}
}
+ /**
+ * Set defaults when creating new entity
+ * (don't call this set defaults as already in use with different signature in some places)
+ *
+ * @param $params
+ * @param $defaults
+ */
+ static function setCreateDefaults(&$params, $defaults) {
+ if (isset($params['id'])) {
+ return;
+ }
+ foreach ($defaults as $key => $value) {
+ if (!array_key_exists($key, $params) || $params[$key] === NULL) {
+ $params[$key] = $value;
+ }
+ }
+ }
+
/**
* @param string $prefix
* @param bool $addRandomString
* @return object
*/
static function add(&$params, $ids = array()) {
- $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
- $params['is_current_member'] = CRM_Utils_Array::value('is_current_member', $params, FALSE);
- $params['is_admin'] = CRM_Utils_Array::value('is_admin', $params, FALSE);
- $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
+ $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('membershipStatus', $ids));
+ if (!$id) {
+ CRM_Core_DAO::setCreateDefaults($params, self::getDefaults());
+ //copy name to label when not passed.
+ if (empty($params['label']) && !empty($params['name'])) {
+ $params['label'] = $params['name'];
+ }
+
+ if (empty($params['name']) && !empty($params['label'])) {
+ $params['name'] = $params['label'];
+ }
+ }
// set all other defaults to false.
- if ($params['is_default']) {
+ if (!empty($params['is_default'])) {
$query = "UPDATE civicrm_membership_status SET is_default = 0";
CRM_Core_DAO::executeQuery($query,
CRM_Core_DAO::$_nullArray
);
}
- //copy name to label when not passed.
- if (empty($params['label']) && !empty($params['name'])) {
- $params['label'] = $params['name'];
- }
- //for add mode, copy label to name.
- $statusId = !empty($params['id']) ? $params['id'] : CRM_Utils_Array::value('membershipStatus', $ids);
- if (!$statusId && !empty($params['label']) && empty($params['name'])) {
- $params['name'] = $params['label'];
- }
// action is taken depending upon the mode
$membershipStatus = new CRM_Member_DAO_MembershipStatus();
$membershipStatus->copyValues($params);
- $membershipStatus->id = $statusId;
+ $membershipStatus->id = $id;
$membershipStatus->save();
return $membershipStatus;
}
+ /**
+ * Get defaults for new entity
+ * @return array
+ */
+ static function getDefaults() {
+ return array(
+ 'is_active' => FALSE,
+ 'is_current_member' => FALSE,
+ 'is_admin' => FALSE,
+ 'is_default' => FALSE,
+ );
+ }
+
/**
* Function to get membership status
*
}
else {
if (!$id) {
- self::setDefaults($params);
+ CRM_Core_DAO::setCreateDefaults($params, self::getDefaults());
if (empty($params['name'])) {
$params['name'] = CRM_Utils_String::munge(CRM_Utils_Array::value('label', $params), '_', 64);
}
}
- /**
- * Set defaults when creating new entity
- * @param $params
- */
- static function setDefaults(&$params) {
- foreach (self::getDefaults() as $key => $value) {
- if (empty($params[$key])) {
- $params[$key] = $value;
- }
- }
- }
-
/**
* Takes a bunch of params that are needed to match certain criteria and
* retrieves the relevant objects.
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
-/**
- * Adjust Metadata for Create action
- *
- * The metadata is used for setting defaults, documentation & validation
- * @param array $params array or parameters determined by getfields
- */
-function _civicrm_api3_membership_status_create_spec(&$params) {
- $params['name']['api.aliases'] = array('label');
-}
-
/**
* Get a membership status.
*