소스 검색

Ticket #4558 - Build-in API support: Courses.

AntonLV 2 년 전
부모
커밋
8a657b0af2

+ 8 - 0
modules/boonex/courses/classes/BxCoursesGridCntDataManage.php

@@ -72,6 +72,14 @@ class BxCoursesGridCntDataManage extends BxTemplGrid
         return parent::getCode($isDisplayHeader);
         return parent::getCode($isDisplayHeader);
     }
     }
 
 
+    public function getCodeAPI($bForceReturn = false)
+    {
+        if(empty($this->_aNodeInfo) || !is_array($this->_aNodeInfo) || $this->_aNodeInfo['level'] != $this->_iLevelMax)
+            return [];
+
+        return parent::getCodeAPI($bForceReturn);
+    }
+
     protected function _getCellContentId($mixedValue, $sKey, $aField, $aRow)
     protected function _getCellContentId($mixedValue, $sKey, $aField, $aRow)
     {
     {
         $iContentId = (int)$mixedValue;
         $iContentId = (int)$mixedValue;

+ 17 - 6
modules/boonex/courses/classes/BxCoursesGridCntStructureManage.php

@@ -78,6 +78,14 @@ class BxCoursesGridCntStructureManage extends BxTemplGrid
         return parent::getCode($isDisplayHeader);
         return parent::getCode($isDisplayHeader);
     }
     }
 
 
