/** * The function returns all the Organization for all membershipTypes . * * @param int $membershipTypeId * * @return array */ public static function getMembershipTypeOrganization($membershipTypeId = NULL) { $allMembershipTypes = array(); $membershipType = new CRM_Member_DAO_MembershipType(); if (isset($membershipTypeId)) { $membershipType->id = $membershipTypeId; } $membershipType->find(); while ($membershipType->fetch()) { $allMembershipTypes[$membershipType->id] = $membershipType->member_of_contact_id; } return $allMembershipTypes; }
/** * Browse all membership types. * * * @return void */ public function browse() { // get all membership types sorted by weight $membershipType = array(); $dao = new CRM_Member_DAO_MembershipType(); $dao->orderBy('weight'); $dao->find(); while ($dao->fetch()) { if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('view contributions of type ' . CRM_Contribute_PseudoConstant::financialType($dao->financial_type_id))) { continue; } $links = self::links(); $membershipType[$dao->id] = array(); CRM_Core_DAO::storeValues($dao, $membershipType[$dao->id]); $membershipType[$dao->id]['period_type'] = CRM_Utils_Array::value($dao->period_type, CRM_Core_SelectValues::periodType(), ''); $membershipType[$dao->id]['visibility'] = CRM_Utils_Array::value($dao->visibility, CRM_Core_SelectValues::memberVisibility(), ''); //adding column for relationship type label. CRM-4178. if ($dao->relationship_type_id) { //If membership associated with 2 or more relationship then display all relationship with comma separated $relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dao->relationship_type_id); $relTypeNames = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dao->relationship_direction); $membershipType[$dao->id]['relationshipTypeName'] = NULL; foreach ($relTypeIds as $key => $value) { $relationshipName = 'label_' . $relTypeNames[$key]; if ($membershipType[$dao->id]['relationshipTypeName']) { $membershipType[$dao->id]['relationshipTypeName'] .= ", "; } $membershipType[$dao->id]['relationshipTypeName'] .= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $value, $relationshipName); } $membershipType[$dao->id]['maxRelated'] = CRM_Utils_Array::value('max_related', $membershipType[$dao->id]); } if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($dao->financial_type_id))) { unset($links[CRM_Core_Action::UPDATE], $links[CRM_Core_Action::ENABLE], $links[CRM_Core_Action::DISABLE]); } if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($dao->financial_type_id))) { unset($links[CRM_Core_Action::DELETE]); } // 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 (!isset($dao->is_reserved)) { if ($dao->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } $membershipType[$dao->id]['order'] = $membershipType[$dao->id]['weight']; $membershipType[$dao->id]['action'] = CRM_Core_Action::formLink($links, $action, array('id' => $dao->id), ts('more'), FALSE, 'membershipType.manage.action', 'MembershipType', $dao->id); } } $returnURL = CRM_Utils_System::url('civicrm/admin/member/membershipType', "reset=1&action=browse"); CRM_Utils_Weight::addOrder($membershipType, 'CRM_Member_DAO_MembershipType', 'id', $returnURL); CRM_Member_BAO_MembershipType::convertDayFormat($membershipType); $this->assign('rows', $membershipType); }
/** * Browse all membership types. * * * @return void * @access public * @static */ function browse() { CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js'); // get all membership types sorted by weight $membershipType = array(); $dao = new CRM_Member_DAO_MembershipType(); $dao->orderBy('weight'); $dao->find(); while ($dao->fetch()) { $membershipType[$dao->id] = array(); CRM_Core_DAO::storeValues($dao, $membershipType[$dao->id]); //adding column for relationship type label. CRM-4178. if ($dao->relationship_type_id) { //If membership associated with 2 or more relationship then display all relationship with comma separated $relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dao->relationship_type_id); $relTypeNames = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dao->relationship_direction); $membershipType[$dao->id]['relationshipTypeName'] = NULL; foreach ($relTypeIds as $key => $value) { $relationshipName = 'label_' . $relTypeNames[$key]; if ($membershipType[$dao->id]['relationshipTypeName']) { $membershipType[$dao->id]['relationshipTypeName'] .= ", "; } $membershipType[$dao->id]['relationshipTypeName'] .= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $value, $relationshipName); } $membershipType[$dao->id]['maxRelated'] = CRM_Utils_Array::value('max_related', $membershipType[$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 (!isset($dao->is_reserved)) { if ($dao->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } $membershipType[$dao->id]['order'] = $membershipType[$dao->id]['weight']; $membershipType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id), ts('more'), FALSE, 'membershipType.manage.action', 'MembershipType', $dao->id); } } $returnURL = CRM_Utils_System::url('civicrm/admin/member/membershipType', "reset=1&action=browse"); CRM_Utils_Weight::addOrder($membershipType, 'CRM_Member_DAO_MembershipType', 'id', $returnURL); CRM_Member_BAO_MembershipType::convertDayFormat($membershipType); $this->assign('rows', $membershipType); }
/** * Function to retrieve all Membership Types associated * with an Organization * * @param int $orgID Id of Organization * * @return Array array of the details of membership types * @static */ static function getMembershipTypesByOrg($orgID) { $membershipTypes = array(); $dao = new CRM_Member_DAO_MembershipType(); $dao->member_of_contact_id = $orgID; $dao->find(); while ($dao->fetch()) { $membershipTypes[$dao->id] = array(); CRM_Core_DAO::storeValues($dao, $membershipTypes[$dao->id]); } return $membershipTypes; }
/** * Browse all membership types. * * * @return void * @access public * @static */ function browse() { // get all membership types sorted by weight $membershipType = array(); require_once 'CRM/Member/DAO/MembershipType.php'; $dao = new CRM_Member_DAO_MembershipType(); $dao->orderBy('weight'); $dao->find(); require_once 'CRM/Utils/Money.php'; while ($dao->fetch()) { $membershipType[$dao->id] = array(); CRM_Core_DAO::storeValues($dao, $membershipType[$dao->id]); // fix the display of the monetary value, CRM-4038 if (CRM_Utils_Array::value('minimum_fee', $membershipType[$dao->id])) { $membershipType[$dao->id]['minimum_fee'] = CRM_Utils_Money::format($membershipType[$dao->id]['minimum_fee'], null, '%a'); } //adding column for relationship type label. CRM-4178. if ($dao->relationship_type_id) { //If membership associated with 2 or more relationship then display all relationship with comma separated $relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dao->relationship_type_id); $relTypeNames = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dao->relationship_direction); $membershipType[$dao->id]['relationshipTypeName'] = null; foreach ($relTypeIds as $key => $value) { $relationshipName = 'label_' . $relTypeNames[$key]; if ($membershipType[$dao->id]['relationshipTypeName']) { $membershipType[$dao->id]['relationshipTypeName'] .= ", "; } $membershipType[$dao->id]['relationshipTypeName'] .= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $value, $relationshipName); } } // 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 (!isset($dao->is_reserved)) { if ($dao->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } $membershipType[$dao->id]['order'] = $membershipType[$dao->id]['weight']; $membershipType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id)); } } $returnURL = CRM_Utils_System::url('civicrm/admin/member/membershipType', "reset=1&action=browse"); require_once 'CRM/Utils/Weight.php'; CRM_Utils_Weight::addOrder($membershipType, 'CRM_Member_DAO_MembershipType', 'id', $returnURL); CRM_Member_BAO_MembershipType::convertDayFormat($membershipType); $this->assign('rows', $membershipType); }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } //need to assign custom data type and subtype to the template $this->assign('customDataType', 'Membership'); $this->assign('customDataSubType', $this->_memType); $this->assign('entityID', $this->_id); if ($this->_action & CRM_Core_Action::DELETE) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if ($this->_context == 'standalone') { require_once 'CRM/Contact/Form/NewContact.php'; CRM_Contact_Form_NewContact::buildQuickForm($this); } $selOrgMemType[0][0] = $selMemTypeOrg[0] = ts('- select -'); $dao = new CRM_Member_DAO_MembershipType(); $dao->domain_id = CRM_Core_Config::domainID(); $dao->find(); $membershipType = array(); while ($dao->fetch()) { if ($dao->is_active) { $membershipType[$dao->id] = $dao->name; if ($this->_mode && !$dao->minimum_fee) { continue; } else { if (!CRM_Utils_Array::value($dao->member_of_contact_id, $selMemTypeOrg)) { $selMemTypeOrg[$dao->member_of_contact_id] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $dao->member_of_contact_id, 'display_name', 'id'); $selOrgMemType[$dao->member_of_contact_id][0] = ts('- select -'); } if (!CRM_Utils_Array::value($dao->id, $selOrgMemType[$dao->member_of_contact_id])) { $selOrgMemType[$dao->member_of_contact_id][$dao->id] = $dao->name; } } } } // show organization by default, if only one organization in // the list if (count($selMemTypeOrg) == 2) { unset($selMemTypeOrg[0], $selOrgMemType[0][0]); } //sort membership organization and type, CRM-6099 natcasesort($selMemTypeOrg); foreach ($selOrgMemType as $index => $orgMembershipType) { natcasesort($orgMembershipType); $selOrgMemType[$index] = $orgMembershipType; } $memTypeJs = array('onChange' => "buildCustomData( 'Membership', this.value );"); //build the form for auto renew. $recurProcessor = $autoRenew = array(); if ($this->_mode || $this->_action & CRM_Core_Action::UPDATE) { $autoRenewElement = $this->addElement('checkbox', 'auto_renew', ts('Membership renewed automatically'), null, array('onclick' => "buildReceiptANDNotice( );")); if ($this->_mode) { //get the valid recurring processors. $recurring = CRM_Core_PseudoConstant::paymentProcessor(false, false, 'is_recur = 1'); $recurProcessor = array_intersect_assoc($this->_processors, $recurring); $autoRenew = array(); if (!empty($recurProcessor)) { if (!empty($membershipType)) { $sql = ' SELECT id, auto_renew, duration_unit, duration_interval FROM civicrm_membership_type WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; $recurMembershipTypes = CRM_Core_DAO::executeQuery($sql); while ($recurMembershipTypes->fetch()) { $autoRenew[$recurMembershipTypes->id] = $recurMembershipTypes->auto_renew; foreach (array('id', 'auto_renew', 'duration_unit', 'duration_interval') as $fld) { $this->_recurMembershipTypes[$recurMembershipTypes->id][$fld] = $recurMembershipTypes->{$fld}; } } } $memTypeJs = array('onChange' => "buildCustomData( 'Membership', this.value ); buildAutoRenew(this.value, null );"); } } } $allowAutoRenew = false; if ($this->_mode && !empty($recurProcessor)) { $allowAutoRenew = true; } $this->assign('allowAutoRenew', $allowAutoRenew); $this->assign('autoRenewOptions', json_encode($autoRenew)); $this->assign('recurProcessor', json_encode($recurProcessor)); $sel =& $this->addElement('hierselect', 'membership_type_id', ts('Membership Organization and Type'), $memTypeJs); $sel->setOptions(array($selMemTypeOrg, $selOrgMemType)); $elements = array(); if ($sel) { $elements[] = $sel; } $this->applyFilter('__ALL__', 'trim'); $this->addDate('join_date', ts('Member Since'), false, array('formatType' => 'activityDate')); $this->addDate('start_date', ts('Start Date'), false, array('formatType' => 'activityDate')); $endDate = $this->addDate('end_date', ts('End Date'), false, array('formatType' => 'activityDate')); if ($endDate) { $elements[] = $endDate; } $this->add('text', 'source', ts('Source'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'source')); if (!$this->_mode) { $this->add('select', 'status_id', ts('Membership Status'), array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(null, null, 'label')); $statusOverride = $this->addElement('checkbox', 'is_override', ts('Status Override?'), null, array('onClick' => 'showHideMemberStatus()')); if ($statusOverride) { $elements[] = $statusOverride; } $this->addElement('checkbox', 'record_contribution', ts('Record Membership Payment?')); require_once 'CRM/Contribute/PseudoConstant.php'; $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType()); $this->add('text', 'total_amount', ts('Amount')); $this->addRule('total_amount', ts('Please enter a valid amount.'), 'money'); $this->addDate('receive_date', ts('Received'), false, array('formatType' => 'activityDate')); $this->add('select', 'payment_instrument_id', ts('Paid By'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), false, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);")); $this->add('text', 'trxn_id', ts('Transaction ID')); $this->addRule('trxn_id', ts('Transaction ID already exists in Database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $this->_id, 'trxn_id')); $allowStatuses = array(); $statuses = CRM_Contribute_PseudoConstant::contributionStatus(); if ($this->_onlinePendingContributionId) { $statusNames = CRM_Contribute_PseudoConstant::contributionStatus(null, 'name'); foreach ($statusNames as $val => $name) { if (in_array($name, array('In Progress', 'Overdue'))) { continue; } $allowStatuses[$val] = $statuses[$val]; } } else { $allowStatuses = $statuses; } $this->add('select', 'contribution_status_id', ts('Payment Status'), $allowStatuses); $this->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number')); } $this->addElement('checkbox', 'send_receipt', ts('Send Confirmation and Receipt?'), null, array('onclick' => "return showHideByValue('send_receipt','','notice','table-row','radio',false);")); $this->add('textarea', 'receipt_text_signup', ts('Receipt Message')); if ($this->_mode) { $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, true, array('onChange' => "buildAutoRenew( null, this.value );")); require_once 'CRM/Core/Payment/Form.php'; CRM_Core_Payment_Form::buildCreditCard($this, true); } // Retrieve the name and email of the contact - this will be the TO for receipt email if ($this->_contactID) { require_once 'CRM/Contact/BAO/Contact/Location.php'; list($this->_memberDisplayName, $this->_memberEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); $this->assign('emailExists', $this->_memberEmail); $this->assign('displayName', $this->_memberDisplayName); } $isRecur = false; if ($this->_action & CRM_Core_Action::UPDATE) { $recurContributionId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'contribution_recur_id'); if ($recurContributionId) { $isRecur = true; require_once 'CRM/Member/BAO/Membership.php'; if (CRM_Member_BAO_Membership::isCancelSubscriptionSupported($this->_id)) { $this->assign('cancelAutoRenew', CRM_Utils_System::url('civicrm/contribute/unsubscribe', "reset=1&mid={$this->_id}")); } foreach ($elements as $elem) { $elem->freeze(); } } } $this->assign('isRecur', $isRecur); $this->addFormRule(array('CRM_Member_Form_Membership', 'formRule'), $this); require_once "CRM/Core/BAO/Preferences.php"; $mailingInfo =& CRM_Core_BAO_Preferences::mailingPreferences(); $this->assign('outBound_option', $mailingInfo['outBound_option']); parent::buildQuickForm(); }