| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup UnaBaseView UNA Base Representation Classes
- * @{
- */
- /**
- * System services for connections.
- */
- class BxBaseServiceConnections extends BxDol
- {
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * get grid with friends connections
- */
- public function serviceConnectionsTable ($iProfileId = 0)
- {
- if(!$iProfileId && bx_get('profile_id') !== false)
- $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
- if(!$iProfileId)
- return false;
- $oGrid = BxDolGrid::getObjectInstance('sys_grid_connections');
- if(!$oGrid)
- return false;
- $oGrid->setProfile($iProfileId);
- return $oGrid->getCode();
- }
- /**
- * get grid with friends connection requests
- */
- public function serviceConnectionsRequestTable ()
- {
- $oGrid = BxDolGrid::getObjectInstance('sys_grid_connections_requests');
- if (!$oGrid)
- return false;
- return $oGrid->getCode();
- }
- /**
- * get number of received unconfirmed connections (friend requests)
- * @param $sConnectionsObject connections object to get unconfirmed connections from
- * @param $mixedId id to get connections for, if omitted then logged-in profile id is used
- * @return number
- */
- public function serviceGetUnconfirmedConnectionsNum ($sConnectionsObject, $mixedId = 0)
- {
- $oConnection = BxDolConnection::getObjectInstance($sConnectionsObject);
- if (!$oConnection)
- return 0;
- if (!$mixedId)
- $mixedId = bx_get_logged_profile_id();
- $i = 0;
- $a = $oConnection->getConnectedInitiators($mixedId, 0); // get received friend requests
- foreach ($a as $iId)
- if (BxDolProfile::getInstance($iId))
- ++$i;
- return $i;
- }
- public function serviceGetLiveUpdatesUnconfirmedConnections($sModule, $sConnectionsObject, $aMenuItemParent, $aMenuItemChild, $iCount = 0)
- {
- $iProfile = bx_get_logged_profile_id();
- $oProfile = BxDolProfile::getInstance($iProfile);
- if(!$oProfile || $oProfile->getModule() != $sModule)
- return false;
- $iCountNew = (int)$this->serviceGetUnconfirmedConnectionsNum($sConnectionsObject, $iProfile);
- if($iCountNew == (int)$iCount)
- return false;
- return array(
- 'count' => $iCountNew, // required
- 'method' => 'bx_menu_show_live_update(oData)', // required
- 'data' => array(
- 'code' => BxDolTemplate::getInstance()->parseHtmlByTemplateName('menu_item_addon', array(
- 'content' => '{count}'
- )),
- 'mi_parent' => $aMenuItemParent,
- 'mi_child' => $aMenuItemChild
- ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
- );
- }
- /**
- * get number of initiated connections (like "my subscriptions")
- * @param $sConnectionsObject connections object to get connections from
- * @param $mixedId id to get connections for, if omitted then logged-in profile id is used
- * @return number
- */
- public function serviceGetConnectedContentNum ($sConnectionsObject, $mixedId = 0, $isMutual = false)
- {
- $oConnection = BxDolConnection::getObjectInstance($sConnectionsObject);
- if (!$oConnection)
- return 0;
- if (!$mixedId)
- $mixedId = bx_get_logged_profile_id();
- $i = 0;
- $a = $oConnection->getConnectedContent($mixedId, $isMutual, 0, BX_CONNECTIONS_LIST_NO_LIMIT); // get received friend requests
- foreach ($a as $iId)
- if (BxDolProfile::getInstance($iId))
- ++$i;
- return $i;
- }
- /**
- * get number of received connections (like "subscribed me")
- * @param $sConnectionsObject connections object to get connections from
- * @param $mixedId id to get connections for, if omitted then logged-in profile id is used
- * @return number
- */
- public function serviceGetConnectedInitiatorsNum ($sConnectionsObject, $mixedId = 0, $isMutual = false)
- {
- $oConnection = BxDolConnection::getObjectInstance($sConnectionsObject);
- if (!$oConnection)
- return 0;
- if (!$mixedId)
- $mixedId = bx_get_logged_profile_id();
- $i = 0;
- $a = $oConnection->getConnectedInitiators($mixedId, $isMutual, 0, BX_CONNECTIONS_LIST_NO_LIMIT); // get received friend requests
- foreach ($a as $iId)
- if (BxDolProfile::getInstance($iId))
- ++$i;
- return $i;
- }
- /**
- * get grid with subscriptions connections
- */
- public function serviceSubscriptionsTable ($iProfileId = 0)
- {
- if(!$iProfileId && bx_get('profile_id') !== false)
- $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
- $aProfile = BxDolProfile::getInstance($iProfileId)->getInfo();
- if(empty($aProfile) || !is_array($aProfile))
- return false;
- $CNF = &BxDolModule::getInstance($aProfile['type'])->_oConfig->CNF;
- if(getParam($CNF['PARAM_PUBLIC_SBSN']) != 'on' && $aProfile['id'] != bx_get_logged_profile_id())
- return false;
- $oGrid = BxDolGrid::getObjectInstance('sys_grid_subscriptions');
- if (!$oGrid)
- return false;
- $oGrid->setProfileId($iProfileId);
- $sContent = $oGrid->getCode();
- if(empty($sContent))
- return false;
- return BxDolTemplate::getInstance()->parseHtmlByName('connections_list.html', array(
- 'name' => 'subscriptions',
- 'content' => $sContent
- ));
- }
- /**
- * get grid with subscribed me connections
- */
- public function serviceSubscribedMeTable ($iProfileId = 0)
- {
- if(!$iProfileId && bx_get('profile_id') !== false)
- $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
- $aProfile = BxDolProfile::getInstance($iProfileId)->getInfo();
- if(empty($aProfile) || !is_array($aProfile))
- return false;
- $CNF = &BxDolModule::getInstance($aProfile['type'])->_oConfig->CNF;
- if(getParam($CNF['PARAM_PUBLIC_SBSD']) != 'on' && $aProfile['id'] != bx_get_logged_profile_id())
- return false;
- $oGrid = BxDolGrid::getObjectInstance('sys_grid_subscribed_me');
- if(!$oGrid)
- return false;
- $oGrid->setProfileId($iProfileId);
- $sContent = $oGrid->getCode();
- if(empty($sContent))
- return false;
- return BxDolTemplate::getInstance()->parseHtmlByName('connections_list.html', array(
- 'name' => 'subscribers',
- 'content' => $sContent
- ));
- }
- /**
- * get grid with 'relations' connections
- */
- public function serviceRelationsTable ($iProfileId = 0)
- {
- if(!BxDolRelation::isEnabled())
- return false;
- if(!$iProfileId && bx_get('profile_id') !== false)
- $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
- $aProfile = BxDolProfile::getInstance($iProfileId)->getInfo();
- if(empty($aProfile) || !is_array($aProfile))
- return false;
- if(!BxDolConnection::getObjectInstance('sys_profiles_relations')->isRelationAvailableFromProfile($aProfile['type']))
- return false;
- $oGrid = BxDolGrid::getObjectInstance('sys_grid_relations');
- if (!$oGrid)
- return false;
- $oGrid->setProfileId($iProfileId);
- $sContent = $oGrid->getCode();
- if(empty($sContent))
- return false;
- return BxDolTemplate::getInstance()->parseHtmlByName('connections_list.html', array(
- 'name' => 'relations',
- 'content' => $sContent
- ));
- }
- /**
- * get grid with 'related me' connections
- */
- public function serviceRelatedMeTable ($iProfileId = 0)
- {
- if(!BxDolRelation::isEnabled())
- return false;
- if(!$iProfileId && bx_get('profile_id') !== false)
- $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
- $aProfile = BxDolProfile::getInstance($iProfileId)->getInfo();
- if(empty($aProfile) || !is_array($aProfile))
- return false;
- if(!BxDolConnection::getObjectInstance('sys_profiles_relations')->isRelationAvailableWithProfile($aProfile['type']))
- return false;
- $oGrid = BxDolGrid::getObjectInstance('sys_grid_related_me');
- if(!$oGrid)
- return false;
- $oGrid->setProfileId($iProfileId);
- $sContent = $oGrid->getCode();
- if(empty($sContent))
- return false;
- return BxDolTemplate::getInstance()->parseHtmlByName('connections_list.html', array(
- 'name' => 'related-me',
- 'content' => $sContent
- ));
- }
- /*
- * Get notification data for Notifications module - action Subscribe.
- */
- public function serviceGetNotificationsPost($aEvent)
- {
- $iOwner = (int)$aEvent['owner_id'];
- $oOwner = BxDolProfile::getInstance($iOwner);
- if(!$oOwner)
- return array();
- $iProfile = (int)$aEvent['object_id'];
- $oProfile = BxDolProfile::getInstance($iProfile);
- if(!$oProfile)
- return array();
- return array(
- 'entry_sample' => '_sys_profile_sample_single',
- 'entry_url' => $oOwner->getUrl(),
- 'entry_caption' => $oProfile->getDisplayName(),
- 'entry_author' => $oProfile->id(),
- 'lang_key' => '_sys_profile_subscription_added',
- );
- }
- /*
- * Get notification data for Notifications module - action Friend.
- */
- public function serviceGetNotificationsPostFriendship($aEvent)
- {
- $iOwner = (int)$aEvent['owner_id'];
- $oOwner = BxDolProfile::getInstance($iOwner);
- if(!$oOwner)
- return array();
- $iProfile = (int)$aEvent['object_id'];
- $oProfile = BxDolProfile::getInstance($iProfile);
- if(!$oProfile)
- return array();
- $sLangKey = '_sys_profile_friendship_added';
- if(isset($aEvent['content']['request']) && (int)$aEvent['content']['request'] == 1)
- $sLangKey = '_sys_profile_friend_request_added';
- return array(
- 'entry_sample' => '_sys_profile_sample_single',
- 'entry_url' => $oOwner->getUrl(),
- 'entry_caption' => $oProfile->getDisplayName(),
- 'entry_author' => $oProfile->id(),
- 'lang_key' => $sLangKey,
- );
- }
- public function serviceAlertResponseConnections($oAlert)
- {
- $sMethod = 'process' . bx_gen_method_name($oAlert->sUnit . '_' . $oAlert->sAction);
- if(!method_exists($this, $sMethod))
- return;
-
- $this->$sMethod($oAlert);
- }
- protected function processSysProfilesFriendsConnectionAdded(&$oAlert)
- {
- if((int)$oAlert->aExtras['mutual'] != 1)
- return;
- $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
- $oConnection->addConnection((int)$oAlert->aExtras['initiator'], (int)$oAlert->aExtras['content'], array('alert_extras' => array('silent_mode' => 1)));
- $oConnection->addConnection((int)$oAlert->aExtras['content'], (int)$oAlert->aExtras['initiator'], array('alert_extras' => array('silent_mode' => 1)));
- }
- protected function processSysProfilesFriendsConnectionRemoved(&$oAlert)
- {
- if((int)$oAlert->aExtras['mutual'] != 1)
- return;
- $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
- $oConnection->removeConnection((int)$oAlert->aExtras['initiator'], (int)$oAlert->aExtras['content']);
- $oConnection->removeConnection((int)$oAlert->aExtras['content'], (int)$oAlert->aExtras['initiator']);
- }
- }
- /** @} */
|