5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * File for the CiviCRM APIv3 membership status functions
33 * @package CiviCRM_APIv3
34 * @subpackage API_Membership
36 * @copyright CiviCRM LLC (c) 2004-2013
37 * @version $Id: MembershipStatus.php 30171 2010-10-14 09:11:27Z mover $
42 * Files required for this package
45 require_once 'CRM/Member/BAO/MembershipStatus.php';
48 * Create a Membership Status
50 * This API is used for creating a Membership Status
52 * @param array $params an associative array of name/value property values of civicrm_membership_status
54 * @return array of newly created membership status property values.
55 * {@getfields MembershipStatus_create}
58 function civicrm_api3_membership_status_create($params) {
59 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
63 * Adjust Metadata for Create action
65 * The metadata is used for setting defaults, documentation & validation
66 * @param array $params array or parameters determined by getfields
68 function _civicrm_api3_membership_status_create_spec(&$params) {
69 $params['name']['api.aliases'] = array('label');
73 * Get a membership status.
75 * This api is used for finding an existing membership status.
77 * @param array $params an associative array of name/value property values of civicrm_membership_status
79 * @return Array of all found membership status property values.
80 * {@getfields MembershipStatus_get}
83 function civicrm_api3_membership_status_get($params) {
84 return _civicrm_api3_basic_get('CRM_Member_BAO_MembershipStatus', $params);
88 * Update an existing membership status
90 * This api is used for updating an existing membership status.
91 * Required parrmeters : id of a membership status
93 * @param Array $params an associative array of name/value property values of civicrm_membership_status
94 * @deprecated - should just use create
96 * @return array of updated membership status property values
99 function &civicrm_api3_membership_status_update($params) {
101 civicrm_api3_verify_mandatory($params, NULL, array('id'));
102 //don't allow duplicate names.
103 $name = CRM_Utils_Array
::value('name', $params);
105 require_once 'CRM/Member/DAO/MembershipStatus.php';
106 $status = new CRM_Member_DAO_MembershipStatus();
107 $status->name
= $params['name'];
108 if ($status->find(TRUE) && $status->id
!= $params['id']) {
109 return civicrm_api3_create_error(ts('A membership status with this name already exists.'));
113 require_once 'CRM/Member/BAO/MembershipStatus.php';
114 $membershipStatusBAO = new CRM_Member_BAO_MembershipStatus();
115 $membershipStatusBAO->id
= $params['id'];
116 if ($membershipStatusBAO->find(TRUE)) {
117 $fields = $membershipStatusBAO->fields();
118 foreach ($fields as $name => $field) {
119 if (array_key_exists($name, $params)) {
120 $membershipStatusBAO->$name = $params[$name];
123 $membershipStatusBAO->save();
125 $membershipStatus = array();
126 _civicrm_api3_object_to_array(clone($membershipStatusBAO), $membershipStatus);
127 $membershipStatus['is_error'] = 0;
128 return $membershipStatus;
132 * Deletes an existing membership status
134 * This API is used for deleting a membership status
136 * @param array Params array containing 'id' - Id of the membership status to be deleted
137 * {@getfields MembershipStatus_delete}
142 function civicrm_api3_membership_status_delete($params) {
144 $memberStatusDelete = CRM_Member_BAO_MembershipStatus
::del($params['id'], TRUE);
145 return $memberStatusDelete ?
civicrm_api3_create_error($memberStatusDelete['error_message']) : civicrm_api3_create_success();
149 * Derives the Membership Status of a given Membership Reocrd
151 * This API is used for deriving Membership Status of a given Membership
152 * record using the rules encoded in the membership_status table.
154 * @param Int $membershipID Id of a membership
155 * @param String $statusDate
157 * @return Array Array of status id and status name
160 function civicrm_api3_membership_status_calc($membershipParams) {
162 if (!($membershipID = CRM_Utils_Array
::value('membership_id', $membershipParams))) {
163 return civicrm_api3_create_error('membershipParams do not contain membership_id');
167 SELECT start_date, end_date, join_date
168 FROM civicrm_membership
172 $params = array(1 => array($membershipID, 'Integer'));
173 $dao = &CRM_Core_DAO
::executeQuery($query, $params);
175 require_once 'CRM/Member/BAO/MembershipStatus.php';
177 // Take the is_admin column in MembershipStatus into consideration when requested
178 if (! CRM_Utils_Array
::value('ignore_admin_only', $membershipParams) ) {
179 $result = &CRM_Member_BAO_MembershipStatus
::getMembershipStatusByDate($dao->start_date
, $dao->end_date
, $dao->join_date
, 'today', TRUE);
182 $result = &CRM_Member_BAO_MembershipStatus
::getMembershipStatusByDate($dao->start_date
, $dao->end_date
, $dao->join_date
);
185 //make is error zero only when valid status found.
186 if (CRM_Utils_Array
::value('id', $result)) {
187 $result['is_error'] = 0;
191 $result = civicrm_api3_create_error('did not find a membership record');