Skip to content

Commit

Permalink
Ticket #3275
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Mar 25, 2021
1 parent e651677 commit c840e01
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 48 deletions.
24 changes: 22 additions & 2 deletions modules/boonex/donations/classes/BxDonationsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class BxDonationsConfig extends BxBaseModGeneralConfig

protected $_iOwner;
protected $_bShowTitle;
protected $_bEnableOther;
protected $_aBillingTypes;
protected $_aPeriodUnits;

Expand All @@ -38,7 +39,8 @@ public function __construct($aModule)
'FIELD_TITLE' => 'title',
'FIELD_PERIOD' => 'period',
'FIELD_PERIOD_UNIT' => 'period_unit',
'FIELD_PRICE' => 'price',
'FIELD_AMOUNT' => 'amount',
'FIELD_CUSTOM' => 'custom',

// page URIs
'URL_MAKE' => 'page.php?i=donations-make',
Expand All @@ -47,8 +49,14 @@ public function __construct($aModule)

// some params
'PARAM_SHOW_TITLE' => 'bx_donations_show_title',
'PARAM_ENABLE_OTHER' => 'bx_donations_enable_other',
'PARAM_AMOUNT_PRECISION' => 'bx_donations_amount_precision',

'PARAM_OTHER_NAME' => 'other',
'PARAM_OTHER_PERIOD' => 1,
'PARAM_OTHER_PERIOD_UNIT' => 'month',
'PARAM_OTHER_PRICE_MIN' => 5,

// objects
'OBJECT_GRID_LIST' => 'bx_donations_list',
'OBJECT_GRID_LIST_ALL' => 'bx_donations_list_all',
Expand Down Expand Up @@ -96,6 +104,7 @@ public function init(&$oDb)
$this->_oDb = &$oDb;

$this->_bShowTitle = $this->_oDb->getParam($this->CNF['PARAM_SHOW_TITLE']) == 'on';
$this->_bEnableOther = $this->_oDb->getParam($this->CNF['PARAM_ENABLE_OTHER']) == 'on';
}

public function getHtmlIds($sKey = '')
Expand All @@ -105,7 +114,7 @@ public function getHtmlIds($sKey = '')

return isset($this->_aHtmlIds[$sKey]) ? $this->_aHtmlIds[$sKey] : '';
}

public function getOwner()
{
return $this->_iOwner;
Expand All @@ -115,6 +124,12 @@ public function isShowTitle()
{
return $this->_bShowTitle;
}

public function isEnableOther()
{
return $this->_bEnableOther;
}

public function getBillingTypes()
{
return $this->_aBillingTypes;
Expand All @@ -129,6 +144,11 @@ public function getTypeName($sName)
{
return uriGenerate($sName, $this->CNF['TABLE_TYPES'], $this->CNF['FIELD_NAME']);
}

public function getTypeNameCustom()
{
return $this->getTypeName($this->CNF['PARAM_OTHER_NAME'] . '_' . bx_get_logged_profile_id());
}
}

/** @} */
15 changes: 14 additions & 1 deletion modules/boonex/donations/classes/BxDonationsDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ public function getTypes($aParams)
'period' => 0,
);

$sWhereClause .= "AND `tt`.`period`" . ($aParams['type'] == 'by_btype_single' ? '=' : '<>') . ":period";
$sWhereClause .= "AND `tt`.`period`" . ($aParams['type'] == 'by_btype_single' ? '=' : '<>') . ":period AND `tt`.`custom`='0'";

if(isset($aParams['active'])) {
$aMethod['params'][1]['active'] = (int)$aParams['active'];

$sWhereClause .= " AND `tt`.`active`=:active";
}
break;

case 'conditions':
Expand Down Expand Up @@ -110,6 +116,13 @@ public function getTypeOrderMax()
return (int)$this->getOne("SELECT MAX(`order`) FROM `" . $CNF['TABLE_TYPES'] . "` WHERE 1");
}

