UNA
BxDolConnection Class Reference
Inheritance diagram for BxDolConnection:
BxDolFactory iBxDolFactoryObject BxBaseConnection BxDolBan BxDolRelation BxTemplConnection BxBaseModGroupsConnectionFans BxCoursesConnectionFans BxEventsConnectionFans BxGroupsConnectionFans BxOrgsConnectionFans BxSpacesConnectionFans

Public Member Functions

 init ()
 
 getType ()
 
 getTable ()
 
 isProfileInitiator ()
 
 isProfileContent ()
 
 checkAllowedConnect ($iInitiator, $iContent, $isPerformAction=false, $isMutual=false, $isInvertResult=false, $isSwap=false, $isCheckExists=true)
 
 actionAdd ($iContent=0, $iInitiator=false)
 
 actionRemove ($iContent=0, $iInitiator=false)
 
 actionReject ($iContent=0, $iInitiator=false)
 
 addConnection ($iInitiator, $iContent, $aParams=array())
 
 removeConnection ($iInitiator, $iContent)
 
 getConnectionsAsArray ($sContentType, $iId1, $iId2, $isMutual=false, $iStart=0, $iLimit=BX_CONNECTIONS_LIST_LIMIT, $iOrder=BX_CONNECTIONS_ORDER_NONE)
 
 getCommonContent ($iInitiator1, $iInitiator2, $isMutual=false, $iStart=0, $iLimit=BX_CONNECTIONS_LIST_LIMIT, $iOrder=BX_CONNECTIONS_ORDER_NONE)
 
 getCommonContentCount ($iInitiator1, $iInitiator2, $isMutual=false)
 
 getConnectedContentCount ($iInitiator, $isMutual=false, $iFromDate=0)
 
 getConnectedInitiatorsCount ($iContent, $isMutual=false)
 
 getConnectedContent ($iInitiator, $isMutual=false, $iStart=0, $iLimit=BX_CONNECTIONS_LIST_LIMIT, $iOrder=BX_CONNECTIONS_ORDER_NONE)
 
 getConnectedContentByType ($iInitiator, $mixedType, $isMutual=false, $iStart=0, $iLimit=BX_CONNECTIONS_LIST_LIMIT, $iOrder=BX_CONNECTIONS_ORDER_NONE)
 
 getConnectedInitiators ($iContent, $isMutual=false, $iStart=0, $iLimit=BX_CONNECTIONS_LIST_LIMIT, $iOrder=BX_CONNECTIONS_ORDER_NONE)
 
 getConnectedInitiatorsByType ($iContent, $mixedType, $isMutual=false, $iStart=0, $iLimit=BX_CONNECTIONS_LIST_LIMIT, $iOrder=BX_CONNECTIONS_ORDER_NONE)
 
 getConnectionsAsSQLParts ($sContentType, $sContentTable, $sContentField, $iId1, $iId2, $isMutual=false)
 
 getCommonContentAsSQLParts ($sContentTable, $sContentField, $iInitiator1, $iInitiator2, $isMutual=false)
 
 getConnectedContentAsSQLParts ($sContentTable, $sContentField, $iInitiator, $isMutual=false)
 
 getConnectedContentAsSQLPartsMultiple ($sContentTable, $sContentField, $sInitiatorTable, $sInitiatorField, $isMutual=false)
 
 getConnectedInitiatorsAsSQLParts ($sInitiatorTable, $sInitiatorField, $iContent, $isMutual=false)
 
 getConnectedInitiatorsAsSQLPartsMultiple ($sInitiatorTable, $sInitiatorField, $sContentTable, $sContentField, $isMutual=false)
 
 getConnectionsAsCondition ($sContentType, $sContentField, $iId1, $iId2, $isMutual=false)
 
 getCommonContentAsCondition ($sContentField, $iInitiator1, $iInitiator2, $iMutual=false)
 
 getConnectedContentAsCondition ($sContentField, $iInitiator, $iMutual=false)
 
 getConnectedInitiatorsAsCondition ($sContentField, $iContent, $iMutual=false)
 
 isConnected ($iInitiator, $iContent, $isMutual=false)
 
 isConnectedNotMutual ($iInitiator, $iContent)
 
 onDeleteInitiatorAndContent ($iId)
 
 onDeleteInitiator ($iIdInitiator)
 
 onDeleteContent ($iIdContent)
 
 onModuleDeleteInitiatorAndContent ($sTable, $sFieldId)
 
 onModuleDeleteInitiator ($sTable, $sFieldId)
 
 onModuleDeleteContent ($sTable, $sFieldId)
 
 onModuleProfileDeleteInitiatorAndContent ($sModuleName)
 
 onModuleProfileDeleteInitiator ($sModuleName)
 
 onModuleProfileDeleteContent ($sModuleName)
 

