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

Ticket #5542 - Extended search: Add search by Visibility.

AntonLV 3 месяцев назад
Родитель
Сommit
fe0548b0d8

+ 22 - 8
template/scripts/BxBaseSearchExtended.php

@@ -99,6 +99,9 @@ class BxBaseSearchExtended extends BxDolSearchExtended
             $oForm->initChecker([], $aParams['cond']);
         }
 
+        if($this->_bFilterMode && ($iContextId = $aParams['context_id'] ?? false))
+            $oForm->setSubmittedValue('allow_view_to', -$iContextId, $oForm->aFormAttrs['method']);
+
         if(!$oForm->isSubmittedAndValid() && !$this->_bFilterMode  && (!$this->_bIsApi || !isset($aParams['search_params'])))
             return $this->_bIsApi ? [$this->getResultsAPI([], $iStart, $iPerPage)] : '';
 
@@ -326,27 +329,32 @@ class BxBaseSearchExtended extends BxDolSearchExtended
         ]);
     }
 
-    protected function &prepareForm($aParams = array())
+    protected function &prepareForm($aParams = [])
     {
         if(!empty($this->_oForm) && $this->_oForm instanceof BxDolForm)
             return $this->_oForm;
 
+        $iContextId = (int)($aParams['context_id'] ?? 0);
+        $sContextIdParam = $aParams['context_id_param'] ?? 'profile_id';
+
         $sForm = 'sys_search_extended_' . $this->_sObject;
         $sFormSubmit = 'search' . $this->_sObject;
 
         list($sPageLink, $aPageParams) = bx_get_base_url_inline();
-        
+
+        $sAction = !empty($aPageParams['i']) ? BxDolPermalinks::getInstance()->permalink(bx_append_url_params($sPageLink, ['i' => $aPageParams['i']])) : $sPageLink;
+        if($iContextId)
+            $sAction = bx_append_url_params($sAction, [$sContextIdParam => $iContextId]);
+
         $mDefValues = bx_get('filters');
-       
-        if ($mDefValues){
+        if($mDefValues)
             $mDefValues = json_decode($mDefValues, true);
-        }
 
         $aForm = array(
             'form_attrs' => array(
                 'id' => $sForm,
                 'name' => $sForm,
-                'action' => !empty($aPageParams['i']) ? BxDolPermalinks::getInstance()->permalink(bx_append_url_params($sPageLink, array('i' => $aPageParams['i']))) : $sPageLink,
+                'action' => $sAction,
                 'method' => 'post'
             ),
             'params' => array(
@@ -406,11 +414,17 @@ class BxBaseSearchExtended extends BxDolSearchExtended
                 $aForm['inputs'][$aField['name']]['manual_input'] = true;
         }
 
-        $aForm['inputs']['search'] = array(
+        if($iContextId && isset($aForm['inputs']['allow_view_to']))
+            $aForm['inputs']['allow_view_to'] = array_merge($aForm['inputs']['allow_view_to'], [
+                'type' => 'hidden',
+                'value' => -$iContextId
+            ]);
+
+        $aForm['inputs']['search'] = [
             'type' => 'submit',
             'name' => $sFormSubmit,
             'value' => _t($this->_bFilterMode ? '_Apply' : '_Search')
-        );
+        ];
 
         $sClass = 'BxTemplSearchExtendedForm';
         if(!empty($this->_sFormClassName)) {

+ 1 - 1
template/scripts/BxBaseSearchExtendedForm.php

@@ -228,7 +228,7 @@ class BxBaseSearchExtendedForm extends BxTemplFormView
         }
 
         $aInput['values'] = $aValues;
-        return $this->genInputSelect($aInput);
+        return $this->{'genInput' . ($aInput['type'] == 'hidden' ? 'Standard' : 'Select')}($aInput);
     }
 
     function addCssJsCore ()

+ 23 - 17
template/scripts/BxBaseSearchExtendedServices.php

@@ -100,35 +100,41 @@ class BxBaseSearchExtendedServices extends BxDol
 
         $sResults = $oSearch->getResults($aParams);
 
-        if (bx_is_api()){
+        if(bx_is_api())
             return $sResults;
-        }
-        
+
         return !empty($sResults) ? $sResults : (isset($aParams['show_empty']) && (bool)$aParams['show_empty'] ? MsgBox(_t('_Empty')) : ''); 
     }
 
     public function prepareParams(&$aParams)
     {
-        if(empty($aParams['object']) && bx_get('object') !== false)
-            $aParams['object'] = bx_process_input(bx_get('object'), BX_DATA_TEXT);
+        $this->_prepareParamEmpty('object', BX_DATA_TEXT, $aParams);
+        $this->_prepareParamEmpty('context_id', BX_DATA_INT, $aParams);
+        $this->_prepareParamEmpty('template', BX_DATA_TEXT, $aParams);
 
-        if(!isset($aParams['show_empty']) && bx_get('show_empty') !== false)
-            $aParams['show_empty'] = (bool)bx_get('show_empty');
+        if(($sK = 'show_empty') && !isset($aParams[$sK]) && ($iShowEmpty = bx_get($sK)) !== false)
+            $aParams[$sK] = (bool)$iShowEmpty;
 
-        if(empty($aParams['template']) && bx_get('template') !== false)
-            $aParams['template'] = bx_process_input(bx_get('template'), BX_DATA_TEXT);
+        if(($sK = 'cond') && empty($aParams[$sK]) && ($sCond = bx_get('cond')) !== false)
+            $aParams[$sK] = BxDolSearchExtended::decodeConditions(bx_process_input($sCond, BX_DATA_TEXT));
 
-        if(empty($aParams['cond']) && bx_get('cond') !== false)
-            $aParams['cond'] = BxDolSearchExtended::decodeConditions(bx_process_input(bx_get('cond'), BX_DATA_TEXT));
+        $this->_prepareParamIsset('start', BX_DATA_INT, $aParams);
+        $this->_prepareParamIsset('per_page', BX_DATA_INT, $aParams);
 
-        if(!isset($aParams['start']) && bx_get('start') !== false)
-            $aParams['start'] = (int)bx_get('start');
+        if(($sK = 'total') && !isset($aParams[$sK]) && ($mixedTotal = bx_get($sK)) !== false)
+            $aParams[$sK] = is_numeric($mixedTotal) ? (int)$mixedTotal : $mixedTotal == 'true';
+    }
 
-        if(!isset($aParams['per_page']) && bx_get('per_page') !== false)
-            $aParams['per_page'] = (int)bx_get('per_page');
+    protected function _prepareParamEmpty($sParam, $iDataType, &$aParams)
+    {
+        if(empty($aParams[$sParam]) && ($mixedValue = bx_get($sParam)) !== false)
+            $aParams[$sParam] = bx_process_input($mixedValue, $iDataType);
+    }
 
-        if(!isset($aParams['total']) && ($mixedTotal = bx_get('total')) !== false)
-            $aParams['total'] = is_numeric($mixedTotal) ? (int)$mixedTotal : $mixedTotal == 'true';
+    protected function _prepareParamIsset($sParam, $iDataType, &$aParams)
+    {
+        if(!isset($aParams[$sParam]) && ($mixedValue = bx_get($sParam)) !== false)
+            $aParams[$sParam] = bx_process_input($mixedValue, $iDataType);
     }
 }