public function insertType($aSet)
{
$CNF = &$this->_oConfig->CNF;

return (int)$this->query("INSERT INTO `" . $CNF['TABLE_TYPES'] . "` SET " . $this->arrayToSQL($aSet)) > 0 ? $this->lastId() : false;
}

public function deleteTypes($aWhere)
{
$CNF = &$this->_oConfig->CNF;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function _getCellEntry($mixedValue, $sKey, $aField, $aRow)

$sTitlekey = '_bx_donations_txt_amount_' . ($this->_oModule->_oConfig->isShowTitle() ? 'with' : 'wo') . '_title';

$sAmount = _t_format_currency($aRow['type_price'], getParam($CNF['PARAM_AMOUNT_PRECISION']));
$sAmount = _t_format_currency($aRow['type_amount'], getParam($CNF['PARAM_AMOUNT_PRECISION']));
$sAmount = _t('_bx_donations_txt_amount_single', $sAmount);

return parent::_getCellDefault(_t($sTitlekey, $sAmount, _t($aRow['type_title'])), $sKey, $aField, $aRow);
Expand Down
69 changes: 57 additions & 12 deletions modules/boonex/donations/classes/BxDonationsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,53 @@ public function actionCheckName()
));
}

public function actionMakeOther()
{
$CNF = &$this->_oConfig->CNF;

$sBillingType = bx_process_input(bx_get('btype'));
$bBillingTypeRecurring = $sBillingType == BX_DONATIONS_BTYPE_RECURRING;

$fAmount = bx_process_input(bx_get('amount'), BX_DATA_FLOAT);
if(empty($sBillingType) || empty($fAmount))
return echoJson(array());

if($fAmount < $CNF['PARAM_OTHER_PRICE_MIN'])
return echoJson(array('msg' => _t('_bx_donations_err_min_value', _t_format_currency($CNF['PARAM_OTHER_PRICE_MIN'], getParam($CNF['PARAM_AMOUNT_PRECISION'])))));

$iOwner = $this->_oConfig->getOwner();
$sModule = $this->getName();
$iTypeId = $this->_oDb->insertType(array(
$CNF['FIELD_NAME'] => $this->_oConfig->getTypeNameCustom(),
$CNF['FIELD_PERIOD'] => $bBillingTypeRecurring ? $CNF['PARAM_OTHER_PERIOD'] : 0,
$CNF['FIELD_PERIOD_UNIT'] => $bBillingTypeRecurring ? $CNF['PARAM_OTHER_PERIOD_UNIT'] : '',
$CNF['FIELD_AMOUNT'] => $fAmount,
$CNF['FIELD_CUSTOM'] => 1
));

$oPayments = BxDolPayments::getInstance();

$aResult = array();
switch($sBillingType) {
case BX_DONATIONS_BTYPE_SINGLE:
$aResultSrv = $oPayments->addToCart($iOwner, $sModule, $iTypeId, 1);
if(!empty($aResultSrv['code']))
$aResult = array('msg' => isset($aResultSrv['message']) ? $aResultSrv['message'] : _t('_bx_donations_err_cannot_perform'));
else
$aResult = array('redirect' => $oPayments->getCartUrl($iOwner));
break;

case BX_DONATIONS_BTYPE_RECURRING:
$aResultSrv = $oPayments->subscribeWithAddons($iOwner, '', $sModule, $iTypeId, 1);
if(!empty($aResultSrv['code']))
$aResult = array('msg' => isset($aResultSrv['message']) ? $aResultSrv['message'] : _t('_bx_donations_err_cannot_perform'));
else
$aResult = isset($aResultSrv['popup']) || isset($aResultSrv['redirect']) ? $aResultSrv : array('redirect' => $oPayments->getSubscriptionsUrl());
break;
}

return echoJson($aResult);
}

