Kaynağa Gözat

Ticket #4575 - Events: Enhancements. Point 4.

AntonLV 2 yıl önce
ebeveyn
işleme
17a3eda7e9

+ 59 - 1
inc/classes/BxDolLabel.php

@@ -66,10 +66,46 @@ class BxDolLabel extends BxDolFactory implements iBxDolSingleton
         echoJson($aResult);
         echoJson($aResult);
     }
     }
 
 
-    public function getLabels($aParams = array())
+    public function getLabels($aParams = [])
     {
     {
         return $this->_oDb->getLabels($aParams);
         return $this->_oDb->getLabels($aParams);
     }
     }
+    
+    public function getLabelsSystem()
+    {
+        $iParentId = $iLevel = 0;
+        return $this->_getLabelsSystem($iParentId, $iLevel);
+    }
+    
+    public function getLabelsContext($iProfileId = 0)
+    {
+        if(!$iProfileId)
+            $iProfileId = bx_get_logged_profile_id();
+
+        $aModules = bx_srv('system', 'get_modules_by_type', ['context']);
+
+        $aResults = [];
+        foreach($aModules as $aModule) {
+            if(bx_srv($aModule['name'], 'act_as_profile'))
+                continue;
+
+            $aContextPids = bx_srv($aModule['name'], 'get_participating_profiles', [$iProfileId]);
+            if(empty($aContextPids) || !is_array($aContextPids))
+                continue;
+
+            foreach($aContextPids as $iContextPid) {
+                $aContextInfo = bx_srv($aModule['name'], 'get_content_info_by_profile_id', [$iContextPid]);
+                if(empty($aContextInfo['hashtag']))
+                    continue;
+
+                $aResults[] = [
+                    'value' => $aContextInfo['hashtag']
+                ];
+            }
+        }
+
+        return $aResults;
+    }
 
 
     public function getLabelUrl($sKeyword, $mixedSection = false) 
     public function getLabelUrl($sKeyword, $mixedSection = false) 
     {   
     {   
@@ -123,6 +159,28 @@ class BxDolLabel extends BxDolFactory implements iBxDolSingleton
 
 
         bx_alert('label', 'deleted', $iId, false, array('label' => $aLabel));
         bx_alert('label', 'deleted', $iId, false, array('label' => $aLabel));
     }
     }
+
+    protected function _getLabelsSystem($iParentId, $iLevel)
+    {
+        $aLabels = $this->getLabels(['type' => 'parent', 'parent' => $iParentId]);
+        if(empty($aLabels) || !is_array($aLabels))
+            return [];
+
+        $aResults = [];
+        foreach($aLabels as $aLabel) {
+            $aResult = [
+                'value' => $aLabel['value']
+            ];
+
+            $aSubitems = $this->_getLabelsSystem($aLabel['id'], $iLevel + 1);
+            if(!empty($aSubitems) && is_array($aSubitems))
+                $aResult['subitems'] = $aSubitems;
+            
+            $aResults[] = $aResult;
+        }
+
+        return $aResults;
+    }
 }
 }
 
 
 /** @} */
 /** @} */

+ 3 - 6
template/scripts/BxBaseFormView.php

@@ -1778,11 +1778,8 @@ BLAH;
 
 
         $sKeyPlaceholder = $aInput['caption_src'] . '_placeholder';
         $sKeyPlaceholder = $aInput['caption_src'] . '_placeholder';
         if(strcmp($sKeyPlaceholder, _t($sKeyPlaceholder)) != 0)
         if(strcmp($sKeyPlaceholder, _t($sKeyPlaceholder)) != 0)
