BxDolConnection.php 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. /**
  10. * Default limit for connections list in Counter.
  11. */
  12. define('BX_CONNECTIONS_LIST_COUNTER', 5);
  13. /**
  14. * Default limit for connections lists
  15. */
  16. define('BX_CONNECTIONS_LIST_LIMIT', 1000);
  17. /**
  18. * No limit for connections lists.
  19. * Is needed for Total Number calculation.
  20. */
  21. define('BX_CONNECTIONS_LIST_NO_LIMIT', -1);
  22. /**
  23. * Connections order: no order
  24. */
  25. define('BX_CONNECTIONS_ORDER_NONE', 0);
  26. /**
  27. * Connections order: by addded time, asceding
  28. */
  29. define('BX_CONNECTIONS_ORDER_ADDED_ASC', 1);
  30. /**
  31. * Connections order: by addded time, desceding
  32. */
  33. define('BX_CONNECTIONS_ORDER_ADDED_DESC', 2);
  34. /**
  35. * Connection type: one-way
  36. */
  37. define('BX_CONNECTIONS_TYPE_ONE_WAY', 'one-way');
  38. /**
  39. * Connection type: mutual
  40. */
  41. define('BX_CONNECTIONS_TYPE_MUTUAL', 'mutual');
  42. /**
  43. * Connections content type: content
  44. */
  45. define('BX_CONNECTIONS_CONTENT_TYPE_CONTENT', 'content');
  46. /**
  47. * Connections content type: initiators
  48. */
  49. define('BX_CONNECTIONS_CONTENT_TYPE_INITIATORS', 'initiators');
  50. /**
  51. * Connections content type: common
  52. */
  53. define('BX_CONNECTIONS_CONTENT_TYPE_COMMON', 'common');
  54. /**
  55. * Connection is usefull when you need to organize some sorts of connections between different content,
  56. * for example: friends, contacts, favorites, block lists, subscriptions, etc.
  57. *
  58. * Two types of connections are supported one way connections (block list, favourites) and mutual (friends).
  59. *
  60. * For automatic handling of connections (like, add/remove connection in frontend) refer to JS function: @see bx_conn_action()
  61. *
  62. * @section connection_create Creating the Connection object:
  63. *
  64. * Step 1:
  65. * Add record to 'sys_objects_connection' table:
  66. * - object: name of the connection object, in the format: vendor prefix, underscore, module prefix, underscore, internal identifier or nothing;
  67. * for example: bx_blogs_favorites - favorite blogs for users in blogs module.
  68. * - table: table name with connections, see step 2
  69. * - type: 'one-way' or 'mutual'
  70. * - override_class_name: user defined class name which is derived from one of base classes.
  71. * - override_class_file: the location of the user defined class, leave it empty if class is located in system folders.
  72. *
  73. * Step 2:
  74. * Create table for connections:
  75. * @code
  76. * CREATE TABLE `my_sample_connections` (
  77. * `id` int(11) NOT NULL AUTO_INCREMENT,
  78. * `initiator` int(11) NOT NULL,
  79. * `content` int(11) NOT NULL,
  80. * `mutual` tinyint(4) NOT NULL, -- can re removed for one-way connections
  81. * `added` int(10) unsigned NOT NULL,
  82. * PRIMARY KEY (`id`),
  83. * UNIQUE KEY `initiator` (`initiator`,`content`),
  84. * KEY `content` (`content`)
  85. * )
  86. * @endcode
  87. *
  88. *
  89. * @section example Example of usage
  90. *
  91. * Check if two profiles are friends:
  92. * @code
  93. * $oConnectionFriends = BxDolConnection::getObjectInstance('bx_profiles_friends'); // get friends connections object
  94. * if ($oConnectionFriends) // check if connections is available for using
  95. * 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
  96. * @endcode
  97. *
  98. * Get mutual content IDs (friends IDs)
  99. * @code
  100. * $oConnectionFriends = BxDolConnection::getObjectInstance('bx_profiles_friends'); // get friends connections object
  101. * if ($oConnectionFriends) // check if connections is available for using
  102. * print_r($oConnection->getConnectedContent(100, 1)); // print array of friends IDs of 100's profile
  103. * @endcode
  104. *
  105. */
  106. class BxDolConnection extends BxDolFactory implements iBxDolFactoryObject
  107. {
  108. protected $_sObject;
  109. protected $_aObject;
  110. protected $_oQuery;
  111. protected $_sType;
  112. /**
  113. * Constructor
  114. * @param $aObject array of connection options
  115. */
  116. protected function __construct($aObject)
  117. {
  118. parent::__construct();
  119. $this->_sObject = $aObject['object'];
  120. $this->_aObject = $aObject;
  121. $this->_aObject['per_page_default'] = 20;
  122. $this->_sType = $aObject['type'];
  123. $this->_oQuery = new BxDolConnectionQuery($aObject);
  124. }
  125. /**
  126. * Get connection object instance by object name
  127. * @param $sObject object name
  128. * @return object instance or false on error
  129. */
  130. static public function getObjectInstance($sObject)
  131. {
  132. if (!$sObject)
  133. return false;
  134. if (isset($GLOBALS['bxDolClasses']['BxTemplConnection!'.$sObject]))
  135. return $GLOBALS['bxDolClasses']['BxTemplConnection!'.$sObject];
  136. $aObject = BxDolConnectionQuery::getConnectionObject($sObject);
  137. if (!$aObject || !is_array($aObject))
  138. return false;
  139. $sClass = empty($aObject['override_class_name']) ? 'BxTemplConnection' : $aObject['override_class_name'];
  140. if (!empty($aObject['override_class_file']))
  141. require_once(BX_DIRECTORY_PATH_ROOT . $aObject['override_class_file']);
  142. $o = new $sClass($aObject);
  143. $o->init();
  144. return ($GLOBALS['bxDolClasses']['BxTemplConnection!'.$sObject] = $o);
  145. }
  146. /**
  147. * Init something here if it's needed.
  148. */
  149. public function init()
  150. {
  151. }
  152. /**
  153. * Get connection type.
  154. * return BX_CONNECTIONS_TYPE_ONE_WAY or BX_CONNECTIONS_TYPE_MUTUAL
  155. */
  156. public function getType()
  157. {
  158. return $this->_sType;
  159. }
  160. /**
  161. * Get connection table.
  162. * return string with table name.
  163. */
  164. public function getTable()
  165. {
  166. return $this->_aObject['table'];
  167. }
  168. /**
  169. * Checks whether connection's Initiator is profile or not.
  170. * return boolean.
  171. */
  172. public function isProfileInitiator()
  173. {
  174. return (int)$this->_aObject['profile_initiator'] != 0;
  175. }
  176. /**
  177. * Checks whether connection's Content is profile or not.
  178. * return boolean.
  179. */
  180. public function isProfileContent()
  181. {
  182. return (int)$this->_aObject['profile_content'] != 0;
  183. }
  184. /**
  185. * Check whether connection between Initiator and Content can be established.
  186. */
  187. public function checkAllowedConnect ($iInitiator, $iContent, $isPerformAction = false, $isMutual = false, $isInvertResult = false, $isSwap = false, $isCheckExists = true)
  188. {
  189. $aResult = $this->_checkAllowedConnect($iInitiator, $iContent, $isPerformAction, $isMutual, $isInvertResult, $isSwap, $isCheckExists);
  190. return $aResult['code'] == 0 ? CHECK_ACTION_RESULT_ALLOWED : $aResult['message'];
  191. }
  192. public function checkAllowedAddConnection ($iInitiator, $iContent, $isPerformAction = false, $isMutual = false, $isInvertResult = false, $isSwap = false, $isCheckExists = true)
  193. {
  194. $aResult = $this->_checkAllowedConnect($iInitiator, $iContent, $isPerformAction, $isMutual, $isInvertResult, $isSwap, $isCheckExists);
  195. return $aResult['code'] == 0 || ($aResult['code'] == 4 && $this->_sObject == 'sys_profiles_friends') ? CHECK_ACTION_RESULT_ALLOWED : $aResult['message'];
  196. }
  197. public function checkAllowedRemoveConnection ($iInitiator, $iContent, $isPerformAction = false, $isMutual = false, $isInvertResult = false, $isSwap = false, $isCheckExists = true)
  198. {
  199. $aResult = $this->_checkAllowedConnect($iInitiator, $iContent, $isPerformAction, $isMutual, $isInvertResult, $isSwap, $isCheckExists);
  200. return $aResult['code'] == 0 || ($aResult['code'] == 4 && $this->_sObject == 'sys_profiles_friends') ? CHECK_ACTION_RESULT_ALLOWED : $aResult['message'];
  201. }
  202. /**
  203. * Add new connection.
  204. * @param $iContent content to make connection to, in most cases some content id, or other profile id in case of friends
  205. * @return array
  206. */
  207. public function actionAdd ($iContent = 0, $iInitiator = false)
  208. {
  209. if (!$iContent)
  210. $iContent = bx_process_input($_POST['id'], BX_DATA_INT);
  211. return $this->_action ($iInitiator ? $iInitiator : bx_get_logged_profile_id(), $iContent, 'addConnection', '_sys_conn_err_connection_already_exists', true);
  212. }
  213. /**
  214. * Remove connection. This method is wrapper for @see removeConnection to be called from @see conn.php upon AJAX request to this file.
  215. * @param $iContent content to make connection to, in most cases some content id, or other profile id in case of friends
  216. * @return array
  217. */
  218. public function actionRemove ($iContent = 0, $iInitiator = false)
  219. {
  220. if (!$iContent)
  221. $iContent = bx_process_input($_POST['id'], BX_DATA_INT);
  222. if ($iContent != bx_get_logged_profile_id() && BX_CONNECTIONS_TYPE_MUTUAL == $this->_aObject['type']) {
  223. $a = $this->actionReject($iContent, $iInitiator);
  224. if (false == $a['err'])
  225. return $a;
  226. }
  227. return $this->_action ($iInitiator ? $iInitiator : bx_get_logged_profile_id(), $iContent, 'removeConnection', '_sys_conn_err_connection_does_not_exists', false, true);
  228. }
  229. /**
  230. * Reject connection request. This method is wrapper for @see removeConnection to be called from @see conn.php upon AJAX request to this file.
  231. * @param $iContent content to make connection to, in most cases some content id, or other profile id in case of friends
  232. * @return array
  233. */
  234. public function actionReject ($iContent = 0, $iInitiator = false)
  235. {
  236. if (!$iContent)
  237. $iContent = bx_process_input($_POST['id'], BX_DATA_INT);
  238. return $this->_action($iContent, $iInitiator ? $iInitiator : bx_get_logged_profile_id(), 'removeConnection', '_sys_conn_err_connection_does_not_exists', false, true);
  239. }
  240. protected function _action ($iInitiator, $iContent, $sMethod, $sErrorKey, $isMutual = false, $isInvert = false)
  241. {
  242. bx_import('BxDolLanguages');
  243. if(!$iContent || !$iInitiator)
  244. return ['err' => true, 'msg' => _t('_sys_conn_err_input_data_is_not_defined')];
  245. $sMethodCheck = 'checkAllowed' . bx_gen_method_name($sMethod);
  246. if(($mixedResult = $this->{method_exists($this, $sMethodCheck) ? $sMethodCheck : 'checkAllowedConnect'}($iInitiator, $iContent, false, false, $isInvert)) !== CHECK_ACTION_RESULT_ALLOWED)
  247. return ['err' => true, 'msg' => $mixedResult];
  248. if (!$this->$sMethod((int)$iInitiator, (int)$iContent)) {
  249. if ($isMutual && BX_CONNECTIONS_TYPE_MUTUAL == $this->_sType && $this->isConnected((int)$iInitiator, (int)$iContent, false) && !$this->isConnected((int)$iInitiator, (int)$iContent, true))
  250. return ['err' => true, 'msg' => _t('_sys_conn_err_connection_is_awaiting_confirmation')];
  251. return ['err' => true, 'msg' => _t($sErrorKey)];
  252. }
  253. return ['err' => false, 'msg' => _t('_sys_conn_msg_success')];
  254. }
  255. public function outputActionResult ($mixed, $sFormat = 'json')
  256. {
  257. switch ($sFormat) {
  258. case 'html':
  259. echo $mixed;
  260. break;
  261. case 'json':
  262. default:
  263. header('Content-Type: application/json; charset=utf-8');
  264. echo json_encode($mixed);
  265. }
  266. exit;
  267. }
  268. /**
  269. * Add new connection.
  270. * @param $iInitiator initiator of the connection, in most cases some profile id
  271. * @param $iContent content to make connection to, in most cases some content id, or other profile id in case of friends
  272. * @return true - if connection was added, false - if connection already exists or error occured
  273. */
  274. public function addConnection ($iInitiator, $iContent, $aParams = array())
  275. {
  276. $iMutual = 0;
  277. $iInitiator = (int)$iInitiator;
  278. $iContent = (int)$iContent;
  279. $aAlertExtras = [
  280. 'initiator' => &$iInitiator,
  281. 'content' => &$iContent,
  282. 'mutual' => &$iMutual,
  283. 'object' => $this,
  284. ];
  285. if(!empty($aParams['alert_extras']) && is_array($aParams['alert_extras']))
  286. $aAlertExtras = array_merge($aAlertExtras, $aParams['alert_extras']);
  287. /**
  288. * @hooks
  289. * @hookdef hook-bx_dol_connection-connection_before_add '{object_name}', 'connection_before_add' - hook before connection was added. Connection params can be overridden
  290. * - $unit_name - connection object name
  291. * - $action - equals `connection_before_add`
  292. * - $object_id - not used
  293. * - $sender_id - logged in profile id
  294. * - $extra_params - array of additional params with the following array keys:
  295. * - `initiator` - [int] by ref, profile id who created the connection, can be overridden in hook processing
  296. * - `content` - [int] by ref, profile id with whom the connection was created, can be overridden in hook processing
  297. * - `mutual` - [int] by ref, if the relation is mutual or not, can be overridden in hook processing
  298. * - `object` - [object] an instance of relation, @see BxDolConnection
  299. * @hook @ref hook-bx_dol_connection-connection_before_add
  300. */
  301. bx_alert($this->_sObject, 'connection_before_add', 0, bx_get_logged_profile_id(), $aAlertExtras);
  302. if (!$this->_oQuery->addConnection((int)$iInitiator, (int)$iContent, $iMutual))
  303. return false;
  304. /**
  305. * @hooks
  306. * @hookdef hook-bx_dol_connection-connection_added '{object_name}', 'connection_added' - hook after connection was added. Connection params can be overridden
  307. * It's equivalent to @ref hook-bx_dol_connection-connection_before_add
  308. * @hook @ref hook-bx_dol_connection-connection_added
  309. */
  310. bx_alert($this->_sObject, 'connection_added', 0, bx_get_logged_profile_id(), $aAlertExtras);
  311. $this->onAdded($iInitiator, $iContent, $iMutual);
  312. return true;
  313. }
  314. public function onAdded($iInitiator, $iContent, $iMutual)
  315. {
  316. $this->checkAllowedConnect ($iInitiator, $iContent, true, $iMutual, false);
  317. $bMutual = false;
  318. /**
  319. * Call socket.
  320. */
  321. if(($oSockets = BxDolSockets::getInstance()) && $oSockets->isEnabled()){
  322. $aMessageInitiator = $aMessageContent = [
  323. 'object' => $this->_sObject,
  324. 'action' => 'added',
  325. ];
  326. if(bx_is_api()) {
  327. $aMessageInitiator = array_merge($aMessageInitiator, [
  328. 'user' => BxDolProfile::getDataForPage($iInitiator)
  329. ]);
  330. $aMessageContent = array_merge($aMessageContent, [
  331. 'user' => BxDolProfile::getDataForPage($iContent)
  332. ]);
  333. }
  334. $oSockets->sendEvent('sys_connections', $iInitiator , 'changed', json_encode($aMessageInitiator));
  335. $oSockets->sendEvent('sys_connections', $iContent , 'changed', json_encode($aMessageContent));
  336. }
  337. if($this->_aObject['type'] == BX_CONNECTIONS_TYPE_ONE_WAY || ($bMutual = ($this->_aObject['type'] == BX_CONNECTIONS_TYPE_MUTUAL && $iMutual))) {
  338. $oProfileQuery = BxDolProfileQuery::getInstance();
  339. /**
  340. * Update recommendations.
  341. */
  342. if($this->_aObject['profile_initiator']) {
  343. $aInitiator = $oProfileQuery->getInfoById($iInitiator);
  344. if(bx_srv($aInitiator['type'], 'act_as_profile'))
  345. BxDolRecommendation::updateData($iInitiator);
  346. }
  347. if($bMutual && $this->_aObject['profile_content']) {
  348. $aContent = $oProfileQuery->getInfoById($iContent);
  349. if(bx_srv($aContent['type'], 'act_as_profile'))
  350. BxDolRecommendation::updateData($iContent);
  351. }
  352. }
  353. }
  354. /**
  355. * Remove connection.
  356. * @param $iInitiator initiator of the connection
  357. * @param $iContent connected content or other profile id in case of friends
  358. * @return true - if connection was removed, false - if connection isn't exist or error occured
  359. */
  360. public function removeConnection ($iInitiator, $iContent)
  361. {
  362. if (!($aConnection = $this->_oQuery->getConnection((int)$iInitiator, (int)$iContent))) // connection doesn't exist
  363. return false;
  364. if (!$this->_oQuery->removeConnection((int)$iInitiator, (int)$iContent))
  365. return false;
  366. /**
  367. * @hooks
  368. * @hookdef hook-bx_dol_connection-connection_removed '{object_name}', 'connection_removed' - hook after a connection was removed.
  369. * - $unit_name - connection object name
  370. * - $action - equals `connection_removed`
  371. * - $object_id - not used
  372. * - $sender_id - logged in profile id
  373. * - $extra_params - array of additional params with the following array keys:
  374. * - `initiator` - [int] profile id who created the connection
  375. * - `content` - [int] profile id with whom the connection was created
  376. * - `mutual` - [int] if the relation is mutual or not
  377. * - `object` - [object] an instance of relation, @see BxDolConnection
  378. * @hook @ref hook-bx_dol_connection-connection_removed
  379. */
  380. bx_alert($this->_sObject, 'connection_removed', 0, bx_get_logged_profile_id(), array(
  381. 'initiator' => (int)$iInitiator,
  382. 'content' => (int)$iContent,
  383. 'mutual' => isset($aConnection['mutual']) ? $aConnection['mutual'] : 0,
  384. 'object' => $this,
  385. ));
  386. $this->onRemoved($iInitiator, $iContent);
  387. return true;
  388. }
  389. /**
  390. * TODO: Improve - add $iMutual like in onAdded
  391. */
  392. public function onRemoved($iInitiator, $iContent)
  393. {
  394. /**
  395. * Call socket.
  396. */
  397. if(($oSockets = BxDolSockets::getInstance()) && $oSockets->isEnabled()){
  398. $aMessageInitiator = $aMessageContent = [
  399. 'object' => $this->_sObject,
  400. 'action' => 'deleted',
  401. ];
  402. if(bx_is_api()) {
  403. $aMessageInitiator = array_merge($aMessageInitiator, [
  404. 'user' => BxDolProfile::getDataForPage($iInitiator)
  405. ]);
  406. $aMessageContent = array_merge($aMessageContent, [
  407. 'user' => BxDolProfile::getDataForPage($iContent)
  408. ]);
  409. }
  410. $oSockets->sendEvent('sys_connections', $iInitiator , 'changed', json_encode($aMessageInitiator));
  411. $oSockets->sendEvent('sys_connections', $iContent , 'changed', json_encode($aMessageContent));
  412. }
  413. }
  414. /**
  415. * Compound function, which calls getCommonContent, getConnectedContent or getConnectedInitiators depending on $sContentType
  416. * @param $sContentType content type to get BX_CONNECTIONS_CONTENT_TYPE_CONTENT, BX_CONNECTIONS_CONTENT_TYPE_INITIATORS or BX_CONNECTIONS_CONTENT_TYPE_COMMON
  417. * @param $iId1 one content or initiator
  418. * @param $iId2 second content or initiator only in case of BX_CONNECTIONS_CONTENT_TYPE_COMMON content type
  419. * @param $isMutual get mutual connections only
  420. * @return array of available connections
  421. */
  422. public function getConnectionsAsArray ($sContentType, $iId1, $iId2, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  423. {
  424. if (BX_CONNECTIONS_CONTENT_TYPE_COMMON == $sContentType)
  425. return $this->getCommonContent($iId1, $iId2, $isMutual, $iStart, $iLimit, $iOrder);
  426. if (BX_CONNECTIONS_CONTENT_TYPE_INITIATORS == $sContentType)
  427. $sMethod = 'getConnectedInitiators';
  428. else
  429. $sMethod = 'getConnectedContent';
  430. return $this->$sMethod($iId1, $isMutual, $iStart, $iLimit, $iOrder);
  431. }
  432. /**
  433. * Get common content IDs between two initiators
  434. * @param $iInitiator1 one initiator
  435. * @param $iInitiator2 second initiator
  436. * @param $isMutual get mutual connections only
  437. * @return array of available connections
  438. */
  439. public function getCommonContent ($iInitiator1, $iInitiator2, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  440. {
  441. return $this->_oQuery->getCommonContent($iInitiator1, $iInitiator2, $isMutual, $iStart, $iLimit, $iOrder);
  442. }
  443. /**
  444. * Get common content count between two initiators
  445. * @param $iInitiator1 one initiator
  446. * @param $iInitiator2 second initiator
  447. * @param $isMutual get mutual connections only
  448. * @return number of connections
  449. */
  450. public function getCommonContentCount ($iInitiator1, $iInitiator2, $isMutual = false)
  451. {
  452. return $this->_oQuery->getCommonContentCount($iInitiator1, $iInitiator2, $isMutual);
  453. }
  454. /**
  455. * Get connected content count
  456. * @param $iInitiator initiator of the connection
  457. * @param $isMutual get mutual connections only
  458. * @return number of connections
  459. */
  460. public function getConnectedContentCount ($iInitiator, $isMutual = false, $iFromDate = 0)
  461. {
  462. return $this->_oQuery->getConnectedContentCount($iInitiator, $isMutual, $iFromDate);
  463. }
  464. /**
  465. * Get connected content count
  466. * @param $iInitiator initiator of the connection
  467. * @param $isMutual get mutual connections only
  468. * @param $aParams additional params
  469. * @return number of connections
  470. */
  471. public function getConnectedContentCountExt ($iInitiator, $isMutual = false, $aParams = [])
  472. {
  473. return $this->_oQuery->getConnectedContentCountExt($iInitiator, $isMutual, $aParams);
  474. }
  475. /**
  476. * Get connected initiators count
  477. * @param $iContent content of the connection
  478. * @param $isMutual get mutual connections only
  479. * @return number of connections
  480. */
  481. public function getConnectedInitiatorsCount ($iContent, $isMutual = false)
  482. {
  483. return $this->_oQuery->getConnectedInitiatorsCount($iContent, $isMutual);
  484. }
  485. /**
  486. * Get connected content IDs
  487. * @param $iInitiator initiator of the connection
  488. * @param $isMutual get mutual connections only
  489. * @return array of available connections
  490. */
  491. public function getConnectedContent ($iInitiator, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  492. {
  493. return $this->_oQuery->getConnectedContent($iInitiator, $isMutual, $iStart, $iLimit, $iOrder);
  494. }
  495. /**
  496. * Get connected content IDs for specified type
  497. * @param $iInitiator initiator of the connection
  498. * @param $mixedType type of content or an array of types
  499. * @param $isMutual get mutual connections only
  500. * @return array of available connections
  501. */
  502. public function getConnectedContentByType ($iInitiator, $mixedType, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  503. {
  504. return $this->_oQuery->getConnectedContentByType($iInitiator, $mixedType, $isMutual, $iStart, $iLimit, $iOrder);
  505. }
  506. /**
  507. * Get connected content IDs for specified type
  508. * @param $iInitiator initiator of the connection
  509. * @param $iDate get connections appeared since this date
  510. * @param $isMutual get mutual connections only
  511. * @return array of available connections
  512. */
  513. public function getConnectedContentSince ($iInitiator, $iDate, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  514. {
  515. return $this->_oQuery->getConnectedContentSince($iInitiator, $iDate, $isMutual, $iStart, $iLimit, $iOrder);
  516. }
  517. /**
  518. * Get connected initiators IDs
  519. * @param $iContent content of the connection
  520. * @param $isMutual get mutual connections only
  521. * @return array of available connections
  522. */
  523. public function getConnectedInitiators ($iContent, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  524. {
  525. return $this->_oQuery->getConnectedInitiators($iContent, $isMutual, $iStart, $iLimit, $iOrder);
  526. }
  527. /**
  528. * Get connected initiators IDs
  529. * @param $iContent content of the connection
  530. * @param $mixedType type of content or an array of types
  531. * @param $isMutual get mutual connections only
  532. * @return array of available connections
  533. */
  534. public function getConnectedInitiatorsByType ($iContent, $mixedType, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  535. {
  536. return $this->_oQuery->getConnectedInitiatorsByType($iContent, $mixedType, $isMutual, $iStart, $iLimit, $iOrder);
  537. }
  538. /**
  539. * Get connected initiators IDs
  540. * @param $iContent content of the connection
  541. * @param $iDate get connections appeared since this date
  542. * @param $isMutual get mutual connections only
  543. * @return array of available connections
  544. */
  545. public function getConnectedInitiatorsSince ($iContent, $iDate, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  546. {
  547. return $this->_oQuery->getConnectedInitiatorsSince($iContent, $iDate, $isMutual, $iStart, $iLimit, $iOrder);
  548. }
  549. /**
  550. * Similar to getConnectionsAsArray, but for getCommonContentAsSQLParts, getConnectedContentAsSQLParts or getConnectedInitiatorsAsSQLParts methods
  551. * @see getConnectionsAsArray
  552. */
  553. public function getConnectionsAsSQLParts ($sContentType, $sContentTable, $sContentField, $iId1, $iId2, $isMutual = false)
  554. {
  555. if (BX_CONNECTIONS_CONTENT_TYPE_COMMON == $sContentType)
  556. return $this->getCommonContentAsSQLParts($sContentTable, $sContentField, $iId1, $iId2, $isMutual);
  557. if (BX_CONNECTIONS_CONTENT_TYPE_INITIATORS == $sContentType)
  558. $sMethod = 'getConnectedInitiatorsAsSQLParts';
  559. else
  560. $sMethod = 'getConnectedContentAsSQLParts';
  561. return $this->$sMethod($sContentTable, $sContentField, $iId1, $isMutual);
  562. }
  563. /**
  564. * Get necessary parts of SQL query to use connections in other queries
  565. * @param $sContentTable content table or alias
  566. * @param $sContentField content table field or field alias
  567. * @param $iInitiator initiator of the connection
  568. * @param $isMutual get mutual connections only
  569. * @return array of SQL string parts, for now 'join' part only is returned
  570. */
  571. public function getCommonContentAsSQLParts ($sContentTable, $sContentField, $iInitiator1, $iInitiator2, $isMutual = false)
  572. {
  573. return $this->_oQuery->getCommonContentSQLParts($sContentTable, $sContentField, $iInitiator1, $iInitiator2, $isMutual);
  574. }
  575. /**
  576. * Get necessary parts of SQL query to use connections in other queries
  577. * @param $sContentTable content table or alias
  578. * @param $sContentField content table field or field alias
  579. * @param $iInitiator initiator of the connection
  580. * @param $isMutual get mutual connections only
  581. * @return array of SQL string parts, for now 'join' part only is returned
  582. */
  583. public function getConnectedContentAsSQLParts ($sContentTable, $sContentField, $iInitiator, $isMutual = false)
  584. {
  585. return $this->_oQuery->getConnectedContentSQLParts($sContentTable, $sContentField, $iInitiator, $isMutual);
  586. }
  587. public function getConnectedContentAsSQLPartsExt ($sContentTable, $sContentField, $iInitiator, $isMutual = false)
  588. {
  589. return $this->_oQuery->getConnectedContentSQLPartsExt($sContentTable, $sContentField, $iInitiator, $isMutual);
  590. }
  591. /**
  592. * Get necessary parts of SQL query to use connections in other queries
  593. * @param $sContentTable content table or alias
  594. * @param $sContentField content table field or field alias
  595. * @param $sInitiatorTable initiator table or alias
  596. * @param $sInitiatorField initiator table field or field alias
  597. * @param $iInitiator initiator of the connection
  598. * @param $isMutual get mutual connections only
  599. * @return array of SQL string parts, for now 'join' part only is returned
  600. */
  601. public function getConnectedContentAsSQLPartsMultiple ($sContentTable, $sContentField, $sInitiatorTable, $sInitiatorField, $isMutual = false)
  602. {
  603. return $this->_oQuery->getConnectedContentSQLPartsMultiple($sContentTable, $sContentField, $sInitiatorTable, $sInitiatorField, $isMutual);
  604. }
  605. /**
  606. * Get necessary parts of SQL query to use connections in other queries
  607. * @param $sInitiatorTable initiator table or alias
  608. * @param $sInitiatorField initiator table field or field alias
  609. * @param $iContent content of the connection
  610. * @param $isMutual get mutual connections only
  611. * @return array of SQL string parts, for now 'join' part only is returned
  612. */
  613. public function getConnectedInitiatorsAsSQLParts ($sInitiatorTable, $sInitiatorField, $iContent, $isMutual = false)
  614. {
  615. return $this->_oQuery->getConnectedInitiatorsSQLParts($sInitiatorTable, $sInitiatorField, $iContent, $isMutual);
  616. }
  617. /**
  618. * Get necessary parts of SQL query to use connections in other queries
  619. * @param $sInitiatorTable initiator table or alias
  620. * @param $sInitiatorField initiator table field or field alias
  621. * @param $sContentTable content table or alias
  622. * @param $sContentField content table field or field alias
  623. * @param $isMutual get mutual connections only
  624. * @return array of SQL string parts, for now 'join' part only is returned
  625. */
  626. public function getConnectedInitiatorsAsSQLPartsMultiple ($sInitiatorTable, $sInitiatorField, $sContentTable, $sContentField, $isMutual = false)
  627. {
  628. return $this->_oQuery->getConnectedInitiatorsSQLPartsMultiple ($sInitiatorTable, $sInitiatorField, $sContentTable, $sContentField, $isMutual);
  629. }
  630. /**
  631. * Similar to getConnectionsAsArray, but for getCommonContentAsCondition, getConnectedContentAsCondition or getConnectedInitiatorsAsCondition methods
  632. * @see getConnectionsAsArray
  633. */
  634. public function getConnectionsAsCondition ($sContentType, $sContentField, $iId1, $iId2, $isMutual = false)
  635. {
  636. if (BX_CONNECTIONS_CONTENT_TYPE_COMMON == $sContentType)
  637. return $this->getCommonContentAsCondition($sContentField, $iId1, $iId2, $isMutual);
  638. if (BX_CONNECTIONS_CONTENT_TYPE_INITIATORS == $sContentType)
  639. $sMethod = 'getConnectedInitiatorsAsCondition';
  640. else
  641. $sMethod = 'getConnectedContentAsCondition';
  642. return $this->$sMethod($sContentField, $iId1, $isMutual);
  643. }
  644. /**
  645. * Get necessary condition array to use connections in search classes
  646. * @param $sContentField content table field name
  647. * @param $iInitiator initiator of the connection
  648. * @param $iMutual get mutual connections only
  649. * @return array of conditions, for now with 'restriction' and 'join' parts
  650. */
  651. public function getCommonContentAsCondition ($sContentField, $iInitiator1, $iInitiator2, $iMutual = false)
  652. {
  653. return array(
  654. 'restriction' => array (
  655. 'connections_' . $this->_sObject => array(
  656. 'value' => $iInitiator1,
  657. 'field' => 'initiator',
  658. 'operator' => '=',
  659. 'table' => 'c',
  660. ),
  661. 'connections_mutual_' . $this->_sObject => array(
  662. 'value' => $iMutual,
  663. 'field' => 'mutual',
  664. 'operator' => '=',
  665. 'table' => 'c',
  666. ),
  667. 'connections2_' . $this->_sObject => array(
  668. 'value' => $iInitiator2,
  669. 'field' => 'initiator',
  670. 'operator' => '=',
  671. 'table' => 'c2',
  672. ),
  673. 'connections2_mutual_' . $this->_sObject => array(
  674. 'value' => $iMutual,
  675. 'field' => 'mutual',
  676. 'operator' => '=',
  677. 'table' => 'c2',
  678. ),
  679. ),
  680. 'join' => array (
  681. 'connections_' . $this->_sObject => array(
  682. 'type' => 'INNER',
  683. 'table' => $this->_aObject['table'],
  684. 'table_alias' => 'c',
  685. 'mainField' => $sContentField,
  686. 'onField' => 'content',
  687. 'joinFields' => array(),
  688. ),
  689. 'connections2_' . $this->_sObject => array(
  690. 'type' => 'INNER',
  691. 'table' => $this->_aObject['table'],
  692. 'table_alias' => 'c2',
  693. 'mainTable' => 'c',
  694. 'mainField' => 'content',
  695. 'onField' => 'content',
  696. 'joinFields' => array(),
  697. ),
  698. ),
  699. );
  700. }
  701. /**
  702. * Get necessary condition array to use connections in search classes
  703. * @param $sContentField content table field name
  704. * @param $iInitiator initiator of the connection
  705. * @param $iMutual get mutual connections only
  706. * @return array of conditions, for now with 'restriction' and 'join' parts
  707. */
  708. public function getConnectedContentAsCondition ($sContentField, $iInitiator, $iMutual = false)
  709. {
  710. $sOperation = '=';
  711. if(is_array($iInitiator))
  712. $sOperation = 'in';
  713. return array(
  714. 'restriction' => array (
  715. 'connections_' . $this->_sObject => array(
  716. 'value' => $iInitiator,
  717. 'field' => 'initiator',
  718. 'operator' => $sOperation,
  719. 'table' => $this->_aObject['table'],
  720. ),
  721. 'connections_mutual_' . $this->_sObject => array(
  722. 'value' => $iMutual,
  723. 'field' => 'mutual',
  724. 'operator' => '=',
  725. 'table' => $this->_aObject['table'],
  726. ),
  727. ),
  728. 'join' => array (
  729. 'connections_' . $this->_sObject => array(
  730. 'type' => 'INNER',
  731. 'table' => $this->_aObject['table'],
  732. 'mainField' => $sContentField,
  733. 'onField' => 'content',
  734. 'joinFields' => array(),//'initiator'),
  735. ),
  736. ),
  737. );
  738. }
  739. /**
  740. * Get necessary condition array to use connections in search classes
  741. * @param $sContentField content table field name
  742. * @param $iInitiator initiator of the connection
  743. * @param $iMutual get mutual connections only
  744. * @return array of conditions, for now with 'restriction' and 'join' parts
  745. */
  746. public function getConnectedInitiatorsAsCondition ($sContentField, $iContent, $iMutual = false)
  747. {
  748. $sOperation = '=';
  749. if(is_array($iContent))
  750. $sOperation = 'in';
  751. return array(
  752. 'restriction' => array (
  753. 'connections_' . $this->_sObject => array(
  754. 'value' => $iContent,
  755. 'field' => 'content',
  756. 'operator' => $sOperation,
  757. 'table' => $this->_aObject['table'],
  758. ),
  759. 'connections_mutual_' . $this->_sObject => array(
  760. 'value' => $iMutual,
  761. 'field' => 'mutual',
  762. 'operator' => '=',
  763. 'table' => $this->_aObject['table'],
  764. ),
  765. ),
  766. 'join' => array (
  767. 'connections_' . $this->_sObject => array(
  768. 'type' => 'INNER',
  769. 'table' => $this->_aObject['table'],
  770. 'mainField' => $sContentField,
  771. 'onField' => 'initiator',
  772. 'joinFields' => array(),//'initiator'),
  773. ),
  774. ),
  775. );
  776. }
  777. /**
  778. * Check if initiator and content are connected.
  779. * In case if friends this function in conjunction with isMutual parameter can be used to check pending friend requests.
  780. * @param $iInitiator initiator of the connection
  781. * @param $iContent connected content or other profile id in case of friends
  782. * @return true - if content and initiator are connected or false - in all other cases
  783. */
  784. public function isConnected ($iInitiator, $iContent, $isMutual = false)
  785. {
  786. $oConnection = $this->_oQuery->getConnection ($iInitiator, $iContent);
  787. if (!$oConnection)
  788. return false;
  789. return false === $isMutual ? true : (isset($oConnection['mutual']) ? $oConnection['mutual'] : false);
  790. }
  791. /**
  792. * Check if initiator and content are connected but connetion is not mutual, for checking pending connection requests.
  793. * This method makes sense only when type of connection is mutual.
  794. * @param $iInitiator initiator of the connection
  795. * @param $iContent connected content or other profile id in case of friends
  796. * @return true - if content and initiator are connected but connection is not mutual or false in all other cases
  797. */
  798. public function isConnectedNotMutual ($iInitiator, $iContent)
  799. {
  800. $oConnection = $this->_oQuery->getConnection ($iInitiator, $iContent);
  801. if (!$oConnection)
  802. return false;
  803. return $oConnection['mutual'] ? false : true;
  804. }
  805. public function getConnection ($iInitiator, $iContent)
  806. {
  807. return $this->_oQuery->getConnection($iInitiator, $iContent);
  808. }
  809. public function getConnectionById ($iId)
  810. {
  811. return $this->_oQuery->getConnectionById($iId);
  812. }
  813. /**
  814. * Must be called when some content is deleted which can have connections as 'content' or as 'initiator', to delete any associated data
  815. * @param $iId which can be as conetnt ot initiator
  816. * @return true if some connections were deleted
  817. */
  818. public function onDeleteInitiatorAndContent ($iId)
  819. {
  820. $b = $this->onDeleteInitiator ($iId);
  821. $b = $this->onDeleteContent ($iId) || $b;
  822. return $b;
  823. }
  824. /**
  825. * Must be called when some content is deleted which can have connections as 'initiator', to delete any associated data
  826. * @param $iIdInitiator initiator id
  827. * @return true if some connections were deleted
  828. */
  829. public function onDeleteInitiator ($iIdInitiator)
  830. {
  831. if(!$this->_oQuery->onDelete ($iIdInitiator, 'initiator'))
  832. return false;
  833. /**
  834. * @hooks
  835. * @hookdef hook-bx_dol_connection-connection_removed_all '{object_name}', 'connection_removed_all' - hook after all connections with deleted 'initiator' were removed.
  836. * - $unit_name - connection object name
  837. * - $action - equals `connection_removed_all`
  838. * - $object_id - not used
  839. * - $sender_id - logged in profile id
  840. * - $extra_params - array of additional params with the following array keys:
  841. * - `initiator` - [int] profile id who created the connection
  842. * - `object` - [object] an instance of relation, @see BxDolConnection
  843. * @hook @ref hook-bx_dol_connection-connection_removed_all
  844. */
  845. bx_alert($this->_sObject, 'connection_removed_all', 0, bx_get_logged_profile_id(), array(
  846. 'initiator' => (int)$iIdInitiator,
  847. 'object' => $this,
  848. ));
  849. return true;
  850. }
  851. /**
  852. * Must be called when some content is deleted which can have connections as 'content', to delete any associated data
  853. * @param $iIdInitiator initiator id
  854. * @return true if some connections were deleted
  855. */
  856. public function onDeleteContent ($iIdContent)
  857. {
  858. if(!$this->_oQuery->onDelete ($iIdContent, 'content'))
  859. return false;
  860. /**
  861. * @hooks
  862. * @hookdef hook-bx_dol_connection-connection_removed_all '{object_name}', 'connection_removed_all' - hook after all connections with deleted 'content' were removed.
  863. * - $unit_name - connection object name
  864. * - $action - equals `connection_removed_all`
  865. * - $object_id - not used
  866. * - $sender_id - logged in profile id
  867. * - $extra_params - array of additional params with the following array keys:
  868. * - `content` - [int] profile id with whom the connection was created
  869. * - `object` - [object] an instance of relation, @see BxDolConnection
  870. * @hook @ref hook-bx_dol_connection-connection_removed_all
  871. */
  872. bx_alert($this->_sObject, 'connection_removed_all', 0, bx_get_logged_profile_id(), array(
  873. 'content' => (int)$iIdContent,
  874. 'object' => $this,
  875. ));
  876. return true;
  877. }
  878. /**
  879. * Must be called when module (which can have connections as 'content' or as 'initiator') is deleted, to delete any associated data.
  880. * This method call may be automated via @see BxBaseModGeneralInstaller::_aConnections property.
  881. * @param $sTable table name with data which have assiciations with the connection
  882. * @param $sFieldId id field name which is associated with the connection
  883. * @return number of deleted connections
  884. */
  885. public function onModuleDeleteInitiatorAndContent ($sTable, $sFieldId)
  886. {
  887. $iAffected = $this->onModuleDeleteInitiator ($sTable, $sFieldId);
  888. $iAffected += $this->onModuleDeleteContent ($sTable, $sFieldId);
  889. return $iAffected;
  890. }
  891. /**
  892. * Must be called when module (which can have connections as 'initiator') is deleted, to delete any associated data.
  893. * This method call may be automated via @see BxBaseModGeneralInstaller::_aConnections property.
  894. * @param $sTable table name with data which have assiciations with the connection
  895. * @param $sFieldId id field name which is associated with the connection
  896. * @return number of deleted connections
  897. */
  898. public function onModuleDeleteInitiator ($sTable, $sFieldId)
  899. {
  900. return $this->_oQuery->onModuleDelete ($sTable, $sFieldId, 'initiator');
  901. }
  902. /**
  903. * Must be called when module (which can have connections as 'content') is deleted, to delete any associated data.
  904. * This method call may be automated via @see BxBaseModGeneralInstaller::_aConnections property.
  905. * @param $sTable table name with data which have assiciations with the connection
  906. * @param $sFieldId id field name which is associated with the connection
  907. * @return number of deleted connections
  908. */
  909. public function onModuleDeleteContent ($sTable, $sFieldId)
  910. {
  911. return $this->_oQuery->onModuleDelete ($sTable, $sFieldId, 'content');
  912. }
  913. /**
  914. * 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.
  915. * This method call may be automated via @see BxBaseModGeneralInstaller::_aConnections property.
  916. * @param $sModuleName module name to delete connections for
  917. * @return number of deleted connections
  918. */
  919. public function onModuleProfileDeleteInitiatorAndContent ($sModuleName)
  920. {
  921. $iAffected = $this->onModuleProfileDeleteInitiator ($sModuleName);
  922. $iAffected += $this->onModuleProfileDeleteContent ($sModuleName);
  923. return $iAffected;
  924. }
  925. /**
  926. * Must be called when module (which can have connections as 'initiator' with 'sys_profiles' table) is deleted, to delete any associated data.
  927. * This method call may be automated via @see BxBaseModGeneralInstaller::_aConnections property.
  928. * @param $sModuleName module name to delete connections for
  929. * @return number of deleted connections
  930. */
  931. public function onModuleProfileDeleteInitiator ($sModuleName)
  932. {
  933. return $this->_oQuery->onModuleProfileDelete ($sModuleName, 'initiator');
  934. }
  935. /**
  936. * Must be called when module (which can have connections as 'content' with 'sys_profiles' table) is deleted, to delete any associated data.
  937. * This method call may be automated via @see BxBaseModGeneralInstaller::_aConnections property.
  938. * @param $sModuleName module name to delete connections for
  939. * @return number of deleted connections
  940. */
  941. public function onModuleProfileDeleteContent ($sModuleName)
  942. {
  943. return $this->_oQuery->onModuleProfileDelete ($sModuleName, 'content');
  944. }
  945. protected function _checkAllowedConnect ($iInitiator, $iContent, $isPerformAction = false, $isMutual = false, $isInvertResult = false, $isSwap = false, $isCheckExists = true)
  946. {
  947. $sErr = _t('_sys_txt_access_denied');
  948. if(!$iInitiator || !$iContent || $iInitiator == $iContent)
  949. return ['code' => 1, 'message' => $sErr];
  950. $oInitiator = BxDolProfile::getInstance($iInitiator);
  951. $oContent = BxDolProfile::getInstance($iContent);
  952. if(!$oInitiator || !$oContent)
  953. return ['code' => 2, 'message' => $sErr];
  954. // check ACL
  955. if(($mixedResult = $this->_checkAllowedConnectInitiator($oInitiator, $isPerformAction)) !== CHECK_ACTION_RESULT_ALLOWED)
  956. return ['code' => 3, 'message' => $mixedResult];
  957. $iCode = 0;
  958. $sMessage = '';
  959. // check content's visibility
  960. if(!$this->isConnected($iContent, $iInitiator) && ($mixedResult = $this->_checkAllowedConnectContent($oContent)) !== CHECK_ACTION_RESULT_ALLOWED)
  961. list($iCode, $sMessage) = [4, $mixedResult];
  962. if(!$isCheckExists)
  963. return ['code' => $iCode, 'message' => $sMessage != '' ? $sMessage : null];
  964. if($isSwap)
  965. $isConnected = $this->isConnected($iContent, $iInitiator, $isMutual);
  966. else
  967. $isConnected = $this->isConnected($iInitiator, $iContent, $isMutual);
  968. if($isInvertResult)
  969. $isConnected = !$isConnected;
  970. if($isConnected)
  971. list($iCode, $sMessage) = [5, $sErr];
  972. return ['code' => $iCode, 'message' => $sMessage != '' ? $sMessage : null];
  973. }
  974. protected function _checkAllowedConnectInitiator ($oInitiator, $isPerformAction = false)
  975. {
  976. $aCheck = checkActionModule($oInitiator->id(), 'connect', 'system', $isPerformAction);
  977. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  978. return $aCheck[CHECK_ACTION_MESSAGE];
  979. return CHECK_ACTION_RESULT_ALLOWED;
  980. }
  981. protected function _checkAllowedConnectContent ($oContent)
  982. {
  983. return $oContent->checkAllowedProfileView();
  984. }
  985. }
  986. /** @} */