/**
* SERVICE METHODS
Expand Down Expand Up @@ -107,11 +154,11 @@ public function serviceGetCartItem($mixedItemId)
'id' => $aItem[$CNF['FIELD_ID']],
'author_id' => $this->_oConfig->getOwner(),
'name' => $aItem[$CNF['FIELD_NAME']],
'title' => _t($this->_oConfig->isShowTitle() ? $aItem[$CNF['FIELD_TITLE']] : '_bx_donations_txt_cart_item_title'),
'description' => '',
'title' => _t($this->_oConfig->isShowTitle() && !empty($aItem[$CNF['FIELD_TITLE']]) ? $aItem[$CNF['FIELD_TITLE']] : '_bx_donations_txt_cart_item_title'),
'description' => _t('_bx_donations_txt_cart_item_description', getParam('site_title')),
'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_MAKE']),
'price_single' => $aItem[$CNF['FIELD_PRICE']],
'price_recurring' => $aItem[$CNF['FIELD_PRICE']],
'price_single' => $aItem[$CNF['FIELD_AMOUNT']],
'price_recurring' => $aItem[$CNF['FIELD_AMOUNT']],
'period_recurring' => $aItem[$CNF['FIELD_PERIOD']],
'period_unit_recurring' => $aItem[$CNF['FIELD_PERIOD_UNIT']],
'trial_recurring' => ''
Expand All @@ -138,11 +185,11 @@ public function serviceGetCartItems($iSellerId)
'id' => $aItem[$CNF['FIELD_ID']],
'author_id' => $this->_oConfig->getOwner(),
'name' => $aItem[$CNF['FIELD_NAME']],
'title' => _t($bShowTitle ? $aItem[$CNF['FIELD_TITLE']] : '_bx_donations_txt_cart_item_title'),
'description' => '',
'title' => _t($bShowTitle && !empty($aItem[$CNF['FIELD_TITLE']]) ? $aItem[$CNF['FIELD_TITLE']] : '_bx_donations_txt_cart_item_title'),
'description' => _t('_bx_donations_txt_cart_item_description', getParam('site_title')),
'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_MAKE']),
'price_single' => $aItem[$CNF['FIELD_PRICE']],
'price_recurring' => $aItem[$CNF['FIELD_PRICE']],
'price_single' => $aItem[$CNF['FIELD_AMOUNT']],
'price_recurring' => $aItem[$CNF['FIELD_AMOUNT']],
'period_recurring' => $aItem[$CNF['FIELD_PERIOD']],
'period_unit_recurring' => $aItem[$CNF['FIELD_PERIOD_UNIT']],
'trial_recurring' => ''
Expand Down Expand Up @@ -194,10 +241,6 @@ protected function _serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItem
if(empty($aItem) || !is_array($aItem))
return array();

$aType = $this->_oDb->getTypeById($iItemId);
if(empty($aType) || !is_array($aType))
return array();

if(!$this->_oDb->registerEntry($iClientId, $iItemId, $iItemCount, $sOrder, $sLicense))
return array();

Expand All @@ -206,6 +249,7 @@ protected function _serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItem
'profile_id' => $iClientId,
'order' => $sOrder,
'type' => $sType,
'amount' => (float)$aItem['price_' . $sType],
'count' => $iItemCount
));

Expand Down Expand Up @@ -233,6 +277,7 @@ protected function _serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iIt
return true;
}


/*
* INTERNAL METHODS
*/
Expand Down
51 changes: 41 additions & 10 deletions modules/boonex/donations/classes/BxDonationsTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,19 @@ public function getBlockMake($sSelected = 'single')
$sHtmlIdBTypeLink = $this->_oConfig->getHtmlIds('link_billing_type');

$bShowTitle = $this->_oConfig->isShowTitle();
$bEnableOther = $this->_oConfig->isEnableOther();
$aPeriodUnits = $this->_oConfig->getPeriodUnits();

$aMenuBillingTypes = array();
$aTmplVarsBillingTypes = array();

