Răsfoiți Sursa

#3166 Ability to use custom conditions in browse service method

Alex Trofimov 5 ani în urmă
părinte
comite
5aa6068a18

+ 6 - 1
inc/classes/BxDolSearch.php

@@ -107,7 +107,7 @@ class BxDolSearch extends BxDol
             $oEx->setCenterContentUnitSelector(false);
             $oEx->setSingleSearch($bSingle);
             $oEx->setCustomSearchCondition($this->_aCustomSearchCondition);
-            $oEx->aCurrent = array_merge($oEx->aCurrent, $this->_aCustomCurrentCondition);
+            $oEx->aCurrent = array_merge_recursive($oEx->aCurrent, $this->_aCustomCurrentCondition);
             if ($this->_sUnitTemplate)
                 $oEx->setUnitTemplate($this->_sUnitTemplate);
 
@@ -405,6 +405,11 @@ class BxDolSearchResult implements iBxDolReplaceable
         $this->_aCustomSearchCondition = $a;
     }
     
+    public function setCustomCurrentCondition($a)
+    {
+        $this->aCurrent = array_merge_recursive($this->aCurrent, $a);
+    }
+
     public function setCategoriesCondition($sKeyword)
     {
 		$this->aCurrent['join']['multicat'] = array(

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

@@ -479,6 +479,7 @@ class BxBaseModGeneralModule extends BxDolModule
      * @subsubsection bx_base_general-browse browse
      * 
      * @code bx_srv('bx_posts', 'browse', [...]); @endcode
+     * @code {{~bx_posts:browse[{"mode":"author", "params":{"author":"10"}}]~}} @endcode
      * 
      * Universal browse method.
      * @param $aParams custom browse params, possible params are the following:
@@ -494,6 +495,12 @@ class BxBaseModGeneralModule extends BxDolModule
      * @ref bx_base_general-browse "browse"
      */
     public function serviceBrowse ($aParams = array())
+    {
+        unset($aParams['params']['condition']);
+        return $this->serviceBrowseWithCondition ($aParams);
+    }
+
+    public function serviceBrowseWithCondition ($aParams = array())
     {
         $aDefaults = array (
             'mode' => 'recent',
@@ -2309,6 +2316,8 @@ class BxBaseModGeneralModule extends BxDolModule
         $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
         $o->setAjaxPaginate($bAjaxPaginate);
         $o->setUnitParams(array('context' => $sMode));
+        if (isset($aParams['condition']) && is_array($aParams['condition']))
+            $o->setCustomCurrentCondition($aParams['condition']);
 
         if ($o->isError)
             return '';