Răsfoiți Sursa

Ticket #2892 - Point №1. Usage in Market and Paid Levels.

AntonLV 6 ani în urmă
părinte
comite
2b973f41a0

+ 43 - 19
modules/boonex/acl/classes/BxAclGridView.php

@@ -13,15 +13,23 @@ require_once('BxAclGridLevels.php');
 
 class BxAclGridView extends BxAclGridLevels
 {
-	protected $_iOwner;
-	protected $_oPayment;
-	protected $_bTypeSingle;
-	protected $_bTypeRecurring;
+    /**
+     * Array with check_sum => JS_code pairs of all JS codes 
+     * which should be added to the page.
+     */
+    protected $_aJsCodes;
+
+    protected $_iOwner;
+    protected $_oPayment;
+    protected $_bTypeSingle;
+    protected $_bTypeRecurring;
 
     public function __construct ($aOptions, $oTemplate = false)
     {
         parent::__construct ($aOptions, $oTemplate);
 
+        $this->_aJsCodes = array();
+
         $this->_iOwner = $this->_oModule->_oConfig->getOwner();
         $this->_oPayment = BxDolPayments::getInstance();
         $this->_bTypeSingle = $this->_oPayment->isAcceptingPayments($this->_iOwner, BX_PAYMENT_TYPE_SINGLE);
@@ -52,7 +60,15 @@ class BxAclGridView extends BxAclGridLevels
 
     public function getCode($isDisplayHeader = true)
     {
-    	return $this->_oPayment->getCartJs() . parent::getCode($isDisplayHeader);
+    	return parent::getCode($isDisplayHeader) . $this->getJsCode();
+    }
+
+    public function getJsCode()
+    {
+        if(empty($this->_aJsCodes) || !is_array($this->_aJsCodes))
+            return '';
+
+        return implode('', $this->_aJsCodes);
     }
 
     protected function _getCellLevelIcon($mixedValue, $sKey, $aField, $aRow)
@@ -69,19 +85,23 @@ class BxAclGridView extends BxAclGridLevels
         return  parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
     }
 
-	protected function _getActionBuy ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
+    protected function _getActionBuy ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
     {
         if((float)$aRow['price'] == 0 || !$this->_bTypeSingle || $this->_bTypeRecurring)
             return '';
 
     	$aJs = $this->_oPayment->getAddToCartJs($this->_iOwner, $this->MODULE, $aRow['id'], 1, true);
     	if(!empty($aJs) && is_array($aJs)) {
-    		list($sJsCode, $sJsMethod) = $aJs;
+            list($sJsCode, $sJsMethod) = $aJs;
 
-    		$a['attr'] = array(
-    		    'title' => bx_html_attribute(_t('_bx_acl_grid_action_buy_title')),
-    			'onclick' => $sJsMethod
-    		);
+            $sJsCodeCheckSum = md5($sJsCode);
+            if(!isset($this->_aJsCodes[$sJsCodeCheckSum]))
+                $this->_aJsCodes[$sJsCodeCheckSum] = $sJsCode;
+
+            $a['attr'] = array(
+                'title' => bx_html_attribute(_t('_bx_acl_grid_action_buy_title')),
+                'onclick' => $sJsMethod
+            );
     	}
 
         return  parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
@@ -93,16 +113,20 @@ class BxAclGridView extends BxAclGridLevels
             return '';
 
     	$aJs = $this->_oPayment->getSubscribeJs($this->_iOwner, '', $this->MODULE, $aRow['id'], 1);
-		if(!empty($aJs) && is_array($aJs)) {
-			list($sJsCode, $sJsMethod) = $aJs;
+        if(!empty($aJs) && is_array($aJs)) {
+            list($sJsCode, $sJsMethod) = $aJs;
+
+            $sJsCodeCheckSum = md5($sJsCode);
+            if(!isset($this->_aJsCodes[$sJsCodeCheckSum]))
+                $this->_aJsCodes[$sJsCodeCheckSum] = $sJsCode;
 
-    		$a['attr'] = array(
-    			'title' => bx_html_attribute(_t('_bx_acl_grid_action_subscribe_title')),
-    			'onclick' => $sJsMethod
-    		);
-		}
+            $a['attr'] = array(
+                'title' => bx_html_attribute(_t('_bx_acl_grid_action_subscribe_title')),
+                'onclick' => $sJsMethod
+            );
+        }
 
-    	return  parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
+    	return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
     }
 }
 

+ 28 - 1
modules/boonex/market/classes/BxMarketMenuView.php

@@ -14,11 +14,20 @@
  */
 class BxMarketMenuView extends BxBaseModTextMenuView
 {
+    /**
+     * Array with check_sum => JS_code pairs of all JS codes 
+     * which should be added to the page.
+     */
+    protected $_aJsCodes;
+
     public function __construct($aObject, $oTemplate = false)
     {
         $this->MODULE = 'bx_market';
+
         parent::__construct($aObject, $oTemplate);
 
+        $this->_aJsCodes = array();
+
         $this->addMarkers(array(
             'js_object' => $this->_oModule->_oConfig->getJsObject('entry')
         ));
@@ -26,7 +35,15 @@ class BxMarketMenuView extends BxBaseModTextMenuView
 
     public function getCode ()
     {
-    	return parent::getCode() . BxDolPayments::getInstance()->getCartJs();
+    	return parent::getCode() . $this->getJsCode();
+    }
+
+    public function getJsCode()
+    {
+        if(empty($this->_aJsCodes) || !is_array($this->_aJsCodes))
+            return '';
+
+        return implode('', $this->_aJsCodes);
     }
 
     protected function _isVisible ($a)
@@ -59,6 +76,11 @@ class BxMarketMenuView extends BxBaseModTextMenuView
                     break;
 
                 list($sJsCode, $sJsMethod) = $aJs;
+
+                $sJsCodeCheckSum = md5($sJsCode);
+                if(!isset($this->_aJsCodes[$sJsCodeCheckSum]))
+                    $this->_aJsCodes[$sJsCodeCheckSum] = $sJsCode;
+
                 $aCurrency = $this->_oModule->_oConfig->getCurrency();
 
                 $bResult = true;
@@ -87,6 +109,11 @@ class BxMarketMenuView extends BxBaseModTextMenuView
                     break;
 
                 list($sJsCode, $sJsMethod) = $aJs;
+
+                $sJsCodeCheckSum = md5($sJsCode);
+                if(!isset($this->_aJsCodes[$sJsCodeCheckSum]))
+                    $this->_aJsCodes[$sJsCodeCheckSum] = $sJsCode;
+
                 $aCurrency = $this->_oModule->_oConfig->getCurrency();
 
                 $bResult = true;

+ 10 - 0
modules/boonex/market/classes/BxMarketMenuViewActions.php

@@ -21,6 +21,16 @@ class BxMarketMenuViewActions extends BxBaseModTextMenuViewActions
         parent::__construct($aObject, $oTemplate);
     }
 
+    public function getCode ()
+    {
+        $sCode = parent::getCode();
+
+        if(!empty($this->_oMenuActions))
+            $sCode .= $this->_oMenuActions->getJsCode();
+
+    	return $sCode;
+    }
+    
     protected function _getMenuItemDownload($aItem)
     {
         return $this->_getMenuItemByNameActions($aItem);