$aBillingTypes = $this->_oConfig->getBillingTypes();
foreach($aBillingTypes as $sBillingType) {
$aMenuBillingTypes[] = array('name' => $sHtmlIdBTypeLink . $sBillingType, 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . ".changeType(this, '" . $sBillingType . "')", 'target' => '_self', 'title' => _t('_bx_donations_txt_do_' . $sBillingType));
$aTypes = $this->_oDb->getTypes(array('type' => 'by_btype_' . $sBillingType, 'active' => 1));
if(empty($aTypes) || !is_array($aTypes))
continue;

$aTmplVarsTypes = array();

$aTypes = $this->_oDb->getTypes(array('type' => 'by_btype_' . $sBillingType));
foreach($aTypes as $aType) {
$sDuration = '';

Expand All @@ -78,7 +79,7 @@ public function getBlockMake($sSelected = 'single')

list($sJsCode, $sOnclick) = $aJs;

$sAmount = _t_format_currency($aType[$CNF['FIELD_PRICE']], getParam($CNF['PARAM_AMOUNT_PRECISION']));
$sAmount = _t_format_currency($aType[$CNF['FIELD_AMOUNT']], getParam($CNF['PARAM_AMOUNT_PRECISION']));
$sAmount = _t('_bx_donations_txt_amount_' . $sBillingType, $sAmount, $sDuration);

$aTmplVarsTypes[] = array(
Expand All @@ -93,19 +94,49 @@ public function getBlockMake($sSelected = 'single')
);
}

$aTmplVarsBillingTypes[] = array(
'class' => $sBillingType . ($sBillingType == $sSelected ? ' active' : ''),
if($bEnableOther)
$aTmplVarsTypes[] = array(
'onclick' => $sJsObject . ".other(this, '" . $sBillingType . "')",
'bx_if:show_title' => array(
'condition' => $bShowTitle,
'content' => array(
'title' => _t('_bx_donations_txt_other_title')
)
),
'amount' => _t('_bx_donations_txt_other_value')
);

$aTmplVarsBillingTypes[$sBillingType] = array(
'class' => $sBillingType,
'bx_repeat:types' => $aTmplVarsTypes
);

$aMenuBillingTypes[] = array('name' => $sHtmlIdBTypeLink . $sBillingType, 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . ".changeType(this, '" . $sBillingType . "')", 'target' => '_self', 'title' => _t('_bx_donations_txt_do_' . $sBillingType));
}

$oMenuBillingTypes = new BxTemplMenu(array('template' => 'menu_buttons_hor.html', 'menu_id'=> $this->_oConfig->getHtmlIds('menu_billing_types'), 'menu_items' => $aMenuBillingTypes));
$oMenuBillingTypes->setSelected('', $sHtmlIdBTypeLink . $sSelected);
$iTmplVarsBillingTypes = count($aTmplVarsBillingTypes);
if($iTmplVarsBillingTypes > 1 && isset($aTmplVarsBillingTypes[$sSelected]))
$aTmplVarsBillingTypes[$sSelected]['class'] .= ' active';
else if($iTmplVarsBillingTypes > 0)
$aTmplVarsBillingTypes[key($aTmplVarsBillingTypes)]['class'] .= ' active';

$aTmplVarsMenu = array();
if(count($aMenuBillingTypes) > 1) {
$oMenuBillingTypes = new BxTemplMenu(array('template' => 'menu_buttons_hor.html', 'menu_id'=> $this->_oConfig->getHtmlIds('menu_billing_types'), 'menu_items' => $aMenuBillingTypes));
$oMenuBillingTypes->setSelected('', $sHtmlIdBTypeLink . $sSelected);

$aTmplVarsMenu = array(
'menu_billing_type' => $oMenuBillingTypes->getCode(),
);
}

$sTmplName = 'block_make.html';
$aTmplVars = array(
'menu_billing_type' => $oMenuBillingTypes->getCode(),
'bx_repeat:billing_types' => $aTmplVarsBillingTypes,
'bx_if:show_menu' => array(
'condition' => !empty($aTmplVarsMenu),
'content' => $aTmplVarsMenu
),
'bx_repeat:billing_types' => array_values($aTmplVarsBillingTypes),
'js_code' => $sJsCode . $this->getJsCode('main')
);

Expand Down
14 changes: 10 additions & 4 deletions modules/boonex/donations/install/langs/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<!-- Settings -->
<string name="_bx_donations_option_show_title"><![CDATA[Show donation title in addition to amount]]></string>
<string name="_bx_donations_option_enable_other"><![CDATA[Enable 'Other' choice (can be used with One-Time donations).]]></string>
<string name="_bx_donations_option_amount_precision"><![CDATA[Number of digits after the decimal point in amounts]]></string>


Expand All @@ -26,9 +27,9 @@
<string name="_bx_donations_form_type_input_period_unit"><![CDATA[Period unit]]></string>
<string name="_bx_donations_form_type_input_inf_period_unit"><![CDATA[Leave empty for single time donation.]]></string>
<string name="_bx_donations_form_type_input_err_period_unit"><![CDATA[You need to select a period unit here.]]></string>
<string name="_bx_donations_form_type_input_sys_price"><![CDATA[Price]]></string>
<string name="_bx_donations_form_type_input_price"><![CDATA[Price]]></string>
<string name="_bx_donations_form_type_input_err_price"><![CDATA[You need to enter a price here.]]></string>
<string name="_bx_donations_form_type_input_sys_amount"><![CDATA[Amount]]></string>
<string name="_bx_donations_form_type_input_amount"><![CDATA[Amount]]></string>
<string name="_bx_donations_form_type_input_err_amount"><![CDATA[You need to enter a amount here.]]></string>

<string name="_bx_donations_form_type_input_sys_do_submit"><![CDATA[Submit]]></string>
<string name="_bx_donations_form_type_input_do_submit"><![CDATA[Submit]]></string>
Expand Down Expand Up @@ -71,10 +72,11 @@
<string name="_bx_donations_menu_item_title_list_submenu_list"><![CDATA[My Donations]]></string>

<!-- Grids -->
<string name="_bx_donations_grid_column_active"><![CDATA[Active]]></string>
<string name="_bx_donations_grid_column_name"><![CDATA[Name]]></string>
<string name="_bx_donations_grid_column_title"><![CDATA[Title]]></string>
<string name="_bx_donations_grid_column_period"><![CDATA[Period]]></string>
<string name="_bx_donations_grid_column_price"><![CDATA[Price]]></string>
<string name="_bx_donations_grid_column_amount"><![CDATA[Amount]]></string>
<string name="_bx_donations_grid_column_title_lst_profile_id"><![CDATA[Profile]]></string>
<string name="_bx_donations_grid_column_title_lst_entry"><![CDATA[Donation]]></string>
<string name="_bx_donations_grid_column_title_lst_billing_type"><![CDATA[Billing]]></string>
Expand All @@ -100,6 +102,7 @@
<string name="_bx_donations_msg_empty_owner"><![CDATA['Main seller' is empty. You need to mark some profile as 'Main seller' in Settings of currently active Payment app.]]></string>
<string name="_bx_donations_msg_performed"><![CDATA[The action was successfully performed.]]></string>
<string name="_bx_donations_err_price_duplicate"><![CDATA[Similar donation plan is already exists.]]></string>
<string name="_bx_donations_err_min_value"><![CDATA[The value should exceed {0}.]]></string>
<string name="_bx_donations_err_cannot_perform"><![CDATA[An error appeared. Please report.]]></string>

<!-- Other -->
Expand All @@ -115,4 +118,7 @@
<string name="_bx_donations_txt_do_single"><![CDATA[One-Time Donations]]></string>
<string name="_bx_donations_txt_do_recurring"><![CDATA[Recurring Donations]]></string>
<string name="_bx_donations_txt_cart_item_title"><![CDATA[Donation]]></string>
<string name="_bx_donations_txt_cart_item_description"><![CDATA[Donation on {0}]]></string>
<string name="_bx_donations_txt_other_title"><![CDATA[Your own value]]></string>
<string name="_bx_donations_txt_other_value"><![CDATA[Other]]></string>
</resources>
Loading

0 comments on commit c840e01

Please sign in to comment.