X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fv3%2FMembership.php;h=63823a516cac8e252c844e3c6f44d957aaffa8f6;hb=244bbdd85415317b95f70bf85a3ecb036c4fe840;hp=1893186bdf72e06498e9d9055179c523a9d7300c;hpb=1861d923dd4e29ac945caa98e1efbeda0bb71483;p=civicrm-core.git diff --git a/api/v3/Membership.php b/api/v3/Membership.php index 1893186bdf..63823a516c 100644 --- a/api/v3/Membership.php +++ b/api/v3/Membership.php @@ -1,8 +1,7 @@ id]); - return civicrm_api3_create_success($membership, $params, 'membership', 'create', $membershipBAO); + return civicrm_api3_create_success($membership, $params, 'Membership', 'create', $membershipBAO); } /** - * Adjust Metadata for Create action + * Adjust Metadata for Create action. * - * The metadata is used for setting defaults, documentation & validation - * @param array $params array or parameters determined by getfields + * The metadata is used for setting defaults, documentation & validation. + * + * @param array $params + * Array of parameters determined by getfields. */ function _civicrm_api3_membership_create_spec(&$params) { $params['contact_id']['api.required'] = 1; @@ -155,37 +150,43 @@ function _civicrm_api3_membership_create_spec(&$params) { $params['membership_type_id']['api.aliases'] = array('membership_type'); $params['status_id']['api.aliases'] = array('membership_status'); $params['skipStatusCal'] = array( - 'title' => 'Skip status calculation. By default this is 0 if id is not set and 1 if it is set.' + 'title' => 'Skip status calculation. By default this is 0 if id is not set and 1 if it is set.', ); $params['num_terms'] = array( 'title' => 'Number of terms to add/renew. If this parameter is passed, dates will be calculated automatically. If no id is passed (new membership) and no dates are given, num_terms will be assumed to be 1.', 'type' => CRM_Utils_Type::T_INT, ); } + /** - * Adjust Metadata for Get action + * Adjust Metadata for Get action. + * + * The metadata is used for setting defaults, documentation & validation. * - * The metadata is used for setting defaults, documentation & validation - * @param array $params array or parameters determined by getfields + * @param array $params + * Array of parameters determined by getfields. */ function _civicrm_api3_membership_get_spec(&$params) { $params['membership_type_id']['api.aliases'] = array('membership_type'); + $params['active_only'] = array( + 'title' => 'Only retrieve active memberships', + 'type' => CRM_Utils_Type::T_BOOLEAN, + ); } /** - * Get contact membership record. + * Get contact Membership record. * * This api will return the membership records for the contacts * having membership based on the relationship with the direct members. * - * @param Array $params key/value pairs for contact_id and some + * @param array $params + * Key/value pairs for contact_id and some. * options affecting the desired results; has legacy support * for just passing the contact_id itself as the argument * - * @return Array of all found membership property values. - * @access public - * @todo needs some love - basically only a get for a given contact right now - * {@getfields membership_get} + * @return array + * Array of all found membership property values. */ function civicrm_api3_membership_get($params) { $activeOnly = $membershipTypeId = $membershipType = NULL; @@ -200,38 +201,42 @@ function civicrm_api3_membership_get($params) { $params['status_id'] = array('IN' => CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent()); } - $options = _civicrm_api3_get_options_from_params($params, TRUE,'membership', 'get'); + $options = _civicrm_api3_get_options_from_params($params, TRUE, 'Membership', 'get'); if ($options['is_count']) { return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); } $membershipValues = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE, 'Membership'); $return = $options['return']; - if(empty($membershipValues) || + if (empty($membershipValues) || (!empty($return) && !array_key_exists('related_contact_id', $return) && !array_key_exists('relationship_name', $return) ) ) { - return civicrm_api3_create_success($membershipValues, $params, 'membership', 'get'); + return civicrm_api3_create_success($membershipValues, $params, 'Membership', 'get'); } - $members = _civicrm_api3_membership_relationsship_get_customv2behaviour($params, $membershipValues, $contactID ); - return civicrm_api3_create_success($members, $params, 'membership', 'get'); + $members = _civicrm_api3_membership_relationsship_get_customv2behaviour($params, $membershipValues, $contactID); + return civicrm_api3_create_success($members, $params, 'Membership', 'get'); } /** + * Perform api v2 custom behaviour. + * * When we copied apiv3 from api v2 we brought across some custom behaviours - in the case of * membership a complicated return array is constructed. The original * behaviour made contact_id a required field. We still need to keep this for v3 when contact_id * is passed in as part of the reasonable expectation developers have that we will keep the api * as stable as possible * - * @param array $params parameters passed into get function + * @param array $params + * Parameters passed into get function. * @param int $membershipTypeId * @param $activeOnly * - * @return array result for calling function + * @return array + * result for calling function */ function _civicrm_api3_membership_get_customv2behaviour(&$params, $membershipTypeId, $activeOnly) { // get the membership for the given contact ID @@ -246,13 +251,15 @@ function _civicrm_api3_membership_get_customv2behaviour(&$params, $membershipTyp /** - * non-standard behaviour inherited from v2 + * Non-standard behaviour inherited from v2. * - * @param array $params parameters passed into get function + * @param array $params + * Parameters passed into get function. * @param $membershipValues * @param int $contactID * - * @return array result for calling function + * @return array + * result for calling function */ function _civicrm_api3_membership_relationsship_get_customv2behaviour(&$params, $membershipValues, $contactID) { $relationships = array(); @@ -278,7 +285,7 @@ function _civicrm_api3_membership_relationsship_get_customv2behaviour(&$params, $members = $membershipValues; - // populating contacts in members array based on their relationship with direct members. + // Populating contacts in members array based on their relationship with direct members. if (!empty($relationships)) { foreach ($relationships as $relTypeId => $membershipId) { // As members are not direct members, there should not be