Przeglądaj źródła

Ticket #4971 - Build-in API support: Multilevel hierarchy in Spaces.

AntonLV 8 miesięcy temu
rodzic
commit
37704f2660

+ 25 - 6
modules/boonex/spaces/classes/BxSpacesFormEntry.php

@@ -22,13 +22,32 @@ class BxSpacesFormEntry extends BxBaseModGroupsFormEntry
     
     protected function genCustomInputParentSpace($aInput)
     {
-        $iCurrent = bx_get('id');
-        if ($iCurrent === false)
-            $iCurrent = - 1;
-        $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . "modules/?r=" . $this->_oModule->_oConfig->getUri() . "/ajax_get_parent_space&id=" . $iCurrent;
+        $iCurrent = ($iCurrent = bx_get('id')) !== false ? (int)$iCurrent : - 1;
+
+        if($this->_bIsApi) {
+            $aInput = array_merge($aInput, [
+                'title' => $aInput['caption'], 
+                'ajax_get_suggestions' => $this->_oModule->_oConfig->getName() . "/ajax_get_parent_space&params[]=" . $iCurrent . "&params[]=",
+                'value_data' => []
+            ]);
+
+            if(!empty($aInput['value']) && is_array($aInput['value']))
+                foreach($aInput['value'] as $iProfileId)
+                    if(($oProfile = BxDolProfile::getInstance($iProfileId)) !== false) {
+                        $aProfile = $oProfile->getUnitAPI();
+                        $aInput['value_data'][] = $aProfile['author_data'];
+                    }
+        }
+        else {
+            $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . "modules/?r=" . $this->_oModule->_oConfig->getUri() . "/ajax_get_parent_space&id=" . $iCurrent;
+            if (isset($aInput['value']) && !is_array($aInput['value']))
+                $aInput['value'] = array($aInput['value']);
+        }
+
+        if(($sK = 'custom') && (empty($aInput[$sK]) || !is_array($aInput[$sK])))
+            $aInput[$sK] = [];
         $aInput['custom']['only_once'] = 1;
-        if (isset($aInput['value']) && !is_array($aInput['value']))
-            $aInput['value'] = array($aInput['value']);
+
         return $this->genCustomInputUsernamesSuggestions($aInput);
     }
     

+ 29 - 9
modules/boonex/spaces/classes/BxSpacesModule.php

@@ -27,6 +27,7 @@ class BxSpacesModule extends BxBaseModGroupsModule
     {
         $a = parent::serviceGetSafeServices();
         return array_merge($a, array (
+            'AjaxGetParentSpace' => '',
             'BrowseTopLevel' => '',
         ));
     }
@@ -105,7 +106,19 @@ class BxSpacesModule extends BxBaseModGroupsModule
         header('Content-Type:text/javascript; charset=utf-8');
         echo(json_encode($a));
     }
-    
+
+    public function serviceAjaxGetParentSpace ($iContentId, $mixedParams)
+    {
+        if(!$mixedParams)
+            return [];
+
+        $aParams = is_array($mixedParams) ? $mixedParams : json_decode($mixedParams, true);
+        if(!isset($aParams['term']))
+            return [];
+
+        return $this->getListSpacesForParent($aParams['term'], $iContentId, 10);
+    }
+
     public function getListSpacesForParent ($sTerm, $iContentId, $iLimit)
     {
         $CNF = &$this->_oConfig->CNF;
@@ -121,14 +134,21 @@ class BxSpacesModule extends BxBaseModGroupsModule
         $aTmp = $this->_oDb->searchByTermForParentSpace(bx_get_logged_profile_id(), $iContentId, $iLevelsLimit, $sTerm, $iLimit);
         foreach ($aTmp as $aSpace) {
             $oProfile = BxDolProfile::getInstance($aSpace['profile_id']);
-
-            $aRv[] = array (
-                'label' => $this->serviceProfileName($aSpace['content_id']),
-                'value' => $aSpace['profile_id'],
-                'url' => $oProfile->getUrl(),
-                'thumb' => $oProfile->getThumb(),
-                'unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
-            );
+            if(!$oProfile)
+                continue;
+
+            if ($this->_bIsApi)
+                $aRv[] = array_merge(BxDolProfile::getData($oProfile), [
+                    'label' => $oProfile->getDisplayName()
+                ]);
+            else
+                $aRv[] = array (
+                    'label' => $this->serviceProfileName($aSpace['content_id']),
+                    'value' => $aSpace['profile_id'],
+                    'url' => $oProfile->getUrl(),
+                    'thumb' => $oProfile->getThumb(),
+                    'unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
+                );
         }
         return $aRv;
     }