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

#4558 - Build-in API support (dashboard)

romanlesnikov 1 год назад
Родитель
Сommit
fc19acc1de

+ 12 - 8
template/scripts/BxBaseDashboardServices.php

@@ -68,11 +68,13 @@ class BxBaseDashboardServices extends BxDol
         $iProfileId = (int)bx_get_logged_profile_id();
         $iV1 = $bEmpty ? 0 : BxDolConnection::getObjectInstance('sys_profiles_friends')->getConnectedContentCount($iProfileId, true);
         $iV2 =$bEmpty ? 0 :  BxDolConnection::getObjectInstance('sys_profiles_friends')->getConnectedContentCount($iProfileId, true, $iStartDate);
-        $aData['friends'] = ['title' => 'Friends', 'key' => 'friends', 'type' => 'growth', 'url' =>'/friends', 'current' => $iV1, 'prev' => $iV2, 'growth' => $iV2 > 0 ? round(($iV1 - $iV2)/$iV2*100, 2) : 0];
+        $aData[] = ['title' => 'Friends', 'key' => 'friends', 'type' => 'growth', 'url' =>'/friends', 'current' => $iV1, 'prev' => $iV2, 'growth' => $iV2 > 0 ? round(($iV1 - $iV2)/$iV2*100, 2) : 0];
         
         $iV1 = $bEmpty ? 0 : BxDolConnection::getObjectInstance('sys_profiles_subscriptions')->getConnectedContentCount($iProfileId, false);
         $iV2 = $bEmpty ? 0 : BxDolConnection::getObjectInstance('sys_profiles_subscriptions')->getConnectedContentCount($iProfileId, false, $iStartDate);
-        $aData['followers'] = ['title' =>'Followers', 'key' => 'followers', 'type' => 'growth', 'url' =>'/followers', 'current' => $iV1, 'prev' => $iV2, 'growth' =>  $iV2 > 0 ? round(($iV1 - $iV2)/$iV2*100 ,2) : 0];
+        $aData[] = ['title' =>'Followers', 'key' => 'followers', 'type' => 'growth', 'url' =>'/followers', 'current' => $iV1, 'prev' => $iV2, 'growth' =>  $iV2 > 0 ? round(($iV1 - $iV2)/$iV2*100 ,2) : 0];
+        
+        $oPermalink = BxDolPermalinks::getInstance();
         
         $aModules = bx_srv('system', 'get_modules_by_type', ['content']);
         foreach($aModules as $aModule) {
@@ -81,10 +83,10 @@ class BxBaseDashboardServices extends BxDol
             if (method_exists($oModule->_oDb, 'getStatByProfile')){
                 $a = $bEmpty ? [] : $oModule->_oDb->getStatByProfile($iProfileId);
                 $aIcon = explode($CNF['ICON'], ' ');
-                $aData[$aModule['name']] = array_merge(['key' => $aModule['name'], 'title' => $aModule['title'], 'url' => $CNF['URL_HOME'], 'icon' => $CNF['ICON'], 'type' => 'simple'], $a);
+                $aData[] = array_merge(['key' => $aModule['name'], 'title' => $aModule['title'], 'add_url' => $CNF['URI_ADD_ENTRY'], 'url' => $oPermalink->permalink($CNF['URL_HOME']), 'action' => 'views', 'icon' => $CNF['ICON'], 'type' => 'simple'], $a);
             }
         }
-        
+       
         $aModules = bx_srv('system', 'get_modules_by_type', ['context']);
         foreach($aModules as $aModule) {
             $oModule = BxDolModule::getInstance($aModule['name']);
@@ -104,14 +106,16 @@ class BxBaseDashboardServices extends BxDol
                             $iMembers += $oConnection->getConnectedInitiatorsCount($oProfile->id(), true);
                         }
                     }
-                }    
-                $aData[$aModule['name']] = array_merge(['key' => $aModule['name'], 'title' => $aModule['title'], 'url' => $CNF['URL_HOME'], 'icon' => $CNF['ICON'], 'type' => 'simple', 'members' => $iMembers], $a);
+                } 
+                $aData[] = array_merge(['key' => $aModule['name'], 'title' => $aModule['title'], 'url' => $oPermalink->permalink($CNF['URL_HOME']), 'add_url' => str_replace('edit-', 'create-',$CNF['URI_EDIT_ENTRY']), 'action' => 'member',  'icon' => $CNF['ICON'], 'type' => 'simple', 'members' => $iMembers], $a);
             }
         }
         
         $bApi = bx_is_api();
-        if($bApi)
-            return [bx_api_get_block('dashboard_stat', $aData)];
+        if($bApi){
+            $oMenu = BxDolMenu::getObjectInstance('sys_account_dashboard_manage_tools');
+            return [bx_api_get_block('dashboard_stat', ['modules' => $aData, 'manage' => $oMenu->getCodeAPI()])];
+        }
     }
     
     public function serviceManageAudit()

+ 10 - 0
template/scripts/BxBasePage.php

@@ -551,6 +551,16 @@ class BxBasePage extends BxDolPage
                 $oMenuSubmenu->setObjectSubmenu($sSubmenu, []);
 
             $a['menu'] = $oMenuSubmenu->getCodeAPI();
+            if ($sModuleName && $sModuleName != 'system'){
+                $oModule = BxDolModule::getInstance($sModuleName);
+                if ($oModule){
+                    $CNF = &$oModule->_oConfig->CNF;
+                    $a['menu']['name'] = $oModule->getName();
+                    $a['menu']['title'] = $oModule->getModuleTitle();
+                    $a['menu']['icon'] = $CNF['ICON'];
+                    $a['menu']['add_url'] = $CNF['URI_ADD_ENTRY'] ? $CNF['URI_ADD_ENTRY']: str_replace('edit-', 'create-',$CNF['URI_EDIT_ENTRY']);
+                }    
+            }
         }
 
         /**

+ 4 - 3
template/scripts/BxBaseServiceProfiles.php

@@ -129,12 +129,13 @@ class BxBaseServiceProfiles extends BxDol
 
     public function serviceProfileMenu ($iProfileId = 0)
     {
-        if(($oMenu = BxDolMenu::getObjectInstance('sys_profile_stats')) !== false) {
-            if(bx_is_api())
+        if(bx_is_api()){
+            $oMenu = BxDolMenu::getObjectInstance('sys_site');
                 return [
                     bx_api_get_block ('profile_menu', $oMenu->getCodeAPI())
                 ];
-
+        }
+        if(($oMenu = BxDolMenu::getObjectInstance('sys_profile_stats')) !== false) {
             return $oMenu->getCode();
         }
         else