Просмотр исходного кода

Ticket #4971 - Build-in API support: Transfer page blocks/menu items params into the app.

AntonLV 7 месяцев назад
Родитель
Сommit
9d7aeeeec1
3 измененных файлов с 57 добавлено и 2 удалено
  1. 30 0
      inc/classes/BxDolMenu.php
  2. 7 1
      template/scripts/BxBaseMenu.php
  3. 20 1
      template/scripts/BxBasePage.php

+ 30 - 0
inc/classes/BxDolMenu.php

@@ -530,6 +530,36 @@ class BxDolMenu extends BxDolFactory implements iBxDolFactoryObject, iBxDolRepla
         return $sHiddenOnCssClasses;
     }
 
+    protected function _updateVisibilityParamsAPI(&$a)
+    {
+        $aValues = [
+            'hidden_on' => [
+                pow(2, BX_DB_HIDDEN_PHONE - 1) => 'phone',
+                pow(2, BX_DB_HIDDEN_TABLET - 1) => 'tablet',
+                pow(2, BX_DB_HIDDEN_DESKTOP - 1) => 'desktop',
+                pow(2, BX_DB_HIDDEN_MOBILE - 1) => 'mobile-app'
+            ],
+            'hidden_on_col' => [
+                pow(2, 0) => 'thin-col',
+                pow(2, 1) => 'half-col',
+                pow(2, 2) => 'wide-col',
+                pow(2, 3) => 'full-col'
+            ]
+        ];
+
+        foreach(['hidden_on', 'hidden_on_col'] as $sK)
+            if(!empty($a[$sK])) {
+                $aHoResults = [];
+                foreach($aValues[$sK] as $iHiddenOn => $sHiddenOn)
+                    if((int)$a[$sK] & $iHiddenOn)
+                        $aHoResults[] = $sHiddenOn;
+
+                $a[$sK] = $aHoResults;
+            }
+            else
+                $a[$sK] = false;
+    }
+
     /**
      * Replace provided markers in menu item array, curently markers are replaced in title, link and onclick fields.
      * @param $a menu item array

+ 7 - 1
template/scripts/BxBaseMenu.php

@@ -317,7 +317,9 @@ class BxBaseMenu extends BxDolMenu
 
         if ($this->_bIsApi) {
             list ($sIcon, $sIconUrl, $sIconA, $sIconHtml) = $this->_getMenuIcon($a);
-
+if($this->_sObject == 'sys_site') {
+    var_dump($a); exit;
+}
             $aResult = [
                 'id' => $a['id'],
                 'name' => $a['name'],
@@ -328,11 +330,15 @@ class BxBaseMenu extends BxDolMenu
                 'image' => $sIconUrl ? $sIconUrl : '',
                 'submenu' => !empty($a['submenu_object']) ? $a['submenu_object'] : '',
                 'addon' => $this->_bDisplayAddons ? $this->_getMenuAddon($a) : '',
+                'hidden_on' => isset($a['hidden_on']) ? $a['hidden_on'] : false,
+                'hidden_on_col' => isset($a['hidden_on_col']) ? $a['hidden_on_col'] : false,
                 'config' => isset($a['config_api']) ? $a['config_api'] : '',
                 'primary' => isset($a['primary']) ? $a['primary'] : 0,
                 'persistent' => isset($a['persistent']) ? $a['persistent'] : 0,
             ];
 
+            $this->_updateVisibilityParamsAPI($aResult);
+
             if(($aMarkers = $this->_getMenuMarkers($a)) && is_array($aMarkers))
                 $this->addMarkers($aMarkers);
             $aResult = $this->_replaceMarkers($aResult);

+ 20 - 1
template/scripts/BxBasePage.php

@@ -741,8 +741,15 @@ class BxBasePage extends BxDolPage
 
     public function getPageBlocksAPI($aBlocks = [])
     {
+        $aHiddenOn = [
+            pow(2, BX_DB_HIDDEN_PHONE - 1) => 'phone',
+            pow(2, BX_DB_HIDDEN_TABLET - 1) => 'tablet',
+            pow(2, BX_DB_HIDDEN_DESKTOP - 1) => 'desktop',
+            pow(2, BX_DB_HIDDEN_MOBILE - 1) => 'mobile-app'
+        ];
+        $aFieldsUnset = ['object', 'cell_id', 'title_system', 'class', 'submenu', 'tabs', 'async', 'visible_for_levels', 'type', 'text', 'text_updated', 'help', 'cache_lifetime', 'active', 'active_api', 'copyable', 'deletable', 'order'];
+
         $bBlocks = !empty($aBlocks) && is_array($aBlocks);
-        $aFieldsUnset = ['object', 'cell_id', 'title_system', 'class', 'submenu', 'tabs', 'async', 'visible_for_levels', 'hidden_on', 'type', 'text', 'text_updated', 'help', 'cache_lifetime', 'active', 'active_api', 'copyable', 'deletable', 'order'];
 
         $aCells = $this->_oQuery->getPageBlocks(true);
         foreach($aCells as $sKey => &$aCell) {
@@ -793,6 +800,18 @@ class BxBasePage extends BxDolPage
                     'source' => $sSource
                 ]);
 
+                if(($sK = 'hidden_on') && !empty($aBlock[$sK])) {
+                    $aHoResults = [];
+                    foreach($aHiddenOn as $iHiddenOn => $sHiddenOn)
+                        if((int)$aBlock[$sK] & $iHiddenOn)
+                            $aHoResults[] = $sHiddenOn;
+
+                    $aCells[$sKey][$i][$sK] = $aHoResults;
+                }
+                else 
+                    $aCells[$sKey][$i][$sK] = false;
+                    
+
                 $aCells[$sKey][$i] = array_diff_key($aCells[$sKey][$i], array_flip($aFieldsUnset));
             }
         }