Procházet zdrojové kódy

Ticket #3728 - Profiles: Add 'People you may know' block: Core changes.

AntonLV před 4 roky
rodič
revize
7fae6159e8

+ 10 - 2
inc/classes/BxDolConnection.php

@@ -625,13 +625,17 @@ class BxDolConnection extends BxDolFactory implements iBxDolFactoryObject
      */
     public function getConnectedContentAsCondition ($sContentField, $iInitiator, $iMutual = false)
     {
+        $sOperation = '=';
+        if(is_array($iInitiator))
+            $sOperation = 'in';
+
         return array(
 
             'restriction' => array (
                 'connections_' . $this->_sObject => array(
                     'value' => $iInitiator,
                     'field' => 'initiator',
-                    'operator' => '=',
+                    'operator' => $sOperation,
                     'table' => $this->_aObject['table'],
                 ),
                 'connections_mutual_' . $this->_sObject => array(
@@ -664,13 +668,17 @@ class BxDolConnection extends BxDolFactory implements iBxDolFactoryObject
      */
     public function getConnectedInitiatorsAsCondition ($sContentField, $iContent, $iMutual = false)
     {
+        $sOperation = '=';
+        if(is_array($iContent))
+            $sOperation = 'in';
+
         return array(
 
             'restriction' => array (
                 'connections_' . $this->_sObject => array(
                     'value' => $iContent,
                     'field' => 'content',
-                    'operator' => '=',
+                    'operator' => $sOperation,
                     'table' => $this->_aObject['table'],
                 ),
                 'connections_mutual_' . $this->_sObject => array(

+ 6 - 1
inc/classes/BxDolSearch.php

@@ -715,7 +715,12 @@ class BxDolSearchResult implements iBxDolReplaceable
             $aSql[$sKey] .= $sValue;
 
         // execution
-        $sqlQuery = "SELECT " . $aSql['ownFields'];
+        $sqlQuery = 'SELECT';
+
+        if(isset($this->aCurrent['distinct']) && $this->aCurrent['distinct'] === true)
+            $sqlQuery .= ' DISTINCT';
+
+        $sqlQuery .= ' ' . $aSql['ownFields'];
 
         $sqlQuery .= ' ' . $aSql['from'];
 

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

@@ -685,6 +685,43 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
     {
         return $this->_serviceBrowse ('active', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
     }
+    
+    /**
+     * @page service Service Calls
+     * @section bx_base_profile Base Profile
+     * @subsection bx_base_profile-browse Browse
+     * @subsubsection bx_base_profile-browse_familiar_profiles browse_familiar_profiles
+     * 
+     * @code bx_srv('bx_persons', 'browse_familiar_profiles', [...]); @endcode
+     * 
+     * Browse profiles you might be familiar with. By default using 'Profile Friends' connection.
+     * @param $bEmptyMessage optional, display or not "empty" message when there is no content
+     * @param $bAjaxPaginate optional, use AJAX paginate or not
+     * 
+     * @see BxBaseModProfileModule::serviceBrowseFamiliarProfiles
+     */
+    /** 
+     * @ref bx_base_profile-browse_familiar_profiles "browse_familiar_profiles"
+     */
+    public function serviceBrowseFamiliarProfiles ($sConnection = '', $sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = false)
+    {
+        $aParams = [
+            'object' => 'sys_profiles_friends',
+            'profile' => bx_get_logged_profile_id(),
+        ];
+
+        if(!empty($sConnection)) {
+            if(is_string($sConnection))
+                $aParams['object'] = $sConnection;
+            else if(is_array($sConnection))
+                $aParams = array_merge($aParams, $sConnection);
+        }
+
+        if($sUnitView)
+            $aParams['unit_view'] = $sUnitView;
+
+        return $this->_serviceBrowse ('familiar', $aParams, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
+    }
 
     /**
      * @page service Service Calls

+ 41 - 4
modules/base/profile/classes/BxBaseModProfileSearchResult.php

@@ -16,9 +16,18 @@ class BxBaseModProfileSearchResult extends BxBaseModGeneralSearchResult
     public function __construct($sMode = '', $aParams = array())
     {
         parent::__construct($sMode, $aParams);
-        $this->aUnitViews = array('gallery' => 'unit_with_cover.html', 'gallery_wo_info' => 'unit_wo_info.html', 'showcase' => 'unit_with_cover_showcase.html', 'showcase_wo_info' => 'unit_wo_info_showcase.html', 'simple' => 'unit_wo_links.html');
+
+        $this->aUnitViews = [
+            'unit' => 'unit_wo_cover.html', 
+            'unit_wo_info' => 'unit_wo_info.html', 
+            'gallery' => 'unit_with_cover.html', 
+            'showcase' => 'unit_with_cover_showcase.html', 
+            'showcase_wo_info' => 'unit_wo_info_showcase.html', 
+            'simple' => 'unit_wo_links.html'
+        ];
         if (!empty($aParams['unit_views']) && is_array($aParams['unit_views']))
             $this->aUnitViews = array_merge ($this->aUnitViews, $aParams['unit_views']);
+
         if (!empty($aParams['unit_view']))
             $this->sUnitViewDefault = $aParams['unit_view'];
         
@@ -30,15 +39,16 @@ class BxBaseModProfileSearchResult extends BxBaseModGeneralSearchResult
             'bx-def-margin-sec-neg'
         ));
 
-        if(in_array($this->sUnitTemplate, array('unit_wo_info.html', 'unit_wo_info_showcase.html'))) {
+        if(in_array($this->sUnitTemplate, ['unit_wo_cover.html', 'unit_wo_info.html', 'unit_wo_info_showcase.html']))
             $this->removeContainerClass('bx-def-margin-sec-neg');
-        }
-        if(in_array($this->sUnitTemplate, array('unit_with_cover_showcase.html', 'unit_wo_info_showcase.html'))) {
+
+        if(in_array($this->sUnitTemplate, ['unit_with_cover_showcase.html', 'unit_wo_info_showcase.html'])) {
             $this->bShowcaseView = true;
 
             if($this->sUnitTemplate == 'unit_wo_info_showcase.html')
                 $this->addContainerAttribute(array('bx-sc-group-cells' => 3));
         }
+
         if ($sMode == 'recommended')
             $this->bRecommendedView=true;
     }
@@ -114,6 +124,33 @@ class BxBaseModProfileSearchResult extends BxBaseModGeneralSearchResult
         return true;
     }
     
+    protected function _setFamiliarConnectionsConditions ($aParams)
+    {
+        $oConnection = isset($aParams['object']) ? BxDolConnection::getObjectInstance($aParams['object']) : false;
+        if (!$oConnection || !isset($aParams['profile']) || !(int)$aParams['profile'])
+            return false;
+
+        $iProfile = (int)$aParams['profile'];
+        $sContentType = isset($aParams['type']) ? $aParams['type'] : BX_CONNECTIONS_CONTENT_TYPE_CONTENT;
+        $isMutual = isset($aParams['mutual']) ? $aParams['mutual'] : false;
+
+        $aIds = $oConnection->getConnectionsAsArray($sContentType, $iProfile, false, $isMutual);
+
+        $aCondition = $oConnection->getConnectionsAsCondition ($sContentType, 'id', $aIds, false, $isMutual);
+
+        $this->aCurrent['distinct'] = true;
+        $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aCondition['join']);
+        $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aCondition['restriction'], [
+            'connected' => [
+                'value' => array_merge([$iProfile], $aIds),
+                'field' => 'id',
+                'operator' => 'not in',
+            ]
+        ]);
+
+        return true;
+    }
+    
     protected function _setConditionsForRecommended ()
     {
         $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');