Static Public Member Functions

static getObjectInstance ($sObject)
 

Protected Member Functions

 __construct ($aObject)
 

Detailed Description

Connection is usefull when you need to organize some sorts of connections between different content, for example: friends, contacts, favorites, block lists, subscriptions, etc.

Two types of connections are supported one way connections (block list, favourites) and mutual (friends).

For automatic handling of connections (like, add/remove connection in frontend) refer to JS function:

See also
bx_conn_action()

Creating the Connection object:

Step 1: Add record to 'sys_objects_connection' table:

  • object: name of the connection object, in the format: vendor prefix, underscore, module prefix, underscore, internal identifier or nothing; for example: bx_blogs_favorites - favorite blogs for users in blogs module.
  • table: table name with connections, see step 2
  • type: 'one-way' or 'mutual'
  • override_class_name: user defined class name which is derived from one of base classes.
  • override_class_file: the location of the user defined class, leave it empty if class is located in system folders.

Step 2: Create table for connections:

CREATE TABLE `my_sample_connections` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`initiator` int(11) NOT NULL,
`content` int(11) NOT NULL,
`mutual` tinyint(4) NOT NULL, -- can re removed for one-way connections
`added` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `initiator` (`initiator`,`content`),
KEY `content` (`content`)
)

Example of usage

Check if two profiles are friends:

$oConnectionFriends = BxDolConnection::getObjectInstance('bx_profiles_friends'); // get friends connections object
if ($oConnectionFriends) // check if connections is available for using
echo $oConnectionFriends->isConnected (100, 200, true) ? "100 and 200 are friends" : "100 and 200 aren't friends"; // check if profiles with IDs 100 and 200 have mutual connections

Get mutual content IDs (friends IDs)

$oConnectionFriends = BxDolConnection::getObjectInstance('bx_profiles_friends'); // get friends connections object
if ($oConnectionFriends) // check if connections is available for using
print_r($oConnection->getConnectedContent(100, 1)); // print array of friends IDs of 100's profile

Constructor & Destructor Documentation

◆ __construct()

BxDolConnection::__construct (   $aObject)
protected

Constructor

Parameters
$aObjectarray of connection options

Member Function Documentation

◆ actionAdd()

BxDolConnection::actionAdd (   $iContent = 0,
  $iInitiator = false 
)

Add new connection.

Parameters
$iContentcontent to make connection to, in most cases some content id, or other profile id in case of friends
Returns
array

◆ actionReject()

BxDolConnection::actionReject (   $iContent = 0,
  $iInitiator = false 
)

Reject connection request. This method is wrapper for

See also
removeConnection to be called from
conn.php upon AJAX request to this file.
Parameters
$iContentcontent to make connection to, in most cases some content id, or other profile id in case of friends
Returns
array

◆ actionRemove()

BxDolConnection::actionRemove (   $iContent = 0,
  $iInitiator = false 
)

Remove connection. This method is wrapper for

See also
removeConnection to be called from
conn.php upon AJAX request to this file.
Parameters
$iContentcontent to make connection to, in most cases some content id, or other profile id in case of friends
Returns
array

◆ addConnection()

BxDolConnection::addConnection (   $iInitiator,
  $iContent,
  $aParams = array() 
)

Add new connection.

Parameters
$iInitiatorinitiator of the connection, in most cases some profile id
$iContentcontent to make connection to, in most cases some content id, or other profile id in case of friends
Returns
true - if connection was added, false - if connection already exists or error occured

◆ checkAllowedConnect()

BxDolConnection::checkAllowedConnect (   $iInitiator,
  $iContent,
  $isPerformAction = false,
  $isMutual = false,
  $isInvertResult = false,
  $isSwap = false,
  $isCheckExists = true 
)

Check whether connection between Initiator and Content can be established.

◆ getCommonContent()

BxDolConnection::getCommonContent (   $iInitiator1,
  $iInitiator2,
  $isMutual = false,
  $iStart = 0,
  $iLimit = BX_CONNECTIONS_LIST_LIMIT,
  $iOrder = BX_CONNECTIONS_ORDER_NONE 
)

Get common content IDs between two initiators

Parameters
$iInitiator1one initiator
$iInitiator2second initiator
$isMutualget mutual connections only
Returns
array of available connections

◆ getCommonContentAsCondition()

BxDolConnection::getCommonContentAsCondition (   $sContentField,
  $iInitiator1,
  $iInitiator2,
  $iMutual = false 
)

Get necessary condition array to use connections in search classes

