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