-            $sValue .= $oLabel->getLabelPlaceholder($sKeyPlaceholder);           
+            $sValue .= $oLabel->getLabelPlaceholder($sKeyPlaceholder);                   
 
 
-       // print_r($aInput);
-         
-        
         $aInputLabels = array(
         $aInputLabels = array(
             'type' => 'custom',
             'type' => 'custom',
             'name' => $sName,
             'name' => $sName,
@@ -1799,9 +1796,9 @@ BLAH;
         
         
         if (bx_is_api()){
         if (bx_is_api()){
             $aInput['type'] = 'labels';
             $aInput['type'] = 'labels';
-            $aInput['ajax_get_suggestions'] = 'system/select_labels/TemplLabelsServices&params[]=';
+            $aInput['ajax_get_suggestions'] = 'system/get_labels/TemplLabelsServices&params[]=';
         }
         }
-        
+
         return $this->oTemplate->parseHtmlByName('label_select_field.html', array(
         return $this->oTemplate->parseHtmlByName('label_select_field.html', array(
             'js_object' => $oLabel->getJsObjectName(),
             'js_object' => $oLabel->getJsObjectName(),
             'js_code' => $oLabel->getJsCodeForm(),
             'js_code' => $oLabel->getJsCodeForm(),

+ 26 - 39
template/scripts/BxBaseLabel.php

@@ -307,47 +307,34 @@ class BxBaseLabel extends BxDolLabel
         $aCheckbox = $aInput;
         $aCheckbox = $aInput;
         $aCheckbox['type'] = 'checkbox';
         $aCheckbox['type'] = 'checkbox';
         $aCheckbox['name'] .= '[]';
         $aCheckbox['name'] .= '[]';
-        
-        $aModules = bx_srv('system', 'get_modules_by_type', ['context']);
+
+        $aLabels = $this->getLabelsContext($iProfileId);
 
 
         $aTmplVarsLabels = [];
         $aTmplVarsLabels = [];
-        foreach($aModules as $aModule) {
-            if(bx_srv($aModule['name'], 'act_as_profile'))
-                continue;
-
-            $aContextPids = bx_srv($aModule['name'], 'get_participating_profiles', [$iProfileId]);
-            if(empty($aContextPids) || !is_array($aContextPids))
-                continue;
-
-            foreach($aContextPids as $iContextPid) {
-                $aContextInfo = bx_srv($aModule['name'], 'get_content_info_by_profile_id', [$iContextPid]);
-                if(empty($aContextInfo['hashtag']))
-                    continue;
-
-                $sLabelValue = $aContextInfo['hashtag'];
-
-                $sHtmlId = 'sys_label_' . $sLabelValue;
-                $bChecked = $bInputValue && in_array($sLabelValue, $aInput['value']);
-
-                $aCheckbox['value'] = $sLabelValue;
-                $aCheckbox['checked'] = $bChecked ? 1 : 0;
-                $aCheckbox['attrs']['id'] = $sHtmlId;
-
-                $aTmplVarsLabels[] = [
-                    'checkbox' => $oForm->genInput($aCheckbox),
-                    'html_id_label' => $sHtmlId,
-                    'title' => $sLabelValue,
-                    'title_attr' => bx_html_attribute($sLabelValue),
-                    'bx_if:show_sublist_link' => [
-                        'condition' => false,
-                        'content' => []
-                    ],
-                    'bx_if:show_sublist' => [
-                        'condition' => false,
-                        'content' => [],
-                    ]
-                ];
-            }
+        foreach($aLabels as $aLabel) {
+            $sLabelValue = $aLabel['value'];
+
+            $sHtmlId = 'sys_label_' . $sLabelValue;
+            $bChecked = $bInputValue && in_array($sLabelValue, $aInput['value']);
+
+            $aCheckbox['value'] = $sLabelValue;
+            $aCheckbox['checked'] = $bChecked ? 1 : 0;
+            $aCheckbox['attrs']['id'] = $sHtmlId;
+
+            $aTmplVarsLabels[] = [
+                'checkbox' => $oForm->genInput($aCheckbox),
+                'html_id_label' => $sHtmlId,
+                'title' => $sLabelValue,
+                'title_attr' => bx_html_attribute($sLabelValue),
+                'bx_if:show_sublist_link' => [
+                    'condition' => false,
+                    'content' => []
+                ],
+                'bx_if:show_sublist' => [
+                    'condition' => false,
+                    'content' => [],
+                ]
+            ];
         }
         }
 
 
         $sContent = $this->_oTemplate->parseHtmlByName('label_select_list_level.html', [
         $sContent = $this->_oTemplate->parseHtmlByName('label_select_list_level.html', [

+ 6 - 2
template/scripts/BxBaseLabelsServices.php

@@ -17,10 +17,14 @@ class BxBaseLabelsServices extends BxDol
         parent::__construct();
         parent::__construct();
     }
     }
 
 
-    public function serviceSelectLabels()
+    public function serviceGetLabels()
     {
     {
         $oLabel = BxDolLabel::getInstance();
         $oLabel = BxDolLabel::getInstance();
-        return 'todo';
+
+        return [
+            'system' => $oLabel->getLabelsSystem(),
+            'context' => $oLabel->getLabelsContext()
+        ];
     }
     }
 }
 }