/** * Update an existing membership status. * * This api is used for updating an existing membership status. * Required parameters: id of a membership status * * @param array $params * Array of name/value property values of civicrm_membership_status. * * @deprecated - should just use create * * @return array * Array of updated membership status property values */ function civicrm_api3_membership_status_update($params) { civicrm_api3_verify_mandatory($params, NULL, array('id')); //don't allow duplicate names. $name = CRM_Utils_Array::value('name', $params); if ($name) { $status = new CRM_Member_DAO_MembershipStatus(); $status->name = $params['name']; if ($status->find(TRUE) && $status->id != $params['id']) { return civicrm_api3_create_error(ts('A membership status with this name already exists.')); } } $membershipStatusBAO = new CRM_Member_BAO_MembershipStatus(); $membershipStatusBAO->id = $params['id']; if ($membershipStatusBAO->find(TRUE)) { $fields = $membershipStatusBAO->fields(); foreach ($fields as $name => $field) { if (array_key_exists($name, $params)) { $membershipStatusBAO->{$name} = $params[$name]; } } $membershipStatusBAO->save(); } $membershipStatus = array(); _civicrm_api3_object_to_array(clone $membershipStatusBAO, $membershipStatus); $membershipStatus['is_error'] = 0; return $membershipStatus; }
/** * Create memberships for related contacts, taking into account the maximum related memberships. * * @param array $params * Array of key - value pairs. * @param CRM_Core_DAO $dao * Membership object. * * @param bool $reset * * @return array|null * Membership details, if created. * * @throws \CRM_Core_Exception */ public static function createRelatedMemberships(&$params, &$dao, $reset = FALSE) { static $relatedContactIds = array(); if ($reset) { // not sure why a static var is in use here - we need a way to reset it from the test suite $relatedContactIds = array(); return FALSE; } $membership = new CRM_Member_DAO_Membership(); $membership->id = $dao->id; // required since create method doesn't return all the // parameters in the returned membership object if (!$membership->find(TRUE)) { return; } $deceasedStatusId = array_search('Deceased', CRM_Member_PseudoConstant::membershipStatus()); // FIXME : While updating/ renewing the // membership, if the relationship is PAST then // the membership of the related contact must be // expired. // For that, getting Membership Status for which // is_current_member is 0. It works for the // generated data as there is only one membership // status having is_current_member = 0. // But this wont work exactly if there will be // more than one status having is_current_member = 0. $membershipStatus = new CRM_Member_DAO_MembershipStatus(); $membershipStatus->is_current_member = 0; if ($membershipStatus->find(TRUE)) { $expiredStatusId = $membershipStatus->id; } else { $expiredStatusId = array_search('Expired', CRM_Member_PseudoConstant::membershipStatus()); } $allRelatedContacts = array(); $relatedContacts = array(); if (!is_a($membership, 'CRM_Core_Error')) { $allRelatedContacts = CRM_Member_BAO_Membership::checkMembershipRelationship($membership->id, $membership->contact_id, CRM_Utils_Array::value('action', $params)); } // check for loops. CRM-4213 // remove repeated related contacts, which already inherited membership. $relatedContactIds[$membership->contact_id] = TRUE; foreach ($allRelatedContacts as $cid => $status) { if (empty($relatedContactIds[$cid])) { $relatedContactIds[$cid] = TRUE; //don't create membership again for owner contact. $nestedRelationship = FALSE; if ($membership->owner_membership_id) { $nestedRelMembership = new CRM_Member_DAO_Membership(); $nestedRelMembership->id = $membership->owner_membership_id; $nestedRelMembership->contact_id = $cid; $nestedRelationship = $nestedRelMembership->find(TRUE); $nestedRelMembership->free(); } if (!$nestedRelationship) { $relatedContacts[$cid] = $status; } } } //lets cleanup related membership if any. if (empty($relatedContacts)) { self::deleteRelatedMemberships($membership->id); } else { // Edit the params array unset($params['id']); // Reminder should be sent only to the direct membership unset($params['reminder_date']); // unset the custom value ids if (is_array(CRM_Utils_Array::value('custom', $params))) { foreach ($params['custom'] as $k => $v) { unset($params['custom'][$k]['id']); } } if (!isset($params['membership_type_id'])) { $params['membership_type_id'] = $membership->membership_type_id; } // max_related should be set in the parent membership unset($params['max_related']); // Number of inherited memberships available - NULL is interpreted as unlimited, '0' as none $available = $membership->max_related == NULL ? PHP_INT_MAX : $membership->max_related; // will be used to queue potential memberships to be created. $queue = array(); foreach ($relatedContacts as $contactId => $relationshipStatus) { //use existing membership record. $relMembership = new CRM_Member_DAO_Membership(); $relMembership->contact_id = $contactId; $relMembership->owner_membership_id = $membership->id; $relMemIds = array(); if ($relMembership->find(TRUE)) { $params['id'] = $relMemIds['membership'] = $relMembership->id; } $params['contact_id'] = $contactId; $params['owner_membership_id'] = $membership->id; // set status_id as it might have been changed for // past relationship $params['status_id'] = $membership->status_id; if ($deceasedStatusId && CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'is_deceased')) { $params['status_id'] = $deceasedStatusId; } elseif (CRM_Utils_Array::value('action', $params) & CRM_Core_Action::UPDATE && $relationshipStatus == CRM_Contact_BAO_Relationship::PAST) { $params['status_id'] = $expiredStatusId; } //don't calculate status again in create( ); $params['skipStatusCal'] = TRUE; //do create activity if we changed status. if ($params['status_id'] != $relMembership->status_id) { $params['createActivity'] = TRUE; } // we should not created contribution record for related contacts, CRM-3371 unset($params['contribution_status_id']); //CRM-16857: Do not create multiple line-items for inherited membership through priceset. unset($params['lineItems']); unset($params['line_item']); if ($params['status_id'] == $deceasedStatusId || $params['status_id'] == $expiredStatusId) { // related membership is not active so does not count towards maximum CRM_Member_BAO_Membership::create($params, $relMemIds); } else { // related membership already exists, so this is just an update if (isset($params['id'])) { if ($available > 0) { CRM_Member_BAO_Membership::create($params, $relMemIds); $available--; } else { // we have run out of inherited memberships, so delete extras self::deleteMembership($params['id']); } // we need to first check if there will remain inherited memberships, so queue it up } else { $queue[] = $params; } } } // now go over the queue and create any available related memberships reset($queue); while ($available > 0 && ($params = each($queue))) { CRM_Member_BAO_Membership::create($params['value'], $relMemIds); $available--; } } }
public function preProcess() { //custom data related code $this->_cdType = CRM_Utils_Array::value('type', $_GET); $this->assign('cdType', FALSE); if ($this->_cdType) { $this->assign('cdType', TRUE); return CRM_Custom_Form_CustomData::preProcess($this); } // get price set id. $this->_priceSetId = CRM_Utils_Array::value('priceSetId', $_GET); $this->set('priceSetId', $this->_priceSetId); $this->assign('priceSetId', $this->_priceSetId); // action $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add'); $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this); $this->_processors = array(); CRM_Core_Resources::singleton()->addSetting(array('ids' => array('contact' => $this->_contactID))); // check for edit permission if (!CRM_Core_Permission::checkActionPermission('CiviMember', $this->_action)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page')); } if ($this->_action & CRM_Core_Action::DELETE) { $contributionID = CRM_Member_BAO_Membership::getMembershipContributionId($this->_id); // check delete permission for contribution if ($this->_id && $contributionID && !CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) { CRM_Core_Error::fatal(ts("This Membership is linked to a contribution. You must have 'delete in CiviContribute' permission in order to delete this record.")); } } $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->assign('context', $this->_context); if ($this->_id) { $this->_memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'membership_type_id'); $this->_membershipIDs[] = $this->_id; } $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this); $this->assign('membershipMode', $this->_mode); if ($this->_mode) { $this->_paymentProcessor = array('billing_mode' => 1); $validProcessors = array(); $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'billing_mode IN ( 1, 3 )'); foreach ($processors as $ppID => $label) { $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($ppID, $this->_mode); if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) { continue; } elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') { continue; } else { $paymentObject = CRM_Core_Payment::singleton($this->_mode, $paymentProcessor, $this); $error = $paymentObject->checkConfig(); if (empty($error)) { $validProcessors[$ppID] = $label; } $paymentObject = NULL; } } if (empty($validProcessors)) { CRM_Core_Error::fatal(ts('Could not find valid payment processor for this page')); } else { $this->_processors = $validProcessors; } // also check for billing information // get the billing location type $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate'); // CRM-8108 remove ts around Billing location type //$this->_bltID = array_search( ts('Billing'), $locationTypes ); $this->_bltID = array_search('Billing', $locationTypes); if (!$this->_bltID) { CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing'))); } $this->set('bltID', $this->_bltID); $this->assign('bltID', $this->_bltID); $this->_fields = array(); CRM_Core_Payment_Form::setCreditCardFields($this); // this required to show billing block $this->assign_by_ref('paymentProcessor', $paymentProcessor); $this->assign('hidePayPalExpress', TRUE); } if ($this->_action & CRM_Core_Action::ADD) { if (!CRM_Member_BAO_Membership::statusAvailabilty($this->_contactID)) { // all possible statuses are disabled - redirect back to contact form CRM_Core_Error::statusBounce(ts('There are no configured membership statuses. You cannot add this membership until your membership statuses are correctly configured')); } if ($this->_contactID) { //check whether contact has a current membership so we can alert user that they may want to do a renewal instead $contactMemberships = array(); $memParams = array('contact_id' => $this->_contactID); CRM_Member_BAO_Membership::getValues($memParams, $contactMemberships, TRUE); $cMemTypes = array(); foreach ($contactMemberships as $mem) { $cMemTypes[] = $mem['membership_type_id']; } if (count($cMemTypes) > 0) { $memberorgs = CRM_Member_BAO_MembershipType::getMemberOfContactByMemTypes($cMemTypes); $mems_by_org = array(); foreach ($contactMemberships as $memid => $mem) { $mem['member_of_contact_id'] = CRM_Utils_Array::value($mem['membership_type_id'], $memberorgs); if (CRM_Utils_Array::value('membership_end_date', $mem)) { $mem['membership_end_date'] = CRM_Utils_Date::customformat($mem['membership_end_date']); } $mem['membership_type'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $mem['membership_type_id'], 'name', 'id'); $mem['membership_status'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $mem['status_id'], 'label', 'id'); if ($this->_mode) { $mem['renewUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$mem['id']}&context=membership&selectedChild=member&mode=live"); } else { $mem['renewUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$mem['id']}&context=membership&selectedChild=member"); } $mem['membershipTab'] = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->_contactID}&selectedChild=member"); $mems_by_org[$mem['member_of_contact_id']] = $mem; } $resources = CRM_Core_Resources::singleton(); $resources->addSetting(array('existingMems' => array('memberorgs' => $mems_by_org))); $resources->addScriptFile('civicrm', 'templates/CRM/Member/Form/Membership.js'); } } else { $resources = CRM_Core_Resources::singleton(); $resources->addScriptFile('civicrm', 'templates/CRM/Member/Form/MembershipStandalone.js'); $statuses = array(); $membershipStatus = new CRM_Member_DAO_MembershipStatus(); $membershipStatus->is_current_member = 1; $membershipStatus->find(); $membershipStatus->selectAdd(); $membershipStatus->selectAdd('id'); while ($membershipStatus->fetch()) { $statuses[$membershipStatus->id] = $membershipStatus->label; } $membershipStatus->free(); $passthru = array('typeorgs' => CRM_Member_BAO_MembershipType::getMembershipTypeOrganization(), 'memtypes' => CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE), 'statuses' => $statuses); $resources->addSetting(array('existingMems' => $passthru)); } } // when custom data is included in this page if (CRM_Utils_Array::value('hidden_custom', $_POST)) { CRM_Custom_Form_CustomData::preProcess($this); CRM_Custom_Form_CustomData::buildQuickForm($this); CRM_Custom_Form_CustomData::setDefaultValues($this); } // CRM-4395, get the online pending contribution id. $this->_onlinePendingContributionId = NULL; if (!$this->_mode && $this->_id && $this->_action & CRM_Core_Action::UPDATE) { $this->_onlinePendingContributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($this->_id, 'Membership'); } $this->assign('onlinePendingContributionId', $this->_onlinePendingContributionId); $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail(); // Set title if ($this->_contactID) { $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactID); // Check if this is default domain contact CRM-10482 if (CRM_Contact_BAO_Contact::checkDomainContact($this->_contactID)) { $displayName .= ' (' . ts('default organization') . ')'; } // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container CRM_Utils_System::setTitle(ts('Membership for') . ' ' . $displayName); } parent::preProcess(); }
/** * Function that return the status ids whose is_current_member is set. * * @return array */ public static function getMembershipStatusCurrent() { $statusIds = array(); $membershipStatus = new CRM_Member_DAO_MembershipStatus(); $membershipStatus->is_current_member = 1; $membershipStatus->find(); $membershipStatus->selectAdd(); $membershipStatus->selectAdd('id'); while ($membershipStatus->fetch()) { $statusIds[] = $membershipStatus->id; } $membershipStatus->free(); return $statusIds; }
/** * function to create memberships for related contacts * * @param array $params array of key - value pairs * @param object $membership membership object * * @return null|relatedMembership array of memberships if created * @static * @access public */ static function createRelatedMemberships(&$params, &$membership) { static $relatedContactIds = array(); // required since create method doesn't return all the // parameters in the returned membership object if (!$membership->find(true)) { return; } require_once 'CRM/Member/PseudoConstant.php'; $deceasedStatusId = array_search('Deceased', CRM_Member_PseudoConstant::membershipStatus()); $allRelatedContacts = array(); $relatedContacts = array(); if (!is_a($membership, 'CRM_Core_Error')) { $allRelatedContacts = CRM_Member_BAO_Membership::checkMembershipRelationship($membership->id, $membership->contact_id, CRM_Utils_Array::value('action', $params)); } // check for loops. CRM-4213 // remove repeated related contacts, which already inherited membership. $relatedContactIds[$membership->contact_id] = true; foreach ($allRelatedContacts as $cid => $status) { if (!CRM_Utils_Array::value($cid, $relatedContactIds)) { $relatedContactIds[$cid] = true; //don't create membership again for owner contact. $nestedRelationship = false; if ($membership->owner_membership_id) { $nestedRelMembership = new CRM_Member_DAO_Membership(); $nestedRelMembership->id = $membership->owner_membership_id; $nestedRelMembership->contact_id = $cid; $nestedRelationship = $nestedRelMembership->find(true); $nestedRelMembership->free(); } if (!$nestedRelationship) { $relatedContacts[$cid] = $status; } } } //lets cleanup related membership if any. if (empty($relatedContacts)) { require_once 'CRM/Member/BAO/Membership.php'; CRM_Member_BAO_Membership::deleteRelatedMemberships($membership->id); } else { // Edit the params array unset($params['id']); // Reminder should be sent only to the direct membership unset($params['reminder_date']); // unset the custom value ids if (is_array(CRM_Utils_Array::value('custom', $params))) { foreach ($params['custom'] as $k => $v) { unset($params['custom'][$k]['id']); } } if (!isset($params['membership_type_id'])) { $params['membership_type_id'] = $membership->membership_type_id; } foreach ($relatedContacts as $contactId => $relationshipStatus) { //use existing membership record. $relMembership = new CRM_Member_DAO_Membership(); $relMembership->contact_id = $contactId; $relMembership->owner_membership_id = $membership->id; $relMemIds = array(); if ($relMembership->find(true)) { $params['id'] = $relMemIds['membership'] = $relMembership->id; } $params['contact_id'] = $contactId; $params['owner_membership_id'] = $membership->id; // set status_id as it might have been changed for // past relationship $params['status_id'] = $membership->status_id; if ($deceasedStatusId && CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'is_deceased')) { $params['status_id'] = $deceasedStatusId; } else { if (CRM_Utils_Array::value('action', $params) & CRM_Core_Action::UPDATE && $relationshipStatus == CRM_Contact_BAO_Relationship::PAST) { // FIXME : While updating/ renewing the // membership, if the relationship is PAST then // the membership of the related contact must be // expired. // For that, getting Membership Status for which // is_current_member is 0. It works for the // generated data as there is only one membership // status having is_current_member = 0. // But this wont work exactly if there will be // more than one status having is_current_member = 0. require_once 'CRM/Member/DAO/MembershipStatus.php'; $membershipStatus = new CRM_Member_DAO_MembershipStatus(); $membershipStatus->is_current_member = 0; if ($membershipStatus->find(true)) { $params['status_id'] = $membershipStatus->id; } } } //don't calculate status again in create( ); $params['skipStatusCal'] = true; //do create activity if we changed status. if ($params['status_id'] != $relMembership->status_id) { $params['createActivity'] = true; } // we should not created contribution record for related contacts, CRM-3371 unset($params['contribution_status_id']); CRM_Member_BAO_Membership::create($params, $relMemIds); } } }
/** * Browse all custom data groups. * * * @return void */ public function browse() { // get all custom groups sorted by weight $membershipStatus = array(); $dao = new CRM_Member_DAO_MembershipStatus(); $dao->orderBy('weight'); $dao->find(); while ($dao->fetch()) { $membershipStatus[$dao->id] = array(); CRM_Core_DAO::storeValues($dao, $membershipStatus[$dao->id]); // form all action links $action = array_sum(array_keys($this->links())); // update enable/disable links depending on if it is is_reserved or is_active if (!$dao->is_reserved) { if ($dao->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } $membershipStatus[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id), ts('more'), FALSE, 'membershipStatus.manage.action', 'MembershipStatus', $dao->id); } if ($startEvent = CRM_Utils_Array::value('start_event', $membershipStatus[$dao->id])) { $membershipStatus[$dao->id]['start_event'] = $startEvent == 'join_date' ? 'member since' : str_replace("_", " ", $startEvent); } if ($endEvent = CRM_Utils_Array::value('end_event', $membershipStatus[$dao->id])) { $membershipStatus[$dao->id]['end_event'] = $endEvent == 'join_date' ? 'member since' : str_replace("_", " ", $endEvent); } } // Add order changing widget to selector $returnURL = CRM_Utils_System::url('civicrm/admin/member/membershipStatus', "reset=1&action=browse"); CRM_Utils_Weight::addOrder($membershipStatus, 'CRM_Member_DAO_MembershipStatus', 'id', $returnURL); $this->assign('rows', $membershipStatus); }
/** * function to create memberships for related contacts * * @param array $params array of key - value pairs * @param object $membership membership object * * @return null|relatedMembership array of memberships if created * @static * @access public */ static function createRelatedMemberships(&$params, &$membership) { static $relatedContactIds = array(); // required since create method doesn't return all the // parameters in the returned membership object if (!$membership->find(true)) { return; } $allRelatedContacts = array(); $relatedContacts = array(); if (!is_a($membership, 'CRM_Core_Error')) { $allRelatedContacts = CRM_Member_BAO_Membership::checkMembershipRelationship($membership->id, $membership->contact_id, CRM_Utils_Array::value('action', $params)); } // check for loops. CRM-4213 // remove repeated related contacts, which already inherited membership. $relatedContactIds[$membership->contact_id] = true; foreach ($allRelatedContacts as $cid => $status) { if (!CRM_Utils_Array::value($cid, $relatedContactIds)) { $relatedContacts[$cid] = $status; $relatedContactIds[$cid] = true; } } if (!empty($relatedContacts)) { // delete all the related membership records before creating CRM_Member_BAO_Membership::deleteRelatedMemberships($membership->id); // Edit the params array unset($params['id']); // Reminder should be sent only to the direct membership unset($params['reminder_date']); // unset the custom value ids if (is_array(CRM_Utils_Array::value('custom', $params))) { foreach ($params['custom'] as $k => $v) { unset($params['custom'][$k]['id']); } } if (!isset($params['membership_type_id'])) { $params['membership_type_id'] = $membership->membership_type_id; } foreach ($relatedContacts as $contactId => $relationshipStatus) { $params['contact_id'] = $contactId; $params['owner_membership_id'] = $membership->id; // set status_id as it might have been changed for // past relationship $params['status_id'] = $membership->status_id; if (CRM_Utils_Array::value('action', $params) & CRM_Core_Action::UPDATE && $relationshipStatus == CRM_Contact_BAO_Relationship::PAST) { // FIXME : While updating/ renewing the // membership, if the relationship is PAST then // the membership of the related contact must be // expired. // For that, getting Membership Status for which // is_current_member is 0. It works for the // generated data as there is only one membership // status having is_current_member = 0. // But this wont work exactly if there will be // more than one status having is_current_member = 0. require_once 'CRM/Member/DAO/MembershipStatus.php'; $membership = new CRM_Member_DAO_MembershipStatus(); $membership->is_current_member = 0; if ($membership->find(true)) { $params['status_id'] = $membership->id; } } // we should not created contribution record for related contacts, CRM-3371 unset($params['contribution_status_id']); CRM_Member_BAO_Membership::create($params, CRM_Core_DAO::$_nullArray); } } }
/** * Returns the list of fields that can be exported * * @param bool $prefix * * @return array */ static function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields = self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['membership_status'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }
/** * Function that return the status ids whose is_current_member is set * * @return * @static */ function getMembershipStatusCurrent() { $statusIds = array(); require_once 'CRM/Member/DAO/MembershipStatus.php'; $membershipStatus = new CRM_Member_DAO_MembershipStatus(); $membershipStatus->is_current_member = 1; $membershipStatus->find(); $membershipStatus->selectAdd(); $membershipStatus->selectAdd('id'); while ($membershipStatus->fetch()) { $statusIds[] = $membershipStatus->id; } $membershipStatus->free(); return $statusIds; }
/** * @param $rev */ public function upgrade_3_2_beta4($rev) { $upgrade = new CRM_Upgrade_Form(); $config = CRM_Core_Config::singleton(); $seedLocale = $config->lcMessages; //handle missing civicrm_uf_field.help_pre $hasLocalizedPreHelpCols = FALSE; // CRM-6451: for multilingual sites we need to find the optimal // locale to use as the final civicrm_membership_status.name column $domain = new CRM_Core_DAO_Domain(); $domain->find(TRUE); $locales = array(); if ($domain->locales) { $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); // optimal: an English locale foreach (array('en_US', 'en_GB', 'en_AU') as $loc) { if (in_array($loc, $locales)) { $seedLocale = $loc; break; } } // if no English and no $config->lcMessages: use the first available if (!$seedLocale) { $seedLocale = $locales[0]; } $upgrade->assign('seedLocale', $seedLocale); $upgrade->assign('locales', $locales); $localizedColNames = array(); foreach ($locales as $loc) { $localizedName = "help_pre_{$loc}"; $localizedColNames[$localizedName] = $localizedName; } $columns = CRM_Core_DAO::executeQuery('SHOW COLUMNS FROM civicrm_uf_field'); while ($columns->fetch()) { if (strpos($columns->Field, 'help_pre') !== FALSE && in_array($columns->Field, $localizedColNames)) { $hasLocalizedPreHelpCols = TRUE; break; } } } $upgrade->assign('hasLocalizedPreHelpCols', $hasLocalizedPreHelpCols); $upgrade->processSQL($rev); // now civicrm_membership_status.name has possibly localised strings, so fix them $i18n = new CRM_Core_I18n($seedLocale); $statuses = array(array('name' => 'New', 'start_event' => 'join_date', 'end_event' => 'join_date', 'end_event_adjust_unit' => 'month', 'end_event_adjust_interval' => '3', 'is_current_member' => '1', 'is_admin' => '0', 'is_default' => '0', 'is_reserved' => '0'), array('name' => 'Current', 'start_event' => 'start_date', 'end_event' => 'end_date', 'is_current_member' => '1', 'is_admin' => '0', 'is_default' => '1', 'is_reserved' => '0'), array('name' => 'Grace', 'start_event' => 'end_date', 'end_event' => 'end_date', 'end_event_adjust_unit' => 'month', 'end_event_adjust_interval' => '1', 'is_current_member' => '1', 'is_admin' => '0', 'is_default' => '0', 'is_reserved' => '0'), array('name' => 'Expired', 'start_event' => 'end_date', 'start_event_adjust_unit' => 'month', 'start_event_adjust_interval' => '1', 'is_current_member' => '0', 'is_admin' => '0', 'is_default' => '0', 'is_reserved' => '0'), array('name' => 'Pending', 'start_event' => 'join_date', 'end_event' => 'join_date', 'is_current_member' => '0', 'is_admin' => '0', 'is_default' => '0', 'is_reserved' => '1'), array('name' => 'Cancelled', 'start_event' => 'join_date', 'end_event' => 'join_date', 'is_current_member' => '0', 'is_admin' => '0', 'is_default' => '0', 'is_reserved' => '0'), array('name' => 'Deceased', 'is_current_member' => '0', 'is_admin' => '1', 'is_default' => '0', 'is_reserved' => '1')); $statusIds = array(); $insertedNewRecord = FALSE; foreach ($statuses as $status) { $dao = new CRM_Member_DAO_MembershipStatus(); // try to find an existing English status $dao->name = $status['name']; // // if not found, look for translated status name // if (!$dao->find(true)) { // $found = false; // $dao->name = $i18n->translate($status['name']); // } // if found, update name and is_reserved if ($dao->find(TRUE)) { $dao->name = $status['name']; $dao->is_reserved = $status['is_reserved']; if ($status['is_reserved']) { $dao->is_active = 1; } // if not found, prepare a new row for insertion } else { $insertedNewRecord = TRUE; foreach ($status as $property => $value) { $dao->{$property} = $value; } $dao->weight = CRM_Utils_Weight::getDefaultWeight('CRM_Member_DAO_MembershipStatus'); } // add label (translated name) and save (UPDATE or INSERT) $dao->label = $i18n->translate($status['name']); $dao->save(); $statusIds[$dao->id] = $dao->id; } //disable all status those are customs. if ($insertedNewRecord) { $sql = ' UPDATE civicrm_membership_status SET is_active = 0 WHERE id NOT IN ( ' . implode(',', $statusIds) . ' )'; CRM_Core_DAO::executeQuery($sql); } }
/** * adds $value['foo_display'] for each $value['foo'] enum from civicrm_membership_status * * @param array $values (reference) the array up for enhancing * @return void */ static function addDisplayEnums(&$values) { $enumFields =& CRM_Member_DAO_MembershipStatus::getEnums(); foreach ($enumFields as $enum) { if (isset($values[$enum])) { $values[$enum . '_display'] = CRM_Member_DAO_MembershipStatus::tsEnum($enum, $values[$enum]); } } }
/** * class constructor */ function __construct() { parent::__construct(); }
/** * Update an existing membership status * * This api is used for updating an existing membership status. * Required parrmeters : id of a membership status * * @param Array $params an associative array of name/value property values of civicrm_membership_status * * @return array of updated membership status property values * @access public */ function &civicrm_membership_status_update(&$params) { _civicrm_initialize(); if (!is_array($params)) { return civicrm_create_error('Params is not an array'); } if (!isset($params['id'])) { return civicrm_create_error('Required parameter missing'); } //don't allow duplicate names. $name = CRM_Utils_Array::value('name', $params); if ($name) { require_once 'CRM/Member/DAO/MembershipStatus.php'; $status = new CRM_Member_DAO_MembershipStatus(); $status->name = $params['name']; if ($status->find(TRUE) && $status->id != $params['id']) { return civicrm_create_error(ts('A membership status with this name already exists.')); } } require_once 'CRM/Member/BAO/MembershipStatus.php'; $membershipStatusBAO = new CRM_Member_BAO_MembershipStatus(); $membershipStatusBAO->id = $params['id']; if ($membershipStatusBAO->find(TRUE)) { $fields = $membershipStatusBAO->fields(); foreach ($fields as $name => $field) { if (array_key_exists($name, $params)) { $membershipStatusBAO->{$name} = $params[$name]; } } $membershipStatusBAO->save(); } $membershipStatus = array(); _civicrm_object_to_array(clone $membershipStatusBAO, $membershipStatus); $membershipStatus['is_error'] = 0; return $membershipStatus; }