Explorar el Código

#4558 - Build-in API support: Groups invite.

roman.lesnikov@gmail.com hace 2 años
padre
commit
7115beeab1

+ 5 - 0
modules/base/general/classes/BxBaseModGeneralFormEntry.php

@@ -1102,6 +1102,11 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         $aInput['custom']['only_once'] = 1;
         
         $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . "modules/?r=" . $this->_oModule->_oConfig->getUri() . "/ajax_get_profiles";
+        if (bx_is_api()){
+            $aInput['ajax_get_suggestions'] = $this->_oModule->_oConfig->getName() . "/get_profiles&params[]=";
+            $aProfile = BxDolProfile::getInstance($aInput['value'])->getUnitAPI(0, ['template' => 'unit_wo_info']);
+            $aInput['value_data'] = [$aProfile['author_data']];
+        }
         return $this->genCustomInputUsernamesSuggestions($aInput);
     }
     

+ 11 - 0
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -324,6 +324,15 @@ class BxBaseModGeneralModule extends BxDolModule
         header('Content-Type:text/javascript; charset=utf-8');
         echo(json_encode($a));
     }
+    
+    public function serviceGetProfiles ($sParams)
+    {
+        $aOptions = json_decode($sParams, true);
+        if (!$sParams || !isset($aOptions['term']))
+            return [];
+
+        return BxDolService::call('system', 'profiles_search', array($aOptions['term']), 'TemplServiceProfiles');
+    }
 
     public function actionGetBrowsingFilters()
     {
@@ -432,6 +441,8 @@ class BxBaseModGeneralModule extends BxDolModule
             'EntityActions' => '',
             'EntitySocialSharing' => '',
             'MyEntriesActions' => '',
+            
+            'GetProfiles' => '',
         );
     }
 

+ 6 - 2
modules/base/groups/classes/BxBaseModGroupsFormsEntryHelper.php

@@ -55,18 +55,19 @@ class BxBaseModGroupsFormsEntryHelper extends BxBaseModProfileFormsEntryHelper
 
         // check and display form
         $oForm = $this->getObjectFormInvite($sDisplay);
+
         if(!$oForm)
             return $bErrorMsg ? ($this->_bIsApi ? [bx_api_get_msg('_sys_txt_error_occured')] : MsgBox(_t('_sys_txt_error_occured'))) : '';
 
         $oForm->initChecker($aContentInfo);
         if (!$oForm->isSubmittedAndValid())
-            return $this->_bIsApi ? [bx_api_get_block('form', $oForm->getCodeAPI(), ['ext' => ['name' => $this->_oModule->getName(), 'request' => ['url' => '/api.php?r=' . $this->_oModule->getName() . '/entity_invite', 'immutable' => true]]])] : $oForm->getCode();
+            return $this->_bIsApi ? [bx_api_get_block('form', $oForm->getCodeAPI(), ['ext' => ['name' => $this->_oModule->getName(), 'request' => ['url' => '/api.php?r=' . $this->_oModule->getName() . '/entity_invite&params[]=' . $iContentId . '&params[]=' . $sDisplay, 'immutable' => true]]])] : $oForm->getCode();
 
         $this->onDataInviteBefore($aContentInfo[$CNF['FIELD_ID']], $aContentInfo);
 
         if (!$oForm->update($aContentInfo[$CNF['FIELD_ID']])) {
             if (!$oForm->isValid())
-                return $this->_bIsApi ? [bx_api_get_block('form', $oForm->getCodeAPI(), ['ext' => ['name' => $this->_oModule->getName(), 'request' => ['url' => '/api.php?r=' . $this->_oModule->getName() . '/entity_invite', 'immutable' => true]]])] : $oForm->getCode();
+                return $this->_bIsApi ? [bx_api_get_block('form', $oForm->getCodeAPI(), ['ext' => ['name' => $this->_oModule->getName(), 'request' => ['url' => '/api.php?r=' . $this->_oModule->getName() . '/entity_invit&params[]=' . $iContentId . '&params[]=' . $sDisplay, 'immutable' => true]]])] : $oForm->getCode();
             else
                 return $this->_bIsApi ?  [bx_api_get_msg('_sys_txt_error_entry_update')] : MsgBox(_t('_sys_txt_error_entry_update'));
         }
@@ -81,6 +82,9 @@ class BxBaseModGroupsFormsEntryHelper extends BxBaseModProfileFormsEntryHelper
         $this->_oModule->$sCheckFunction($aContentInfo, true);
 
         // Redirect
+         if (bx_is_api())
+            return [$this->redirectAfterEdit($aContentInfo)];
+        else
         $this->redirectAfterEdit($aContentInfo);
     }
 

+ 6 - 4
modules/base/groups/classes/BxBaseModGroupsModule.php

@@ -60,11 +60,13 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
         echo(json_encode($a));
     }
     
-    public function serviceGetInitialMembers ()
+    public function serviceGetInitialMembers ($sParams)
     {
-        $sTerm = bx_get('term');
-
-        $a = BxDolService::call('system', 'profiles_search', [$sTerm, ['module' => $this->_oConfig->getName()]], 'TemplServiceProfiles');
+        $aOptions = json_decode($sParams, true);
+        if (!$sParams || !isset($aOptions['term']))
+            return [];
+        
+        $a = BxDolService::call('system', 'profiles_search', [$aOptions['term'], ['module' => $this->_oConfig->getName()]], 'TemplServiceProfiles');
 
         return $a;
     }

+ 1 - 1
modules/base/profile/classes/BxBaseModProfileDb.php

@@ -75,7 +75,7 @@ class BxBaseModProfileDb extends BxBaseModGeneralDb
         
         $sWhere = '';
         foreach ($this->_oConfig->CNF['FIELDS_QUICK_SEARCH'] as $sField) {
-        	$aBindings[$sField] = $sTerm . '%';
+        	$aBindings[$sField] = '%' . $sTerm . '%';
 
             $sWhere .= " OR `c`.`$sField` LIKE :" . $sField;
         }