/** * 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; }
/** * 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); }
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 * @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; }