+    public function getCodeAPI($bForceReturn = false)
+    {
+        if($this->_iLevel > $this->_iLevelMax)
+            return [];
+
+        return parent::getCodeAPI($bForceReturn);
+    }
+
     public function performActionAdd()
     public function performActionAdd()
     {
     {
     	$CNF = &$this->_oModule->_oConfig->CNF;
     	$CNF = &$this->_oModule->_oConfig->CNF;
@@ -179,7 +187,7 @@ class BxCoursesGridCntStructureManage extends BxTemplGrid
     protected function _getCellHeaderCnL2($sKey, $aField)
     protected function _getCellHeaderCnL2($sKey, $aField)
     {
     {
         if($this->_iLevelMax < 2 || $this->_iLevel >= 2)
         if($this->_iLevelMax < 2 || $this->_iLevel >= 2)
-            return '';
+            return $this->_bIsApi ? [] : '';
 
 
         $aField['title'] = ucfirst($this->_aLevelToNodePl[2]);
         $aField['title'] = ucfirst($this->_aLevelToNodePl[2]);
         return parent::_getCellHeaderDefault($sKey, $aField);
         return parent::_getCellHeaderDefault($sKey, $aField);
@@ -188,7 +196,7 @@ class BxCoursesGridCntStructureManage extends BxTemplGrid
     protected function _getCellHeaderCnL3($sKey, $aField)
     protected function _getCellHeaderCnL3($sKey, $aField)
     {
     {
         if($this->_iLevelMax < 3 || $this->_iLevel >= 3)
         if($this->_iLevelMax < 3 || $this->_iLevel >= 3)
-            return '';
+            return $this->_bIsApi ? [] : '';
 
 
         $aField['title'] = ucfirst($this->_aLevelToNodePl[3]);
         $aField['title'] = ucfirst($this->_aLevelToNodePl[3]);
         return parent::_getCellHeaderDefault($sKey, $aField);
         return parent::_getCellHeaderDefault($sKey, $aField);
@@ -197,13 +205,16 @@ class BxCoursesGridCntStructureManage extends BxTemplGrid
     protected function _getCellHeaderCounters($sKey, $aField)
     protected function _getCellHeaderCounters($sKey, $aField)
     {
     {
         if($this->_iLevel != $this->_iLevelMax)
         if($this->_iLevel != $this->_iLevelMax)
-            return '';
+            return $this->_bIsApi ? [] : '';
 
 
         return parent::_getCellHeaderDefault($sKey, $aField);
         return parent::_getCellHeaderDefault($sKey, $aField);
     }
     }
 
 
     protected function _getCellTitle($mixedValue, $sKey, $aField, $aRow)
     protected function _getCellTitle($mixedValue, $sKey, $aField, $aRow)
     {
     {
+        if($this->_bIsApi)
+            return ['type' => 'text', 'value'=> $mixedValue]; 
+
         $mixedValue = $this->_oModule->_oTemplate->parseHtmlByName('name_link.html', [
         $mixedValue = $this->_oModule->_oTemplate->parseHtmlByName('name_link.html', [
             'href' => bx_append_url_params($this->_sPageUrl, ['parent_id' => $aRow['id']]),
             'href' => bx_append_url_params($this->_sPageUrl, ['parent_id' => $aRow['id']]),
             'title' => bx_html_attribute($mixedValue),
             'title' => bx_html_attribute($mixedValue),
@@ -216,7 +227,7 @@ class BxCoursesGridCntStructureManage extends BxTemplGrid
     protected function _getCellCnL2($mixedValue, $sKey, $aField, $aRow)
     protected function _getCellCnL2($mixedValue, $sKey, $aField, $aRow)
     {
     {
         if($this->_iLevelMax < 2 || $this->_iLevel >= 2)
         if($this->_iLevelMax < 2 || $this->_iLevel >= 2)
-            return '';
+            return $this->_bIsApi ? [] : '';
 
 
         return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
         return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
     }
     }
@@ -224,7 +235,7 @@ class BxCoursesGridCntStructureManage extends BxTemplGrid
     protected function _getCellCnL3($mixedValue, $sKey, $aField, $aRow)
     protected function _getCellCnL3($mixedValue, $sKey, $aField, $aRow)
     {
     {
         if($this->_iLevelMax < 3 || $this->_iLevel >= 3)
         if($this->_iLevelMax < 3 || $this->_iLevel >= 3)
-            return '';
+            return $this->_bIsApi ? [] : '';
 
 
         return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
         return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
     }
     }
@@ -232,7 +243,7 @@ class BxCoursesGridCntStructureManage extends BxTemplGrid
     protected function _getCellCounters($mixedValue, $sKey, $aField, $aRow)
     protected function _getCellCounters($mixedValue, $sKey, $aField, $aRow)
     {
     {
         if($this->_iLevel != $this->_iLevelMax)
         if($this->_iLevel != $this->_iLevelMax)
-            return '';
+            return $this->_bIsApi ? [] : '';
 
 
         $sCounters = '';
         $sCounters = '';
         if(!empty($mixedValue) && ($aCounters = json_decode(html_entity_decode($mixedValue), true)))
         if(!empty($mixedValue) && ($aCounters = json_decode(html_entity_decode($mixedValue), true)))

+ 20 - 4
modules/boonex/courses/classes/BxCoursesModule.php

@@ -277,6 +277,12 @@ class BxCoursesModule extends BxBaseModGroupsModule
             return '';
             return '';
 
 
         $oGrid->setEntryId($aContentInfo[$CNF['FIELD_ID']]);
         $oGrid->setEntryId($aContentInfo[$CNF['FIELD_ID']]);
+
+        if($this->_bIsApi)
+            return [
+                bx_api_get_block('grid', $oGrid->getCodeAPI())
+            ];
+
         return $oGrid->getCode();
         return $oGrid->getCode();
     }
     }
     
     
@@ -300,33 +306,43 @@ class BxCoursesModule extends BxBaseModGroupsModule
             return '';
             return '';
 
 
         $oGrid->setEntryId($aContentInfo[$CNF['FIELD_ID']]);
         $oGrid->setEntryId($aContentInfo[$CNF['FIELD_ID']]);
+
+        if($this->_bIsApi)
+            return [
+                bx_api_get_block('grid', $oGrid->getCodeAPI())
+            ];
+
         return $oGrid->getCode();
         return $oGrid->getCode();
     }
     }
     
     
     public function serviceEntityStructureL1Block($iContentId = 0)
     public function serviceEntityStructureL1Block($iContentId = 0)
     {
     {
         if(!$this->_oConfig->isContent() || $this->_oConfig->getContentLevelMax() == 1)
         if(!$this->_oConfig->isContent() || $this->_oConfig->getContentLevelMax() == 1)
-            return '';
+            return $this->_bIsApi ? [] : '';
 
 
-        return $this->_serviceTemplateFuncEx ('entryStructureByLevel', $iContentId, [
+        $mixedResult = $this->_serviceTemplateFuncEx ('entryStructureByLevel', $iContentId, [
             'level' => 1,
             'level' => 1,
             'selected' => ($iNodeId = bx_get('parent_id')) !== false ? (int)$iNodeId : 0,
             'selected' => ($iNodeId = bx_get('parent_id')) !== false ? (int)$iNodeId : 0,
             'start' => ($iStart = bx_get('start')) !== false ? (int)$iStart : 0,
             'start' => ($iStart = bx_get('start')) !== false ? (int)$iStart : 0,
             'per_page' => ($iPerPage = bx_get('per_page')) !== false ? (int)$iPerPage : 0,
             'per_page' => ($iPerPage = bx_get('per_page')) !== false ? (int)$iPerPage : 0,
         ]);
         ]);
+
+        return $this->_bIsApi ? [bx_api_get_block('entity_structure_l1', $mixedResult)] : $mixedResult;
     }
     }
 
 
     public function serviceEntityStructureL2Block($iContentId = 0, $iParentId = 0)
     public function serviceEntityStructureL2Block($iContentId = 0, $iParentId = 0)
     {
     {
         if(!$this->_oConfig->isContent())
         if(!$this->_oConfig->isContent())
-            return '';
+            return $this->_bIsApi ? [] : '';
 
 
         if(!$iParentId && ($_iParentId = bx_get('parent_id')) !== false)
         if(!$iParentId && ($_iParentId = bx_get('parent_id')) !== false)
             $iParentId = (int)$_iParentId;
             $iParentId = (int)$_iParentId;
 
 
-        return $this->_serviceTemplateFuncEx ('entryStructureByParentMl' . $this->_oConfig->getContentLevelMax(), $iContentId, [
+        $mixedResult = $this->_serviceTemplateFuncEx ('entryStructureByParentMl' . $this->_oConfig->getContentLevelMax(), $iContentId, [
             'parent_id' => $iParentId
             'parent_id' => $iParentId
         ]);
         ]);
+
+        return $this->_bIsApi ? [bx_api_get_block('entity_structure_l2', $mixedResult)] : $mixedResult;
     }
     }
     
     
     public function serviceEntityNodeBlock($iContentId = 0, $iNodeId = 0, $iUsage = false)
     public function serviceEntityNodeBlock($iContentId = 0, $iNodeId = 0, $iUsage = false)

+ 48 - 27
modules/boonex/courses/classes/BxCoursesTemplate.php

@@ -78,6 +78,9 @@ class BxCoursesTemplate extends BxBaseModGroupsTemplate
         $iLevelMax = $this->_oConfig->getContentLevelMax();
         $iLevelMax = $this->_oConfig->getContentLevelMax();
         $aLevelToNodePl = $this->_oConfig->getContentLevel2Node(false);
         $aLevelToNodePl = $this->_oConfig->getContentLevel2Node(false);
 
 
+        $sTmplKeysSelected = $this->_bIsApi ? 'selected' : 'bx_if:selected';
+        $sTmplKeysCounters = $this->_bIsApi ? 'counters' : 'bx_repeat:counters';
+        
         $aTmplVarsNodes = [];
         $aTmplVarsNodes = [];
         foreach($aNodes as $iKey => $aNode) {
         foreach($aNodes as $iKey => $aNode) {
             $aTmplVarsCounters = [];
             $aTmplVarsCounters = [];
@@ -87,20 +90,29 @@ class BxCoursesTemplate extends BxBaseModGroupsTemplate
                     'cn_value' => $aNode['cn_l' . $i]
                     'cn_value' => $aNode['cn_l' . $i]
                 ];
                 ];
 
 
-            $aTmplVarsNodes[] = $this->parseHtmlByName('node_l' . $iLevel . '.html', array_merge($aNode, [
-                'bx_if:selected' => [
-                    'condition' => $aNode['node_id'] == $iSelected,
+            $bSelected = $aNode['node_id'] == $iSelected;
+            $sLink = BX_DOL_URL_ROOT . $oPermalink->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&' . $CNF['FIELD_ID'] . '=' . $iContentId, [
+                'parent_id' => $aNode['node_id']
+            ]);
+            $aNode = array_merge($aNode, [
+                $sTmplKeysSelected => $this->_bIsApi ? $bSelected : [
+                    'condition' => $bSelected,
                     'content' => [true]
                     'content' => [true]
                 ],
                 ],
                 'index' => $iKey,
                 'index' => $iKey,
-                'link' => BX_DOL_URL_ROOT . $oPermalink->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&' . $CNF['FIELD_ID'] . '=' . $iContentId, [
-                    'parent_id' => $aNode['node_id']
-                ]),
+                'link' => $this->_bIsApi ? bx_api_get_relative_url($sLink) : $sLink,
                 'status' => $this->_getNodeStatus($iProfileId, $iContentId, $aNode['node_id']),
                 'status' => $this->_getNodeStatus($iProfileId, $iContentId, $aNode['node_id']),
-                'bx_repeat:counters' => $aTmplVarsCounters
-            ]));
+                $sTmplKeysCounters => $aTmplVarsCounters
+            ]);
+
+            $aTmplVarsNodes[] = $this->_bIsApi ? $aNode : [
+                'node' => $this->parseHtmlByName('node_l' . $iLevel . '.html', $aNode)
+            ];
         }
         }
 
 
+        if($this->_bIsApi)
+            return $aTmplVarsNodes;
+
         $oPaginate = new BxTemplPaginate([
         $oPaginate = new BxTemplPaginate([
             'start' => $iStart,
             'start' => $iStart,
             'per_page' => $iPerPage,
             'per_page' => $iPerPage,
@@ -134,13 +146,15 @@ class BxCoursesTemplate extends BxBaseModGroupsTemplate
         ]);
         ]);
 
 
         if(empty($aNodes) || !is_array($aNodes))
         if(empty($aNodes) || !is_array($aNodes))
-            return '';
+            return $this->_bIsApi ? [] : '';
 
 
         $sJsObject = $this->_oConfig->getJsObject('entry');
         $sJsObject = $this->_oConfig->getJsObject('entry');
         $oPermalink = BxDolPermalinks::getInstance();
         $oPermalink = BxDolPermalinks::getInstance();
         
         
         $iLevelMax = $this->_oConfig->getContentLevelMax();
         $iLevelMax = $this->_oConfig->getContentLevelMax();
 
 
+        $aTmplKeysShowPass = $this->_bIsApi ? 'show_pass' : 'bx_if:show_pass';
+
         $aTmplVarsNodes = [];
         $aTmplVarsNodes = [];
         foreach($aNodes as $iKey => $aNode) {
         foreach($aNodes as $iKey => $aNode) {
             list($iPassPercent, $sPassProgress, $sPassStatus, $sPassTitle) = $this->_getNodePass($iProfileId, $iContentId, $aNode);
             list($iPassPercent, $sPassProgress, $sPassStatus, $sPassTitle) = $this->_getNodePass($iProfileId, $iContentId, $aNode);
@@ -149,27 +163,34 @@ class BxCoursesTemplate extends BxBaseModGroupsTemplate
                 'node_id' => $aNode['node_id']
                 'node_id' => $aNode['node_id']
             ]);
             ]);
 
 
-            $aTmplVarsNodes[] = [
-                'node' => $this->parseHtmlByName('ml' . $iLevelMax . '_node_l' . $aNode['level'] . '.html', array_merge($aNode, [
-                    'level_max' => $iLevelMax,
-                    'index' => $iKey,
-                    'link' => $sLink,
-                    'pass_percent' => $iPassPercent,
-                    'pass_progress' => $sPassProgress,
-                    'pass_status' => $sPassStatus,
-                    'bx_if:show_pass' => [
-                        'condition' => $sPassTitle,
-                        'content' => [
-                            'js_object' => $sJsObject,
-                            'id' => $aNode['node_id'],
-                            'pass_href' => $sLink,
-                            'pass_title' => $sPassTitle,
-                        ]
+            $bShowPass = !empty($sPassTitle);
+
+            $aNode = array_merge($aNode, [
+                'level_max' => $iLevelMax,
+                'index' => $iKey,
+                'link' => $this->_bIsApi ? bx_api_get_relative_url($sLink) : $sLink,
+                'pass_percent' => $iPassPercent,
+                'pass_progress' => $sPassProgress,
+                'pass_status' => $sPassStatus,
+                $aTmplKeysShowPass => $this->_bIsApi ? $bShowPass : [
+                    'condition' => $bShowPass,
+                    'content' => [
+                        'js_object' => $sJsObject,
+                        'id' => $aNode['node_id'],
+                        'pass_href' => $sLink,
+                        'pass_title' => $sPassTitle,
                     ]
                     ]
-                ]))
+                ]
+            ]);
+
+            $aTmplVarsNodes[] = $this->_bIsApi ? $aNode : [
+                'node' => $this->parseHtmlByName('ml' . $iLevelMax . '_node_l' . $aNode['level'] . '.html', $aNode)
             ];
             ];
         }
         }
 
 
