Procházet zdrojové kódy

Ticket #2356 - related changes in Paid Levels module.

AntonLV před 7 roky
rodič
revize
c87b050ee3

+ 29 - 20
inc/classes/BxDolAclQuery.php

@@ -318,33 +318,42 @@ class BxDolAclQuery extends BxDolDb implements iBxDolSingleton
     function insertLevelByProfileId($iProfileId, $iMembershipId, $iDateStarts, $aPeriod, $sTransactionId)
     function insertLevelByProfileId($iProfileId, $iMembershipId, $iDateStarts, $aPeriod, $sTransactionId)
     {
     {
     	$aBindings = array(
     	$aBindings = array(
-			'member_id' => $iProfileId,
-			'level_id' => $iMembershipId,
-			'transaction_id' => $sTransactionId,
-			'date_starts' => $iDateStarts
-		);
+            'member_id' => $iProfileId,
+            'level_id' => $iMembershipId,
+            'transaction_id' => $sTransactionId,
+            'date_starts' => $iDateStarts
+        );
 
 
     	$sSetClause = '';
     	$sSetClause = '';
     	if((int)$aPeriod['period'] != 0) {
     	if((int)$aPeriod['period'] != 0) {
-    		$aBindings['period'] = (int)$aPeriod['period'];
+            $aBindings['period'] = (int)$aPeriod['period'];
+
+            switch($aPeriod['period_unit']) {
+                case MEMBERSHIP_PERIOD_UNIT_DAY:
+                case MEMBERSHIP_PERIOD_UNIT_WEEK:
+                    if($aPeriod['period_unit'] == MEMBERSHIP_PERIOD_UNIT_WEEK)
+                        $aBindings['period'] *= 7;
+
+                    $sSetClause = "DATE_ADD(FROM_UNIXTIME(:date_starts), INTERVAL :period DAY)";
+                    break;
+
+                case MEMBERSHIP_PERIOD_UNIT_MONTH:
+                    $sSetClause = "DATE_ADD(FROM_UNIXTIME(:date_starts), INTERVAL :period MONTH)";
+                    break;
 
 
-	    	switch($aPeriod['period_unit']) {
-	    		case MEMBERSHIP_PERIOD_UNIT_DAY:
-	    		case MEMBERSHIP_PERIOD_UNIT_WEEK:
-	    			if($aPeriod['period_unit'] == MEMBERSHIP_PERIOD_UNIT_WEEK)
-	    				$aBindings['period'] *= 7;
+                case MEMBERSHIP_PERIOD_UNIT_YEAR:
+                    $sSetClause = "DATE_ADD(FROM_UNIXTIME(:date_starts), INTERVAL :period YEAR)";
+                    break;
+            }
 
 
-	    			$sSetClause = ", `DateExpires`=DATE_ADD(FROM_UNIXTIME(:date_starts), INTERVAL :period DAY)";
-	    			break;
+            if(!empty($sSetClause) && !empty($aPeriod['period_reserve'])) {
+                $aBindings['reserve'] = (int)$aPeriod['period_reserve'];
 
 
-	    		case MEMBERSHIP_PERIOD_UNIT_MONTH:
-	    			$sSetClause = ", `DateExpires`=DATE_ADD(FROM_UNIXTIME(:date_starts), INTERVAL :period MONTH)";
-	    			break;
+                $sSetClause = "DATE_ADD(" . $sSetClause . ", INTERVAL :reserve DAY)";
+            }
 
 
-	    		case MEMBERSHIP_PERIOD_UNIT_YEAR:
-	    			$sSetClause = ", `DateExpires`=DATE_ADD(FROM_UNIXTIME(:date_starts), INTERVAL :period YEAR)";
-	    			break;
-	    	}
+            if(!empty($sSetClause))
+                $sSetClause = ", `DateExpires`=" . $sSetClause;
     	}
     	}
 
 
         $sQuery = $this->prepare("INSERT `sys_acl_levels_members` SET `IDMember`=:member_id, `IDLevel`=:level_id, `DateStarts`=FROM_UNIXTIME(:date_starts), `TransactionID`=:transaction_id" . $sSetClause);
         $sQuery = $this->prepare("INSERT `sys_acl_levels_members` SET `IDMember`=:member_id, `IDLevel`=:level_id, `DateStarts`=FROM_UNIXTIME(:date_starts), `TransactionID`=:transaction_id" . $sSetClause);

+ 23 - 18
modules/boonex/acl/classes/BxAclConfig.php

@@ -28,36 +28,41 @@ class BxAclConfig extends BxBaseModGeneralConfig
         parent::__construct($aModule);
         parent::__construct($aModule);
 
 
         $this->CNF = array (
         $this->CNF = array (
-        	'TABLE_PRICES' => $aModule['db_prefix'] . 'level_prices',
+            'TABLE_PRICES' => $aModule['db_prefix'] . 'level_prices',
 
 
-        	'URL_ADMINISTRATION' => 'page.php?i=acl-administration',
-        	'URL_VIEW' => 'page.php?i=acl-view',
+            // page URIs
+            'URL_ADMINISTRATION' => 'page.php?i=acl-administration',
+            'URL_VIEW' => 'page.php?i=acl-view',
 
 
-        	'OBJECT_GRID_ADMINISTRATION' => 'bx_acl_administration',
-        	'OBJECT_GRID_VIEW' => 'bx_acl_view',
-        	'OBJECT_FORM_PRICE' => 'bx_acl_price',
+            // some params
+            'PARAM_RECURRING_RESERVE' => 'bx_acl_recurring_reserve',
+
+            // objects 
+            'OBJECT_GRID_ADMINISTRATION' => 'bx_acl_administration',
+            'OBJECT_GRID_VIEW' => 'bx_acl_view',
+            'OBJECT_FORM_PRICE' => 'bx_acl_price',
             'OBJECT_FORM_PRICE_DISPLAY_ADD' => 'bx_acl_price_add',
             'OBJECT_FORM_PRICE_DISPLAY_ADD' => 'bx_acl_price_add',
-        	'OBJECT_FORM_PRICE_DISPLAY_EDIT' => 'bx_acl_price_edit',
-        	'OBJECT_FORM_PRELISTS_PERIOD_UNITS' => 'bx_acl_period_units',
+            'OBJECT_FORM_PRICE_DISPLAY_EDIT' => 'bx_acl_price_edit',
+            'OBJECT_FORM_PRELISTS_PERIOD_UNITS' => 'bx_acl_period_units',
         );
         );
 
 
-		$this->_aGridObjects = array(
-			'administration' => $this->CNF['OBJECT_GRID_ADMINISTRATION'],
-			'view' => $this->CNF['OBJECT_GRID_VIEW'],
-		);
+        $this->_aGridObjects = array(
+            'administration' => $this->CNF['OBJECT_GRID_ADMINISTRATION'],
+            'view' => $this->CNF['OBJECT_GRID_VIEW'],
+        );
 
 
-		$this->_aPrefixes = array(
-        	'style' => 'bx-acl',
-        	'option' => 'bx_acl_',
+        $this->_aPrefixes = array(
+            'style' => 'bx-acl',
+            'option' => 'bx_acl_',
         );
         );
 
 
         $this->_aJsClasses = array(
         $this->_aJsClasses = array(
-        	'main' => 'BxAclMain',
-        	'administration' => 'BxAclAdministration',
+            'main' => 'BxAclMain',
+            'administration' => 'BxAclAdministration',
         );
         );
         $this->_aJsObjects = array(
         $this->_aJsObjects = array(
             'main' => 'oAclMain',
             'main' => 'oAclMain',
-	        'administration' => 'oAclAdministration',
+            'administration' => 'oAclAdministration',
         );
         );
 
 
         $sHtmlPrefix = str_replace('_', '-', $this->_sName);
         $sHtmlPrefix = str_replace('_', '-', $this->_sName);

+ 14 - 8
modules/boonex/acl/classes/BxAclModule.php

@@ -457,20 +457,26 @@ class BxAclModule extends BxDolModule
     
     
     protected function _serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, $sType)
     protected function _serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, $sType)
     {
     {
+        $CNF = &$this->_oConfig->CNF;
+
     	$aItem = $this->serviceGetCartItem($iItemId);
     	$aItem = $this->serviceGetCartItem($iItemId);
         if(empty($aItem) || !is_array($aItem))
         if(empty($aItem) || !is_array($aItem))
-			return array();
+            return array();
+
+        $oAcl = BxDolAcl::getInstance();
 
 
         $aItemInfo = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemId));
         $aItemInfo = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemId));
