Merge pull request #4923 from colemanw/invoice_id
[civicrm-core.git] / api / v3 / MembershipType.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
731a0992 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26*/
27
28/**
29 * File for the CiviCRM APIv3 membership type functions
30 *
31 * @package CiviCRM_APIv3
32 * @subpackage API_Membership
33 *
731a0992 34 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
35 * @version $Id: MembershipType.php 30171 2010-10-14 09:11:27Z mover $
36 *
37 */
38
6a488035
TO
39/**
40 * API to Create or update a Membership Type
41 *
cf470720
TO
42 * @param array $params
43 * An associative array of name/value property values of civicrm_membership_type.
6a488035 44 *
a6c01b45 45 * @return array
72b3a70c 46 * newly created or updated membership type property values.
6a488035
TO
47 */
48function civicrm_api3_membership_type_create($params) {
174dbdd5
E
49 $ids['membershipType'] = CRM_Utils_Array::value('id', $params);
50 $ids['memberOfContact'] = CRM_Utils_Array::value('member_of_contact_id', $params);
51 $ids['contributionType'] = CRM_Utils_Array::value('financial_type_id', $params);
6a488035 52
174dbdd5 53 $membershipTypeBAO = CRM_Member_BAO_MembershipType::add($params, $ids);
6a488035
TO
54 $membershipType = array();
55 _civicrm_api3_object_to_array($membershipTypeBAO, $membershipType[$membershipTypeBAO->id]);
56 CRM_Member_PseudoConstant::membershipType(NULL, TRUE);
174dbdd5
E
57 civicrm_api3('membership', 'getfields', array('cache_clear' => 1, 'fieldname' => 'membership_type_id'));
58 civicrm_api3('profile', 'getfields', array('action' => 'submit', 'cache_clear' => 1));
6a488035
TO
59 return civicrm_api3_create_success($membershipType, $params, 'membership_type', 'create', $membershipTypeBAO);
60}
11e09c59
TO
61
62/**
6a488035 63 * Adjust Metadata for Create action
1c88e578 64 *
6a488035 65 * The metadata is used for setting defaults, documentation & validation
cf470720
TO
66 * @param array $params
67 * Array or parameters determined by getfields.
6a488035
TO
68 */
69function _civicrm_api3_membership_type_create_spec(&$params) {
70 // todo could set default here probably
71 $params['domain_id']['api.required'] = 1;
72 $params['member_of_contact_id']['api.required'] = 1;
35671d00 73 $params['financial_type_id']['api.required'] = 1;
6a488035
TO
74 $params['name']['api.required'] = 1;
75 $params['duration_unit']['api.required'] = 1;
76 $params['duration_interval']['api.required'] = 1;
77}
78
79/**
80 * Get a Membership Type.
81 *
82 * This api is used for finding an existing membership type.
83 *
cf470720
TO
84 * @param array $params
85 * An associative array of name/value property values of civicrm_membership_type.
6a488035
TO
86 * {getfields MembershipType_get}
87 *
16b10e64
CW
88 * @return array
89 * Array of all found membership type property values.
6a488035
TO
90 */
91function civicrm_api3_membership_type_get($params) {
6a488035
TO
92 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
93}
94
95/**
96 * Deletes an existing membership type
97 *
98 * This API is used for deleting a membership type
7c285037 99 * Required parameters : id of a membership type
6a488035 100 *
cf470720 101 * @param array $params
6a488035 102 *
a6c01b45 103 * @return boolean
72b3a70c 104 * true if success, else false
6a488035
TO
105 */
106function civicrm_api3_membership_type_delete($params) {
8c33a68c 107 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
6a488035 108}