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

#1678 - Allow to edit 'author' field by admin/moderator in content modules

RomanL 4 лет назад
Родитель
Сommit
3598bb7496

+ 30 - 2
modules/base/general/classes/BxBaseModGeneralFormEntry.php

@@ -64,6 +64,17 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         if (isset($CNF['FIELD_LOCATION_PREFIX']) && isset($this->aInputs[$CNF['FIELD_LOCATION_PREFIX']])) {
             $this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]['manual_input'] = true;
         }
+        
+        if ($this->_oModule->checkAllowedEditAnyEntry(false) === CHECK_ACTION_RESULT_ALLOWED && isset($CNF['FIELD_AUTHOR']) && isset($this->aParams['view_mode']) && $this->aParams['view_mode'] != 1){
+            $this->aInputs = array_merge([
+                $CNF['FIELD_AUTHOR'] => [
+                    'type' => 'custom',
+                    'name' => $CNF['FIELD_AUTHOR'],
+                    'db' => ['pass' => 'Xss'],
+                    'caption' => '_sys_form_input_caption_author'
+                ],
+            ], $this->aInputs);
+        }
 
         if (isset($CNF['FIELD_PHOTO']) && isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
             $this->aInputs[$CNF['FIELD_PHOTO']]['storage_object'] = $CNF['OBJECT_STORAGE'];
@@ -333,7 +344,14 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         $aPrivacyFields = $this->_getPrivacyFields();
         foreach($aPrivacyFields as $sField => $sObject)
             $this->_preloadPrivacyField($sField, $sObject, $aValues);
-
+        
+        if (isset($CNF['FIELD_AUTHOR']) && isset($this->aInputs[$CNF['FIELD_AUTHOR']])){
+            if (isset($aValues[$CNF['FIELD_AUTHOR']]))
+                $aValues[$CNF['FIELD_AUTHOR']] = [$aValues[$CNF['FIELD_AUTHOR']]];
+            else
+                $aValues[$CNF['FIELD_AUTHOR']] = [bx_get_logged_profile_id()];
+        }
+        
         parent::initChecker ($aValues, $aSpecificValues);
 
         foreach($aPrivacyFields as $sField => $sObject)
@@ -344,7 +362,7 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
 
-        if (isset($CNF['FIELD_AUTHOR']) && empty($aValsToAdd[$CNF['FIELD_AUTHOR']]))
+        if (isset($CNF['FIELD_AUTHOR']) && empty($aValsToAdd[$CNF['FIELD_AUTHOR']]) && (!isset($this->aInputs[$CNF['FIELD_AUTHOR']]) || empty($this->getCleanValue($CNF['FIELD_AUTHOR']))))
             $aValsToAdd[$CNF['FIELD_AUTHOR']] = (isset($CNF['FIELD_ANONYMOUS']) && isset($this->aInputs[$CNF['FIELD_ANONYMOUS']]) && $this->getCleanValue($CNF['FIELD_ANONYMOUS']) ? -1 : 1) * bx_get_logged_profile_id ();
 
         if (isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']]) && empty($this->getCleanValue($CNF['FIELD_ADDED'])))
@@ -973,6 +991,16 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         return $this->genInputButton($aInput);
     }
     
+    protected function genCustomInputAuthor ($aInput)
+    {
+        if(empty($aInput['custom']) || !is_array($aInput['custom']))
+            $aInput['custom'] = array();
+        $aInput['custom']['only_once'] = 1;
+        
+        $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . "modules/?r=" . $this->_oModule->_oConfig->getUri() . "/ajax_get_profiles";
+        return $this->genCustomInputUsernamesSuggestions($aInput);
+    }
+    
     protected function _isMulticatEnabled(){
         $CNF = $this->_oModule->_oConfig->CNF;
         return isset($CNF['PARAM_MULTICAT_ENABLED']) && $CNF['PARAM_MULTICAT_ENABLED'] === true && isset($CNF['FIELD_MULTICAT']);

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

@@ -146,6 +146,19 @@ class BxBaseModGeneralModule extends BxDolModule
             echo 'ok';
         }
     }
+    
+    /**
+     * Get possible recipients for start conversation form
+     */
+    public function actionAjaxGetProfiles ()
+    {
+        $sTerm = bx_get('term');
+
+        $a = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
+
+        header('Content-Type:text/javascript; charset=utf-8');
+        echo(json_encode($a));
+    }
 
     // ====== SERVICE METHODS
     

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

@@ -2318,6 +2318,7 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_form_account_input_submit"><![CDATA[Submit]]></string>
 	<string name="_sys_form_checkbox_value_off"><![CDATA[No]]></string>
 	<string name="_sys_form_checkbox_value_on"><![CDATA[Yes]]></string>
+    <string name="_sys_form_input_caption_author"><![CDATA[Author]]></string>
 	<string name="_sys_form_comment"><![CDATA[Comment]]></string>
 	<string name="_sys_form_comment_input_caption_cmt_author_id"><![CDATA[Author]]></string>
 	<string name="_sys_form_comment_input_caption_cmt_text"><![CDATA[Text]]></string>