+        $aMembershipInfo = $oAcl->getMemberMembershipInfo($iClientId);
+
+        $aPeriod = array('period' => (int)$aItemInfo['period'], 'period_unit' => $aItemInfo['period_unit']);
+        if($sType == BX_ACL_LICENSE_TYPE_RECURRING && (int)$aItemInfo['trial'] > 0 && (int)$aItemInfo['level_id'] != (int)$aMembershipInfo['id'])
+            $aPeriod = array('period' => (int)$aItemInfo['trial'], 'period_unit' => 'day');
 
 
-        $iPeriod = (int)$aItemInfo['period'];
-        $sPeriodUnit = $aItemInfo['period_unit'];
-		if($sType == BX_ACL_LICENSE_TYPE_RECURRING && (int)$aItemInfo['trial'] > 0) {
-		    $iPeriod = (int)$aItemInfo['trial'];
-		    $sPeriodUnit = 'day';
-		}
+        $iReserve = (int)getParam($CNF['PARAM_RECURRING_RESERVE']);
+        if(!empty($iReserve))
+            $aPeriod['period_reserve'] = $iReserve;
 
 
-        if(!BxDolAcl::getInstance()->setMembership($iClientId, $aItemInfo['level_id'], array('period' => $iPeriod, 'period_unit' => $sPeriodUnit), false, $sLicense))
+        if(!$oAcl->setMembership($iClientId, $aItemInfo['level_id'], $aPeriod, true, $sLicense))
             return array();
             return array();
 
 
         return $aItem;
         return $aItem;