Parameters
$sContentFieldcontent table field name
$iInitiatorinitiator of the connection
$iMutualget mutual connections only
Returns
array of conditions, for now with 'restriction' and 'join' parts

◆ getCommonContentAsSQLParts()

BxDolConnection::getCommonContentAsSQLParts (   $sContentTable,
  $sContentField,
  $iInitiator1,
  $iInitiator2,
  $isMutual = false 
)

Get necessary parts of SQL query to use connections in other queries

Parameters
$sContentTablecontent table or alias
$sContentFieldcontent table field or field alias
$iInitiatorinitiator of the connection
$isMutualget mutual connections only
Returns
array of SQL string parts, for now 'join' part only is returned

◆ getCommonContentCount()

BxDolConnection::getCommonContentCount (   $iInitiator1,
  $iInitiator2,
  $isMutual = false 
)

Get common content count between two initiators

Parameters
$iInitiator1one initiator
$iInitiator2second initiator
$isMutualget mutual connections only
Returns
number of connections

◆ getConnectedContent()

BxDolConnection::getConnectedContent (   $iInitiator,
  $isMutual = false,
  $iStart = 0,
  $iLimit = BX_CONNECTIONS_LIST_LIMIT,
  $iOrder = BX_CONNECTIONS_ORDER_NONE 
)

Get connected content IDs

Parameters
$iInitiatorinitiator of the connection
$isMutualget mutual connections only
Returns
array of available connections

◆ getConnectedContentAsCondition()

BxDolConnection::getConnectedContentAsCondition (   $sContentField,
  $iInitiator,
  $iMutual = false 
)

Get necessary condition array to use connections in search classes

Parameters
$sContentFieldcontent table field name
$iInitiatorinitiator of the connection
$iMutualget mutual connections only
Returns
array of conditions, for now with 'restriction' and 'join' parts

◆ getConnectedContentAsSQLParts()

BxDolConnection::getConnectedContentAsSQLParts (   $sContentTable,
  $sContentField,
  $iInitiator,
  $isMutual = false 
)

Get necessary parts of SQL query to use connections in other queries

Parameters
$sContentTablecontent table or alias
$sContentFieldcontent table field or field alias
$iInitiatorinitiator of the connection
$isMutualget mutual connections only
Returns
array of SQL string parts, for now 'join' part only is returned

◆ getConnectedContentAsSQLPartsMultiple()

BxDolConnection::getConnectedContentAsSQLPartsMultiple (   $sContentTable,
  $sContentField,
  $sInitiatorTable,
  $sInitiatorField,
  $isMutual = false 
)

Get necessary parts of SQL query to use connections in other queries

Parameters
$sContentTablecontent table or alias
$sContentFieldcontent table field or field alias
$sInitiatorTableinitiator table or alias
$sInitiatorFieldinitiator table field or field alias
$iInitiatorinitiator of the connection
$isMutualget mutual connections only
Returns
array of SQL string parts, for now 'join' part only is returned

◆ getConnectedContentByType()

BxDolConnection::getConnectedContentByType (   $iInitiator,
  $mixedType,
  $isMutual = false,
  $iStart = 0,
  $iLimit = BX_CONNECTIONS_LIST_LIMIT,
  $iOrder = BX_CONNECTIONS_ORDER_NONE 
)

Get connected content IDs for specified type

Parameters
$iInitiatorinitiator of the connection
$mixedTypetype of content or an array of types
$isMutualget mutual connections only
Returns
array of available connections

◆ getConnectedContentCount()

BxDolConnection::getConnectedContentCount (   $iInitiator,
  $isMutual = false,
  $iFromDate = 0 
)

Get connected content count

Parameters
$iInitiatorinitiator of the connection
$isMutualget mutual connections only
Returns
number of connections

◆ getConnectedInitiators()

BxDolConnection::getConnectedInitiators (   $iContent,
  $isMutual = false,
  $iStart = 0,
  $iLimit = BX_CONNECTIONS_LIST_LIMIT,
  $iOrder = BX_CONNECTIONS_ORDER_NONE 
)

Get connected initiators IDs

Parameters
$iContentcontent of the connection
$isMutualget mutual connections only
Returns
array of available connections

◆ getConnectedInitiatorsAsCondition()

BxDolConnection::getConnectedInitiatorsAsCondition (   $sContentField,
  $iContent,
  $iMutual = false 
)

Get necessary condition array to use connections in search classes

Parameters
$sContentFieldcontent table field name
$iInitiatorinitiator of the connection
$iMutualget mutual connections only
Returns
array of conditions, for now with 'restriction' and 'join' parts

◆ getConnectedInitiatorsAsSQLParts()

