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