+ 15 - 11
modules/boonex/acl/classes/BxAclStudioPage.php

@@ -9,10 +9,12 @@
  * @{
  * @{
  */
  */
 
 
+define('BX_DOL_STUDIO_MOD_TYPE_MANAGE', 'manage');
+
 class BxAclStudioPage extends BxTemplStudioModule
 class BxAclStudioPage extends BxTemplStudioModule
 {
 {
-	protected $MODULE;
-	protected $_oModule;
+    protected $MODULE;
+    protected $_oModule;
 
 
     function __construct($sModule = "", $sPage = "")
     function __construct($sModule = "", $sPage = "")
     {
     {
@@ -20,29 +22,31 @@ class BxAclStudioPage extends BxTemplStudioModule
     	$this->_oModule = BxDolModule::getInstance($this->MODULE);
     	$this->_oModule = BxDolModule::getInstance($this->MODULE);
 
 
         parent::__construct($sModule, $sPage);
         parent::__construct($sModule, $sPage);
+
+        $this->aMenuItems[] = array('name' => BX_DOL_STUDIO_MOD_TYPE_MANAGE, 'icon' => 'wrench', 'title' => '_bx_acl_lmi_cpt_manage');
     }
     }
 
 
-    protected function getSettings()
+    protected function getManage()
     {
     {
-	    if (!isAdmin()) {
+        if (!isAdmin()) {
             $this->_oTemplate->displayAccessDenied();
             $this->_oTemplate->displayAccessDenied();
             return;
             return;
         }
         }
 
 
     	$sContent = '';
     	$sContent = '';
 
 
-		$sGrid = $this->_oModule->_oConfig->getGridObject('administration');
-		$oGrid = BxDolGrid::getObjectInstance($sGrid, BxDolStudioTemplate::getInstance());
+        $sGrid = $this->_oModule->_oConfig->getGridObject('administration');
+        $oGrid = BxDolGrid::getObjectInstance($sGrid, BxDolStudioTemplate::getInstance());
         if(!$oGrid)
         if(!$oGrid)
             return $sContent;
             return $sContent;
 
 
-		if($this->_oModule->_oConfig->getOwner() == 0)
-			$sContent .= $this->_oModule->_oTemplate->displayEmptyOwner();
+        if($this->_oModule->_oConfig->getOwner() == 0)
+            $sContent .= $this->_oModule->_oTemplate->displayEmptyOwner();
 
 
-		$sContent .= $this->_oModule->_oTemplate->getJsCode('administration', array('sObjNameGrid' => $sGrid));
-		$sContent .= $oGrid->getCode();
+        $sContent .= $this->_oModule->_oTemplate->getJsCode('administration', array('sObjNameGrid' => $sGrid));
+        $sContent .= $oGrid->getCode();
 
 
-		return $sContent;
+        return $sContent;
     }
     }
 }
 }
 
 

+ 9 - 1
modules/boonex/acl/install/langs/en.xml

@@ -1,8 +1,12 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
 <resources name="en" flag="gb" title="English">
 <resources name="en" flag="gb" title="English">
-
 	<string name="_bx_acl"><![CDATA[Paid Levels]]></string>
 	<string name="_bx_acl"><![CDATA[Paid Levels]]></string>
 
 
+
+        <!-- Option -->
+        <string name="_bx_acl_option_recurring_reserve"><![CDATA[Reserve (in days) to accept and process recurring payment notification]]></string>
+
+
 	<!-- Pages -->
 	<!-- Pages -->
 	<string name="_bx_acl_page_title_sys_view"><![CDATA[Membership]]></string>
 	<string name="_bx_acl_page_title_sys_view"><![CDATA[Membership]]></string>
 	<string name="_bx_acl_page_title_view"><![CDATA[Membership]]></string>
 	<string name="_bx_acl_page_title_view"><![CDATA[Membership]]></string>
@@ -10,6 +14,10 @@
 	<string name="_bx_acl_page_block_title_view"><![CDATA[Membership]]></string>
 	<string name="_bx_acl_page_block_title_view"><![CDATA[Membership]]></string>
 
 
 
 
+        <!-- Menus -->
+        <string name="_bx_acl_lmi_cpt_manage"><![CDATA[Manage]]></string>
+
+
 	<!-- Forms -->
 	<!-- Forms -->
 	<string name="_bx_acl_form_price"><![CDATA[Price]]></string>
 	<string name="_bx_acl_form_price"><![CDATA[Price]]></string>
 	<string name="_bx_acl_form_price_display_add"><![CDATA[Add]]></string>
 	<string name="_bx_acl_form_price_display_add"><![CDATA[Add]]></string>

+ 8 - 8
modules/boonex/acl/install/sql/disable.sql

@@ -1,6 +1,14 @@
 SET @sName = 'bx_acl';
 SET @sName = 'bx_acl';
 
 
 
 
+-- SETTINGS
+SET @iTypeId = (SELECT `ID` FROM `sys_options_types` WHERE `name` = @sName LIMIT 1);
+SET @iCategId = (SELECT `ID` FROM `sys_options_categories` WHERE `type_id` = @iTypeId LIMIT 1);
+DELETE FROM `sys_options` WHERE `category_id` = @iCategId;
+DELETE FROM `sys_options_categories` WHERE `type_id` = @iTypeId;
+DELETE FROM `sys_options_types` WHERE `id` = @iTypeId;
+
+
 -- PAGES
 -- PAGES
 DELETE FROM `sys_objects_page` WHERE `module` = @sName;
 DELETE FROM `sys_objects_page` WHERE `module` = @sName;
 DELETE FROM `sys_pages_blocks` WHERE `module` = @sName;
 DELETE FROM `sys_pages_blocks` WHERE `module` = @sName;
@@ -12,14 +20,6 @@ DELETE FROM `sys_menu_sets` WHERE `module` = @sName;
 DELETE FROM `sys_menu_items` WHERE `module` = @sName;
 DELETE FROM `sys_menu_items` WHERE `module` = @sName;
 
 
 
 
--- SETTINGS
--- SET @iTypeId = (SELECT `ID` FROM `sys_options_types` WHERE `name` = @sName LIMIT 1);
--- SET @iCategId = (SELECT `ID` FROM `sys_options_categories` WHERE `type_id` = @iTypeId LIMIT 1);
--- DELETE FROM `sys_options` WHERE `category_id` = @iCategId;
--- DELETE FROM `sys_options_categories` WHERE `type_id` = @iTypeId;
--- DELETE FROM `sys_options_types` WHERE `id` = @iTypeId;
-
-
 -- ALERTS
 -- ALERTS
 SET @iHandlerId = (SELECT `id` FROM `sys_alerts_handlers` WHERE `name` = @sName LIMIT 1);
 SET @iHandlerId = (SELECT `id` FROM `sys_alerts_handlers` WHERE `name` = @sName LIMIT 1);
 DELETE FROM `sys_alerts` WHERE `handler_id` = @iHandlerId;
 DELETE FROM `sys_alerts` WHERE `handler_id` = @iHandlerId;

+ 14 - 14
modules/boonex/acl/install/sql/enable.sql

@@ -1,6 +1,20 @@
 SET @sName = 'bx_acl';
 SET @sName = 'bx_acl';
 
 
 
 
+-- SETTINGS
+SET @iTypeOrder = (SELECT MAX(`order`) FROM `sys_options_types` WHERE `group` = 'modules');
+INSERT INTO `sys_options_types`(`group`, `name`, `caption`, `icon`, `order`) VALUES 
+('modules', @sName, '_bx_acl', 'bx_acl@modules/boonex/acl/|std-icon.svg', IF(ISNULL(@iTypeOrder), 1, @iTypeOrder + 1));
+SET @iTypeId = LAST_INSERT_ID();
+
+INSERT INTO `sys_options_categories` (`type_id`, `name`, `caption`, `order`)
+VALUES (@iTypeId, @sName, '_bx_acl', 1);
+SET @iCategId = LAST_INSERT_ID();
+
+INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `check`, `check_error`, `extra`, `order`) VALUES
+('bx_acl_recurring_reserve', '2', @iCategId, '_bx_acl_option_recurring_reserve', 'digit', '', '', '', 1);
+
+
 -- PAGE: view levels
 -- PAGE: view levels
 INSERT INTO `sys_objects_page`(`object`, `title_system`, `title`, `module`, `layout_id`, `visible_for_levels`, `visible_for_levels_editable`, `uri`, `url`, `meta_description`, `meta_keywords`, `meta_robots`, `cache_lifetime`, `cache_editable`, `deletable`, `override_class_name`, `override_class_file`) VALUES 
 INSERT INTO `sys_objects_page`(`object`, `title_system`, `title`, `module`, `layout_id`, `visible_for_levels`, `visible_for_levels_editable`, `uri`, `url`, `meta_description`, `meta_keywords`, `meta_robots`, `cache_lifetime`, `cache_editable`, `deletable`, `override_class_name`, `override_class_file`) VALUES 
 ('bx_acl_view', '_bx_acl_page_title_sys_view', '_bx_acl_page_title_view', @sName, 5, 2147483647, 1, 'acl-view', 'page.php?i=acl-view', '', '', '', 0, 1, 0, 'BxAclPageView', 'modules/boonex/acl/classes/BxAclPageView.php');
 ('bx_acl_view', '_bx_acl_page_title_sys_view', '_bx_acl_page_title_view', @sName, 5, 2147483647, 1, 'acl-view', 'page.php?i=acl-view', '', '', '', 0, 1, 0, 'BxAclPageView', 'modules/boonex/acl/classes/BxAclPageView.php');
@@ -15,20 +29,6 @@ INSERT INTO `sys_menu_items` (`set_name`, `module`, `name`, `title_system`, `tit
 ('sys_account_settings', 'bx_acl', 'acl-view', '_bx_acl_menu_item_title_system_acl_view', '_bx_acl_menu_item_title_acl_view', 'page.php?i=acl-view', '', '', 'shield-alt col-red2', '', '', 2147483646, 1, 0, 1, @iMoAccountSettings + 1);
 ('sys_account_settings', 'bx_acl', 'acl-view', '_bx_acl_menu_item_title_system_acl_view', '_bx_acl_menu_item_title_acl_view', 'page.php?i=acl-view', '', '', 'shield-alt col-red2', '', '', 2147483646, 1, 0, 1, @iMoAccountSettings + 1);
 
 
 
 
--- SETTINGS
--- SET @iTypeOrder = (SELECT MAX(`order`) FROM `sys_options_types` WHERE `group` = 'modules');
--- INSERT INTO `sys_options_types`(`group`, `name`, `caption`, `icon`, `order`) VALUES 
--- ('modules', @sName, '_bx_acl', 'bx_acl@modules/boonex/acl/|std-icon.svg', IF(ISNULL(@iTypeOrder), 1, @iTypeOrder + 1));
--- SET @iTypeId = LAST_INSERT_ID();
-
--- INSERT INTO `sys_options_categories` (`type_id`, `name`, `caption`, `order`)
--- VALUES (@iTypeId, @sName, '_bx_acl', 1);
--- SET @iCategId = LAST_INSERT_ID();
-
--- INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `check`, `check_error`, `extra`, `order`) VALUES
--- ('bx_acl_remove_expired_for', '30', @iCategId, '_bx_acl_option_remove_expired_for', 'digit', '', '', '', 3);
-
-
 -- ALERTS
 -- ALERTS
 INSERT INTO `sys_alerts_handlers`(`name`, `class`, `file`, `service_call`) VALUES 
 INSERT INTO `sys_alerts_handlers`(`name`, `class`, `file`, `service_call`) VALUES 
 (@sName, 'BxAclResponse', 'modules/boonex/acl/classes/BxAclResponse.php', '');
 (@sName, 'BxAclResponse', 'modules/boonex/acl/classes/BxAclResponse.php', '');

+ 9 - 1
modules/boonex/russian/data/langs/bx_acl/ru.xml

@@ -1,13 +1,21 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
 <resources name="ru" flag="ru" title="Russian">
 <resources name="ru" flag="ru" title="Russian">
-
 	<string name="_bx_acl"><![CDATA[Платные Уровни]]></string>
 	<string name="_bx_acl"><![CDATA[Платные Уровни]]></string>
 
 
+
+        <!-- Options -->
+        <string name="_bx_acl_option_recurring_reserve"><![CDATA[Резерв (в днях) на принятие и обработку сообщения об оплате подписки.]]></string>
+
+
 	<!-- Pages -->
 	<!-- Pages -->
 	<string name="_bx_acl_page_title_sys_view"><![CDATA[Членство]]></string>
 	<string name="_bx_acl_page_title_sys_view"><![CDATA[Членство]]></string>
 	<string name="_bx_acl_page_title_view"><![CDATA[Членство]]></string>
 	<string name="_bx_acl_page_title_view"><![CDATA[Членство]]></string>
 	<string name="_bx_acl_page_block_title_system_view"><![CDATA[Членство]]></string>
 	<string name="_bx_acl_page_block_title_system_view"><![CDATA[Членство]]></string>
 	<string name="_bx_acl_page_block_title_view"><![CDATA[Членство]]></string>
 	<string name="_bx_acl_page_block_title_view"><![CDATA[Членство]]></string>
+
+
+        <!-- Menus -->
+        <string name="_bx_acl_lmi_cpt_manage"><![CDATA[Управление]]></string>
 	
 	
 
 
 	<!-- Forms -->
 	<!-- Forms -->