+        if($this->_bIsApi)
+            return $aTmplVarsNodes;
+
         return $this->parseHtmlByName('ml' . $iLevelMax . '_nodes_l' . $aNode['level'] . '.html', [
         return $this->parseHtmlByName('ml' . $iLevelMax . '_nodes_l' . $aNode['level'] . '.html', [
             'level_max' => $iLevelMax,
             'level_max' => $iLevelMax,
             'bx_repeat:nodes' => $aTmplVarsNodes
             'bx_repeat:nodes' => $aTmplVarsNodes
@@ -182,7 +203,7 @@ class BxCoursesTemplate extends BxBaseModGroupsTemplate
     public function entryStructureByParentMl2($aContentInfo, $aParams = [])
     public function entryStructureByParentMl2($aContentInfo, $aParams = [])
     {
     {
         if(empty($aParams['parent_id']))
         if(empty($aParams['parent_id']))
-            return '';
+            return $this->_bIsApi ? [] : '';
 
 
         return $this->entryStructureByParentMl1($aContentInfo, $aParams);
         return $this->entryStructureByParentMl1($aContentInfo, $aParams);
     }
     }

+ 1 - 1
studio/template/scripts/BxBaseStudioFormView.php

@@ -86,7 +86,7 @@ class BxBaseStudioFormView extends BxDolStudioForm
             $sValue = '';
             $sValue = '';
             if(key_exists($aLanguage['id'], $aStrings))
             if(key_exists($aLanguage['id'], $aStrings))
                 $sValue = $aStrings[$aLanguage['id']]['string'];
                 $sValue = $aStrings[$aLanguage['id']]['string'];
-            else if(isset($aInput['values'][$aLanguage['name']]))
+            if(!$sValue && isset($aInput['values'][$aLanguage['name']]))
                 $sValue = $aInput['values'][$aLanguage['name']];
                 $sValue = $aInput['values'][$aLanguage['name']];
             $bValue = !empty($sValue);
             $bValue = !empty($sValue);