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

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

roman.lesnikov@gmail.com 2 лет назад
Родитель
Сommit
1cadd8c4eb

+ 4 - 0
modules/base/groups/classes/BxBaseModGroupsFormEntry.php

@@ -103,6 +103,10 @@ class BxBaseModGroupsFormEntry extends BxBaseModProfileFormEntry
     protected function genCustomInputInitialMembers ($aInput)
     {
         $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . "modules/?r=" . $this->_oModule->_oConfig->getUri() . "/ajax_get_initial_members";
+        if (bx_is_api()){
+            $aInput['ajax_get_suggestions'] = $this->_oModule->_oConfig->getName() . "/get_initial_members&params[]=";
+        }
+
         return $this->genCustomInputUsernamesSuggestions($aInput);
     }
 }

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

@@ -47,28 +47,28 @@ class BxBaseModGroupsFormsEntryHelper extends BxBaseModProfileFormsEntryHelper
         list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
 
         if(!$aContentInfo)
-            return $bErrorMsg ? MsgBox(_t('_sys_txt_error_entry_is_not_defined')) : '';
+            return $bErrorMsg ? ($this->_bIsApi ? [bx_api_get_msg('_sys_txt_error_entry_is_not_defined')] : MsgBox('_sys_txt_error_entry_is_not_defined')) : '';
 
         // check access
         if(($sMsg = $this->_oModule->$sCheckFunction($aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED)
-            return $bErrorMsg ? MsgBox($sMsg) : '';
+            return $bErrorMsg ? ($this->_bIsApi ? [bx_api_get_msg($sMsg)] : MsgBox($sMsg)) : '';
 
         // check and display form
         $oForm = $this->getObjectFormInvite($sDisplay);
         if(!$oForm)
-            return $bErrorMsg ? MsgBox(_t('_sys_txt_error_occured')) : '';
+            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 $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', 'immutable' => true]]])] : $oForm->getCode();
 
         $this->onDataInviteBefore($aContentInfo[$CNF['FIELD_ID']], $aContentInfo);
 
         if (!$oForm->update($aContentInfo[$CNF['FIELD_ID']])) {
             if (!$oForm->isValid())
-                return $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', 'immutable' => true]]])] : $oForm->getCode();
             else
-                return MsgBox(_t('_sys_txt_error_entry_update'));
+                return $this->_bIsApi ?  [bx_api_get_msg('_sys_txt_error_entry_update')] : MsgBox(_t('_sys_txt_error_entry_update'));
         }
 
         list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);

+ 10 - 0
modules/base/groups/classes/BxBaseModGroupsModule.php

@@ -60,6 +60,15 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
         echo(json_encode($a));
     }
     
+    public function serviceGetInitialMembers ()
+    {
+        $sTerm = bx_get('term');
+
+        $a = BxDolService::call('system', 'profiles_search', [$sTerm, ['module' => $this->_oConfig->getName()]], 'TemplServiceProfiles');
+
+        return $a;
+    }
+    
     /**
      * Process Process Invitation
      */
@@ -211,6 +220,7 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
     {
         return array_merge(parent::serviceGetSafeServices(), [
             'GetQuestionnaire' => '',
+            'GetInitialMembers' => '',
         ]);
     }
 

+ 5 - 0
modules/base/profile/classes/BxBaseModProfileModule.php

@@ -370,6 +370,10 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
         foreach ($a as $r) {
             $oProfile = BxDolProfile::getInstance($r['profile_id']);
 
+            if (bx_is_api()){
+                $aRet[] = $oProfile->getUnitAPI(0, ['template' => 'unit_wo_info']);
+            }
+            else{
             $aRet[] = array (
             	'label' => $this->serviceProfileName($r['content_id']), 
                 'value' => $r['profile_id'], 
@@ -378,6 +382,7 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
                 'unit' => $oProfile->getUnit(0, ['template' => ['name' => 'unit_wo_info', 'size' => 'icon']])
             );
         }
+        }
 
         return $aRet;
     }

+ 1 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -1751,6 +1751,7 @@
     <string name="_adm_stg_cpt_option_sys_api_cookie_samesite"><![CDATA[Cookies SameSite attribute]]></string>
     <string name="_adm_stg_cpt_option_sys_api_menu_top"><![CDATA[Top Menu]]></string>
     <string name="_adm_stg_cpt_option_sys_api_comments_flat"><![CDATA[Flat comments]]></string>
+    <string name="_adm_stg_cpt_option_sys_api_comments_modal"><![CDATA[Comments in modal]]></string>
     <string name="_adm_stg_cpt_option_sys_api_search_sections"><![CDATA[Search sections]]></string>
     <string name="_adm_stg_cpt_option_sys_api_extended_units"><![CDATA[Use extended units]]></string>
     <string name="_adm_stg_cpt_option_sys_api_conn_in_prof_units"><![CDATA[Use connections lists in profiles/groups units]]></string>

+ 11 - 0
template/scripts/BxBaseFormView.php

@@ -369,6 +369,12 @@ class BxBaseFormView extends BxDolForm
                     $aInput['values_src'] = '';
                 }
                 
+                if (isset($aInput['type']) && 'custom' == $aInput['type']){
+                    $sCustomMethod = 'genCustomInput' . $this->_genMethodName($aInput['name']);
+                    if (method_exists($this, $sCustomMethod))
+                         $aInput = $this->$sCustomMethod($aInput);
+                }
+                
                 if (isset($aInput['type']) && 'block_header' == $aInput['type']){
                     $aInput['name'] = $key;
                 }
@@ -1699,6 +1705,11 @@ BLAH;
             $aTmplVarsInputText['input'] = $this->genInputStandard($aInputText);
         }
 
+       if (bx_is_api()){
+           $aInput['type'] = 'initial_members';
+           return $aInput;
+       }
+        
         $this->addCssJsUi();
 
         $sJsCode = '';