BxDolConnection::getConnectedInitiatorsAsSQLParts (   $sInitiatorTable,
  $sInitiatorField,
  $iContent,
  $isMutual = false 
)

Get necessary parts of SQL query to use connections in other queries

Parameters
$sInitiatorTableinitiator table or alias
$sInitiatorFieldinitiator table field or field alias
$iContentcontent of the connection
$isMutualget mutual connections only
Returns
array of SQL string parts, for now 'join' part only is returned

◆ getConnectedInitiatorsAsSQLPartsMultiple()

BxDolConnection::getConnectedInitiatorsAsSQLPartsMultiple (   $sInitiatorTable,
  $sInitiatorField,
  $sContentTable,
  $sContentField,
  $isMutual = false 
)

Get necessary parts of SQL query to use connections in other queries

Parameters
$sInitiatorTableinitiator table or alias
$sInitiatorFieldinitiator table field or field alias
$sContentTablecontent table or alias
$sContentFieldcontent table field or field alias
$isMutualget mutual connections only
Returns
array of SQL string parts, for now 'join' part only is returned

◆ getConnectedInitiatorsByType()

BxDolConnection::getConnectedInitiatorsByType (   $iContent,
  $mixedType,
  $isMutual = false,
  $iStart = 0,
  $iLimit = BX_CONNECTIONS_LIST_LIMIT,
  $iOrder = BX_CONNECTIONS_ORDER_NONE 
)

Get connected initiators IDs

Parameters
$iContentcontent of the connection
$mixedTypetype of content or an array of types
$isMutualget mutual connections only
Returns
array of available connections

◆ getConnectedInitiatorsCount()

BxDolConnection::getConnectedInitiatorsCount (   $iContent,
  $isMutual = false 
)

Get connected initiators count

Parameters
$iContentcontent of the connection
$isMutualget mutual connections only
Returns
number of connections

◆ getConnectionsAsArray()

BxDolConnection::getConnectionsAsArray (   $sContentType,
  $iId1,
  $iId2,
  $isMutual = false,
  $iStart = 0,
  $iLimit = BX_CONNECTIONS_LIST_LIMIT,
  $iOrder = BX_CONNECTIONS_ORDER_NONE 
)

Compound function, which calls getCommonContent, getConnectedContent or getConnectedInitiators depending on $sContentType

Parameters
$sContentTypecontent type to get BX_CONNECTIONS_CONTENT_TYPE_CONTENT, BX_CONNECTIONS_CONTENT_TYPE_INITIATORS or BX_CONNECTIONS_CONTENT_TYPE_COMMON
$iId1one content or initiator
$iId2second content or initiator only in case of BX_CONNECTIONS_CONTENT_TYPE_COMMON content type
$isMutualget mutual connections only
Returns
array of available connections

◆ getConnectionsAsCondition()

BxDolConnection::getConnectionsAsCondition (   $sContentType,
  $sContentField,
  $iId1,
  $iId2,
  $isMutual = false 
)

Similar to getConnectionsAsArray, but for getCommonContentAsCondition, getConnectedContentAsCondition or getConnectedInitiatorsAsCondition methods

See also
getConnectionsAsArray

◆ getConnectionsAsSQLParts()

BxDolConnection::getConnectionsAsSQLParts (   $sContentType,
  $sContentTable,
  $sContentField,
  $iId1,
  $iId2,
  $isMutual = false 
)

Similar to getConnectionsAsArray, but for getCommonContentAsSQLParts, getConnectedContentAsSQLParts or getConnectedInitiatorsAsSQLParts methods

See also
getConnectionsAsArray

◆ getObjectInstance()

static BxDolConnection::getObjectInstance (   $sObject)
static

Get connection object instance by object name

Parameters
$sObjectobject name
Returns
object instance or false on error

Implements iBxDolFactoryObject.

◆ getTable()

BxDolConnection::getTable ( )

Get connection table. return string with table name.

◆ getType()

BxDolConnection::getType ( )

Get connection type. return BX_CONNECTIONS_TYPE_ONE_WAY or BX_CONNECTIONS_TYPE_MUTUAL

◆ init()

BxDolConnection::init ( )

Init something here if it's needed.

◆ isConnected()

BxDolConnection::isConnected (   $iInitiator,
  $iContent,
  $isMutual = false 
)

Check if initiator and content are connected. In case if friends this function in conjunction with isMutual parameter can be used to check pending friend requests.

Parameters
$iInitiatorinitiator of the connection
$iContentconnected content or other profile id in case of friends
Returns
true - if content and initiator are connected or false - in all other cases

◆ isConnectedNotMutual()

