X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FMember%2FBAO%2FMembershipStatus.php;h=860adfddd6a615ce8649096beadd685b227fcf24;hb=c24be2289c776d9ee74980d0db74996804bd0eff;hp=5c1c8f35b70b5940d2308a6e616f43bbf850a34b;hpb=e01a5ffed559ccb3a64fba29f0ca8964e00d3178;p=civicrm-core.git diff --git a/CRM/Member/BAO/MembershipStatus.php b/CRM/Member/BAO/MembershipStatus.php index 5c1c8f35b7..860adfddd6 100644 --- a/CRM/Member/BAO/MembershipStatus.php +++ b/CRM/Member/BAO/MembershipStatus.php @@ -1,7 +1,7 @@ copyValues($params); if ($membershipStatus->find(TRUE)) { @@ -71,15 +68,17 @@ class CRM_Member_BAO_MembershipStatus extends CRM_Member_DAO_MembershipStatus { } /** - * update the is_active flag in the db + * Update the is_active flag in the db * - * @param int $id id of the database record - * @param boolean $is_active value we want to set the is_active field + * @param int $id + * Id of the database record. + * @param bool $is_active + * Value we want to set the is_active field. * * @return Object DAO object on sucess, null otherwise * @static */ - static function setIsActive($id, $is_active) { + public static function setIsActive($id, $is_active) { return CRM_Core_DAO::setFieldValue('CRM_Member_DAO_MembershipStatus', $id, 'is_active', $is_active); } @@ -87,16 +86,16 @@ class CRM_Member_BAO_MembershipStatus extends CRM_Member_DAO_MembershipStatus { * Takes an associative array and creates a membership Status object * See http://wiki.civicrm.org/confluence/display/CRM/Database+layer * - * @param array $params (reference ) an assoc array of name/value pairs + * @param array $params + * (reference ) an assoc array of name/value pairs. * * @throws Exception - * @return object CRM_Member_BAO_MembershipStatus object - * @access public + * @return CRM_Member_BAO_MembershipStatus object * @static */ - static function create($params){ + public static function create($params) { $ids = array(); - if(!empty($params['id'])){ + if (!empty($params['id'])) { $ids['membershipStatus'] = $params['id']; } else{ @@ -111,53 +110,64 @@ class CRM_Member_BAO_MembershipStatus extends CRM_Member_DAO_MembershipStatus { return $membershipStatusBAO; } /** - * function to add the membership types + * Add the membership types * - * @param array $params reference array contains the values submitted by the form - * @param array $ids array contains the id - this param is deprecated + * @param array $params + * Reference array contains the values submitted by the form. + * @param array $ids + * Array contains the id - this param is deprecated. * - * @access public * @static * * @return object */ - static function add(&$params, $ids = array()) { - $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); - $params['is_current_member'] = CRM_Utils_Array::value('is_current_member', $params, FALSE); - $params['is_admin'] = CRM_Utils_Array::value('is_admin', $params, FALSE); - $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE); + public static function add(&$params, $ids = array()) { + $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('membershipStatus', $ids)); + if (!$id) { + CRM_Core_DAO::setCreateDefaults($params, self::getDefaults()); + //copy name to label when not passed. + if (empty($params['label']) && !empty($params['name'])) { + $params['label'] = $params['name']; + } + + if (empty($params['name']) && !empty($params['label'])) { + $params['name'] = $params['label']; + } + } // set all other defaults to false. - if ($params['is_default']) { + if (!empty($params['is_default'])) { $query = "UPDATE civicrm_membership_status SET is_default = 0"; CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray ); } - //copy name to label when not passed. - if (empty($params['label']) && !empty($params['name'])) { - $params['label'] = $params['name']; - } - - //for add mode, copy label to name. - $statusId = !empty($params['id']) ? $params['id'] : CRM_Utils_Array::value('membershipStatus', $ids); - if (!$statusId && !empty($params['label']) && empty($params['name'])) { - $params['name'] = $params['label']; - } - // action is taken depending upon the mode $membershipStatus = new CRM_Member_DAO_MembershipStatus(); $membershipStatus->copyValues($params); - $membershipStatus->id = $statusId; + $membershipStatus->id = $id; $membershipStatus->save(); return $membershipStatus; } /** - * Function to get membership status + * Get defaults for new entity + * @return array + */ + public static function getDefaults() { + return array( + 'is_active' => FALSE, + 'is_current_member' => FALSE, + 'is_admin' => FALSE, + 'is_default' => FALSE, + ); + } + + /** + * Get membership status * * @param int $membershipStatusId * @@ -175,15 +185,14 @@ class CRM_Member_BAO_MembershipStatus extends CRM_Member_DAO_MembershipStatus { } /** - * Function to delete membership Types + * Delete membership Types * * @param int $membershipStatusId * * @throws CRM_Core_Exception - * @internal param $ * @static */ - static function del($membershipStatusId) { + public static function del($membershipStatusId) { //check dependencies //checking if membership status is present in some other table $check = FALSE; @@ -206,27 +215,32 @@ class CRM_Member_BAO_MembershipStatus extends CRM_Member_DAO_MembershipStatus { } /** - * Function to find the membership status based on start date, end date, join date & status date. + * Find the membership status based on start date, end date, join date & status date. * - * @param string $startDate start date of the member whose membership status is to be calculated. - * @param string $endDate end date of the member whose membership status is to be calculated. - * @param string $joinDate join date of the member whose membership status is to be calculated. + * @param string $startDate + * Start date of the member whose membership status is to be calculated. + * @param string $endDate + * End date of the member whose membership status is to be calculated. + * @param string $joinDate + * Join date of the member whose membership status is to be calculated. * @param \date|string $statusDate status date of the member whose membership status is to be calculated. - * @param boolean $excludeIsAdmin exclude the statuses those having is_admin = 1 - * @param $membershipTypeID - * @param array $membership membership params as available to calling function - passed to the hook + * @param bool $excludeIsAdminExclude the statuses those having is_admin = 1. + * Exclude the statuses those having is_admin = 1. + * @param int $membershipTypeID + * @param array $membership + * Membership params as available to calling function - passed to the hook. * - * @internal param int $membershipType membership type id - passed to the hook * @return array @static */ - static function getMembershipStatusByDate($startDate, $endDate, $joinDate, + static function getMembershipStatusByDate( + $startDate, $endDate, $joinDate, $statusDate = 'today', $excludeIsAdmin = FALSE, $membershipTypeID, $membership = array() ) { $membershipDetails = array(); if (!$statusDate || $statusDate == 'today') { - $statusDate = getDate(); + $statusDate = getdate(); $statusDate = date('Ymd', mktime($statusDate['hours'], $statusDate['minutes'], @@ -293,7 +307,7 @@ class CRM_Member_BAO_MembershipStatus extends CRM_Member_DAO_MembershipStatus { ${$dat . 'Month'} + $membershipStatus->{$eve . '_event_adjust_interval'}, ${$dat . 'Day'}, ${$dat . 'Year'} - )); + )); } // add in days if ($membershipStatus->{$eve . '_event_adjust_unit'} == 'day') { @@ -301,7 +315,7 @@ class CRM_Member_BAO_MembershipStatus extends CRM_Member_DAO_MembershipStatus { ${$dat . 'Month'}, ${$dat . 'Day'} + $membershipStatus->{$eve . '_event_adjust_interval'}, ${$dat . 'Year'} - )); + )); } // add in years if ($membershipStatus->{$eve . '_event_adjust_unit'} == 'year') { @@ -309,7 +323,7 @@ class CRM_Member_BAO_MembershipStatus extends CRM_Member_DAO_MembershipStatus { ${$dat . 'Month'}, ${$dat . 'Day'}, ${$dat . 'Year'} + $membershipStatus->{$eve . '_event_adjust_interval'} - )); + )); } // if no interval and unit, present } @@ -385,4 +399,3 @@ class CRM_Member_BAO_MembershipStatus extends CRM_Member_DAO_MembershipStatus { return $statusIds; } } -