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

Ticket #4971 - Build-in API support: Tasks.

AntonLV 3 месяцев назад
Родитель
Сommit
776dc1d797

+ 5 - 3
modules/boonex/tasks/classes/BxTasksMenuBrowse.php

@@ -81,14 +81,16 @@ class BxTasksMenuBrowse extends BxTemplMenu
             if(!$oContext)
                 continue;
 
+            $sUrl = $this->_oPermalink->permalink(bx_append_url_params($this->_sPageLink, array_merge($this->_aPageParams, [
+                $this->_sParamName => $iId
+            ])));
+
             $aSubmenu[] = [
                 'id' => 'context-' . $iId, 
                 'name' => 'context-' . $iId, 
                 'class_add' => $iId == $this->_iParamValue ? 'bx-menu-tab-active' : '',
                 'class' => '',
-                'link' => $this->_oPermalink->permalink(bx_append_url_params($this->_sPageLink, array_merge($this->_aPageParams, [
-                    $this->_sParamName => $iId
-                ]))), 
+                'link' => $this->_bIsApi ? bx_api_get_relative_url($sUrl) : $sUrl, 
                 'onclick' => '', 
                 'target' => '_self', 
                 'title' => $oContext->getDisplayName(), 

+ 13 - 5
modules/boonex/tasks/classes/BxTasksModule.php

@@ -527,7 +527,11 @@ class BxTasksModule extends BxBaseModTextModule implements iBxDolCalendarService
 
     public function serviceGetBlockMenuBrowse()
     {
-        return $this->_oTemplate->getBlockMenuBrowse();
+        $mixedResult = $this->_oTemplate->getBlockMenuBrowse();
+
+        return $this->_bIsApi ? [
+            bx_api_get_block('tasks_browse', $mixedResult)
+        ] : $mixedResult;
     }
 
     public function serviceGetBlockMenuContext($iProfileId)
@@ -535,14 +539,14 @@ class BxTasksModule extends BxBaseModTextModule implements iBxDolCalendarService
         $CNF = &$this->_oConfig->CNF;
 
         if(!$this->isAllowView($iProfileId))
-            return ''; 
+            return $this->_bIsApi ? [] : ''; 
 
         $oMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU_VIEW_CONTEXT']);
         if(!$oMenu)
-            return '';
+            return $this->_bIsApi ? [] : '';
 
         $oMenu->addMarkers(['profile_id' => $iProfileId]);
-        return $oMenu->getCode();
+        return $this->_bIsApi ? $oMenu->getCodeAPI() : $oMenu->getCode();
     }
 
     public function serviceGetBlockContextPreValues($iContextPid = 0)