BxDolConnection::isConnectedNotMutual (   $iInitiator,
  $iContent 
)

Check if initiator and content are connected but connetion is not mutual, for checking pending connection requests. This method makes sense only when type of connection is mutual.

Parameters
$iInitiatorinitiator of the connection
$iContentconnected content or other profile id in case of friends
Returns
true - if content and initiator are connected but connection is not mutual or false in all other cases

◆ isProfileContent()

BxDolConnection::isProfileContent ( )

Checks whether connection's Content is profile or not. return boolean.

◆ isProfileInitiator()

BxDolConnection::isProfileInitiator ( )

Checks whether connection's Initiator is profile or not. return boolean.

◆ onAdded()

BxDolConnection::onAdded (   $iInitiator,
  $iContent,
  $iMutual 
)

Update recommendations.

◆ onDeleteContent()

BxDolConnection::onDeleteContent (   $iIdContent)

Must be called when some content is deleted which can have connections as 'content', to delete any associated data

Parameters
$iIdInitiatorinitiator id
Returns
true if some connections were deleted

◆ onDeleteInitiator()

BxDolConnection::onDeleteInitiator (   $iIdInitiator)

Must be called when some content is deleted which can have connections as 'initiator', to delete any associated data

Parameters
$iIdInitiatorinitiator id
Returns
true if some connections were deleted

◆ onDeleteInitiatorAndContent()

BxDolConnection::onDeleteInitiatorAndContent (   $iId)

Must be called when some content is deleted which can have connections as 'content' or as 'initiator', to delete any associated data

Parameters
$iIdwhich can be as conetnt ot initiator
Returns
true if some connections were deleted

◆ onModuleDeleteContent()

BxDolConnection::onModuleDeleteContent (   $sTable,
  $sFieldId 
)

Must be called when module (which can have connections as 'content') is deleted, to delete any associated data. This method call may be automated via

See also
BxBaseModGeneralInstaller::_aConnections property.
Parameters
$sTabletable name with data which have assiciations with the connection
$sFieldIdid field name which is associated with the connection
Returns
number of deleted connections

◆ onModuleDeleteInitiator()

BxDolConnection::onModuleDeleteInitiator (   $sTable,
  $sFieldId 
)

Must be called when module (which can have connections as 'initiator') is deleted, to delete any associated data. This method call may be automated via

See also
BxBaseModGeneralInstaller::_aConnections property.
Parameters
$sTabletable name with data which have assiciations with the connection
$sFieldIdid field name which is associated with the connection
Returns
number of deleted connections

◆ onModuleDeleteInitiatorAndContent()

BxDolConnection::onModuleDeleteInitiatorAndContent (   $sTable,
  $sFieldId 
)

Must be called when module (which can have connections as 'content' or as 'initiator') is deleted, to delete any associated data. This method call may be automated via

See also
BxBaseModGeneralInstaller::_aConnections property.
Parameters
$sTabletable name with data which have assiciations with the connection
$sFieldIdid field name which is associated with the connection
Returns
number of deleted connections

◆ onModuleProfileDeleteContent()

BxDolConnection::onModuleProfileDeleteContent (   $sModuleName)

Must be called when module (which can have connections as 'content' with 'sys_profiles' table) is deleted, to delete any associated data. This method call may be automated via

See also
BxBaseModGeneralInstaller::_aConnections property.
Parameters
$sModuleNamemodule name to delete connections for
Returns
number of deleted connections

◆ onModuleProfileDeleteInitiator()

BxDolConnection::onModuleProfileDeleteInitiator (   $sModuleName)

Must be called when module (which can have connections as 'initiator' with 'sys_profiles' table) is deleted, to delete any associated data. This method call may be automated via

See also
BxBaseModGeneralInstaller::_aConnections property.
Parameters
$sModuleNamemodule name to delete connections for
Returns
number of deleted connections

◆ onModuleProfileDeleteInitiatorAndContent()

BxDolConnection::onModuleProfileDeleteInitiatorAndContent (   $sModuleName)

Must be called when module (which can have connections as 'content' or as 'initiator' with 'sys_profiles' table) is deleted, to delete any associated data. This method call may be automated via

See also
BxBaseModGeneralInstaller::_aConnections property.
Parameters
$sModuleNamemodule name to delete connections for
Returns
number of deleted connections

◆ removeConnection()

BxDolConnection::removeConnection (   $iInitiator,
  $iContent 
)

Remove connection.

Parameters
$iInitiatorinitiator of the connection
$iContentconnected content or other profile id in case of friends
Returns
true - if connection was removed, false - if connection isn't exist or error occured

The documentation for this class was generated from the following file: