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

#1689 When profile status isn't 'active' then hide any profile content: connections

Alex Trofimov 4 лет назад
Родитель
Сommit
dbc54c883c
2 измененных файлов с 43 добавлено и 14 удалено
  1. 29 7
      inc/classes/BxDolConnectionQuery.php
  2. 14 7
      samples/connections.php

+ 29 - 7
inc/classes/BxDolConnectionQuery.php

@@ -44,10 +44,13 @@ class BxDolConnectionQuery extends BxDolDb
             $sWhereJoin1 .= $this->prepareAsString(" AND `c`.`mutual` = ?", $isMutual);
             $sWhereJoin2 .= $this->prepareAsString(" AND `c2`.`mutual` = ?", $isMutual);
         }
+
+        $sJoin = $this->_aObject['profile_content'] ? "INNER JOIN `sys_profiles` AS `p1` ON (`p1`.`id` = `c`.`content` AND `p1`.`status` = 'active') INNER JOIN `sys_profiles` AS `p2` ON (`p2`.`id` = `c2`.`content` AND `p2`.`status` = 'active')" : '';
+
         return array(
             'join' => "
                 INNER JOIN `{$this->_sTable}` AS `c` ON (`c`.`content` = `$sContentTable`.`$sContentField` $sWhereJoin1)
-                INNER JOIN `{$this->_sTable}` AS `c2` ON (`c2`.`content` = `c`.`content` $sWhereJoin2)",
+                INNER JOIN `{$this->_sTable}` AS `c2` ON (`c2`.`content` = `c`.`content` $sWhereJoin2)" . $sJoin,
         );
     }
 
@@ -59,9 +62,11 @@ class BxDolConnectionQuery extends BxDolDb
         foreach($aResult['fields'] as $sFieldAlias => $aField)
             $aFields[$sFieldAlias] = "`" . $aField['table_alias'] . "`.`" . $aField['name'] . "`";
 
+        $sJoin = $this->_aObject['profile_content'] ? "INNER JOIN `sys_profiles` ON (`sys_profiles`.`id` = `{$aResult['join']['table_alias']}`.`content` AND `p`.`status` = 'active')" : '';
+
         return array(
             'fields' => $aFields,
-            'join' => $aResult['join']['type'] . " JOIN `" . $aResult['join']['table'] . "` AS `" . $aResult['join']['table_alias'] . "` ON (" . $aResult['join']['condition'] . ")",
+            'join' => $aResult['join']['type'] . " JOIN `" . $aResult['join']['table'] . "` AS `" . $aResult['join']['table_alias'] . "` ON (" . $aResult['join']['condition'] . ") " . $sJoin,
         );
     }
 
@@ -98,8 +103,11 @@ class BxDolConnectionQuery extends BxDolDb
     public function getConnectedInitiatorsSQLParts ($sInitiatorTable, $sInitiatorField, $iContent, $isMutual = false)
     {
         $aResult = $this->getConnectedInitiatorsSQLPartsExt($sInitiatorTable, $sInitiatorField, $iContent, $isMutual);
+
+        $sJoin = $this->_aObject['profile_initiator'] ? "INNER JOIN `sys_profiles` ON (`sys_profiles`.`id` = `{$aResult['join']['table_alias']}`.`initiator` AND `sys_profiles`.`status` = 'active')" : '';
+
         return array(
-            'join' => $aResult['join']['type'] . " JOIN `" . $aResult['join']['table'] . "` AS `" . $aResult['join']['table_alias'] . "` ON (" . $aResult['join']['condition'] . ")",
+            'join' => $aResult['join']['type'] . " JOIN `" . $aResult['join']['table'] . "` AS `" . $aResult['join']['table_alias'] . "` ON (" . $aResult['join']['condition'] . ") " . $sJoin,
         );
     }
 
@@ -136,6 +144,8 @@ class BxDolConnectionQuery extends BxDolDb
         $sWhereJoin = (false !== $isMutual) ? " AND `c2`.`mutual` = :mutual" : "";
         $sJoin = "INNER JOIN `" . $this->_sTable . "` AS `c2` ON (`c2`.`initiator` = :initiator2 AND `c`.`content` = `c2`.`content` $sWhereJoin)";
 
