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 * Create a Membership Status
44 * This API is used for creating a Membership Status
46 * @param array $params an associative array of name/value property values of civicrm_membership_status
48 * @return array of newly created membership status property values.
49 * {@getfields MembershipStatus_create}
52 function civicrm_api3_membership_status_create($params) {
53 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
57 * Adjust Metadata for Create action
59 * The metadata is used for setting defaults, documentation & validation
60 * @param array $params array or parameters determined by getfields
62 function _civicrm_api3_membership_status_create_spec(&$params) {
63 $params['name']['api.aliases'] = array('label');
67 * Get a membership status.
69 * This api is used for finding an existing membership status.
71 * @param array $params an associative array of name/value property values of civicrm_membership_status
73 * @return Array of all found membership status property values.
74 * {@getfields MembershipStatus_get}
77 function civicrm_api3_membership_status_get($params) {
78 return _civicrm_api3_basic_get('CRM_Member_BAO_MembershipStatus', $params);
82 * Update an existing membership status
84 * This api is used for updating an existing membership status.
85 * Required parrmeters : id of a membership status
87 * @param Array $params an associative array of name/value property values of civicrm_membership_status
88 * @deprecated - should just use create
90 * @return array of updated membership status property values
93 function &civicrm_api3_membership_status_update($params) {
95 civicrm_api3_verify_mandatory($params, NULL, array('id'));
96 //don't allow duplicate names.
97 $name = CRM_Utils_Array
::value('name', $params);
99 $status = new CRM_Member_DAO_MembershipStatus();
100 $status->name
= $params['name'];
101 if ($status->find(TRUE) && $status->id
!= $params['id']) {
102 return civicrm_api3_create_error(ts('A membership status with this name already exists.'));
106 $membershipStatusBAO = new CRM_Member_BAO_MembershipStatus();
107 $membershipStatusBAO->id
= $params['id'];
108 if ($membershipStatusBAO->find(TRUE)) {
109 $fields = $membershipStatusBAO->fields();
110 foreach ($fields as $name => $field) {
111 if (array_key_exists($name, $params)) {
112 $membershipStatusBAO->$name = $params[$name];
115 $membershipStatusBAO->save();
117 $membershipStatus = array();
118 _civicrm_api3_object_to_array(clone($membershipStatusBAO), $membershipStatus);
119 $membershipStatus['is_error'] = 0;
120 return $membershipStatus;
124 * Deletes an existing membership status
126 * This API is used for deleting a membership status
128 * @param array Params array containing 'id' - Id of the membership status to be deleted
129 * {@getfields MembershipStatus_delete}
134 function civicrm_api3_membership_status_delete($params) {
136 $memberStatusDelete = CRM_Member_BAO_MembershipStatus
::del($params['id'], TRUE);
137 return $memberStatusDelete ?
civicrm_api3_create_error($memberStatusDelete['error_message']) : civicrm_api3_create_success();
141 * Derives the Membership Status of a given Membership Reocrd
143 * This API is used for deriving Membership Status of a given Membership
144 * record using the rules encoded in the membership_status table.
146 * @param Int $membershipID Id of a membership
147 * @param String $statusDate
149 * @return Array Array of status id and status name
152 function civicrm_api3_membership_status_calc($membershipParams) {
154 if (!($membershipID = CRM_Utils_Array
::value('membership_id', $membershipParams))) {
155 return civicrm_api3_create_error('membershipParams do not contain membership_id');
159 SELECT start_date, end_date, join_date
160 FROM civicrm_membership
164 $params = array(1 => array($membershipID, 'Integer'));
165 $dao = &CRM_Core_DAO
::executeQuery($query, $params);
167 // Take the is_admin column in MembershipStatus into consideration when requested
168 if (! CRM_Utils_Array
::value('ignore_admin_only', $membershipParams) ) {
169 $result = &CRM_Member_BAO_MembershipStatus
::getMembershipStatusByDate($dao->start_date
, $dao->end_date
, $dao->join_date
, 'today', TRUE);
172 $result = &CRM_Member_BAO_MembershipStatus
::getMembershipStatusByDate($dao->start_date
, $dao->end_date
, $dao->join_date
);
175 //make is error zero only when valid status found.
176 if (CRM_Utils_Array
::value('id', $result)) {
177 $result['is_error'] = 0;
181 $result = civicrm_api3_create_error('did not find a membership record');