First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
1909
sites/all/modules/civicrm/CRM/Member/Form/Membership.php
Normal file
1909
sites/all/modules/civicrm/CRM/Member/Form/Membership.php
Normal file
File diff suppressed because it is too large
Load diff
505
sites/all/modules/civicrm/CRM/Member/Form/MembershipBlock.php
Normal file
505
sites/all/modules/civicrm/CRM/Member/Form/MembershipBlock.php
Normal file
|
@ -0,0 +1,505 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* form to process actions on Membership
|
||||
*/
|
||||
class CRM_Member_Form_MembershipBlock extends CRM_Contribute_Form_ContributionPage {
|
||||
|
||||
/**
|
||||
* Store membership price set id
|
||||
*/
|
||||
protected $_memPriceSetId = NULL;
|
||||
|
||||
/**
|
||||
* Set default values for the form. Note that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
//parent::setDefaultValues();
|
||||
$defaults = array();
|
||||
if (isset($this->_id)) {
|
||||
$defaults = CRM_Member_BAO_Membership::getMembershipBlock($this->_id);
|
||||
}
|
||||
$defaults['member_is_active'] = $defaults['is_active'];
|
||||
|
||||
// Set Display Minimum Fee default to true if we are adding a new membership block
|
||||
if (!isset($defaults['id'])) {
|
||||
$defaults['display_min_fee'] = 1;
|
||||
}
|
||||
else {
|
||||
$this->assign('membershipBlockId', $defaults['id']);
|
||||
}
|
||||
if ($this->_id &&
|
||||
($priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 3, 1))
|
||||
) {
|
||||
$defaults['member_price_set_id'] = $priceSetId;
|
||||
$this->_memPriceSetId = $priceSetId;
|
||||
}
|
||||
else {
|
||||
// for membership_types
|
||||
// if ( isset( $defaults['membership_types'] ) ) {
|
||||
$priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 3);
|
||||
$this->assign('isQuick', 1);
|
||||
$this->_memPriceSetId = $priceSetId;
|
||||
$pFIDs = array();
|
||||
if ($priceSetId) {
|
||||
CRM_Core_DAO::commonRetrieveAll('CRM_Price_DAO_PriceField', 'price_set_id', $priceSetId, $pFIDs, $return = array(
|
||||
'html_type',
|
||||
'name',
|
||||
'label',
|
||||
));
|
||||
foreach ($pFIDs as $pid => $pValue) {
|
||||
if ($pValue['html_type'] == 'Radio' && $pValue['name'] == 'membership_amount') {
|
||||
$defaults['mem_price_field_id'] = $pValue['id'];
|
||||
$defaults['membership_type_label'] = $pValue['label'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($defaults['mem_price_field_id'])) {
|
||||
$options = array();
|
||||
$priceFieldOptions = CRM_Price_BAO_PriceFieldValue::getValues($defaults['mem_price_field_id'], $options, 'id', 1);
|
||||
foreach ($options as $k => $v) {
|
||||
$newMembershipType[$v['membership_type_id']] = 1;
|
||||
if (!empty($defaults['auto_renew'])) {
|
||||
$defaults["auto_renew_" . $v['membership_type_id']] = $defaults['auto_renew'][$v['membership_type_id']];
|
||||
}
|
||||
}
|
||||
$defaults['membership_type'] = $newMembershipType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes();
|
||||
|
||||
if (!empty($membershipTypes)) {
|
||||
$this->addElement('checkbox', 'member_is_active', ts('Membership Section Enabled?'));
|
||||
|
||||
$this->addElement('text', 'new_title', ts('Title - New Membership'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'new_title'));
|
||||
|
||||
$this->add('wysiwyg', 'new_text', ts('Introductory Message - New Memberships'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'new_text'));
|
||||
|
||||
$this->addElement('text', 'renewal_title', ts('Title - Renewals'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'renewal_title'));
|
||||
|
||||
$this->add('wysiwyg', 'renewal_text', ts('Introductory Message - Renewals'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'renewal_text'));
|
||||
|
||||
$this->addElement('checkbox', 'is_required', ts('Require Membership Signup'));
|
||||
$this->addElement('checkbox', 'display_min_fee', ts('Display Membership Fee'));
|
||||
$this->addElement('checkbox', 'is_separate_payment', ts('Separate Membership Payment'));
|
||||
$this->addElement('text', 'membership_type_label', ts('Membership Types Label'), array('placeholder' => ts('Membership')));
|
||||
|
||||
$paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1');
|
||||
$paymentProcessorIds = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage',
|
||||
$this->_id, 'payment_processor'
|
||||
);
|
||||
$paymentProcessorId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $paymentProcessorIds);
|
||||
$isRecur = TRUE;
|
||||
foreach ($paymentProcessorId as $dontCare => $id) {
|
||||
if (!array_key_exists($id, $paymentProcessor)) {
|
||||
$isRecur = FALSE;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$membership = $membershipDefault = $params = array();
|
||||
foreach ($membershipTypes as $k => $v) {
|
||||
$membership[] = $this->createElement('advcheckbox', $k, NULL, $v);
|
||||
$membershipDefault[] = $this->createElement('radio', NULL, NULL, NULL, $k);
|
||||
$membershipRequired[$k] = NULL;
|
||||
if ($isRecur) {
|
||||
$autoRenew = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $k, 'auto_renew');
|
||||
$membershipRequired[$k] = $autoRenew;
|
||||
$autoRenewOptions = array();
|
||||
if ($autoRenew) {
|
||||
$autoRenewOptions = array(ts('Not offered'), ts('Give option'), ts('Required'));
|
||||
$this->addElement('select', "auto_renew_$k", ts('Auto-renew'), $autoRenewOptions);
|
||||
//CRM-15573
|
||||
if ($autoRenew == 2) {
|
||||
$this->freeze("auto_renew_$k");
|
||||
$params['id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipBlock', $this->_id, 'id', 'entity_id');
|
||||
}
|
||||
$this->_renewOption[$k] = $autoRenew;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//CRM-15573
|
||||
if (!empty($params['id'])) {
|
||||
$params['membership_types'] = serialize($membershipRequired);
|
||||
CRM_Member_BAO_MembershipBlock::create($params);
|
||||
}
|
||||
$this->add('hidden', "mem_price_field_id", '', array('id' => "mem_price_field_id"));
|
||||
$this->assign('is_recur', $isRecur);
|
||||
if (isset($this->_renewOption)) {
|
||||
$this->assign('auto_renew', $this->_renewOption);
|
||||
}
|
||||
$this->addGroup($membership, 'membership_type', ts('Membership Types'));
|
||||
$this->addGroup($membershipDefault, 'membership_type_default', ts('Membership Types Default'))
|
||||
->setAttribute('allowClear', TRUE);
|
||||
|
||||
$this->addFormRule(array('CRM_Member_Form_MembershipBlock', 'formRule'), $this->_id);
|
||||
}
|
||||
$price = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviMember');
|
||||
if (CRM_Utils_System::isNull($price)) {
|
||||
$this->assign('price', FALSE);
|
||||
}
|
||||
else {
|
||||
$this->assign('price', TRUE);
|
||||
}
|
||||
$this->add('select', 'member_price_set_id', ts('Membership Price Set'), (array('' => ts('- none -')) + $price));
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$single = $session->get('singleForm');
|
||||
if ($single) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Save'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
}
|
||||
else {
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation.
|
||||
*
|
||||
* @param array $params
|
||||
* (ref.) an assoc array of name/value pairs.
|
||||
*
|
||||
* @param $files
|
||||
* @param int $contributionPageId
|
||||
*
|
||||
* @return bool|array
|
||||
* mixed true or array of errors
|
||||
*/
|
||||
public static function formRule($params, $files, $contributionPageId = NULL) {
|
||||
$errors = array();
|
||||
|
||||
if (!empty($params['member_price_set_id'])) {
|
||||
//check if this price set has membership type both auto-renew and non-auto-renew memberships.
|
||||
$bothTypes = CRM_Price_BAO_PriceSet::isMembershipPriceSetContainsMixOfRenewNonRenew($params['member_price_set_id']);
|
||||
|
||||
//check for supporting payment processors
|
||||
//if both auto-renew and non-auto-renew memberships
|
||||
if ($bothTypes) {
|
||||
$paymentProcessorIds = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage',
|
||||
$contributionPageId, 'payment_processor'
|
||||
);
|
||||
|
||||
$paymentProcessorId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $paymentProcessorIds);
|
||||
|
||||
if (!empty($paymentProcessorId)) {
|
||||
foreach ($paymentProcessorId as $pid) {
|
||||
if ($pid) {
|
||||
$processor = Civi\Payment\System::singleton()->getById($pid);
|
||||
if (!$processor->supports('MultipleConcurrentPayments')) {
|
||||
$errors['member_price_set_id'] = ts('The membership price set associated with this online contribution allows a user to select BOTH an auto-renew AND a non-auto-renew membership. This requires submitting multiple processor transactions, and is not supported for one or more of the payment processors enabled under the Amounts tab.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($params['member_is_active'])) {
|
||||
|
||||
// don't allow price set w/ membership signup, CRM-5095
|
||||
if ($contributionPageId && ($setID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $contributionPageId, NULL, 1))) {
|
||||
|
||||
$extends = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'extends');
|
||||
if ($extends != CRM_Core_Component::getComponentID('CiviMember')) {
|
||||
$errors['member_is_active'] = ts('You cannot enable both Membership Signup and a Contribution Price Set on the same online contribution page.');
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($params['member_price_set_id'])) {
|
||||
return $errors;
|
||||
}
|
||||
|
||||
if (!isset($params['membership_type']) ||
|
||||
(!is_array($params['membership_type']))
|
||||
) {
|
||||
$errors['membership_type'] = ts('Please select at least one Membership Type to include in the Membership section of this page.');
|
||||
}
|
||||
else {
|
||||
$membershipType = array_values($params['membership_type']);
|
||||
$isRecur = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'is_recur');
|
||||
if (array_sum($membershipType) == 0) {
|
||||
$errors['membership_type'] = ts('Please select at least one Membership Type to include in the Membership section of this page.');
|
||||
}
|
||||
elseif (array_sum($membershipType) > CRM_Price_Form_Field::NUM_OPTION) {
|
||||
// for CRM-13079
|
||||
$errors['membership_type'] = ts('You cannot select more than %1 choices. For more complex functionality, please use a Price Set.', array(1 => CRM_Price_Form_Field::NUM_OPTION));
|
||||
}
|
||||
elseif ($isRecur) {
|
||||
if (empty($params['is_separate_payment']) && array_sum($membershipType) != 0) {
|
||||
$errors['is_separate_payment'] = ts('You need to enable Separate Membership Payment when online contribution page is configured for both Membership and Recurring Contribution');
|
||||
}
|
||||
elseif (!empty($params['is_separate_payment'])) {
|
||||
foreach ($params['membership_type'] as $mt => $dontCare) {
|
||||
if (!empty($params["auto_renew_$mt"])) {
|
||||
$errors["auto_renew_$mt"] = ts('You cannot enable both Recurring Contributions and Auto-renew memberships on the same online contribution page');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//for CRM-1302
|
||||
//if Membership status is not present, then display an error message
|
||||
$dao = new CRM_Member_BAO_MembershipStatus();
|
||||
if (!$dao->find()) {
|
||||
$errors['_qf_default'] = ts('Add status rules, before configuring membership');
|
||||
}
|
||||
|
||||
//give error if default is selected for an unchecked membership type
|
||||
if (!empty($params['membership_type_default']) && !$params['membership_type'][$params['membership_type_default']]) {
|
||||
$errors['membership_type_default'] = ts('Can\'t set default option for an unchecked membership type.');
|
||||
}
|
||||
|
||||
if ($contributionPageId) {
|
||||
$amountBlock = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'amount_block_is_active');
|
||||
|
||||
if (!$amountBlock && !empty($params['is_separate_payment'])) {
|
||||
$errors['is_separate_payment'] = ts('Please enable the contribution amount section to use this option.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
// get the submitted form values.
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
$deletePriceSet = 0;
|
||||
if ($params['membership_type']) {
|
||||
// we do this in case the user has hit the forward/back button
|
||||
$dao = new CRM_Member_DAO_MembershipBlock();
|
||||
$dao->entity_table = 'civicrm_contribution_page';
|
||||
$dao->entity_id = $this->_id;
|
||||
$dao->find(TRUE);
|
||||
$membershipID = $dao->id;
|
||||
if ($membershipID) {
|
||||
$params['id'] = $membershipID;
|
||||
}
|
||||
|
||||
$membershipTypes = array();
|
||||
if (is_array($params['membership_type'])) {
|
||||
foreach ($params['membership_type'] as $k => $v) {
|
||||
if ($v) {
|
||||
$membershipTypes[$k] = CRM_Utils_Array::value("auto_renew_$k", $params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_id && !empty($params['member_price_set_id'])) {
|
||||
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'amount_block_is_active', 0);
|
||||
}
|
||||
|
||||
// check for price set.
|
||||
$priceSetID = CRM_Utils_Array::value('member_price_set_id', $params);
|
||||
if (!empty($params['member_is_active']) && is_array($membershipTypes) && !$priceSetID) {
|
||||
$usedPriceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 2);
|
||||
if (empty($params['mem_price_field_id']) && !$usedPriceSetId) {
|
||||
$pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245));
|
||||
$setParams['title'] = $this->_values['title'];
|
||||
if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle, 'id', 'name')) {
|
||||
$setParams['name'] = $pageTitle;
|
||||
}
|
||||
elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle . '_' . $this->_id, 'id', 'name')) {
|
||||
$setParams['name'] = $pageTitle . '_' . $this->_id;
|
||||
}
|
||||
else {
|
||||
$timeSec = explode(".", microtime(TRUE));
|
||||
$setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
|
||||
}
|
||||
$setParams['is_quick_config'] = 1;
|
||||
$setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember');
|
||||
$setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
|
||||
$priceSet = CRM_Price_BAO_PriceSet::create($setParams);
|
||||
$priceSetID = $priceSet->id;
|
||||
$fieldParams['price_set_id'] = $priceSet->id;
|
||||
}
|
||||
elseif ($usedPriceSetId) {
|
||||
$setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember');
|
||||
$setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
|
||||
$setParams['id'] = $usedPriceSetId;
|
||||
$priceSet = CRM_Price_BAO_PriceSet::create($setParams);
|
||||
$priceSetID = $priceSet->id;
|
||||
$fieldParams['price_set_id'] = $priceSet->id;
|
||||
}
|
||||
else {
|
||||
$fieldParams['id'] = CRM_Utils_Array::value('mem_price_field_id', $params);
|
||||
$priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('mem_price_field_id', $params), 'price_set_id');
|
||||
}
|
||||
$editedFieldParams = array(
|
||||
'price_set_id' => $priceSetID,
|
||||
'name' => 'membership_amount',
|
||||
);
|
||||
$editedResults = array();
|
||||
CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
|
||||
if (empty($editedResults['id'])) {
|
||||
$fieldParams['name'] = strtolower(CRM_Utils_String::munge('Membership Amount', '_', 245));
|
||||
if (empty($params['mem_price_field_id'])) {
|
||||
CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceField', 0, 1, array('price_set_id' => $priceSetID));
|
||||
}
|
||||
$fieldParams['weight'] = 1;
|
||||
}
|
||||
else {
|
||||
$fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults);
|
||||
}
|
||||
|
||||
$fieldParams['label'] = !empty($params['membership_type_label']) ? $params['membership_type_label'] : ts('Membership');
|
||||
$fieldParams['is_active'] = 1;
|
||||
$fieldParams['html_type'] = 'Radio';
|
||||
$fieldParams['is_required'] = !empty($params['is_required']) ? 1 : 0;
|
||||
$fieldParams['is_display_amounts'] = !empty($params['display_min_fee']) ? 1 : 0;
|
||||
$rowCount = 1;
|
||||
$options = array();
|
||||
if (!empty($fieldParams['id'])) {
|
||||
CRM_Core_PseudoConstant::populate($options, 'CRM_Price_DAO_PriceFieldValue', TRUE, 'membership_type_id', NULL, " price_field_id = {$fieldParams['id']} ");
|
||||
}
|
||||
|
||||
foreach ($membershipTypes as $memType => $memAutoRenew) {
|
||||
if ($priceFieldID = CRM_Utils_Array::key($memType, $options)) {
|
||||
$fieldParams['option_id'][$rowCount] = $priceFieldID;
|
||||
unset($options[$priceFieldID]);
|
||||
}
|
||||
$membetype = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($memType);
|
||||
$fieldParams['option_label'][$rowCount] = CRM_Utils_Array::value('name', $membetype);
|
||||
$fieldParams['option_amount'][$rowCount] = CRM_Utils_Array::value('minimum_fee', $membetype, 0);
|
||||
$fieldParams['option_weight'][$rowCount] = CRM_Utils_Array::value('weight', $membetype);
|
||||
$fieldParams['option_description'][$rowCount] = CRM_Utils_Array::value('description', $membetype);
|
||||
$fieldParams['default_option'] = CRM_Utils_Array::value('membership_type_default', $params);
|
||||
$fieldParams['option_financial_type_id'][$rowCount] = CRM_Utils_Array::value('financial_type_id', $membetype);
|
||||
|
||||
$fieldParams['membership_type_id'][$rowCount] = $memType;
|
||||
// [$rowCount] = $membetype[''];
|
||||
$rowCount++;
|
||||
}
|
||||
foreach ($options as $priceFieldID => $memType) {
|
||||
CRM_Price_BAO_PriceFieldValue::setIsActive($priceFieldID, '0');
|
||||
}
|
||||
$priceField = CRM_Price_BAO_PriceField::create($fieldParams);
|
||||
}
|
||||
elseif (!$priceSetID) {
|
||||
$deletePriceSet = 1;
|
||||
}
|
||||
|
||||
$params['is_required'] = CRM_Utils_Array::value('is_required', $params, FALSE);
|
||||
$params['is_active'] = CRM_Utils_Array::value('member_is_active', $params, FALSE);
|
||||
|
||||
if ($priceSetID) {
|
||||
$params['membership_types'] = 'null';
|
||||
$params['membership_type_default'] = CRM_Utils_Array::value('membership_type_default', $params, 'null');
|
||||
$params['membership_types'] = serialize($membershipTypes);
|
||||
$params['display_min_fee'] = CRM_Utils_Array::value('display_min_fee', $params, FALSE);
|
||||
$params['is_separate_payment'] = CRM_Utils_Array::value('is_separate_payment', $params, FALSE);
|
||||
}
|
||||
$params['entity_table'] = 'civicrm_contribution_page';
|
||||
$params['entity_id'] = $this->_id;
|
||||
|
||||
$dao = new CRM_Member_DAO_MembershipBlock();
|
||||
$dao->copyValues($params);
|
||||
$dao->save();
|
||||
|
||||
if ($priceSetID && $params['is_active']) {
|
||||
CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $this->_id, $priceSetID);
|
||||
}
|
||||
|
||||
if ($deletePriceSet || !CRM_Utils_Array::value('member_is_active', $params, FALSE)) {
|
||||
|
||||
if ($this->_memPriceSetId) {
|
||||
$pFIDs = array();
|
||||
$conditionParams = array(
|
||||
'price_set_id' => $this->_memPriceSetId,
|
||||
'html_type' => 'radio',
|
||||
'name' => 'contribution_amount',
|
||||
);
|
||||
|
||||
CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceField', $conditionParams, $pFIDs);
|
||||
if (empty($pFIDs['id'])) {
|
||||
CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $this->_id);
|
||||
CRM_Price_BAO_PriceSet::setIsQuickConfig($this->_memPriceSetId, '0');
|
||||
}
|
||||
else {
|
||||
|
||||
CRM_Price_BAO_PriceField::setIsActive($params['mem_price_field_id'], '0');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
parent::endPostProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Memberships');
|
||||
}
|
||||
|
||||
}
|
159
sites/all/modules/civicrm/CRM/Member/Form/MembershipConfig.php
Normal file
159
sites/all/modules/civicrm/CRM/Member/Form/MembershipConfig.php
Normal file
|
@ -0,0 +1,159 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for offline membership / membership type / membership renewal and membership status forms
|
||||
*
|
||||
*/
|
||||
class CRM_Member_Form_MembershipConfig extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The id of the object being edited / created
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_id;
|
||||
|
||||
/**
|
||||
* The name of the BAO object for this form.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_BAOName;
|
||||
|
||||
/**
|
||||
* Explicitly declare the entity api name.
|
||||
*/
|
||||
public function getDefaultEntity() {
|
||||
return 'MembershipType';
|
||||
}
|
||||
|
||||
public function preProcess() {
|
||||
$this->_id = $this->get('id');
|
||||
$this->_BAOName = $this->get('BAOName');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. MobileProvider that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* defaults
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
|
||||
if (isset($this->_id)) {
|
||||
$params = array('id' => $this->_id);
|
||||
$baoName = $this->_BAOName;
|
||||
$baoName::retrieve($params, $defaults);
|
||||
}
|
||||
|
||||
if (isset($defaults['minimum_fee'])) {
|
||||
$defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a');
|
||||
}
|
||||
|
||||
if (isset($defaults['status'])) {
|
||||
$this->assign('membershipStatus', $defaults['status']);
|
||||
}
|
||||
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
$defaults['is_active'] = 1;
|
||||
}
|
||||
|
||||
if (isset($defaults['member_of_contact_id']) &&
|
||||
$defaults['member_of_contact_id']
|
||||
) {
|
||||
$defaults['member_org'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
|
||||
$defaults['member_of_contact_id'], 'display_name'
|
||||
);
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
if ($this->_action & CRM_Core_Action::RENEW) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Renew'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
}
|
||||
elseif ($this->_action & CRM_Core_Action::DELETE) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Delete'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
}
|
||||
else {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save and New'),
|
||||
'subName' => 'new',
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
716
sites/all/modules/civicrm/CRM/Member/Form/MembershipRenewal.php
Normal file
716
sites/all/modules/civicrm/CRM/Member/Form/MembershipRenewal.php
Normal file
|
@ -0,0 +1,716 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for Membership Renewal
|
||||
*/
|
||||
class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
|
||||
|
||||
/**
|
||||
* Display name of the member.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_memberDisplayName = NULL;
|
||||
|
||||
/**
|
||||
* email of the person paying for the membership (used for receipts)
|
||||
*/
|
||||
protected $_memberEmail = NULL;
|
||||
|
||||
/**
|
||||
* Contact ID of the member.
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_contactID = NULL;
|
||||
|
||||
/**
|
||||
* Display name of the person paying for the membership (used for receipts)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_contributorDisplayName = NULL;
|
||||
|
||||
/**
|
||||
* email of the person paying for the membership (used for receipts)
|
||||
*/
|
||||
protected $_contributorEmail = NULL;
|
||||
|
||||
/**
|
||||
* email of the person paying for the membership (used for receipts)
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_contributorContactID = NULL;
|
||||
|
||||
/**
|
||||
* ID of the person the receipt is to go to
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_receiptContactId = NULL;
|
||||
|
||||
/**
|
||||
* context would be set to standalone if the contact is use is being selected from
|
||||
* the form rather than in the URL
|
||||
*/
|
||||
public $_context;
|
||||
|
||||
/**
|
||||
* End date of renewed membership.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $endDate = NULL;
|
||||
|
||||
/**
|
||||
* Has an email been sent.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $isMailSent = FALSE;
|
||||
|
||||
/**
|
||||
* The name of the renewed membership type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $membershipTypeName = '';
|
||||
|
||||
/**
|
||||
* An array to hold a list of datefields on the form
|
||||
* so that they can be converted to ISO in a consistent manner
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_dateFields = array(
|
||||
'receive_date' => array('default' => 'now'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Pre-process form.
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function preProcess() {
|
||||
|
||||
// This string makes up part of the class names, differentiating them (not sure why) from the membership fields.
|
||||
$this->assign('formClass', 'membershiprenew');
|
||||
parent::preProcess();
|
||||
|
||||
$this->assign('endDate', CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership',
|
||||
$this->_id, 'end_date'
|
||||
)
|
||||
));
|
||||
$this->assign('membershipStatus',
|
||||
CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus',
|
||||
CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership',
|
||||
$this->_id, 'status_id'
|
||||
),
|
||||
'name'
|
||||
)
|
||||
);
|
||||
|
||||
if ($this->_mode) {
|
||||
$membershipFee = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee');
|
||||
if (!$membershipFee) {
|
||||
$statusMsg = ts('Membership Renewal using a credit card requires a Membership fee. Since there is no fee associated with the selected membership type, you can use the normal renewal mode.');
|
||||
CRM_Core_Session::setStatus($statusMsg, '', 'info');
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership',
|
||||
"reset=1&action=renew&cid={$this->_contactID}&id={$this->_id}&context=membership"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// when custom data is included in this page
|
||||
if (!empty($_POST['hidden_custom'])) {
|
||||
CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_memType, 1, 'Membership', $this->_id);
|
||||
CRM_Custom_Form_CustomData::buildQuickForm($this);
|
||||
CRM_Custom_Form_CustomData::setDefaultValues($this);
|
||||
}
|
||||
|
||||
CRM_Utils_System::setTitle(ts('Renew Membership'));
|
||||
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
* @return array
|
||||
* Default values.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
|
||||
$defaults = parent::setDefaultValues();
|
||||
|
||||
// set renewal_date and receive_date to today in correct input format (setDateDefaults uses today if no value passed)
|
||||
list($now, $currentTime) = CRM_Utils_Date::setDateDefaults();
|
||||
$defaults['renewal_date'] = $now;
|
||||
$defaults['receive_date'] = $now;
|
||||
$defaults['receive_date_time'] = $currentTime;
|
||||
|
||||
if ($defaults['id']) {
|
||||
$defaults['record_contribution'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment',
|
||||
$defaults['id'],
|
||||
'contribution_id',
|
||||
'membership_id'
|
||||
);
|
||||
}
|
||||
|
||||
$defaults['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'financial_type_id');
|
||||
|
||||
//CRM-13420
|
||||
if (empty($defaults['payment_instrument_id'])) {
|
||||
$defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
|
||||
}
|
||||
|
||||
$defaults['total_amount'] = CRM_Utils_Money::format(CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
|
||||
$this->_memType,
|
||||
'minimum_fee'
|
||||
), NULL, '%a');
|
||||
|
||||
$defaults['record_contribution'] = 0;
|
||||
$defaults['num_terms'] = 1;
|
||||
$defaults['send_receipt'] = 0;
|
||||
|
||||
//set Soft Credit Type to Gift by default
|
||||
$scTypes = CRM_Core_OptionGroup::values("soft_credit_type");
|
||||
$defaults['soft_credit_type_id'] = CRM_Utils_Array::value(ts('Gift'), array_flip($scTypes));
|
||||
|
||||
$renewalDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('renewal_date', $defaults),
|
||||
NULL, NULL, 'Y-m-d'
|
||||
);
|
||||
$this->assign('renewalDate', $renewalDate);
|
||||
$this->assign('member_is_test', CRM_Utils_Array::value('member_is_test', $defaults));
|
||||
|
||||
if ($this->_mode) {
|
||||
$defaults = $this->getBillingDefaults($defaults);
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
|
||||
parent::buildQuickForm();
|
||||
|
||||
$defaults = parent::setDefaultValues();
|
||||
$this->assign('customDataType', 'Membership');
|
||||
$this->assign('customDataSubType', $this->_memType);
|
||||
$this->assign('entityID', $this->_id);
|
||||
$selOrgMemType[0][0] = $selMemTypeOrg[0] = ts('- select -');
|
||||
|
||||
$allMembershipInfo = array();
|
||||
|
||||
//CRM-16950
|
||||
$taxRates = CRM_Core_PseudoConstant::getTaxRates();
|
||||
$taxRate = CRM_Utils_Array::value($this->allMembershipTypeDetails[$defaults['membership_type_id']]['financial_type_id'], $taxRates);
|
||||
|
||||
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
|
||||
|
||||
// auto renew options if enabled for the membership
|
||||
$options = CRM_Core_SelectValues::memberAutoRenew();
|
||||
|
||||
foreach ($this->allMembershipTypeDetails as $key => $values) {
|
||||
if (!empty($values['is_active'])) {
|
||||
if ($this->_mode && empty($values['minimum_fee'])) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
$memberOfContactId = CRM_Utils_Array::value('member_of_contact_id', $values);
|
||||
if (empty($selMemTypeOrg[$memberOfContactId])) {
|
||||
$selMemTypeOrg[$memberOfContactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
|
||||
$memberOfContactId,
|
||||
'display_name',
|
||||
'id'
|
||||
);
|
||||
|
||||
$selOrgMemType[$memberOfContactId][0] = ts('- select -');
|
||||
}
|
||||
if (empty($selOrgMemType[$memberOfContactId][$key])) {
|
||||
$selOrgMemType[$memberOfContactId][$key] = CRM_Utils_Array::value('name', $values);
|
||||
}
|
||||
}
|
||||
|
||||
//CRM-16950
|
||||
$taxAmount = NULL;
|
||||
$totalAmount = CRM_Utils_Array::value('minimum_fee', $values);
|
||||
if (CRM_Utils_Array::value($values['financial_type_id'], $taxRates)) {
|
||||
$taxAmount = ($taxRate / 100) * CRM_Utils_Array::value('minimum_fee', $values);
|
||||
$totalAmount = $totalAmount + $taxAmount;
|
||||
}
|
||||
|
||||
// build membership info array, which is used to set the payment information block when
|
||||
// membership type is selected.
|
||||
$allMembershipInfo[$key] = array(
|
||||
'financial_type_id' => CRM_Utils_Array::value('financial_type_id', $values),
|
||||
'total_amount' => CRM_Utils_Money::format($totalAmount, NULL, '%a'),
|
||||
'total_amount_numeric' => $totalAmount,
|
||||
'tax_message' => $taxAmount ? ts("Includes %1 amount of %2", array(1 => CRM_Utils_Array::value('tax_term', $invoiceSettings), 2 => CRM_Utils_Money::format($taxAmount))) : $taxAmount,
|
||||
);
|
||||
|
||||
if (!empty($values['auto_renew'])) {
|
||||
$allMembershipInfo[$key]['auto_renew'] = $options[$values['auto_renew']];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('allMembershipInfo', json_encode($allMembershipInfo));
|
||||
|
||||
if ($this->_memType) {
|
||||
$this->assign('orgName', $selMemTypeOrg[$this->allMembershipTypeDetails[$this->_memType]['member_of_contact_id']]);
|
||||
$this->assign('memType', $this->allMembershipTypeDetails[$this->_memType]['name']);
|
||||
}
|
||||
|
||||
// force select of 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;
|
||||
}
|
||||
|
||||
$js = array('onChange' => "setPaymentBlock(); CRM.buildCustomData('Membership', this.value);");
|
||||
$sel = &$this->addElement('hierselect',
|
||||
'membership_type_id',
|
||||
ts('Renewal Membership Organization and Type'), $js
|
||||
);
|
||||
|
||||
$sel->setOptions(array($selMemTypeOrg, $selOrgMemType));
|
||||
$elements = array();
|
||||
if ($sel) {
|
||||
$elements[] = $sel;
|
||||
}
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
$this->addDate('renewal_date', ts('Date Renewal Entered'), FALSE, array('formatType' => 'activityDate'));
|
||||
|
||||
$this->add('select', 'financial_type_id', ts('Financial Type'),
|
||||
array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType()
|
||||
);
|
||||
|
||||
$this->add('text', 'num_terms', ts('Extend Membership by'), array('onchange' => "setPaymentBlock();"), TRUE);
|
||||
$this->addRule('num_terms', ts('Please enter a whole number for how many periods to renew.'), 'integer');
|
||||
|
||||
if (CRM_Core_Permission::access('CiviContribute') && !$this->_mode) {
|
||||
$this->addElement('checkbox', 'record_contribution', ts('Record Renewal Payment?'), NULL, array('onclick' => "checkPayment();"));
|
||||
|
||||
$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' => 'activityDateTime'));
|
||||
|
||||
$this->add('select', 'payment_instrument_id', ts('Payment Method'),
|
||||
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')
|
||||
);
|
||||
|
||||
$this->add('select', 'contribution_status_id', ts('Payment Status'),
|
||||
CRM_Contribute_BAO_Contribution_Utils::getContributionStatuses('membership')
|
||||
);
|
||||
|
||||
$this->add('text', 'check_number', ts('Check Number'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number')
|
||||
);
|
||||
}
|
||||
else {
|
||||
$this->add('text', 'total_amount', ts('Amount'));
|
||||
$this->addRule('total_amount', ts('Please enter a valid amount.'), 'money');
|
||||
}
|
||||
$this->addElement('checkbox', 'send_receipt', ts('Send Confirmation and Receipt?'), NULL,
|
||||
array('onclick' => "showHideByValue( 'send_receipt', '', 'notice', 'table-row', 'radio', false ); showHideByValue( 'send_receipt', '', 'fromEmail', 'table-row', 'radio',false);")
|
||||
);
|
||||
|
||||
$this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
|
||||
|
||||
$this->add('textarea', 'receipt_text_renewal', ts('Renewal Message'));
|
||||
|
||||
// Retrieve the name and email of the contact - this will be the TO for receipt email
|
||||
list($this->_contributorDisplayName,
|
||||
$this->_contributorEmail
|
||||
) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
|
||||
$this->assign('email', $this->_contributorEmail);
|
||||
// The member form uses emailExists. Assigning both while we transition / synchronise.
|
||||
$this->assign('emailExists', $this->_contributorEmail);
|
||||
|
||||
$mailingInfo = Civi::settings()->get('mailing_backend');
|
||||
$this->assign('outBound_option', $mailingInfo['outBound_option']);
|
||||
|
||||
if (CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'contribution_recur_id')) {
|
||||
if (CRM_Member_BAO_Membership::isCancelSubscriptionSupported($this->_id)) {
|
||||
$this->assign('cancelAutoRenew',
|
||||
CRM_Utils_System::url('civicrm/contribute/unsubscribe', "reset=1&mid={$this->_id}")
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->addFormRule(array('CRM_Member_Form_MembershipRenewal', 'formRule'), $this);
|
||||
$this->addElement('checkbox', 'is_different_contribution_contact', ts('Record Payment from a Different Contact?'));
|
||||
$this->addSelect('soft_credit_type_id', array('entity' => 'contribution_soft'));
|
||||
$this->addEntityRef('soft_credit_contact_id', ts('Payment From'), array('create' => TRUE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation.
|
||||
*
|
||||
* @param array $params
|
||||
* (ref.) an assoc array of name/value pairs.
|
||||
*
|
||||
* @return bool|array
|
||||
* mixed true or array of errors
|
||||
*/
|
||||
public static function formRule($params, $files, $self) {
|
||||
$errors = array();
|
||||
if ($params['membership_type_id'][0] == 0) {
|
||||
$errors['membership_type_id'] = ts('Oops. It looks like you are trying to change the membership type while renewing the membership. Please click the "change membership type" link, and select a Membership Organization.');
|
||||
}
|
||||
if ($params['membership_type_id'][1] == 0) {
|
||||
$errors['membership_type_id'] = ts('Oops. It looks like you are trying to change the membership type while renewing the membership. Please click the "change membership type" link and select a Membership Type from the list.');
|
||||
}
|
||||
|
||||
// CRM-20571
|
||||
// Get the Join Date from Membership info as it is not available in the Renewal form
|
||||
$joinDate = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $self->_id, 'join_date');
|
||||
|
||||
// CRM-20571: Check if the renewal date is not before Join Date, if it is then add to 'errors' array
|
||||
// The fields in Renewal form come into this routine in $params array. 'renewal_date' is in the form
|
||||
// We process both the dates before comparison using CRM utils so that they are in same date format
|
||||
if (isset($params['renewal_date'])) {
|
||||
if (CRM_Utils_Date::processDate($params['renewal_date']) < CRM_Utils_Date::processDate($joinDate)) {
|
||||
$errors['renewal_date'] = ts('Renewal date must be the same or later than Member since (Join Date).');
|
||||
}
|
||||
}
|
||||
|
||||
//total amount condition arise when membership type having no
|
||||
//minimum fee
|
||||
if (isset($params['record_contribution'])) {
|
||||
if (!$params['financial_type_id']) {
|
||||
$errors['financial_type_id'] = ts('Please select a Financial Type.');
|
||||
}
|
||||
if (!$params['total_amount']) {
|
||||
$errors['total_amount'] = ts('Please enter a Contribution Amount.');
|
||||
}
|
||||
if (empty($params['payment_instrument_id'])) {
|
||||
$errors['payment_instrument_id'] = ts('Payment Method is a required field.');
|
||||
}
|
||||
}
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the renewal form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// get the submitted form values.
|
||||
$this->_params = $this->controller->exportValues($this->_name);
|
||||
$this->assignBillingName();
|
||||
|
||||
try {
|
||||
$this->submit();
|
||||
$statusMsg = ts('%1 membership for %2 has been renewed.', array(1 => $this->membershipTypeName, 2 => $this->_memberDisplayName));
|
||||
|
||||
if ($this->endDate) {
|
||||
$statusMsg .= ' ' . ts('The new membership End Date is %1.', array(
|
||||
1 => CRM_Utils_Date::customFormat(substr($this->endDate, 0, 8)),
|
||||
));
|
||||
}
|
||||
|
||||
if ($this->isMailSent) {
|
||||
$statusMsg .= ' ' . ts('A renewal confirmation and receipt has been sent to %1.', array(
|
||||
1 => $this->_contributorEmail,
|
||||
));
|
||||
return $statusMsg;
|
||||
}
|
||||
return $statusMsg;
|
||||
}
|
||||
catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
|
||||
CRM_Core_Error::displaySessionError($e->getMessage());
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership',
|
||||
"reset=1&action=renew&cid={$this->_contactID}&id={$this->_id}&context=membership&mode={$this->_mode}"
|
||||
));
|
||||
}
|
||||
|
||||
CRM_Core_Session::setStatus($statusMsg, ts('Complete'), 'success');
|
||||
}
|
||||
|
||||
/**
|
||||
* Process form submission.
|
||||
*
|
||||
* This function is also accessed by a unit test.
|
||||
*/
|
||||
protected function submit() {
|
||||
$this->storeContactFields($this->_params);
|
||||
$this->beginPostProcess();
|
||||
$now = CRM_Utils_Date::getToday(NULL, 'YmdHis');
|
||||
$this->convertDateFieldsToMySQL($this->_params);
|
||||
$this->assign('receive_date', $this->_params['receive_date']);
|
||||
$this->processBillingAddress();
|
||||
list($userName) = CRM_Contact_BAO_Contact_Location::getEmailDetails(CRM_Core_Session::singleton()->get('userID'));
|
||||
$this->_params['total_amount'] = CRM_Utils_Array::value('total_amount', $this->_params,
|
||||
CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee')
|
||||
);
|
||||
$this->_membershipId = $this->_id;
|
||||
$customFieldsFormatted = CRM_Core_BAO_CustomField::postProcess($this->_params,
|
||||
$this->_id,
|
||||
'Membership'
|
||||
);
|
||||
if (empty($this->_params['financial_type_id'])) {
|
||||
$this->_params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'financial_type_id');
|
||||
}
|
||||
$contributionRecurID = NULL;
|
||||
$this->assign('membershipID', $this->_id);
|
||||
$this->assign('contactID', $this->_contactID);
|
||||
$this->assign('module', 'Membership');
|
||||
$this->assign('receiptType', 'membership renewal');
|
||||
$this->_params['currencyID'] = CRM_Core_Config::singleton()->defaultCurrency;
|
||||
$this->_params['invoice_id'] = $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
|
||||
|
||||
if (!empty($this->_params['send_receipt'])) {
|
||||
$this->_params['receipt_date'] = $now;
|
||||
$this->assign('receipt_date', CRM_Utils_Date::mysqlToIso($this->_params['receipt_date']));
|
||||
}
|
||||
else {
|
||||
$this->_params['receipt_date'] = NULL;
|
||||
}
|
||||
|
||||
if ($this->_mode) {
|
||||
$this->_params['register_date'] = $now;
|
||||
$this->_params['description'] = ts("Contribution submitted by a staff person using member's credit card for renewal");
|
||||
$this->_params['amount'] = $this->_params['total_amount'];
|
||||
$this->_params['payment_instrument_id'] = $this->_paymentProcessor['payment_instrument_id'];
|
||||
|
||||
// at this point we've created a contact and stored its address etc
|
||||
// all the payment processors expect the name and address to be in the passed params
|
||||
// so we copy stuff over to first_name etc.
|
||||
$paymentParams = $this->_params;
|
||||
if (!empty($this->_params['send_receipt'])) {
|
||||
$paymentParams['email'] = $this->_contributorEmail;
|
||||
}
|
||||
$paymentParams['is_email_receipt'] = !empty($this->_params['send_receipt']);
|
||||
|
||||
$paymentParams['contactID'] = $this->_contributorContactID;
|
||||
|
||||
CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);
|
||||
|
||||
$payment = $this->_paymentProcessor['object'];
|
||||
|
||||
if (!empty($this->_params['auto_renew'])) {
|
||||
$contributionRecurParams = $this->processRecurringContribution($paymentParams);
|
||||
$contributionRecurID = $contributionRecurParams['contributionRecurID'];
|
||||
$paymentParams = array_merge($paymentParams, $contributionRecurParams);
|
||||
}
|
||||
|
||||
$result = $payment->doPayment($paymentParams);
|
||||
$this->_params = array_merge($this->_params, $result);
|
||||
|
||||
$this->_params['contribution_status_id'] = $result['payment_status_id'];
|
||||
$this->_params['trxn_id'] = $result['trxn_id'];
|
||||
$this->_params['is_test'] = ($this->_mode == 'live') ? 0 : 1;
|
||||
$this->set('params', $this->_params);
|
||||
$this->assign('trxn_id', $result['trxn_id']);
|
||||
}
|
||||
|
||||
$renewalDate = !empty($this->_params['renewal_date']) ? $renewalDate = CRM_Utils_Date::processDate($this->_params['renewal_date']) : NULL;
|
||||
|
||||
// check for test membership.
|
||||
$isTestMembership = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_membershipId, 'is_test');
|
||||
|
||||
// chk for renewal for multiple terms CRM-8750
|
||||
$numRenewTerms = 1;
|
||||
if (is_numeric(CRM_Utils_Array::value('num_terms', $this->_params))) {
|
||||
$numRenewTerms = $this->_params['num_terms'];
|
||||
}
|
||||
|
||||
//if contribution status is pending then set pay later
|
||||
$this->_params['is_pay_later'] = FALSE;
|
||||
if ($this->_params['contribution_status_id'] == array_search('Pending', CRM_Contribute_PseudoConstant::contributionStatus())) {
|
||||
$this->_params['is_pay_later'] = 1;
|
||||
}
|
||||
|
||||
// These variable sets prior to renewMembership may not be required for this form. They were in
|
||||
// a function this form shared with other forms.
|
||||
$membershipSource = NULL;
|
||||
if (!empty($this->_params['membership_source'])) {
|
||||
$membershipSource = $this->_params['membership_source'];
|
||||
}
|
||||
|
||||
$isPending = ($this->_params['contribution_status_id'] == 2) ? TRUE : FALSE;
|
||||
|
||||
list($renewMembership) = CRM_Member_BAO_Membership::processMembership(
|
||||
$this->_contactID, $this->_params['membership_type_id'][1], $isTestMembership,
|
||||
$renewalDate, NULL, $customFieldsFormatted, $numRenewTerms, $this->_membershipId,
|
||||
$isPending,
|
||||
$contributionRecurID, $membershipSource, $this->_params['is_pay_later'], CRM_Utils_Array::value('campaign_id',
|
||||
$this->_params)
|
||||
);
|
||||
|
||||
$this->endDate = CRM_Utils_Date::processDate($renewMembership->end_date);
|
||||
|
||||
$this->membershipTypeName = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id,
|
||||
'name');
|
||||
|
||||
if (!empty($this->_params['record_contribution']) || $this->_mode) {
|
||||
// set the source
|
||||
$this->_params['contribution_source'] = "{$this->membershipTypeName} Membership: Offline membership renewal (by {$userName})";
|
||||
|
||||
//create line items
|
||||
$lineItem = array();
|
||||
$this->_params = $this->setPriceSetParameters($this->_params);
|
||||
CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'],
|
||||
$this->_params, $lineItem[$this->_priceSetId], NULL, $this->_priceSetId
|
||||
);
|
||||
//CRM-11529 for quick config backoffice transactions
|
||||
//when financial_type_id is passed in form, update the
|
||||
//line items with the financial type selected in form
|
||||
if ($submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $this->_params)) {
|
||||
foreach ($lineItem[$this->_priceSetId] as &$li) {
|
||||
$li['financial_type_id'] = $submittedFinancialType;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($lineItem)) {
|
||||
$this->_params['lineItems'] = $lineItem;
|
||||
$this->_params['processPriceSet'] = TRUE;
|
||||
}
|
||||
|
||||
//assign contribution contact id to the field expected by recordMembershipContribution
|
||||
if ($this->_contributorContactID != $this->_contactID) {
|
||||
$this->_params['contribution_contact_id'] = $this->_contributorContactID;
|
||||
if (!empty($this->_params['soft_credit_type_id'])) {
|
||||
$this->_params['soft_credit'] = array(
|
||||
'soft_credit_type_id' => $this->_params['soft_credit_type_id'],
|
||||
'contact_id' => $this->_contactID,
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->_params['contact_id'] = $this->_contactID;
|
||||
//recordMembershipContribution receives params as a reference & adds one variable. This is
|
||||
// not a great pattern & ideally it would not receive as a reference. We assign our params as a
|
||||
// temporary variable to avoid e-notice & to make it clear to future refactorer that
|
||||
// this function is NOT reliant on that var being set
|
||||
$temporaryParams = array_merge($this->_params, array(
|
||||
'membership_id' => $renewMembership->id,
|
||||
'contribution_recur_id' => $contributionRecurID,
|
||||
));
|
||||
//Remove `tax_amount` if it is not calculated.
|
||||
if (CRM_Utils_Array::value('tax_amount', $temporaryParams) === 0) {
|
||||
unset($temporaryParams['tax_amount']);
|
||||
}
|
||||
CRM_Member_BAO_Membership::recordMembershipContribution($temporaryParams);
|
||||
}
|
||||
|
||||
if (!empty($this->_params['send_receipt'])) {
|
||||
|
||||
$receiptFrom = $this->_params['from_email_address'];
|
||||
|
||||
if (!empty($this->_params['payment_instrument_id'])) {
|
||||
$paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
|
||||
$this->_params['paidBy'] = $paymentInstrument[$this->_params['payment_instrument_id']];
|
||||
}
|
||||
//get the group Tree
|
||||
$this->_groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', NULL, $this->_id, FALSE, $this->_memType);
|
||||
|
||||
// retrieve custom data
|
||||
$customFields = $customValues = $fo = array();
|
||||
foreach ($this->_groupTree as $groupID => $group) {
|
||||
if ($groupID == 'info') {
|
||||
continue;
|
||||
}
|
||||
foreach ($group['fields'] as $k => $field) {
|
||||
$field['title'] = $field['label'];
|
||||
$customFields["custom_{$k}"] = $field;
|
||||
}
|
||||
}
|
||||
$members = array(array('member_id', '=', $this->_membershipId, 0, 0));
|
||||
// check whether its a test drive
|
||||
if ($this->_mode == 'test') {
|
||||
$members[] = array('member_test', '=', 1, 0, 0);
|
||||
}
|
||||
CRM_Core_BAO_UFGroup::getValues($this->_contactID, $customFields, $customValues, FALSE, $members);
|
||||
|
||||
$this->assign_by_ref('formValues', $this->_params);
|
||||
if (!empty($this->_params['contribution_id'])) {
|
||||
$this->assign('contributionID', $this->_params['contribution_id']);
|
||||
}
|
||||
|
||||
$this->assign('membership_name', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
|
||||
$renewMembership->membership_type_id
|
||||
));
|
||||
$this->assign('customValues', $customValues);
|
||||
$this->assign('mem_start_date', CRM_Utils_Date::customFormat($renewMembership->start_date));
|
||||
$this->assign('mem_end_date', CRM_Utils_Date::customFormat($renewMembership->end_date));
|
||||
if ($this->_mode) {
|
||||
$this->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters(
|
||||
$this->_params,
|
||||
$this->_bltID
|
||||
));
|
||||
$this->assign('contributeMode', 'direct');
|
||||
$this->assign('isAmountzero', 0);
|
||||
$this->assign('is_pay_later', 0);
|
||||
$this->assign('isPrimary', 1);
|
||||
$this->assign('receipt_text_renewal', $this->_params['receipt_text']);
|
||||
if ($this->_mode == 'test') {
|
||||
$this->assign('action', '1024');
|
||||
}
|
||||
}
|
||||
|
||||
list($this->isMailSent) = CRM_Core_BAO_MessageTemplate::sendTemplate(
|
||||
array(
|
||||
'groupName' => 'msg_tpl_workflow_membership',
|
||||
'valueName' => 'membership_offline_receipt',
|
||||
'contactId' => $this->_receiptContactId,
|
||||
'from' => $receiptFrom,
|
||||
'toName' => $this->_contributorDisplayName,
|
||||
'toEmail' => $this->_contributorEmail,
|
||||
'isTest' => $this->_mode == 'test',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
153
sites/all/modules/civicrm/CRM/Member/Form/MembershipStatus.php
Normal file
153
sites/all/modules/civicrm/CRM/Member/Form/MembershipStatus.php
Normal file
|
@ -0,0 +1,153 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for Membership Type
|
||||
*
|
||||
*/
|
||||
class CRM_Member_Form_MembershipStatus extends CRM_Member_Form_MembershipConfig {
|
||||
|
||||
/**
|
||||
* Set default values for the form. MobileProvider that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = parent::setDefaultValues();
|
||||
|
||||
//finding default weight to be put
|
||||
if (empty($defaults['weight'])) {
|
||||
$defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Member_DAO_MembershipStatus');
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
if ($this->_id) {
|
||||
$name = $this->add('text', 'name', ts('Name'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'name')
|
||||
);
|
||||
$name->freeze();
|
||||
$this->assign('id', $this->_id);
|
||||
}
|
||||
$this->add('text', 'label', ts('Label'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'label'), TRUE
|
||||
);
|
||||
$this->addRule('label', ts('A membership status with this label already exists. Please select another label.'),
|
||||
'objectExists', array('CRM_Member_DAO_MembershipStatus', $this->_id, 'name')
|
||||
);
|
||||
|
||||
$this->add('select', 'start_event', ts('Start Event'), CRM_Core_SelectValues::eventDate(), TRUE);
|
||||
$this->add('select', 'start_event_adjust_unit', ts('Start Event Adjustment'), array('' => ts('- select -')) + CRM_Core_SelectValues::unitList());
|
||||
$this->add('text', 'start_event_adjust_interval', ts('Start Event Adjust Interval'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'start_event_adjust_interval')
|
||||
);
|
||||
$this->add('select', 'end_event', ts('End Event'), array('' => ts('- select -')) + CRM_Core_SelectValues::eventDate());
|
||||
$this->add('select', 'end_event_adjust_unit', ts('End Event Adjustment'), array('' => ts('- select -')) + CRM_Core_SelectValues::unitList());
|
||||
$this->add('text', 'end_event_adjust_interval', ts('End Event Adjust Interval'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'end_event_adjust_interval')
|
||||
);
|
||||
$this->add('checkbox', 'is_current_member', ts('Current Membership?'));
|
||||
$this->add('checkbox', 'is_admin', ts('Administrator Only?'));
|
||||
|
||||
$this->add('text', 'weight', ts('Order'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'weight')
|
||||
);
|
||||
$this->add('checkbox', 'is_default', ts('Default?'));
|
||||
$this->add('checkbox', 'is_active', ts('Enabled?'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
try {
|
||||
CRM_Member_BAO_MembershipStatus::del($this->_id);
|
||||
}
|
||||
catch (CRM_Core_Exception $e) {
|
||||
CRM_Core_Error::statusBounce($e->getMessage(), NULL, ts('Delete Failed'));
|
||||
}
|
||||
CRM_Core_Session::setStatus(ts('Selected membership status has been deleted.'), ts('Record Deleted'), 'success');
|
||||
}
|
||||
else {
|
||||
$params = $ids = array();
|
||||
// store the submitted values in an array
|
||||
$params = $this->exportValues();
|
||||
$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);
|
||||
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$ids['membershipStatus'] = $this->_id;
|
||||
}
|
||||
$oldWeight = NULL;
|
||||
if ($this->_id) {
|
||||
$oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $this->_id, 'weight', 'id');
|
||||
}
|
||||
$params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipStatus', $oldWeight, $params['weight']);
|
||||
|
||||
// only for add mode, set label to name.
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
$params['name'] = $params['label'];
|
||||
}
|
||||
|
||||
$membershipStatus = CRM_Member_BAO_MembershipStatus::add($params, $ids);
|
||||
CRM_Core_Session::setStatus(ts('The membership status \'%1\' has been saved.',
|
||||
array(1 => $membershipStatus->label)
|
||||
), ts('Saved'), 'success');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
443
sites/all/modules/civicrm/CRM/Member/Form/MembershipType.php
Normal file
443
sites/all/modules/civicrm/CRM/Member/Form/MembershipType.php
Normal file
|
@ -0,0 +1,443 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for Membership Type
|
||||
*
|
||||
*/
|
||||
class CRM_Member_Form_MembershipType extends CRM_Member_Form_MembershipConfig {
|
||||
|
||||
/**
|
||||
* Max number of contacts we will display for membership-organisation
|
||||
*/
|
||||
const MAX_CONTACTS = 50;
|
||||
|
||||
public function preProcess() {
|
||||
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
|
||||
$this->_BAOName = 'CRM_Member_BAO_MembershipType';
|
||||
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
|
||||
$this->assign('action', $this->_action);
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$url = CRM_Utils_System::url('civicrm/admin/member/membershipType', 'reset=1');
|
||||
$session->pushUserContext($url);
|
||||
|
||||
$this->setPageTitle(ts('Membership Type'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. MobileProvider that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = parent::setDefaultValues();
|
||||
|
||||
//finding default weight to be put
|
||||
if (!isset($defaults['weight']) || (!$defaults['weight'])) {
|
||||
$defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Member_DAO_MembershipType');
|
||||
}
|
||||
//setting default relationshipType
|
||||
if (isset($defaults['relationship_type_id'])) {
|
||||
//$defaults['relationship_type_id'] = $defaults['relationship_type_id'].'_a_b';
|
||||
// Set values for relation type select box
|
||||
$relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['relationship_type_id']);
|
||||
$relDirections = explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['relationship_direction']);
|
||||
$defaults['relationship_type_id'] = array();
|
||||
foreach ($relTypeIds as $key => $value) {
|
||||
$defaults['relationship_type_id'][] = $value . '_' . $relDirections[$key];
|
||||
}
|
||||
}
|
||||
|
||||
//setting default fixed_period_start_day & fixed_period_rollover_day
|
||||
$periods = array('fixed_period_start_day', 'fixed_period_rollover_day');
|
||||
foreach ($periods as $per) {
|
||||
if (isset($defaults[$per])) {
|
||||
$date = $defaults[$per];
|
||||
|
||||
$defaults[$per] = array();
|
||||
if ($date > 31) {
|
||||
$date = ($date < 999) ? '0' . $date : $date;
|
||||
$defaults[$per]['M'] = substr($date, 0, 2);
|
||||
$defaults[$per]['d'] = substr($date, 2, 3);
|
||||
}
|
||||
else {
|
||||
//special case when only day is rollover and duration is month
|
||||
$defaults['month_fixed_period_rollover_day']['d'] = $date;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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->addSelect('duration_unit', array(), TRUE);
|
||||
|
||||
//period type
|
||||
$this->addSelect('period_type', array(), TRUE);
|
||||
|
||||
$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 = CRM_Core_SelectValues::memberAutoRenew();
|
||||
}
|
||||
|
||||
$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_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $this->_action), TRUE, array('class' => 'crm-select2')
|
||||
);
|
||||
|
||||
$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'),
|
||||
$relTypeInd, FALSE, array('class' => 'crm-select2 huge', 'multiple' => 1));
|
||||
|
||||
$this->addSelect('visibility', array('placeholder' => NULL, 'option_url' => NULL));
|
||||
|
||||
$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) {
|
||||
$result = civicrm_api3("Membership", "get", array("membership_type_id" => $this->_id, "options" => array("limit" => 1)));
|
||||
$membershipRecords = ($result["count"] > 0);
|
||||
if ($membershipRecords) {
|
||||
$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);
|
||||
|
||||
if (CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled')) {
|
||||
$deferredFinancialType = CRM_Financial_BAO_FinancialAccount::getDeferredFinancialType();
|
||||
$this->assign('deferredFinancialType', array_keys($deferredFinancialType));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation.
|
||||
*
|
||||
* @param array $params
|
||||
* (ref.) an assoc array of name/value pairs.
|
||||
*
|
||||
* @return bool|array
|
||||
* mixed true or array of errors
|
||||
*/
|
||||
public static function formRule($params) {
|
||||
$errors = array();
|
||||
|
||||
if (!$params['name']) {
|
||||
$errors['name'] = ts('Please enter a membership type name.');
|
||||
}
|
||||
|
||||
if (($params['minimum_fee'] > 0) && !$params['financial_type_id']) {
|
||||
$errors['financial_type_id'] = ts('Please enter the financial Type.');
|
||||
}
|
||||
|
||||
if (empty($params['duration_interval']) and $params['duration_unit'] != 'lifetime') {
|
||||
$errors['duration_interval'] = ts('Please enter a duration interval.');
|
||||
}
|
||||
|
||||
if (in_array(CRM_Utils_Array::value('auto_renew', $params), array(
|
||||
1,
|
||||
2,
|
||||
))) {
|
||||
if (($params['duration_interval'] > 1 && $params['duration_unit'] == 'year') ||
|
||||
($params['duration_interval'] > 12 && $params['duration_unit'] == 'month')
|
||||
) {
|
||||
$errors['duration_unit'] = ts('Automatic renewals are not supported by the currently available payment processors when the membership duration is greater than 1 year / 12 months.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($params['period_type'] == 'fixed' &&
|
||||
$params['duration_unit'] == 'day'
|
||||
) {
|
||||
$errors['period_type'] = ts('Period type should be Rolling when duration unit is Day');
|
||||
}
|
||||
|
||||
if (($params['period_type'] == 'fixed') &&
|
||||
($params['duration_unit'] == 'year')
|
||||
) {
|
||||
$periods = array('fixed_period_start_day', 'fixed_period_rollover_day');
|
||||
foreach ($periods as $period) {
|
||||
$month = $params[$period]['M'];
|
||||
$date = $params[$period]['d'];
|
||||
if (!$month || !$date) {
|
||||
switch ($period) {
|
||||
case 'fixed_period_start_day':
|
||||
$errors[$period] = ts('Please enter a valid fixed period start day');
|
||||
break;
|
||||
|
||||
case 'fixed_period_rollover_day':
|
||||
$errors[$period] = ts('Please enter a valid fixed period rollover day');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($params['fixed_period_start_day'] && !empty($params['fixed_period_start_day'])) {
|
||||
$params['fixed_period_start_day']['Y'] = date('Y');
|
||||
if (!CRM_Utils_Rule::qfDate($params['fixed_period_start_day'])) {
|
||||
$errors['fixed_period_start_day'] = ts('Please enter valid Fixed Period Start Day');
|
||||
}
|
||||
}
|
||||
|
||||
if ($params['fixed_period_rollover_day'] && !empty($params['fixed_period_rollover_day'])) {
|
||||
$params['fixed_period_rollover_day']['Y'] = date('Y');
|
||||
if (!CRM_Utils_Rule::qfDate($params['fixed_period_rollover_day'])) {
|
||||
$errors['fixed_period_rollover_day'] = ts('Please enter valid Fixed Period Rollover Day');
|
||||
}
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
try {
|
||||
CRM_Member_BAO_MembershipType::del($this->_id);
|
||||
}
|
||||
catch (CRM_Core_Exception $e) {
|
||||
CRM_Core_Error::statusBounce($e->getMessage(), NULL, ts('Membership Type Not Deleted'));
|
||||
}
|
||||
CRM_Core_Session::setStatus(ts('Selected membership type has been deleted.'), ts('Record Deleted'), 'success');
|
||||
}
|
||||
else {
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
$submitted = $this->controller->exportValues($this->_name);
|
||||
|
||||
$fields = array(
|
||||
'name',
|
||||
'weight',
|
||||
'is_active',
|
||||
'member_of_contact_id',
|
||||
'visibility',
|
||||
'period_type',
|
||||
'minimum_fee',
|
||||
'description',
|
||||
'auto_renew',
|
||||
'duration_unit',
|
||||
'duration_interval',
|
||||
'financial_type_id',
|
||||
'fixed_period_start_day',
|
||||
'fixed_period_rollover_day',
|
||||
'month_fixed_period_rollover_day',
|
||||
'max_related',
|
||||
);
|
||||
|
||||
$params = $ids = array();
|
||||
foreach ($fields as $fld) {
|
||||
$params[$fld] = CRM_Utils_Array::value($fld, $submitted, 'NULL');
|
||||
}
|
||||
|
||||
//clean money.
|
||||
if ($params['minimum_fee']) {
|
||||
$params['minimum_fee'] = CRM_Utils_Rule::cleanMoney($params['minimum_fee']);
|
||||
}
|
||||
|
||||
$hasRelTypeVal = FALSE;
|
||||
if (!CRM_Utils_System::isNull($submitted['relationship_type_id'])) {
|
||||
// To insert relation ids and directions with value separator
|
||||
$relTypeDirs = $submitted['relationship_type_id'];
|
||||
$relIds = $relDirection = array();
|
||||
foreach ($relTypeDirs as $key => $value) {
|
||||
$relationId = explode('_', $value);
|
||||
if (count($relationId) == 3 &&
|
||||
is_numeric($relationId[0])
|
||||
) {
|
||||
$relIds[] = $relationId[0];
|
||||
$relDirection[] = $relationId[1] . '_' . $relationId[2];
|
||||
}
|
||||
}
|
||||
if (!empty($relIds)) {
|
||||
$hasRelTypeVal = TRUE;
|
||||
$params['relationship_type_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $relIds);
|
||||
$params['relationship_direction'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $relDirection);
|
||||
}
|
||||
}
|
||||
if (!$hasRelTypeVal) {
|
||||
$params['relationship_type_id'] = $params['relationship_direction'] = $params['max_related'] = 'NULL';
|
||||
}
|
||||
|
||||
if ($params['duration_unit'] == 'lifetime' &&
|
||||
empty($params['duration_interval'])
|
||||
) {
|
||||
$params['duration_interval'] = 1;
|
||||
}
|
||||
|
||||
$periods = array('fixed_period_start_day', 'fixed_period_rollover_day');
|
||||
foreach ($periods as $per) {
|
||||
if (!empty($params[$per]['M']) && !empty($params[$per]['d'])) {
|
||||
$mon = $params[$per]['M'];
|
||||
$dat = $params[$per]['d'];
|
||||
$mon = ($mon < 10) ? '0' . $mon : $mon;
|
||||
$dat = ($dat < 10) ? '0' . $dat : $dat;
|
||||
$params[$per] = $mon . $dat;
|
||||
}
|
||||
elseif ($per == 'fixed_period_rollover_day' && !empty($params['month_fixed_period_rollover_day'])) {
|
||||
$params['fixed_period_rollover_day'] = $params['month_fixed_period_rollover_day']['d'];
|
||||
unset($params['month_fixed_period_rollover_day']);
|
||||
}
|
||||
else {
|
||||
$params[$per] = 'NULL';
|
||||
}
|
||||
}
|
||||
$oldWeight = NULL;
|
||||
|
||||
if ($this->_id) {
|
||||
$oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
|
||||
$this->_id, 'weight', 'id'
|
||||
);
|
||||
}
|
||||
$params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipType',
|
||||
$oldWeight, $params['weight']
|
||||
);
|
||||
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$ids['membershipType'] = $this->_id;
|
||||
}
|
||||
|
||||
$membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
|
||||
|
||||
CRM_Core_Session::setStatus(ts('The membership type \'%1\' has been saved.',
|
||||
array(1 => $membershipType->name)
|
||||
), ts('Saved'), 'success');
|
||||
$session = CRM_Core_Session::singleton();
|
||||
if ($buttonName == $this->getButtonName('upload', 'new')) {
|
||||
$session->replaceUserContext(
|
||||
CRM_Utils_System::url('civicrm/admin/member/membershipType/add', 'action=add&reset=1')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $previousID
|
||||
* @param int $priceSetId
|
||||
* @param int $membershipTypeId
|
||||
* @param $optionsIds
|
||||
*/
|
||||
public static function checkPreviousPriceField($previousID, $priceSetId, $membershipTypeId, &$optionsIds) {
|
||||
if ($previousID) {
|
||||
$editedFieldParams = array(
|
||||
'price_set_id ' => $priceSetId,
|
||||
'name' => $previousID,
|
||||
);
|
||||
$editedResults = array();
|
||||
CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
|
||||
if (!empty($editedResults)) {
|
||||
$editedFieldParams = array(
|
||||
'price_field_id' => $editedResults['id'],
|
||||
'membership_type_id' => $membershipTypeId,
|
||||
);
|
||||
$editedResults = array();
|
||||
CRM_Price_BAO_PriceFieldValue::retrieve($editedFieldParams, $editedResults);
|
||||
$optionsIds['option_id'][1] = CRM_Utils_Array::value('id', $editedResults);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
420
sites/all/modules/civicrm/CRM/Member/Form/MembershipView.php
Normal file
420
sites/all/modules/civicrm/CRM/Member/Form/MembershipView.php
Normal file
|
@ -0,0 +1,420 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for Payment-Instrument
|
||||
*
|
||||
*/
|
||||
class CRM_Member_Form_MembershipView extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The action links that we need to display for the browse screen.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_links = NULL;
|
||||
|
||||
/**
|
||||
* Add context information at the end of a link.
|
||||
*
|
||||
* @return string
|
||||
* extra query parameters
|
||||
*/
|
||||
public function addContext() {
|
||||
$extra = '';
|
||||
foreach (array('context', 'selectedChild') as $arg) {
|
||||
if ($value = CRM_Utils_Request::retrieve($arg, 'String', $this)) {
|
||||
$extra .= "&{$arg}={$value}";
|
||||
}
|
||||
}
|
||||
return $extra;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action Links.
|
||||
*
|
||||
* @return array
|
||||
* (reference) of action links
|
||||
*/
|
||||
public function &links() {
|
||||
if (!(self::$_links)) {
|
||||
self::$_links = array(
|
||||
CRM_Core_Action::DELETE => array(
|
||||
'name' => ts('Delete'),
|
||||
'url' => 'civicrm/contact/view/membership',
|
||||
'qs' => 'action=view&id=%%id%%&cid=%%cid%%&relAction=delete&mid=%%mid%%&reset=1' . $this->addContext(),
|
||||
'title' => ts('Cancel Related Membership'),
|
||||
),
|
||||
CRM_Core_Action::ADD => array(
|
||||
'name' => ts('Create'),
|
||||
'url' => 'civicrm/contact/view/membership',
|
||||
'qs' => 'action=view&id=%%id%%&cid=%%cid%%&relAction=create&rid=%%rid%%&reset=1' . $this->addContext(),
|
||||
'title' => ts('Create Related Membership'),
|
||||
),
|
||||
);
|
||||
}
|
||||
return self::$_links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform create or delete action on related memberships.
|
||||
*
|
||||
* @param string $action
|
||||
* Create or delete.
|
||||
* @param array $owner
|
||||
* Primary membership info (membership_id, contact_id, membership_type ...).
|
||||
*/
|
||||
public function relAction($action, $owner) {
|
||||
switch ($action) {
|
||||
case 'delete':
|
||||
$id = CRM_Utils_Request::retrieve('mid', 'Positive', $this);
|
||||
$relatedContactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
|
||||
$relatedDisplayName = CRM_Contact_BAO_Contact::displayName($relatedContactId);
|
||||
CRM_Member_BAO_Membership::del($id);
|
||||
CRM_Core_Session::setStatus(ts('Related membership for %1 has been deleted.', array(1 => $relatedDisplayName)),
|
||||
ts('Membership Deleted'), 'success');
|
||||
break;
|
||||
|
||||
case 'create':
|
||||
$ids = array();
|
||||
$params = array(
|
||||
'contact_id' => CRM_Utils_Request::retrieve('rid', 'Positive', $this),
|
||||
'membership_type_id' => $owner['membership_type_id'],
|
||||
'owner_membership_id' => $owner['id'],
|
||||
'join_date' => CRM_Utils_Date::processDate($owner['join_date'], NULL, TRUE, 'Ymd'),
|
||||
'start_date' => CRM_Utils_Date::processDate($owner['start_date'], NULL, TRUE, 'Ymd'),
|
||||
'end_date' => CRM_Utils_Date::processDate($owner['end_date'], NULL, TRUE, 'Ymd'),
|
||||
'source' => ts('Manual Assignment of Related Membership'),
|
||||
'is_test' => $owner['is_test'],
|
||||
'campaign_id' => CRM_Utils_Array::value('campaign_id', $owner),
|
||||
'status_id' => $owner['status_id'],
|
||||
'skipStatusCal' => TRUE,
|
||||
'createActivity' => TRUE,
|
||||
);
|
||||
CRM_Member_BAO_Membership::create($params, $ids);
|
||||
$relatedDisplayName = CRM_Contact_BAO_Contact::displayName($params['contact_id']);
|
||||
CRM_Core_Session::setStatus(ts('Related membership for %1 has been created.', array(1 => $relatedDisplayName)),
|
||||
ts('Membership Added'), 'success');
|
||||
break;
|
||||
|
||||
default:
|
||||
CRM_Core_Error::fatal(ts("Invalid action specified in URL"));
|
||||
}
|
||||
|
||||
// Redirect back to membership view page for the owner, without the relAction parameters
|
||||
CRM_Utils_System::redirect(
|
||||
CRM_Utils_System::url(
|
||||
'civicrm/contact/view/membership',
|
||||
"action=view&reset=1&id={$owner['membership_id']}&cid={$owner['contact_id']}" . $this->addContext()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
|
||||
$values = array();
|
||||
$id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
|
||||
|
||||
// Make sure context is assigned to template for condition where we come here view civicrm/membership/view
|
||||
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
|
||||
$this->assign('context', $context);
|
||||
|
||||
if ($id) {
|
||||
$params = array('id' => $id);
|
||||
CRM_Member_BAO_Membership::retrieve($params, $values);
|
||||
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
|
||||
$finTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $values['membership_type_id'], 'financial_type_id');
|
||||
$finType = CRM_Contribute_PseudoConstant::financialType($finTypeId);
|
||||
if (!CRM_Core_Permission::check('view contributions of type ' . $finType)) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->assign('noACL', TRUE);
|
||||
}
|
||||
$membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
|
||||
|
||||
// Do the action on related Membership if needed
|
||||
$relAction = CRM_Utils_Request::retrieve('relAction', 'String', $this);
|
||||
if ($relAction) {
|
||||
$this->relAction($relAction, $values);
|
||||
}
|
||||
|
||||
// build associated contributions
|
||||
$this->assign('accessContribution', FALSE);
|
||||
if (CRM_Core_Permission::access('CiviContribute')) {
|
||||
$this->assign('accessContribution', TRUE);
|
||||
CRM_Member_Page_Tab::associatedContribution($values['contact_id'], $id);
|
||||
}
|
||||
|
||||
//Provide information about membership source when it is the result of a relationship (CRM-1901)
|
||||
$values['owner_membership_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership',
|
||||
$id,
|
||||
'owner_membership_id'
|
||||
);
|
||||
|
||||
if (isset($values['owner_membership_id'])) {
|
||||
$values['owner_contact_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership',
|
||||
$values['owner_membership_id'],
|
||||
'contact_id',
|
||||
'id'
|
||||
);
|
||||
|
||||
$values['owner_display_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
|
||||
$values['owner_contact_id'],
|
||||
'display_name',
|
||||
'id'
|
||||
);
|
||||
|
||||
$direction = strrev($membershipType['relationship_direction']);
|
||||
// To display relationship type in view membership page
|
||||
$relTypeIds = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ",", $membershipType['relationship_type_id']);
|
||||
$sql = "
|
||||
SELECT relationship_type_id,
|
||||
CASE
|
||||
WHEN contact_id_a = {$values['owner_contact_id']} AND contact_id_b = {$values['contact_id']} THEN 'b_a'
|
||||
WHEN contact_id_b = {$values['owner_contact_id']} AND contact_id_a = {$values['contact_id']} THEN 'a_b'
|
||||
END AS 'relType'
|
||||
FROM civicrm_relationship
|
||||
WHERE relationship_type_id IN ($relTypeIds)";
|
||||
$dao = CRM_Core_DAO::executeQuery($sql);
|
||||
$values['relationship'] = NULL;
|
||||
while ($dao->fetch()) {
|
||||
$typeId = $dao->relationship_type_id;
|
||||
$direction = $dao->relType;
|
||||
if ($direction && $typeId) {
|
||||
if ($values['relationship']) {
|
||||
$values['relationship'] .= ',';
|
||||
}
|
||||
$values['relationship'] .= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType',
|
||||
$typeId,
|
||||
"name_$direction",
|
||||
'id'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('has_related', FALSE);
|
||||
// if membership can be granted, and we are the owner of the membership
|
||||
if (!empty($membershipType['relationship_type_id']) && empty($values['owner_membership_id'])) {
|
||||
// display related contacts/membership block
|
||||
$this->assign('has_related', TRUE);
|
||||
$this->assign('max_related', CRM_Utils_Array::value('max_related', $values, ts('Unlimited')));
|
||||
// split the relations in 2 arrays based on direction
|
||||
$relTypeId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_type_id']);
|
||||
$relDirection = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_direction']);
|
||||
foreach ($relTypeId as $rid) {
|
||||
$dir = each($relDirection);
|
||||
$relTypeDir[substr($dir['value'], 0, 1)][] = $rid;
|
||||
}
|
||||
// build query in 2 parts with a UNION if necessary
|
||||
// _x and _y are replaced with _a and _b first, then vice-versa
|
||||
// comment is a qualifier for the relationship - now just job_title
|
||||
$select = "
|
||||
SELECT r.id, c.id as cid, c.display_name as name, c.job_title as comment,
|
||||
rt.name_x_y as relation, r.start_date, r.end_date,
|
||||
m.id as mid, ms.is_current_member, ms.label as status
|
||||
FROM civicrm_relationship r
|
||||
LEFT JOIN civicrm_relationship_type rt ON rt.id = r.relationship_type_id
|
||||
LEFT JOIN civicrm_contact c ON c.id = r.contact_id_x
|
||||
LEFT JOIN civicrm_membership m ON (m.owner_membership_id = {$values['id']}
|
||||
AND m.contact_id = r.contact_id_x AND m.is_test = 0)
|
||||
LEFT JOIN civicrm_membership_status ms ON ms.id = m.status_id
|
||||
WHERE r.contact_id_y = {$values['contact_id']} AND r.is_active = 1 AND c.is_deleted = 0";
|
||||
$query = '';
|
||||
foreach (array('a', 'b') as $dir) {
|
||||
if (isset($relTypeDir[$dir])) {
|
||||
$query .= ($query ? ' UNION ' : '')
|
||||
. str_replace('_y', '_' . $dir, str_replace('_x', '_' . ($dir == 'a' ? 'b' : 'a'), $select))
|
||||
. ' AND r.relationship_type_id IN (' . implode(',', $relTypeDir[$dir]) . ')';
|
||||
}
|
||||
}
|
||||
$query .= " ORDER BY is_current_member DESC";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
$related = array();
|
||||
$relatedRemaining = CRM_Utils_Array::value('max_related', $values, PHP_INT_MAX);
|
||||
$rowElememts = array(
|
||||
'id',
|
||||
'cid',
|
||||
'name',
|
||||
'comment',
|
||||
'relation',
|
||||
'mid',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'is_current_member',
|
||||
'status',
|
||||
);
|
||||
|
||||
while ($dao->fetch()) {
|
||||
$row = array();
|
||||
foreach ($rowElememts as $field) {
|
||||
$row[$field] = $dao->$field;
|
||||
}
|
||||
if ($row['mid'] && ($row['is_current_member'] == 1)) {
|
||||
$relatedRemaining--;
|
||||
$row['action'] = CRM_Core_Action::formLink(self::links(), CRM_Core_Action::DELETE,
|
||||
array(
|
||||
'id' => CRM_Utils_Request::retrieve('id', 'Positive', $this),
|
||||
'cid' => $row['cid'],
|
||||
'mid' => $row['mid'],
|
||||
),
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'membership.relationship.action',
|
||||
'Relationship',
|
||||
CRM_Utils_Request::retrieve('id', 'Positive', $this)
|
||||
);
|
||||
}
|
||||
else {
|
||||
if ($relatedRemaining > 0) {
|
||||
$row['action'] = CRM_Core_Action::formLink(self::links(), CRM_Core_Action::ADD,
|
||||
array(
|
||||
'id' => CRM_Utils_Request::retrieve('id', 'Positive', $this),
|
||||
'cid' => $row['cid'],
|
||||
'rid' => $row['cid'],
|
||||
),
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'membership.relationship.action',
|
||||
'Relationship',
|
||||
CRM_Utils_Request::retrieve('id', 'Positive', $this)
|
||||
);
|
||||
}
|
||||
}
|
||||
$related[] = $row;
|
||||
}
|
||||
$this->assign('related', $related);
|
||||
if ($relatedRemaining <= 0) {
|
||||
$this->assign('related_text', ts('None available'));
|
||||
}
|
||||
else {
|
||||
if ($relatedRemaining < 100000) {
|
||||
$this->assign('related_text', ts('%1 available', array(1 => $relatedRemaining)));
|
||||
}
|
||||
else {
|
||||
$this->assign('related_text', ts('Unlimited', array(1 => $relatedRemaining)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
|
||||
$this->assign('displayName', $displayName);
|
||||
|
||||
// Check if this is default domain contact CRM-10482
|
||||
if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) {
|
||||
$displayName .= ' (' . ts('default organization') . ')';
|
||||
}
|
||||
|
||||
// omitting contactImage from title for now since the summary overlay css doesn't work outside crm-container
|
||||
CRM_Utils_System::setTitle(ts('View Membership for') . ' ' . $displayName);
|
||||
|
||||
// add viewed membership to recent items list
|
||||
$recentTitle = $displayName . ' - ' . ts('Membership Type:') . ' ' . $values['membership_type'];
|
||||
$url = CRM_Utils_System::url('civicrm/contact/view/membership',
|
||||
"action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
|
||||
);
|
||||
|
||||
$recentOther = array();
|
||||
if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::UPDATE)) {
|
||||
$recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership',
|
||||
"action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
|
||||
);
|
||||
}
|
||||
if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::DELETE)) {
|
||||
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership',
|
||||
"action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
|
||||
);
|
||||
}
|
||||
CRM_Utils_Recent::add($recentTitle,
|
||||
$url,
|
||||
$values['id'],
|
||||
'Membership',
|
||||
$values['contact_id'],
|
||||
NULL,
|
||||
$recentOther
|
||||
);
|
||||
|
||||
CRM_Member_Page_Tab::setContext($this, $values['contact_id']);
|
||||
|
||||
$memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $id, "membership_type_id");
|
||||
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', NULL, $id, 0, $memType);
|
||||
CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $id);
|
||||
|
||||
$isRecur = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'contribution_recur_id');
|
||||
|
||||
$autoRenew = $isRecur ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
if (!empty($values['is_test'])) {
|
||||
$values['membership_type'] .= ' (test) ';
|
||||
}
|
||||
|
||||
$subscriptionCancelled = CRM_Member_BAO_Membership::isSubscriptionCancelled($id);
|
||||
$values['auto_renew'] = ($autoRenew && !$subscriptionCancelled) ? 'Yes' : 'No';
|
||||
|
||||
//do check for campaigns
|
||||
if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
|
||||
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
|
||||
$values['campaign'] = $campaigns[$campaignId];
|
||||
}
|
||||
|
||||
$this->assign($values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Done'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
370
sites/all/modules/civicrm/CRM/Member/Form/Search.php
Normal file
370
sites/all/modules/civicrm/CRM/Member/Form/Search.php
Normal file
|
@ -0,0 +1,370 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Membership search.
|
||||
*
|
||||
* Class is a pane in advanced search and the membership search page.
|
||||
*/
|
||||
class CRM_Member_Form_Search extends CRM_Core_Form_Search {
|
||||
|
||||
/**
|
||||
* The params that are sent to the query.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_queryParams;
|
||||
|
||||
/**
|
||||
* Are we restricting ourselves to a single contact.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_single = FALSE;
|
||||
|
||||
/**
|
||||
* Are we restricting ourselves to a single contact.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_limit = NULL;
|
||||
|
||||
/**
|
||||
* Prefix for the controller.
|
||||
*/
|
||||
protected $_prefix = "member_";
|
||||
|
||||
/**
|
||||
* Declare entity reference fields as they will need to be converted to using 'IN'.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $entityReferenceFields = array('membership_type_id');
|
||||
|
||||
/**
|
||||
* Processing needed for buildForm and later.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->set('searchFormName', 'Search');
|
||||
|
||||
$this->_searchButtonName = $this->getButtonName('refresh');
|
||||
$this->_actionButtonName = $this->getButtonName('next', 'action');
|
||||
|
||||
$this->_done = FALSE;
|
||||
|
||||
$this->defaults = array();
|
||||
|
||||
/*
|
||||
* we allow the controller to set force/reset externally, useful when we are being
|
||||
* driven by the wizard framework
|
||||
*/
|
||||
|
||||
$this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean');
|
||||
$this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE);
|
||||
$this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this);
|
||||
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'search');
|
||||
|
||||
$this->assign("context", $this->_context);
|
||||
|
||||
// get user submitted values
|
||||
// get it from controller only if form has been submitted, else preProcess has set this
|
||||
if (!empty($_POST)) {
|
||||
$this->_formValues = $this->controller->exportValues($this->_name);
|
||||
}
|
||||
else {
|
||||
$this->_formValues = $this->get('formValues');
|
||||
}
|
||||
|
||||
if ($this->_force) {
|
||||
$this->postProcess();
|
||||
$this->set('force', 0);
|
||||
}
|
||||
|
||||
$sortID = NULL;
|
||||
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
|
||||
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
|
||||
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
|
||||
);
|
||||
}
|
||||
|
||||
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, $this->entityReferenceFields);
|
||||
$selector = new CRM_Member_Selector_Search($this->_queryParams,
|
||||
$this->_action,
|
||||
NULL,
|
||||
$this->_single,
|
||||
$this->_limit,
|
||||
$this->_context
|
||||
);
|
||||
$prefix = NULL;
|
||||
if ($this->_context == 'basic') {
|
||||
$prefix = $this->_prefix;
|
||||
}
|
||||
|
||||
$this->assign("{$prefix}limit", $this->_limit);
|
||||
$this->assign("{$prefix}single", $this->_single);
|
||||
|
||||
$controller = new CRM_Core_Selector_Controller($selector,
|
||||
$this->get(CRM_Utils_Pager::PAGE_ID),
|
||||
$sortID,
|
||||
CRM_Core_Action::VIEW,
|
||||
$this,
|
||||
CRM_Core_Selector_Controller::TRANSFER,
|
||||
$prefix
|
||||
);
|
||||
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->moveFromSessionToTemplate();
|
||||
|
||||
$this->assign('summary', $this->get('summary'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
$this->addSortNameField();
|
||||
|
||||
CRM_Member_BAO_Query::buildSearchForm($this);
|
||||
|
||||
$rows = $this->get('rows');
|
||||
if (is_array($rows)) {
|
||||
if (!$this->_single) {
|
||||
$this->addRowSelectors($rows);
|
||||
}
|
||||
|
||||
$permission = CRM_Core_Permission::getPermission();
|
||||
|
||||
$this->addTaskMenu(CRM_Member_Task::permissionedTaskTitles($permission));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the label for the sortName field if email searching is on.
|
||||
*
|
||||
* (email searching is a setting under search preferences).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getSortNameLabelWithEmail() {
|
||||
return ts('Member Name or Email');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the label for the sortName field if email searching is off.
|
||||
*
|
||||
* (email searching is a setting under search preferences).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getSortNameLabelWithOutEmail() {
|
||||
return ts('Member Name');
|
||||
}
|
||||
|
||||
/**
|
||||
* The post processing of the form gets done here.
|
||||
*
|
||||
* Key things done during post processing are
|
||||
* - check for reset or next request. if present, skip post procesing.
|
||||
* - now check if user requested running a saved search, if so, then
|
||||
* the form values associated with the saved search are used for searching.
|
||||
* - if user has done a submit with new values the regular post submissing is
|
||||
* done.
|
||||
* The processing consists of using a Selector / Controller framework for getting the
|
||||
* search results.
|
||||
*/
|
||||
public function postProcess() {
|
||||
if ($this->_done) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_done = TRUE;
|
||||
|
||||
$this->_formValues = $this->controller->exportValues($this->_name);
|
||||
|
||||
$this->fixFormValues();
|
||||
|
||||
// We don't show test records in summaries or dashboards
|
||||
if (empty($this->_formValues['member_test']) && $this->_force) {
|
||||
$this->_formValues["member_test"] = 0;
|
||||
}
|
||||
|
||||
CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);
|
||||
|
||||
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, $this->entityReferenceFields);
|
||||
|
||||
$this->set('formValues', $this->_formValues);
|
||||
$this->set('queryParams', $this->_queryParams);
|
||||
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
if ($buttonName == $this->_actionButtonName) {
|
||||
// check actionName and if next, then do not repeat a search, since we are going to the next page
|
||||
|
||||
// hack, make sure we reset the task values
|
||||
$stateMachine = $this->controller->getStateMachine();
|
||||
$formName = $stateMachine->getTaskFormName();
|
||||
$this->controller->resetPage($formName);
|
||||
return;
|
||||
}
|
||||
|
||||
$sortID = NULL;
|
||||
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
|
||||
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
|
||||
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
|
||||
);
|
||||
}
|
||||
|
||||
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, $this->entityReferenceFields);
|
||||
|
||||
$selector = new CRM_Member_Selector_Search($this->_queryParams,
|
||||
$this->_action,
|
||||
NULL,
|
||||
$this->_single,
|
||||
$this->_limit,
|
||||
$this->_context
|
||||
);
|
||||
$selector->setKey($this->controller->_key);
|
||||
|
||||
$prefix = NULL;
|
||||
if ($this->_context == 'basic') {
|
||||
$prefix = $this->_prefix;
|
||||
}
|
||||
|
||||
$controller = new CRM_Core_Selector_Controller($selector,
|
||||
$this->get(CRM_Utils_Pager::PAGE_ID),
|
||||
$sortID,
|
||||
CRM_Core_Action::VIEW,
|
||||
$this,
|
||||
CRM_Core_Selector_Controller::SESSION,
|
||||
$prefix
|
||||
);
|
||||
$controller->setEmbedded(TRUE);
|
||||
|
||||
$query = &$selector->getQuery();
|
||||
$controller->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values.
|
||||
*
|
||||
* @todo - can this function override be removed?
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
return $this->_defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this search has been forced then see if there are any get values, and if so over-ride the post values.
|
||||
*
|
||||
* Note that this means that GET over-rides POST :) & that force with no parameters can be very destructive.
|
||||
*/
|
||||
public function fixFormValues() {
|
||||
if (!$this->_force) {
|
||||
return;
|
||||
}
|
||||
|
||||
$status = CRM_Utils_Request::retrieve('status', 'String');
|
||||
if ($status) {
|
||||
$status = explode(',', $status);
|
||||
$this->_formValues['membership_status_id'] = $this->_defaults['membership_status_id'] = (array) $status;
|
||||
}
|
||||
|
||||
$membershipType = CRM_Utils_Request::retrieve('type', 'String');
|
||||
|
||||
if ($membershipType) {
|
||||
$this->_formValues['membership_type_id'] = array($membershipType);
|
||||
$this->_defaults['membership_type_id'] = array($membershipType);
|
||||
}
|
||||
|
||||
$cid = CRM_Utils_Request::retrieve('cid', 'Positive');
|
||||
|
||||
if ($cid) {
|
||||
$cid = CRM_Utils_Type::escape($cid, 'Integer');
|
||||
if ($cid > 0) {
|
||||
$this->_formValues['contact_id'] = $cid;
|
||||
list($display, $image) = CRM_Contact_BAO_Contact::getDisplayAndImage($cid);
|
||||
$this->_defaults['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid,
|
||||
'sort_name'
|
||||
);
|
||||
// also assign individual mode to the template
|
||||
$this->_single = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
$fromDate = CRM_Utils_Request::retrieve('start', 'Date');
|
||||
if ($fromDate) {
|
||||
list($date) = CRM_Utils_Date::setDateDefaults($fromDate);
|
||||
$this->_formValues['member_start_date_low'] = $this->_defaults['member_start_date_low'] = $date;
|
||||
}
|
||||
|
||||
$toDate = CRM_Utils_Request::retrieve('end', 'Date');
|
||||
if ($toDate) {
|
||||
list($date) = CRM_Utils_Date::setDateDefaults($toDate);
|
||||
$this->_formValues['member_start_date_high'] = $this->_defaults['member_start_date_high'] = $date;
|
||||
}
|
||||
$joinDate = CRM_Utils_Request::retrieve('join', 'Date');
|
||||
if ($joinDate) {
|
||||
list($date) = CRM_Utils_Date::setDateDefaults($joinDate);
|
||||
$this->_formValues['member_join_date_low'] = $this->_defaults['member_join_date_low'] = $date;
|
||||
}
|
||||
|
||||
$joinEndDate = CRM_Utils_Request::retrieve('joinEnd', 'Date');
|
||||
if ($joinEndDate) {
|
||||
list($date) = CRM_Utils_Date::setDateDefaults($joinEndDate);
|
||||
$this->_formValues['member_join_date_high'] = $this->_defaults['member_join_date_high'] = $date;
|
||||
}
|
||||
|
||||
$this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive',
|
||||
$this
|
||||
);
|
||||
|
||||
//LCD also allow restrictions to membership owner via GET
|
||||
$owner = CRM_Utils_Request::retrieve('owner', 'String');
|
||||
if (in_array($owner, array('0', '1'))) {
|
||||
$this->_formValues['member_is_primary'] = $this->_defaults['member_is_primary'] = $owner;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Find Memberships');
|
||||
}
|
||||
|
||||
}
|
190
sites/all/modules/civicrm/CRM/Member/Form/Task.php
Normal file
190
sites/all/modules/civicrm/CRM/Member/Form/Task.php
Normal file
|
@ -0,0 +1,190 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for civimember task actions
|
||||
*
|
||||
*/
|
||||
class CRM_Member_Form_Task extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The task being performed.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_task;
|
||||
|
||||
/**
|
||||
* The additional clause that we restrict the search with.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_componentClause = NULL;
|
||||
|
||||
/**
|
||||
* The array that holds all the component ids.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_componentIds;
|
||||
|
||||
/**
|
||||
* The array that holds all the contact ids.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_contactIds;
|
||||
|
||||
/**
|
||||
* The array that holds all the member ids.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_memberIds;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @param
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
self::preProcessCommon($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
* @param bool $useTable
|
||||
*/
|
||||
public static function preProcessCommon(&$form, $useTable = FALSE) {
|
||||
$form->_memberIds = array();
|
||||
|
||||
$values = $form->controller->exportValues($form->get('searchFormName'));
|
||||
|
||||
$form->_task = $values['task'];
|
||||
$memberTasks = CRM_Member_Task::tasks();
|
||||
$form->assign('taskName', $memberTasks[$form->_task]);
|
||||
|
||||
$ids = array();
|
||||
if ($values['radio_ts'] == 'ts_sel') {
|
||||
foreach ($values as $name => $value) {
|
||||
if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
|
||||
$ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$queryParams = $form->get('queryParams');
|
||||
$sortOrder = NULL;
|
||||
if ($form->get(CRM_Utils_Sort::SORT_ORDER)) {
|
||||
$sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER);
|
||||
}
|
||||
$query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE,
|
||||
CRM_Contact_BAO_Query::MODE_MEMBER
|
||||
);
|
||||
$query->_distinctComponentClause = ' civicrm_membership.id';
|
||||
$query->_groupByComponentClause = ' GROUP BY civicrm_membership.id ';
|
||||
$result = $query->searchQuery(0, 0, $sortOrder);
|
||||
|
||||
while ($result->fetch()) {
|
||||
$ids[] = $result->membership_id;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($ids)) {
|
||||
$form->_componentClause = ' civicrm_membership.id IN ( ' . implode(',', $ids) . ' ) ';
|
||||
$form->assign('totalSelectedMembers', count($ids));
|
||||
}
|
||||
|
||||
$form->_memberIds = $form->_componentIds = $ids;
|
||||
|
||||
//set the context for redirection for any task actions
|
||||
$session = CRM_Core_Session::singleton();
|
||||
|
||||
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form);
|
||||
$urlParams = 'force=1';
|
||||
if (CRM_Utils_Rule::qfKey($qfKey)) {
|
||||
$urlParams .= "&qfKey=$qfKey";
|
||||
}
|
||||
|
||||
$searchFormName = strtolower($form->get('searchFormName'));
|
||||
if ($searchFormName == 'search') {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/member/search', $urlParams));
|
||||
}
|
||||
else {
|
||||
$session->replaceUserContext(CRM_Utils_System::url("civicrm/contact/search/$searchFormName",
|
||||
$urlParams
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the membership id, compute the contact id
|
||||
* since its used for things like send email
|
||||
*/
|
||||
public function setContactIDs() {
|
||||
$this->_contactIds = &CRM_Core_DAO::getContactIDsFromComponent($this->_memberIds,
|
||||
'civicrm_membership'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple shell that derived classes can call to add buttons to.
|
||||
* the form with a customized title for the main Submit
|
||||
*
|
||||
* @param string $title
|
||||
* Title of the main button.
|
||||
* @param string $nextType
|
||||
* @param string $backType
|
||||
* @param bool $submitOnce
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => $nextType,
|
||||
'name' => $title,
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => $backType,
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
277
sites/all/modules/civicrm/CRM/Member/Form/Task/Batch.php
Normal file
277
sites/all/modules/civicrm/CRM/Member/Form/Task/Batch.php
Normal file
|
@ -0,0 +1,277 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality for batch profile update for members
|
||||
*/
|
||||
class CRM_Member_Form_Task_Batch extends CRM_Member_Form_Task {
|
||||
|
||||
/**
|
||||
* The title of the group.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_title;
|
||||
|
||||
/**
|
||||
* Maximum profile fields that will be displayed.
|
||||
*/
|
||||
protected $_maxFields = 9;
|
||||
|
||||
/**
|
||||
* Variable to store redirect path.
|
||||
*/
|
||||
protected $_userContext;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
// initialize the task and row fields
|
||||
parent::preProcess();
|
||||
|
||||
//get the contact read only fields to display.
|
||||
$readOnlyFields = array_merge(array('sort_name' => ts('Name')),
|
||||
CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'contact_autocomplete_options',
|
||||
TRUE, NULL, FALSE, 'name', TRUE
|
||||
)
|
||||
);
|
||||
//get the read only field data.
|
||||
$returnProperties = array_fill_keys(array_keys($readOnlyFields), 1);
|
||||
$contactDetails = CRM_Contact_BAO_Contact_Utils::contactDetails($this->_memberIds,
|
||||
'CiviMember', $returnProperties
|
||||
);
|
||||
$this->assign('contactDetails', $contactDetails);
|
||||
$this->assign('readOnlyFields', $readOnlyFields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$ufGroupId = $this->get('ufGroupId');
|
||||
|
||||
if (!$ufGroupId) {
|
||||
CRM_Core_Error::fatal('ufGroupId is missing');
|
||||
}
|
||||
$this->_title = ts('Update multiple memberships') . ' - ' . CRM_Core_BAO_UFGroup::getTitle($ufGroupId);
|
||||
CRM_Utils_System::setTitle($this->_title);
|
||||
|
||||
$this->addDefaultButtons(ts('Save'));
|
||||
$this->_fields = array();
|
||||
$this->_fields = CRM_Core_BAO_UFGroup::getFields($ufGroupId, FALSE, CRM_Core_Action::VIEW);
|
||||
|
||||
// remove file type field and then limit fields
|
||||
$suppressFields = FALSE;
|
||||
$removehtmlTypes = array('File', 'Autocomplete-Select');
|
||||
foreach ($this->_fields as $name => $field) {
|
||||
if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name) &&
|
||||
in_array($this->_fields[$name]['html_type'], $removehtmlTypes)
|
||||
) {
|
||||
$suppressFields = TRUE;
|
||||
unset($this->_fields[$name]);
|
||||
}
|
||||
|
||||
//fix to reduce size as we are using this field in grid
|
||||
if (is_array($field['attributes']) && !empty($this->_fields[$name]['attributes']['size']) && $this->_fields[$name]['attributes']['size'] > 19) {
|
||||
//shrink class to "form-text-medium"
|
||||
$this->_fields[$name]['attributes']['size'] = 19;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_fields = array_slice($this->_fields, 0, $this->_maxFields);
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'submit',
|
||||
'name' => ts('Update Members(s)'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
|
||||
$this->assign('profileTitle', $this->_title);
|
||||
$this->assign('componentIds', $this->_memberIds);
|
||||
|
||||
//load all campaigns.
|
||||
if (array_key_exists('member_campaign_id', $this->_fields)) {
|
||||
$this->_componentCampaigns = array();
|
||||
CRM_Core_PseudoConstant::populate($this->_componentCampaigns,
|
||||
'CRM_Member_DAO_Membership',
|
||||
TRUE, 'campaign_id', 'id',
|
||||
' id IN (' . implode(' , ', array_values($this->_memberIds)) . ' ) '
|
||||
);
|
||||
}
|
||||
|
||||
$customFields = CRM_Core_BAO_CustomField::getFields('Membership');
|
||||
foreach ($this->_memberIds as $memberId) {
|
||||
$typeId = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $memberId, 'membership_type_id');
|
||||
foreach ($this->_fields as $name => $field) {
|
||||
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
|
||||
$customValue = CRM_Utils_Array::value($customFieldID, $customFields);
|
||||
$entityColumnValue = array();
|
||||
if (!empty($customValue['extends_entity_column_value'])) {
|
||||
$entityColumnValue = explode(CRM_Core_DAO::VALUE_SEPARATOR,
|
||||
$customValue['extends_entity_column_value']
|
||||
);
|
||||
}
|
||||
if ((CRM_Utils_Array::value($typeId, $entityColumnValue)) ||
|
||||
CRM_Utils_System::isNull($entityColumnValue[$typeId])
|
||||
) {
|
||||
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $memberId);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// handle non custom fields
|
||||
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $memberId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('fields', $this->_fields);
|
||||
|
||||
// don't set the status message when form is submitted.
|
||||
$buttonName = $this->controller->getButtonName('submit');
|
||||
|
||||
if ($suppressFields && $buttonName != '_qf_Batch_next') {
|
||||
CRM_Core_Session::setStatus(ts("File or Autocomplete-Select type field(s) in the selected profile are not supported for Update multiple memberships."), ts('Unsupported Field Type'), 'error');
|
||||
}
|
||||
|
||||
$this->addDefaultButtons(ts('Update Memberships'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
if (empty($this->_fields)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$defaults = array();
|
||||
foreach ($this->_memberIds as $memberId) {
|
||||
CRM_Core_BAO_UFGroup::setProfileDefaults(NULL, $this->_fields, $defaults, FALSE, $memberId, 'Membership');
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
$dates = array(
|
||||
'join_date',
|
||||
'membership_start_date',
|
||||
'membership_end_date',
|
||||
);
|
||||
if (isset($params['field'])) {
|
||||
$customFields = array();
|
||||
foreach ($params['field'] as $key => $value) {
|
||||
$ids['membership'] = $key;
|
||||
if (!empty($value['membership_source'])) {
|
||||
$value['source'] = $value['membership_source'];
|
||||
}
|
||||
|
||||
if (!empty($value['membership_type'])) {
|
||||
$membershipTypeId = $value['membership_type_id'] = $value['membership_type'][1];
|
||||
}
|
||||
|
||||
unset($value['membership_source']);
|
||||
unset($value['membership_type']);
|
||||
|
||||
//Get the membership status
|
||||
$value['status_id'] = (CRM_Utils_Array::value('membership_status', $value)) ? $value['membership_status'] : CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $key, 'status_id');
|
||||
unset($value['membership_status']);
|
||||
foreach ($dates as $val) {
|
||||
if (isset($value[$val])) {
|
||||
$value[$val] = CRM_Utils_Date::processDate($value[$val]);
|
||||
}
|
||||
}
|
||||
if (empty($customFields)) {
|
||||
if (empty($value['membership_type_id'])) {
|
||||
$membershipTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $key, 'membership_type_id');
|
||||
}
|
||||
|
||||
// membership type custom data
|
||||
$customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $membershipTypeId);
|
||||
|
||||
$customFields = CRM_Utils_Array::crmArrayMerge($customFields,
|
||||
CRM_Core_BAO_CustomField::getFields('Membership',
|
||||
FALSE, FALSE, NULL, NULL, TRUE
|
||||
)
|
||||
);
|
||||
}
|
||||
//check for custom data
|
||||
$value['custom'] = CRM_Core_BAO_CustomField::postProcess($params['field'][$key],
|
||||
$key,
|
||||
'Membership',
|
||||
$membershipTypeId
|
||||
);
|
||||
|
||||
$membership = CRM_Member_BAO_Membership::add($value, $ids);
|
||||
|
||||
// add custom field values
|
||||
if (!empty($value['custom']) &&
|
||||
is_array($value['custom'])
|
||||
) {
|
||||
CRM_Core_BAO_CustomValueTable::store($value['custom'], 'civicrm_membership', $membership->id);
|
||||
}
|
||||
}
|
||||
|
||||
CRM_Core_Session::setStatus(ts("Your updates have been saved."), ts('Saved'), 'success');
|
||||
}
|
||||
else {
|
||||
CRM_Core_Session::setStatus(ts("No updates have been saved."), ts('Not Saved'), 'alert');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
101
sites/all/modules/civicrm/CRM/Member/Form/Task/Delete.php
Normal file
101
sites/all/modules/civicrm/CRM/Member/Form/Task/Delete.php
Normal file
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to delete a group of
|
||||
* members. This class provides functionality for the actual
|
||||
* deletion.
|
||||
*/
|
||||
class CRM_Member_Form_Task_Delete extends CRM_Member_Form_Task {
|
||||
|
||||
/**
|
||||
* Are we operating in "single mode", i.e. deleting one
|
||||
* specific membership?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_single = FALSE;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
//check for delete
|
||||
if (!CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::DELETE)) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
}
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addDefaultButtons(ts('Delete Memberships'), 'done');
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$deleted = $failed = 0;
|
||||
foreach ($this->_memberIds as $memberId) {
|
||||
if (CRM_Member_BAO_Membership::del($memberId)) {
|
||||
$deleted++;
|
||||
}
|
||||
else {
|
||||
$failed++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($deleted) {
|
||||
$msg = ts('%count membership deleted.', array('plural' => '%count memberships deleted.', 'count' => $deleted));
|
||||
CRM_Core_Session::setStatus($msg, ts('Removed'), 'success');
|
||||
}
|
||||
|
||||
if ($failed) {
|
||||
CRM_Core_Session::setStatus(ts('1 could not be deleted.', array('plural' => '%count could not be deleted.', 'count' => $failed)), ts('Error'), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
113
sites/all/modules/civicrm/CRM/Member/Form/Task/Email.php
Normal file
113
sites/all/modules/civicrm/CRM/Member/Form/Task/Email.php
Normal file
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id: Email.php 45499 2013-02-08 12:31:05Z kurund $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to email a group of
|
||||
* contacts.
|
||||
*/
|
||||
class CRM_Member_Form_Task_Email extends CRM_Member_Form_Task {
|
||||
|
||||
/**
|
||||
* Are we operating in "single mode", i.e. sending email to one
|
||||
* specific contact?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $_single = FALSE;
|
||||
|
||||
/**
|
||||
* Are we operating in "single mode", i.e. sending email to one
|
||||
* specific contact?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $_noEmails = FALSE;
|
||||
|
||||
/**
|
||||
* All the existing templates in the system.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_templates = NULL;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
CRM_Contact_Form_Task_EmailCommon::preProcessFromAddress($this);
|
||||
parent::preProcess();
|
||||
|
||||
// we have all the membership ids, so now we get the contact ids
|
||||
parent::setContactIDs();
|
||||
|
||||
$this->assign('single', $this->_single);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
//enable form element
|
||||
$this->assign('emailTask', TRUE);
|
||||
|
||||
CRM_Contact_Form_Task_EmailCommon::buildQuickForm($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
CRM_Contact_Form_Task_EmailCommon::postProcess($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* List available tokens for this form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listTokens() {
|
||||
$tokens = CRM_Core_SelectValues::contactTokens();
|
||||
return $tokens;
|
||||
}
|
||||
|
||||
}
|
148
sites/all/modules/civicrm/CRM/Member/Form/Task/Label.php
Normal file
148
sites/all/modules/civicrm/CRM/Member/Form/Task/Label.php
Normal file
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class helps to print the labels for contacts
|
||||
*
|
||||
*/
|
||||
class CRM_Member_Form_Task_Label extends CRM_Member_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
$this->setContactIDs();
|
||||
CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Member/Form/Task/Label.js');
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
CRM_Contact_Form_Task_Label::buildLabelForm($this);
|
||||
$this->addElement('checkbox', 'per_membership', ts('Print one label per Membership (rather than per contact)'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* @return array
|
||||
* array of default values
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
$format = CRM_Core_BAO_LabelFormat::getDefaultValues();
|
||||
$defaults['label_name'] = CRM_Utils_Array::value('name', $format);
|
||||
$defaults['merge_same_address'] = 0;
|
||||
$defaults['merge_same_household'] = 0;
|
||||
$defaults['do_not_mail'] = 1;
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$formValues = $this->controller->exportValues($this->_name);
|
||||
$locationTypeID = $formValues['location_type_id'];
|
||||
$respectDoNotMail = CRM_Utils_Array::value('do_not_mail', $formValues);
|
||||
$labelName = $formValues['label_name'];
|
||||
$mergeSameAddress = CRM_Utils_Array::value('merge_same_address', $formValues);
|
||||
$mergeSameHousehold = CRM_Utils_Array::value('merge_same_household', $formValues);
|
||||
$isPerMembership = CRM_Utils_Array::value('per_membership', $formValues);
|
||||
if ($isPerMembership && ($mergeSameAddress || $mergeSameHousehold)) {
|
||||
// this shouldn't happen - perhaps is could if JS is disabled
|
||||
CRM_Core_Session::setStatus(ts('As you are printing one label per membership your merge settings are being ignored'));
|
||||
$mergeSameAddress = $mergeSameHousehold = FALSE;
|
||||
}
|
||||
// so no-one is tempted to refer to this again after relevant values are extracted
|
||||
unset($formValues);
|
||||
|
||||
list($rows, $tokenFields) = CRM_Contact_Form_Task_LabelCommon::getRows($this->_contactIds, $locationTypeID, $respectDoNotMail, $mergeSameAddress, $mergeSameHousehold);
|
||||
|
||||
$individualFormat = FALSE;
|
||||
if ($mergeSameAddress) {
|
||||
CRM_Core_BAO_Address::mergeSameAddress($rows);
|
||||
$individualFormat = TRUE;
|
||||
}
|
||||
if ($mergeSameHousehold) {
|
||||
$rows = CRM_Contact_Form_Task_LabelCommon::mergeSameHousehold($rows);
|
||||
$individualFormat = TRUE;
|
||||
}
|
||||
// format the addresses according to CIVICRM_ADDRESS_FORMAT (CRM-1327)
|
||||
foreach ((array) $rows as $id => $row) {
|
||||
if ($commMethods = CRM_Utils_Array::value('preferred_communication_method', $row)) {
|
||||
$val = array_filter(explode(CRM_Core_DAO::VALUE_SEPARATOR, $commMethods));
|
||||
$comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
|
||||
$temp = array();
|
||||
foreach ($val as $vals) {
|
||||
$temp[] = $comm[$vals];
|
||||
}
|
||||
$row['preferred_communication_method'] = implode(', ', $temp);
|
||||
}
|
||||
$row['id'] = $id;
|
||||
$formatted = CRM_Utils_Address::format($row, 'mailing_format', FALSE, TRUE, $individualFormat, $tokenFields);
|
||||
$rows[$id] = array($formatted);
|
||||
}
|
||||
if ($isPerMembership) {
|
||||
$labelRows = array();
|
||||
$memberships = civicrm_api3('membership', 'get', array(
|
||||
'id' => array('IN' => $this->_memberIds),
|
||||
'return' => 'contact_id',
|
||||
));
|
||||
foreach ($memberships['values'] as $id => $membership) {
|
||||
if (isset($rows[$membership['contact_id']])) {
|
||||
$labelRows[$id] = $rows[$membership['contact_id']];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$labelRows = $rows;
|
||||
}
|
||||
//call function to create labels
|
||||
CRM_Contact_Form_Task_LabelCommon::createLabel($labelRows, $labelName);
|
||||
CRM_Utils_System::civiExit(1);
|
||||
}
|
||||
|
||||
}
|
113
sites/all/modules/civicrm/CRM/Member/Form/Task/PDFLetter.php
Normal file
113
sites/all/modules/civicrm/CRM/Member/Form/Task/PDFLetter.php
Normal file
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to create PDF letter for a group of
|
||||
* contacts or a single contact.
|
||||
*/
|
||||
class CRM_Member_Form_Task_PDFLetter extends CRM_Member_Form_Task {
|
||||
|
||||
/**
|
||||
* All the existing templates in the system.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_templates = NULL;
|
||||
|
||||
public $_single = NULL;
|
||||
|
||||
public $_cid = NULL;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->skipOnHold = $this->skipDeceased = FALSE;
|
||||
parent::preProcess();
|
||||
$this->setContactIDs();
|
||||
CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults.
|
||||
* (non-PHPdoc)
|
||||
* @see CRM_Core_Form::setDefaultValues()
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
return CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
//enable form element
|
||||
$this->assign('suppressForm', FALSE);
|
||||
CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
// TODO: rewrite using contribution token and one letter by contribution
|
||||
$this->setContactIDs();
|
||||
$skipOnHold = isset($this->skipOnHold) ? $this->skipOnHold : FALSE;
|
||||
$skipDeceased = isset($this->skipDeceased) ? $this->skipDeceased : TRUE;
|
||||
CRM_Member_Form_Task_PDFLetterCommon::postProcessMembers(
|
||||
$this, $this->_memberIds, $skipOnHold, $skipDeceased, $this->_contactIds
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* List available tokens for this form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listTokens() {
|
||||
$tokens = CRM_Core_SelectValues::contactTokens();
|
||||
$tokens = array_merge(CRM_Core_SelectValues::membershipTokens(), $tokens);
|
||||
return $tokens;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This class provides the common functionality for creating PDF letter for
|
||||
* members
|
||||
*/
|
||||
class CRM_Member_Form_Task_PDFLetterCommon extends CRM_Contact_Form_Task_PDFLetterCommon {
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
* @todo this is horrible copy & paste code because there is so much risk of breakage
|
||||
* in fixing the existing pdfLetter classes to be suitably generic
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param $membershipIDs
|
||||
* @param $skipOnHold
|
||||
* @param $skipDeceased
|
||||
* @param $contactIDs
|
||||
*/
|
||||
public static function postProcessMembers(&$form, $membershipIDs, $skipOnHold, $skipDeceased, $contactIDs) {
|
||||
$formValues = $form->controller->exportValues($form->getName());
|
||||
list($formValues, $categories, $html_message, $messageToken, $returnProperties) = self::processMessageTemplate($formValues);
|
||||
|
||||
$html
|
||||
= self::generateHTML(
|
||||
$membershipIDs,
|
||||
$returnProperties,
|
||||
$skipOnHold,
|
||||
$skipDeceased,
|
||||
$messageToken,
|
||||
$html_message,
|
||||
$categories
|
||||
);
|
||||
// This seems silly, but the old behavior was to first check `_cid`
|
||||
// and then use the provided `$contactIds`. Probably not even necessary,
|
||||
// but difficult to audit.
|
||||
$contactIDs = $form->_cid ? array($form->_cid) : $contactIDs;
|
||||
self::createActivities($form, $html_message, $contactIDs, $formValues['subject'], CRM_Utils_Array::value('campaign_id', $formValues));
|
||||
|
||||
CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", FALSE, $formValues);
|
||||
|
||||
$form->postProcessHook();
|
||||
|
||||
CRM_Utils_System::civiExit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate htmlfor pdf letters.
|
||||
*
|
||||
* @param array $membershipIDs
|
||||
* @param array $returnProperties
|
||||
* @param bool $skipOnHold
|
||||
* @param bool $skipDeceased
|
||||
* @param array $messageToken
|
||||
* @param $html_message
|
||||
* @param $categories
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function generateHTML($membershipIDs, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $html_message, $categories) {
|
||||
$memberships = CRM_Utils_Token::getMembershipTokenDetails($membershipIDs);
|
||||
$html = array();
|
||||
|
||||
foreach ($membershipIDs as $membershipID) {
|
||||
$membership = $memberships[$membershipID];
|
||||
// get contact information
|
||||
$contactId = $membership['contact_id'];
|
||||
$params = array('contact_id' => $contactId);
|
||||
//getTokenDetails is much like calling the api contact.get function - but - with some minor
|
||||
// special handlings. It precedes the existence of the api
|
||||
list($contacts) = CRM_Utils_Token::getTokenDetails(
|
||||
$params,
|
||||
$returnProperties,
|
||||
$skipOnHold,
|
||||
$skipDeceased,
|
||||
NULL,
|
||||
$messageToken,
|
||||
'CRM_Contribution_Form_Task_PDFLetterCommon'
|
||||
);
|
||||
|
||||
$tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contacts[$contactId], TRUE, $messageToken);
|
||||
$tokenHtml = CRM_Utils_Token::replaceEntityTokens('membership', $membership, $tokenHtml, $messageToken);
|
||||
$tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contacts[$contactId], $categories, TRUE);
|
||||
$tokenHtml = CRM_Utils_Token::parseThroughSmarty($tokenHtml, $contacts[$contactId]);
|
||||
|
||||
$html[] = $tokenHtml;
|
||||
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
}
|
148
sites/all/modules/civicrm/CRM/Member/Form/Task/PickProfile.php
Normal file
148
sites/all/modules/civicrm/CRM/Member/Form/Task/PickProfile.php
Normal file
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality for batch profile update for membership
|
||||
*/
|
||||
class CRM_Member_Form_Task_PickProfile extends CRM_Member_Form_Task {
|
||||
|
||||
/**
|
||||
* The title of the group
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_title;
|
||||
|
||||
/**
|
||||
* Maximum members that should be allowed to update
|
||||
*/
|
||||
protected $_maxMembers = 100;
|
||||
|
||||
/**
|
||||
* Variable to store redirect path
|
||||
*/
|
||||
protected $_userContext;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
// initialize the task and row fields
|
||||
parent::preProcess();
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$this->_userContext = $session->readUserContext();
|
||||
|
||||
CRM_Utils_System::setTitle(ts('Update multiple memberships'));
|
||||
|
||||
$validate = FALSE;
|
||||
//validations
|
||||
if (count($this->_memberIds) > $this->_maxMembers) {
|
||||
CRM_Core_Session::setStatus(ts("The maximum number of members you can select for Update multiple memberships is %1. You have selected %2. Please select fewer members from your search results and try again.", array(
|
||||
1 => $this->_maxMembers,
|
||||
2 => count($this->_memberIds),
|
||||
)), ts('Update multiple records error'), 'error');
|
||||
$validate = TRUE;
|
||||
}
|
||||
|
||||
// than redirect
|
||||
if ($validate) {
|
||||
CRM_Utils_System::redirect($this->_userContext);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$types = array('Membership');
|
||||
$profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE);
|
||||
|
||||
if (empty($profiles)) {
|
||||
CRM_Core_Session::setStatus(ts("You will need to create a Profile containing the %1 fields you want to edit before you can use Update multiple memberships. Navigate to Administer CiviCRM >> CiviCRM Profile to configure a Profile. Consult the online Administrator documentation for more information.", array(1 => $types[0])), ts('Update multiple records error'), 'error');
|
||||
CRM_Utils_System::redirect($this->_userContext);
|
||||
}
|
||||
|
||||
$ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'),
|
||||
array(
|
||||
'' => ts('- select profile -'),
|
||||
) + $profiles, TRUE
|
||||
);
|
||||
$this->addDefaultButtons(ts('Continue'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add local and global form rules.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addRules() {
|
||||
$this->addFormRule(array('CRM_Member_Form_Task_PickProfile', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($fields) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
$this->set('ufGroupId', $params['uf_group_id']);
|
||||
|
||||
// also reset the batch page so it gets new values from the db
|
||||
$this->controller->resetPage('Batch');
|
||||
}
|
||||
|
||||
}
|
104
sites/all/modules/civicrm/CRM/Member/Form/Task/Print.php
Normal file
104
sites/all/modules/civicrm/CRM/Member/Form/Task/Print.php
Normal file
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to print members
|
||||
*/
|
||||
class CRM_Member_Form_Task_Print extends CRM_Member_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preprocess();
|
||||
|
||||
// set print view, so that print templates are called
|
||||
$this->controller->setPrint(1);
|
||||
|
||||
// get the formatted params
|
||||
$queryParams = $this->get('queryParams');
|
||||
|
||||
$sortID = NULL;
|
||||
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
|
||||
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
|
||||
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
|
||||
);
|
||||
}
|
||||
|
||||
$selector = new CRM_Member_Selector_Search($queryParams, $this->_action, $this->_componentClause);
|
||||
$controller = new CRM_Core_Selector_Controller($selector, NULL, $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SCREEN);
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object - it consists of
|
||||
* - displaying the QILL (query in local language)
|
||||
* - displaying elements for saving the search
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
//
|
||||
// just need to add a javacript to popup the window for printing
|
||||
//
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Print Members'),
|
||||
'js' => array('onclick' => 'window.print()'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'back',
|
||||
'name' => ts('Done'),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
// redirect to the main search page after printing is over
|
||||
}
|
||||
|
||||
}
|
66
sites/all/modules/civicrm/CRM/Member/Form/Task/Result.php
Normal file
66
sites/all/modules/civicrm/CRM/Member/Form/Task/Result.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Used for displaying results
|
||||
*
|
||||
*
|
||||
*/
|
||||
class CRM_Member_Form_Task_Result extends CRM_Member_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'done',
|
||||
'name' => ts('Done'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to save a search
|
||||
* Saved Searches are used for saving frequently used queries
|
||||
*/
|
||||
class CRM_Member_Form_Task_SearchTaskHookSample extends CRM_Member_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
$rows = array();
|
||||
// display name and membership details of all selected contacts
|
||||
$memberIDs = implode(',', $this->_memberIds);
|
||||
|
||||
$query = "
|
||||
SELECT mem.start_date as start_date,
|
||||
mem.end_date as end_date,
|
||||
mem.source as source,
|
||||
ct.display_name as display_name
|
||||
FROM civicrm_membership mem
|
||||
INNER JOIN civicrm_contact ct ON ( mem.contact_id = ct.id )
|
||||
WHERE mem.id IN ( $memberIDs )";
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$rows[] = array(
|
||||
'display_name' => $dao->display_name,
|
||||
'start_date' => CRM_Utils_Date::customFormat($dao->start_date),
|
||||
'end_date' => CRM_Utils_Date::customFormat($dao->end_date),
|
||||
'source' => $dao->source,
|
||||
);
|
||||
}
|
||||
$this->assign('rows', $rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'done',
|
||||
'name' => ts('Done'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue