Skip to content

Commit

Permalink
unacms#1689 When profile status isn't 'active' then hide any profile …
Browse files Browse the repository at this point in the history
…content: connections
  • Loading branch information
Alex Trofimov committed Jan 7, 2022
1 parent 9ea0048 commit dbc54c8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
36 changes: 29 additions & 7 deletions inc/classes/BxDolConnectionQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ public function getCommonContentSQLParts ($sContentTable, $sContentField, $iInit
$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,
);
}

Expand All @@ -59,9 +62,11 @@ public function getConnectedContentSQLParts ($sContentTable, $sContentField, $iI
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,
);
}

Expand Down Expand Up @@ -98,8 +103,11 @@ public function getConnectedContentSQLPartsMultiple ($sContentTable, $sContentFi
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,
);
}

Expand Down Expand Up @@ -136,6 +144,8 @@ public function getCommonContent($iInitiator1, $iInitiator2, $isMutual, $iStart,
$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);

Expand All @@ -149,7 +159,10 @@ public function getCommonContent($iInitiator1, $iInitiator2, $isMutual, $iStart,
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
Expand All @@ -161,7 +174,10 @@ public function getConnectedContentByType ($iInitiator, $mixedType, $isMutual =
$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,
Expand All @@ -171,7 +187,10 @@ public function getConnectedContentByType ($iInitiator, $mixedType, $isMutual =
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
Expand All @@ -183,7 +202,10 @@ public function getConnectedInitiatorsByType ($iContent, $mixedType, $isMutual =
$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,
Expand Down
21 changes: 14 additions & 7 deletions samples/connections.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit dbc54c8

Please sign in to comment.