@@ -667,7 +671,11 @@ class BxTasksModule extends BxBaseModTextModule implements iBxDolCalendarService
 
     public function serviceGetBlockTimers()
     {
-        return $this->_oTemplate->getBlockTimers($this->_iProfileId);
+        $mixedResult = $this->_oTemplate->getBlockTimers($this->_iProfileId);
+
+        return $this->_bIsApi ? [
+            bx_api_get_block('tasks_timers', $mixedResult)
+        ] : $mixedResult;
     }
 
     /**

+ 55 - 29
modules/boonex/tasks/classes/BxTasksTemplate.php

@@ -50,33 +50,40 @@ class BxTasksTemplate extends BxBaseModTextTemplate
 
         $iProfileId = bx_get_logged_profile_id();
 
-        $sMenuUse = '';
+        $sMenuUse = $this->_bIsApi ? [] : '';
         if(($oMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_USE_TOOLS_SUBMENU'])) !== false)
-            $sMenuUse = $oMenu->getCode();
+            $sMenuUse = $this->_bIsApi ? $oMenu->getCodeAPI() : $oMenu->getCode();
 
-        $sMenuManage = '';
+        $sMenuManage = $this->_bIsApi ? [] : '';
         if(($oMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_MANAGE_TOOLS_SUBMENU'])) !== false)
-            $sMenuManage = $oMenu->getCode();
+            $sMenuManage = $this->_bIsApi ? $oMenu->getCodeAPI() : $oMenu->getCode();
 
-        $sMenuBrowse = '';
+        $sMenuBrowse = $this->_bIsApi ? [] : '';
         if(($oMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_BROWSE'])) !== false) {
             $oMenu->setProfileId($iProfileId);
-            $sMenuBrowse = $oMenu->getCode();
+            $sMenuBrowse = $this->_bIsApi ? $oMenu->getCodeAPI() : $oMenu->getCode();
         }
 
+        if($this->_bIsApi)
+            return [
+                'menu_use' => $sMenuUse,
+                'menu_browse' => $sMenuBrowse,
+                'menu_manage' => $sMenuManage
+            ];
+
         return $this->parseHtmlByName('menu_browse.html', [
             'menu_use' => $sMenuUse,
-            'bx_if:show_menu_manage' => [
-                'condition' => $sMenuManage != '',
-                'content' => [
-                    'menu_manage' => $sMenuManage
-                ]
-            ],
             'bx_if:show_menu_browse' => [
                 'condition' => $sMenuBrowse != '',
                 'content' => [
                     'menu_browse' => $sMenuBrowse
                 ]
+            ],
+            'bx_if:show_menu_manage' => [
+                'condition' => $sMenuManage != '',
+                'content' => [
+                    'menu_manage' => $sMenuManage
+                ]
             ]
         ]);
     }
@@ -156,51 +163,62 @@ class BxTasksTemplate extends BxBaseModTextTemplate
 
         $aTimers = $this->_oDb->getTimers(['sample' => 'profile_id', 'profile_id' => $iProfileId]);
         if(!$aTimers || !is_array($aTimers))
-            return MsgBox(_t('_Empty'));
+            return $this->_bIsApi ? [] : MsgBox(_t('_Empty'));
 
         $oPermalinks = BxDolPermalinks::getInstance();
 
+        $sKeyTimers = $this->_bIsApi ? 'timers' : 'bx_repeat:timers';
+
         $aTmplVarsSections = [];
         foreach($aTimers as $aTimer) {
             $aContentInfo = $this->_oDb->getContentInfoById($aTimer['content_id']);
             if(!$aContentInfo && !is_array($aContentInfo))
                 continue;
 
-            $sContextType = $sContextTitle = $sContextUrl = '';
+            $sContextType = '';
+            $aTmplVarsContext = [];
             if(($iAllowViewTo = (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) < 0 && ($oContext = BxDolProfile::getInstance(abs($iAllowViewTo))) !== false) {
                 $sContextType = $oContext->getModule();
-                $sContextTitle = $oContext->getDisplayName();
-                $sContextUrl = $oContext->getUrl();
+                $aTmplVarsContext = $this->_bIsApi ? BxDolProfile::getData($oContext) : [
+                    'title' => $oContext->getDisplayName(),
+                    'url' => $oContext->getUrl()
+                ];
             }
 
+            $sUrl = bx_absolute_url($oPermalinks->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]));
+
             if(!isset($aTmplVarsSections[$sContextType]))
                 $aTmplVarsSections[$sContextType] = [
                     'section_title' => $oModule->getModuleTitle($sContextType),
-                    'bx_repeat:timers' => []
+                    $sKeyTimers => []
                 ];
 
-            $aTmplVarsSections[$sContextType]['bx_repeat:timers'][] = [
-                'bx_if:show_context' => [
-                    'condition' => $sContextTitle && $sContextUrl,
-                    'content' => [
-                        'title' => $sContextTitle,
-                        'url' => $sContextUrl
-                    ]
-                ],
+            $aTmplVarsSections[$sContextType][$sKeyTimers][] = array_merge([
                 'content_title' => $aContentInfo[$CNF['FIELD_TITLE']],
-                'content_url' => bx_absolute_url($oPermalinks->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']])),
+                'content_url' => $this->_bIsApi ? bx_api_get_relative_url($sUrl) : $sUrl,
                 'timer' => $this->getTimer($aTimer['content_id'], $iProfileId),
+            ], $this->_bIsApi ? [
+                'context' => $aTmplVarsContext,
+            ] : [
+                'bx_if:show_context' => [
+                    'condition' => !empty($aTmplVarsContext),
+                    'content' => $aTmplVarsContext
+                ],
                 'js_code_timer' => $sJsObject . '.init(' . $aTimer['content_id'] . ', ' . $iProfileId . ', ' . ($aTimer['started'] != 0 ? 1 : 0) . ');'
-            ];
+            ]);
         }
 
+        $aTmplVarsSections = array_values($aTmplVarsSections);
+        if($this->_bIsApi)
+            return $aTmplVarsSections;
+
         $this->addCss(['timer.css']);
         $this->addJs(['timer.js']);
         return $this->parseHtmlByName('browse_timers.html', [
             'js_code' => $this->getJsCode('timer', [
                 'bMulti' => true
             ]),
-            'bx_repeat:sections' => array_values($aTmplVarsSections)
+            'bx_repeat:sections' => $aTmplVarsSections
         ]);
     }
 
@@ -232,6 +250,14 @@ class BxTasksTemplate extends BxBaseModTextTemplate
         ]);
         $oActions->setParams($iContentId, $iProfileId);
 
+        if($this->_bIsApi)
+            return [
+                'hours' => $iHours,
+                'minutes' => $iMinutes,
+                'seconds' => $iSeconds,
+                'actions' => $oActions->getCodeAPI()
+            ];
+
         return $this->parseHtmlByName('entry-timer.html', [
             'html_id' => $this->_oConfig->getHtmlIds('timer') . $iContentId . '-' . $iProfileId,
             'hours' => sprintf("%02d", $iHours),
@@ -240,7 +266,7 @@ class BxTasksTemplate extends BxBaseModTextTemplate
             'actions' => $oActions->getCode()
         ]);
     }
-   
+
     public function getEntriesList($iContextId = 0, $aParams = [])
     {
         $CNF = &$this->_oConfig->CNF;