/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { parent::buildQuickForm(); if ($this->_action & CRM_Core_Action::DELETE) { return; } $this->applyFilter('__ALL__', 'trim'); $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'name'), TRUE); $this->addRule('name', ts('A membership type with this name already exists. Please select another name.'), 'objectExists', array('CRM_Member_DAO_MembershipType', $this->_id)); $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'description')); $this->add('text', 'minimum_fee', ts('Minimum Fee'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'minimum_fee')); $this->addRule('minimum_fee', ts('Please enter a monetary value for the Minimum Fee.'), 'money'); $this->addElement('select', 'duration_unit', ts('Duration') . ' ', CRM_Core_SelectValues::unitList('duration'), array('onchange' => 'showHidePeriodSettings()')); //period type $this->addElement('select', 'period_type', ts('Period Type'), CRM_Core_SelectValues::periodType(), array('onchange' => 'showHidePeriodSettings()')); $this->add('text', 'duration_interval', ts('Duration Interval'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'duration_interval')); $memberOrg =& $this->add('text', 'member_org', ts('Membership Organization'), 'size=30 maxlength=120'); //start day $this->add('date', 'fixed_period_start_day', ts('Fixed Period Start Day'), CRM_Core_SelectValues::date(NULL, 'M d'), FALSE); $msgTemplates = CRM_Core_BAO_MessageTemplates::getMessageTemplates(FALSE); $hasMsgTemplates = FALSE; if (!empty($msgTemplates)) { $hasMsgTemplates = TRUE; } //Auto-renew Option $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1'); $isAuthorize = FALSE; $options = array(); $allowAutoRenewMsg = FALSE; if (is_array($paymentProcessor) && !empty($paymentProcessor)) { $isAuthorize = TRUE; $options = array(ts('No auto-renew option'), ts('Give option, but not required'), ts('Auto-renew required ')); if ($hasMsgTemplates) { $allowAutoRenewMsg = TRUE; $autoRenewReminderMsg = $this->add('select', 'autorenewal_msg_id', ts('Auto-renew Reminder Message'), array('' => ts('- select -')) + $msgTemplates); } } $this->addRadio('auto_renew', ts('Auto-renew Option'), $options, array('onclick' => "setReminder(this.value);")); $this->assign('authorize', $isAuthorize); $this->assign('allowAutoRenewMsg', $allowAutoRenewMsg); //rollover day $this->add('date', 'fixed_period_rollover_day', ts('Fixed Period Rollover Day'), CRM_Core_SelectValues::date(NULL, 'M d'), FALSE); // required in form rule $this->add('hidden', 'action', $this->_action); $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType()); $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE); if (is_array($relTypeInd)) { asort($relTypeInd); } $memberRel =& $this->add('select', 'relationship_type_id', ts('Relationship Type'), array('' => ts('- select -')) + $relTypeInd); $memberRel->setMultiple(TRUE); $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::memberVisibility()); $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'weight')); $this->add('checkbox', 'is_active', ts('Enabled?')); if ($hasMsgTemplates) { $reminderMsg = $this->add('select', 'renewal_msg_id', ts('Renewal Reminder Message'), array('' => ts('- select -')) + $msgTemplates); } $this->assign('hasMsgTemplates', $hasMsgTemplates); $reminderDay =& $this->add('text', 'renewal_reminder_day', ts('Renewal Reminder Day'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'renewal_reminder_day')); $searchRows = $this->get('searchRows'); $searchCount = $this->get('searchCount'); $searchDone = $this->get('searchDone'); if ($searchRows) { $checkBoxes = array(); $chekFlag = 0; foreach ($searchRows as $id => $row) { $checked = ''; if (!$chekFlag) { $checked = array('checked' => NULL); $chekFlag++; } $checkBoxes[$id] = $this->createElement('radio', NULL, NULL, NULL, $id, $checked); } $this->addGroup($checkBoxes, 'contact_check'); $this->assign('searchRows', $searchRows); } $this->assign('searchCount', $searchCount); $this->assign('searchDone', $searchDone); if ($searchDone) { $searchBtn = ts('Search Again'); } elseif ($this->_action & CRM_Core_Action::UPDATE) { $searchBtn = ts('Change'); } else { $searchBtn = ts('Search'); } $membershipRecords = FALSE; if ($this->_action & CRM_Core_Action::UPDATE) { $membershipType = new CRM_Member_BAO_Membership(); $membershipType->membership_type_id = $this->_id; if ($membershipType->find(TRUE)) { $membershipRecords = TRUE; $memberRel->freeze(); } $memberOrg->freeze(); if ($searchDone) { $memberOrg->unfreeze(); } } $this->assign('membershipRecordsExists', $membershipRecords); if ($this->_action & CRM_Core_Action::UPDATE && $reminderDay) { $renewMessage = array(); $returnProperties = array('renewal_msg_id', 'renewal_reminder_day'); CRM_Core_DAO::commonRetrieveAll('CRM_Member_DAO_MembershipType', 'id', $this->_id, $renewMessage, $returnProperties); if (CRM_Utils_Array::value('renewal_msg_id', $renewMessage[$this->_id]) && CRM_Utils_Array::value('renewal_reminder_day', $renewMessage[$this->_id]) && $membershipRecords) { $reminderMsg = $this->add('select', 'renewal_msg_id', ts('Renewal Reminder Message'), array('' => ts('- select -')) + $msgTemplates); $reminderDay->freeze(); } } $this->addElement('submit', $this->getButtonName('refresh'), $searchBtn, array('class' => 'form-submit')); $this->addFormRule(array('CRM_Member_Form_MembershipType', 'formRule')); $this->assign('membershipTypeId', $this->_id); }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { parent::buildQuickForm(); if ($this->_action & CRM_Core_Action::DELETE) { return; } $this->applyFilter('__ALL__', 'trim'); $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'name'), true); $this->addRule('name', ts('A membership type with this name already exists. Please select another name.'), 'objectExists', array('CRM_Member_DAO_MembershipType', $this->_id)); $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'description')); $this->add('text', 'minimum_fee', ts('Minimum Fee'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'minimum_fee')); $this->addRule('minimum_fee', ts('Please enter a monetary value for the Minimum Fee.'), 'money'); $this->addElement('select', 'duration_unit', ts('Duration') . ' ', CRM_Core_SelectValues::unitList('duration'), array('onchange' => 'showHidePeriodSettings()')); //period type $this->addElement('select', 'period_type', ts('Period Type'), CRM_Core_SelectValues::periodType(), array('onchange' => 'showHidePeriodSettings()')); $this->add('text', 'duration_interval', ts('Duration Interval'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'duration_interval')); $memberOrg =& $this->add('text', 'member_org', ts('Membership Organization'), 'size=30 maxlength=120'); //start day $this->add('date', 'fixed_period_start_day', ts('Fixed Period Start Day'), CRM_Core_SelectValues::date('custom', 3, 1, "Md"), false); //rollover day $this->add('date', 'fixed_period_rollover_day', ts('Fixed Period Rollover Day'), CRM_Core_SelectValues::date('custom', 3, 1, "Md"), false); $this->add('hidden', 'action', $this->_action); //required in form rule require_once 'CRM/Contribute/PseudoConstant.php'; $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType()); require_once 'CRM/Contact/BAO/Relationship.php'; $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, null, true); if (is_array($relTypeInd)) { asort($relTypeInd); } $memberRel =& $this->add('select', 'relationship_type_id', ts('Relationship Type'), array('' => ts('- select -')) + $relTypeInd); $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::memberVisibility()); $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'weight')); $this->add('checkbox', 'is_active', ts('Enabled?')); require_once "CRM/Core/BAO/MessageTemplates.php"; $msgTemplates = CRM_Core_BAO_MessageTemplates::getMessageTemplates(); if (!empty($msgTemplates)) { $reminderMsg = $this->add('select', 'renewal_msg_id', ts('Renewal Reminder Message'), array('' => ts('- select -')) + $msgTemplates); } else { $this->assign('noMsgTemplates', true); } $reminderDay =& $this->add('text', 'renewal_reminder_day', ts('Renewal Reminder Day'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'renewal_reminder_day')); $searchRows = $this->get('searchRows'); $searchCount = $this->get('searchCount'); $searchDone = $this->get('searchDone'); if ($searchRows) { $checkBoxes = array(); $chekFlag = 0; foreach ($searchRows as $id => $row) { $checked = ''; if (!$chekFlag) { $checked = array('checked' => null); $chekFlag++; } $checkBoxes[$id] = $this->createElement('radio', null, null, null, $id, $checked); } $this->addGroup($checkBoxes, 'contact_check'); $this->assign('searchRows', $searchRows); } $this->assign('searchCount', $searchCount); $this->assign('searchDone', $searchDone); if ($searchDone) { $searchBtn = ts('Search Again'); } elseif ($this->_action & CRM_Core_Action::UPDATE) { $searchBtn = ts('Change'); } else { $searchBtn = ts('Search'); } $membershipRecords = false; if ($this->_action & CRM_Core_Action::UPDATE) { require_once 'CRM/Member/BAO/Membership.php'; $membershipType = new CRM_Member_BAO_Membership(); $membershipType->membership_type_id = $this->_id; if ($membershipType->find(true)) { $membershipRecords = true; $memberRel->freeze(); } $memberOrg->freeze(); if ($searchDone) { $memberOrg->unfreeze(); } } if ($this->_action & CRM_Core_Action::UPDATE && $reminderDay) { $renewMessage = array(); $returnProperties = array('renewal_msg_id', 'renewal_reminder_day'); CRM_Core_DAO::commonRetrieveAll('CRM_Member_DAO_MembershipType', 'id', $this->_id, $renewMessage, $returnProperties); if (CRM_Utils_Array::value('renewal_msg_id', $renewMessage[$this->_id]) && CRM_Utils_Array::value('renewal_reminder_day', $renewMessage[$this->_id]) && $membershipRecords) { $reminderMsg = $this->add('select', 'renewal_msg_id', ts('Renewal Reminder Message'), array('' => ts('- select -')) + $msgTemplates); $reminderDay->freeze(); $reminderMsg->freeze(); } } $this->addElement('submit', $this->getButtonName('refresh'), $searchBtn, array('class' => 'form-submit')); $this->addFormRule(array('CRM_Member_Form_MembershipType', 'formRule')); $this->assign('membershipTypeId', $this->_id); }
/** * 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); }
/** * Function to build the form * * @return void * @access public */ public function buildQuickForm() { parent::buildQuickForm(); if ($this->_action & CRM_Core_Action::DELETE) { return; } $this->applyFilter('__ALL__', 'trim'); $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'name'), TRUE); $this->addRule('name', ts('A membership type with this name already exists. Please select another name.'), 'objectExists', array('CRM_Member_DAO_MembershipType', $this->_id)); $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'description')); $this->add('text', 'minimum_fee', ts('Minimum Fee'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'minimum_fee')); $this->addRule('minimum_fee', ts('Please enter a monetary value for the Minimum Fee.'), 'money'); $this->addElement('select', 'duration_unit', ts('Duration'), CRM_Core_SelectValues::unitList('duration')); //period type $this->addElement('select', 'period_type', ts('Period Type'), CRM_Core_SelectValues::periodType()); $this->add('text', 'duration_interval', ts('Duration Interval'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'duration_interval')); $props = array('api' => array('params' => array('contact_type' => 'Organization'))); $this->addEntityRef('member_of_contact_id', ts('Membership Organization'), $props, TRUE); //start day $this->add('date', 'fixed_period_start_day', ts('Fixed Period Start Day'), CRM_Core_SelectValues::date(NULL, 'M d'), FALSE); //Auto-renew Option $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1'); $isAuthorize = FALSE; $options = array(); if (is_array($paymentProcessor) && !empty($paymentProcessor)) { $isAuthorize = TRUE; $options = array(ts('No auto-renew option'), ts('Give option, but not required'), ts('Auto-renew required ')); } $this->addRadio('auto_renew', ts('Auto-renew Option'), $options); $this->assign('authorize', $isAuthorize); //rollover day $this->add('date', 'fixed_period_rollover_day', ts('Fixed Period Rollover Day'), CRM_Core_SelectValues::date(NULL, 'M d'), FALSE); $this->add('date', 'month_fixed_period_rollover_day', ts('Fixed Period Rollover Day'), CRM_Core_SelectValues::date(NULL, 'd'), FALSE); $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType()); $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE); if (is_array($relTypeInd)) { asort($relTypeInd); } $memberRel =& $this->add('select', 'relationship_type_id', ts('Relationship Type'), array('' => ts('- select -')) + $relTypeInd); $memberRel->setMultiple(TRUE); $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::memberVisibility()); $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'weight')); $this->add('checkbox', 'is_active', ts('Enabled?')); $membershipRecords = FALSE; if ($this->_action & CRM_Core_Action::UPDATE) { $membershipType = new CRM_Member_BAO_Membership(); $membershipType->membership_type_id = $this->_id; if ($membershipType->find(TRUE)) { $membershipRecords = TRUE; $memberRel->freeze(); } } $this->assign('membershipRecordsExists', $membershipRecords); $this->add('text', 'max_related', ts('Max related'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'max_related')); $this->addFormRule(array('CRM_Member_Form_MembershipType', 'formRule')); $this->assign('membershipTypeId', $this->_id); }