+        $sJoin .= $this->_aObject['profile_content'] ? "INNER JOIN `sys_profiles` AS `p1` ON (`p1`.`id` = `c`.`content` AND `p1`.`status` = 'active') INNER JOIN `sys_profiles` AS `p2` ON (`p2`.`id` = `c2`.`content` AND `p2`.`status` = 'active')" : '';
+
         $sWhere = " AND `c`.`initiator` = :initiator1";
         $sQuery = $this->_getConnectionsQuery($sWhere, $sJoin, '`c`.`content`', $isMutual, $iStart, $iLimit, $iOrder);
 
@@ -149,7 +159,10 @@ class BxDolConnectionQuery extends BxDolDb
     public function getConnectedContent ($iInitiator, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
     {
         $sWhere = " AND `c`.`initiator` = :initiator";
-        $sQuery = $this->_getConnectionsQuery($sWhere, '', '`c`.`content`', $isMutual, $iStart, $iLimit, $iOrder);
+
+        $sJoin = $this->_aObject['profile_content'] ? "INNER JOIN `sys_profiles` `p` ON `p`.`id` = `c`.`content` AND `p`.`status` = 'active'" : '';
+
+        $sQuery = $this->_getConnectionsQuery($sWhere, $sJoin, '`c`.`content`', $isMutual, $iStart, $iLimit, $iOrder);
 
         return $this->getColumn($sQuery, array(
         	'initiator' => $iInitiator
@@ -161,7 +174,10 @@ class BxDolConnectionQuery extends BxDolDb
         $mixedType = is_array($mixedType) ? $mixedType : array($mixedType);
 
         $sWhere = " AND `c`.`initiator` = :initiator";
-        $sQuery = $this->_getConnectionsQuery($sWhere, 'INNER JOIN `sys_profiles` `p` ON `p`.`id` = `c`.`content` AND `p`.`type` IN (' . $this->implode_escape($mixedType) . ')', '`c`.`content`', $isMutual, $iStart, $iLimit, $iOrder);
+
+        $sJoin = $this->_aObject['profile_content'] ? 'INNER JOIN `sys_profiles` `p` ON `p`.`id` = `c`.`content` AND `p`.`status` = \'active\' AND `p`.`type` IN (' . $this->implode_escape($mixedType) . ')' : '';
+
+        $sQuery = $this->_getConnectionsQuery($sWhere, $sJoin, '`c`.`content`', $isMutual, $iStart, $iLimit, $iOrder);
 
         return $this->getColumn($sQuery, array(
             'initiator' => $iInitiator,
@@ -171,7 +187,10 @@ class BxDolConnectionQuery extends BxDolDb
     public function getConnectedInitiators ($iContent, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
     {
         $sWhere = " AND `c`.`content` = :content";
-        $sQuery = $this->_getConnectionsQuery($sWhere, '', '`c`.`initiator`', $isMutual, $iStart, $iLimit, $iOrder);
+
+        $sJoin = $this->_aObject['profile_initiator'] ? 'INNER JOIN `sys_profiles` `p` ON `p`.`id` = `c`.`initiator` AND `p`.`status` = \'active\'' : ''; 
+
+        $sQuery = $this->_getConnectionsQuery($sWhere, $sJoin, '`c`.`initiator`', $isMutual, $iStart, $iLimit, $iOrder);
 
         return $this->getColumn($sQuery, array(
             'content' => $iContent
@@ -183,7 +202,10 @@ class BxDolConnectionQuery extends BxDolDb
         $mixedType = is_array($mixedType) ? $mixedType : array($mixedType);
 
         $sWhere = " AND `c`.`content` = :content";
-        $sQuery = $this->_getConnectionsQuery($sWhere, 'INNER JOIN `sys_profiles` `p` ON `p`.`id` = `c`.`initiator` AND `p`.`type` IN (' . $this->implode_escape($mixedType) . ')', '`c`.`initiator`', $isMutual, $iStart, $iLimit, $iOrder);
+
+        $sJoin = $this->_aObject['profile_initiator'] ? 'INNER JOIN `sys_profiles` `p` ON `p`.`id` = `c`.`initiator` AND `p`.`status` = \'active\' AND `p`.`type` IN (' . $this->implode_escape($mixedType) . ')' : ''; 
+
+        $sQuery = $this->_getConnectionsQuery($sWhere, $sJoin, '`c`.`initiator`', $isMutual, $iStart, $iLimit, $iOrder);
 
         return $this->getColumn($sQuery, array(
             'content' => $iContent,

+ 14 - 7
samples/connections.php

@@ -143,25 +143,32 @@ function PageCompMainCode()
             $f($oConnection->getConnectedInitiatorsAsSQLParts('p', 'id', $iProfileId, 0));
 
         break;
-        case 'search-results':
+        case 'search-results': 
 
             echo "<h2>Common Content (like mutual Friends between two initiators)</h2>";
-            echo BxDolService::call('bx_persons', 'browse_connections', array($iProfileId, 'sys_profiles_friends', 'common', 1, BX_DB_CONTENT_ONLY, $iProfileId2));
+            $a = bx_srv('bx_persons', 'browse_connections', [$iProfileId, 'sys_profiles_friends', 'common', 1, BX_DB_CONTENT_ONLY, $iProfileId2]);
+            echo (isset($a['content']) ? $a['content'] : '');
 
             echo "<h2>Mutual Content (like Friends)</h2>";
-            echo BxDolService::call('bx_persons', 'browse_connections', array($iProfileId, 'sys_profiles_friends', 'content', 1, BX_DB_CONTENT_ONLY));
+            $a = bx_srv('bx_persons', 'browse_connections', [$iProfileId, 'sys_profiles_friends', 'content', 1, BX_DB_CONTENT_ONLY]);
+            echo (isset($a['content']) ? $a['content'] : '');
 
             echo "<h2>Connected Content</h2>";
-            echo BxDolService::call('bx_persons', 'browse_connections', array($iProfileId, 'sys_profiles_friends', 'content', false, BX_DB_CONTENT_ONLY));
+
+            $a = bx_srv('bx_persons', 'browse_connections', [$iProfileId, 'sys_profiles_friends', 'content', false, BX_DB_CONTENT_ONLY]);
+            echo (isset($a['content']) ? $a['content'] : '');
 
             echo "<h2>Connected Initiators</h2>";
-            echo BxDolService::call('bx_persons', 'browse_connections', array($iProfileId, 'sys_profiles_friends', 'initiators', false, BX_DB_CONTENT_ONLY));
+            $a = bx_srv('bx_persons', 'browse_connections', [$iProfileId, 'sys_profiles_friends', 'initiators', false, BX_DB_CONTENT_ONLY]);
+            echo (isset($a['content']) ? $a['content'] : '');
 
             echo "<h2>Connected Content without mutual content (like Friend Requests sent)</h2>";
-            echo BxDolService::call('bx_persons', 'browse_connections', array($iProfileId, 'sys_profiles_friends', 'content', 0, BX_DB_CONTENT_ONLY));
+            $a = bx_srv('bx_persons', 'browse_connections', [$iProfileId, 'sys_profiles_friends', 'content', 0, BX_DB_CONTENT_ONLY]);
+            echo (isset($a['content']) ? $a['content'] : '');
 
             echo "<h2>Connected Initiators without mutual content (like Friend Requests received)</h2>";
-            echo BxDolService::call('bx_persons', 'browse_connections', array($iProfileId, 'sys_profiles_friends', 'initiators', 0, BX_DB_CONTENT_ONLY));
+            $a = BxDolService::call('bx_persons', 'browse_connections', [$iProfileId, 'sys_profiles_friends', 'initiators', 0, BX_DB_CONTENT_ONLY]);
+            echo (isset($a['content']) ? $a['content'] : '');
 
         break;
     }