BxDolConnection.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxDolConnectionQuery');
  10. /**
  11. * Default limit for connections lists
  12. */
  13. define('BX_CONNECTIONS_LIST_LIMIT', 1000);
  14. /**
  15. * Connections order: no order
  16. */
  17. define('BX_CONNECTIONS_ORDER_NONE', 0);
  18. /**
  19. * Connections order: by addded time, asceding
  20. */
  21. define('BX_CONNECTIONS_ORDER_ADDED_ASC', 1);
  22. /**
  23. * Connections order: by addded time, desceding
  24. */
  25. define('BX_CONNECTIONS_ORDER_ADDED_DESC', 2);
  26. /**
  27. * Connection type: one-way
  28. */
  29. define('BX_CONNECTIONS_TYPE_ONE_WAY', 'one-way');
  30. /**
  31. * Connection type: mutual
  32. */
  33. define('BX_CONNECTIONS_TYPE_MUTUAL', 'mutual');
  34. /**
  35. * Connections content type: content
  36. */
  37. define('BX_CONNECTIONS_CONTENT_TYPE_CONTENT', 'content');
  38. /**
  39. * Connections content type: initiators
  40. */
  41. define('BX_CONNECTIONS_CONTENT_TYPE_INITIATORS', 'initiators');
  42. /**
  43. * Connections content type: common
  44. */
  45. define('BX_CONNECTIONS_CONTENT_TYPE_COMMON', 'common');
  46. /**
  47. * @page objects
  48. * @section connection Connection
  49. * @ref BxDolConnection
  50. */
  51. /**
  52. * Connection is usefull when you need to organize some sorts of connections between different content,
  53. * for example: friends, contacts, favorites, block lists, subscriptions, etc.
  54. *
  55. * Two types of connections are supported one way connections (block list, favourites) and mutual (friends).
  56. *
  57. * For automatic handling of connections (like, add/remove connection in frontend) refer to JS function: @see bx_conn_action()
  58. *
  59. * @section connection_create Creating the Connection object:
  60. *
  61. * Step 1:
  62. * Add record to 'sys_objects_connection' table:
  63. * - object: name of the connection object, in the format: vendor prefix, underscore, module prefix, underscore, internal identifier or nothing;
  64. * for example: bx_blogs_favorites - favorite blogs for users in blogs module.
  65. * - table: table name with connections, see step 2
  66. * - type: 'one-way' or 'mutual'
  67. * - override_class_name: user defined class name which is derived from one of base classes.
  68. * - override_class_file: the location of the user defined class, leave it empty if class is located in system folders.
  69. *
  70. * Step 2:
  71. * Create table for connections:
  72. * @code
  73. * CREATE TABLE `my_sample_connections` (
  74. * `id` int(11) NOT NULL AUTO_INCREMENT,
  75. * `initiator` int(11) NOT NULL,
  76. * `content` int(11) NOT NULL,
  77. * `mutual` tinyint(4) NOT NULL, -- can re removed for one-way connections
  78. * `added` int(10) unsigned NOT NULL,
  79. * PRIMARY KEY (`id`),
  80. * UNIQUE KEY `initiator` (`initiator`,`content`),
  81. * KEY `content` (`content`)
  82. * )
  83. * @endcode
  84. *
  85. *
  86. * @section example Example of usage
  87. *
  88. * Check if two profiles are friends:
  89. * @code
  90. * bx_import('BxDolConnection'); // import connection class
  91. * $oConnectionFriends = BxDolConnection::getObjectInstance('bx_profiles_friends'); // get friends connections object
  92. * if ($oConnectionFriends) // check if connections is available for using
  93. * 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
  94. * @endcode
  95. *
  96. * Get mutual content IDs (friends IDs)
  97. * @code
  98. * bx_import('BxDolConnection'); // import connection class
  99. * $oConnectionFriends = BxDolConnection::getObjectInstance('bx_profiles_friends'); // get friends connections object
  100. * if ($oConnectionFriends) // check if connections is available for using
  101. * print_r($oConnection->getConnectedContent(100, 1)); // print array of friends IDs of 100's profile
  102. * @endcode
  103. *
  104. */
  105. class BxDolConnection extends BxDol implements iBxDolFactoryObject
  106. {
  107. protected $_sObject;
  108. protected $_aObject;
  109. protected $_oQuery;
  110. protected $_sType;
  111. /**
  112. * Constructor
  113. * @param $aObject array of connection options
  114. */
  115. protected function __construct($aObject)
  116. {
  117. parent::__construct();
  118. $this->_sObject = $aObject['object'];
  119. $this->_aObject = $aObject;
  120. $this->_sType = $aObject['type'];
  121. $this->_oQuery = new BxDolConnectionQuery($aObject);
  122. }
  123. /**
  124. * Get connection object instance by object name
  125. * @param $sObject object name
  126. * @return object instance or false on error
  127. */
  128. static public function getObjectInstance($sObject)
  129. {
  130. if (!$sObject)
  131. return false;
  132. if (isset($GLOBALS['bxDolClasses']['BxDolConnection!'.$sObject]))
  133. return $GLOBALS['bxDolClasses']['BxDolConnection!'.$sObject];
  134. $aObject = BxDolConnectionQuery::getConnectionObject($sObject);
  135. if (!$aObject || !is_array($aObject))
  136. return false;
  137. $sClass = empty($aObject['override_class_name']) ? 'BxDolConnection' : $aObject['override_class_name'];
  138. if (!empty($aObject['override_class_file']))
  139. require_once(BX_DIRECTORY_PATH_ROOT . $aObject['override_class_file']);
  140. else
  141. bx_import($sClass);
  142. $o = new $sClass($aObject);
  143. return ($GLOBALS['bxDolClasses']['BxDolConnection!'.$sObject] = $o);
  144. }
  145. /**
  146. * Add new connection.
  147. * @param $iContent content to make connection to, in most cases some content id, or other profile id in case of friends
  148. * @return array
  149. */
  150. public function actionAdd ($iContent = 0)
  151. {
  152. if (!$iContent)
  153. $iContent = bx_process_input($_POST['id'], BX_DATA_INT);
  154. return $this->_action (bx_get_logged_profile_id(), $iContent, 'addConnection', '_sys_conn_err_connection_already_exists', true);
  155. }
  156. /**
  157. * Remove connection.
  158. * @param $iContent content to make connection to, in most cases some content id, or other profile id in case of friends
  159. * @return array
  160. */
  161. public function actionRemove ($iContent = 0)
  162. {
  163. if (!$iContent)
  164. $iContent = bx_process_input($_POST['id'], BX_DATA_INT);
  165. $a = $this->actionReject($iContent);
  166. if (false == $a['err'])
  167. return $a;
  168. return $this->_action (bx_get_logged_profile_id(), $iContent, 'removeConnection', '_sys_conn_err_connection_does_not_exists');
  169. }
  170. /**
  171. * Reject connection request.
  172. * @param $iContent content to make connection to, in most cases some content id, or other profile id in case of friends
  173. * @return array
  174. */
  175. public function actionReject ($iContent = 0)
  176. {
  177. if (!$iContent)
  178. $iContent = bx_process_input($_POST['id'], BX_DATA_INT);
  179. return $this->_action ($iContent, bx_get_logged_profile_id(), 'removeConnection', '_sys_conn_err_connection_does_not_exists');
  180. }
  181. protected function _action ($iInitiator, $iContent, $sMethod, $sErrorKey, $isMutual = false)
  182. {
  183. bx_import('BxDolLanguages');
  184. if (!$iContent || !$iInitiator)
  185. return array ('err' => true, 'msg' => _t('_sys_conn_err_input_data_is_not_defined'));
  186. if (!$this->$sMethod((int)$iInitiator, (int)$iContent)) {
  187. if ($isMutual && BX_CONNECTIONS_TYPE_MUTUAL == $this->_sType && $this->isConnected((int)$iInitiator, (int)$iContent, false) && !$this->isConnected((int)$iInitiator, (int)$iContent, true))
  188. return array ('err' => true, 'msg' => _t('_sys_conn_err_connection_is_awaiting_confirmation'));
  189. return array ('err' => true, 'msg' => _t($sErrorKey));
  190. }
  191. return array ('err' => false, 'msg' => _t('_sys_conn_msg_success'));
  192. }
  193. public function outputActionResult ($mixed, $sFormat = 'json')
  194. {
  195. switch ($sFormat) {
  196. case 'json':
  197. default:
  198. header('Content-Type: application/json; charset=utf-8');
  199. echo json_encode($mixed);
  200. }
  201. exit;
  202. }
  203. /**
  204. * Add new connection.
  205. * @param $iInitiator initiator of the connection, in most cases some profile id
  206. * @param $iContent content to make connection to, in most cases some content id, or other profile id in case of friends
  207. * @return true - if connection was added, false - if connection already exists or error occured
  208. */
  209. public function addConnection ($iInitiator, $iContent)
  210. {
  211. $iMutual = 0;
  212. if (!$this->_oQuery->addConnection((int)$iInitiator, (int)$iContent, $iMutual))
  213. return false;
  214. bx_alert($this->_sObject, 'connection_added', 0, getLoggedId(), array(
  215. 'initiator' => (int)$iInitiator,
  216. 'content' => (int)$iContent,
  217. 'mutual' => (int)$iMutual,
  218. 'object' => $this,
  219. ));
  220. return true;
  221. }
  222. /**
  223. * Remove connection.
  224. * @param $iInitiator initiator of the connection
  225. * @param $iContent connected content or other profile id in case of friends
  226. * @return true - if connection was removed, false - if connection isn't exist or error occured
  227. */
  228. public function removeConnection ($iInitiator, $iContent)
  229. {
  230. if (!($aConnection = $this->_oQuery->getConnection((int)$iInitiator, (int)$iContent))) // connection doesn't exist
  231. return false;
  232. if (!$this->_oQuery->removeConnection((int)$iInitiator, (int)$iContent))
  233. return false;
  234. bx_alert($this->_sObject, 'connection_removed', 0, getLoggedId(), array(
  235. 'initiator' => (int)$iInitiator,
  236. 'content' => (int)$iContent,
  237. 'mutual' => isset($aConnection['mutual']) ? $aConnection['mutual'] : 0,
  238. 'object' => $this,
  239. ));
  240. return true;
  241. }
  242. /**
  243. * Compound function, which calls getCommonContent, getConnectedContent or getConnectedInitiators depending on $sContentType
  244. * @param $sContentType content type to get BX_CONNECTIONS_CONTENT_TYPE_CONTENT, BX_CONNECTIONS_CONTENT_TYPE_INITIATORS or BX_CONNECTIONS_CONTENT_TYPE_COMMON
  245. * @param $iId1 one content or initiator
  246. * @param $iId2 second content or initiator only in case of BX_CONNECTIONS_CONTENT_TYPE_COMMON content type
  247. * @param $isMutual get mutual connections only
  248. * @return array of available connections
  249. */
  250. public function getConnectionsAsArray ($sContentType, $iId1, $iId2, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  251. {
  252. if (BX_CONNECTIONS_CONTENT_TYPE_COMMON == $sContentType)
  253. return $this->getCommonContent($iId1, $iId2, $isMutual, $iStart, $iLimit, $iOrder);
  254. if (BX_CONNECTIONS_CONTENT_TYPE_INITIATORS == $sContentType)
  255. $sMethod = 'getConnectedInitiators';
  256. else
  257. $sMethod = 'getConnectedContent';
  258. return $this->$sMethod($iId1, $isMutual, $iStart, $iLimit, $iOrder);
  259. }
  260. /**
  261. * Get common content IDs between two initiators
  262. * @param $iInitiator1 one initiator
  263. * @param $iInitiator2 second initiator
  264. * @param $isMutual get mutual connections only
  265. * @return array of available connections
  266. */
  267. public function getCommonContent ($iInitiator1, $iInitiator2, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  268. {
  269. return $this->_oQuery->getCommonContent($iInitiator1, $iInitiator2, $isMutual, $iStart, $iLimit, $iOrder);
  270. }
  271. /**
  272. * Get connected content IDs
  273. * @param $iInitiator initiator of the connection
  274. * @param $isMutual get mutual connections only
  275. * @return array of available connections
  276. */
  277. public function getConnectedContent ($iInitiator, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  278. {
  279. return $this->_oQuery->getConnectedContent($iInitiator, $isMutual, $iStart, $iLimit, $iOrder);
  280. }
  281. /**
  282. * Get connected initiators IDs
  283. * @param $iContent content of the connection
  284. * @param $isMutual get mutual connections only
  285. * @return array of available connections
  286. */
  287. public function getConnectedInitiators ($iContent, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  288. {
  289. return $this->_oQuery->getConnectedInitiators($iContent, $isMutual, $iStart, $iLimit, $iOrder);
  290. }
  291. /**
  292. * Similar to getConnectionsAsArray, but for getCommonContentAsSQLParts, getConnectedContentAsSQLParts or getConnectedInitiatorsAsSQLParts methods
  293. * @see getConnectionsAsArray
  294. */
  295. public function getConnectionsAsSQLParts ($sContentType, $sContentTable, $sContentField, $iId1, $iId2, $isMutual = false)
  296. {
  297. if (BX_CONNECTIONS_CONTENT_TYPE_COMMON == $sContentType)
  298. return $this->getCommonContentAsSQLParts($sContentTable, $sContentField, $iId1, $iId2, $isMutual);
  299. if (BX_CONNECTIONS_CONTENT_TYPE_INITIATORS == $sContentType)
  300. $sMethod = 'getConnectedInitiatorsAsSQLParts';
  301. else
  302. $sMethod = 'getConnectedContentAsSQLParts';
  303. return $this->$sMethod($sContentTable, $sContentField, $iId1, $isMutual);
  304. }
  305. /**
  306. * Get necessary parts of SQL query to use connections in other queries
  307. * @param $sContentTable content table or alias
  308. * @param $sContentField content table field or field alias
  309. * @param $iInitiator initiator of the connection
  310. * @param $isMutual get mutual connections only
  311. * @return array of SQL string parts, for now 'join' part only is returned
  312. */
  313. public function getCommonContentAsSQLParts ($sContentTable, $sContentField, $iInitiator1, $iInitiator2, $isMutual = false)
  314. {
  315. return $this->_oQuery->getCommonContentSQLParts($sContentTable, $sContentField, $iInitiator1, $iInitiator2, $isMutual);
  316. }
  317. /**
  318. * Get necessary parts of SQL query to use connections in other queries
  319. * @param $sContentTable content table or alias
  320. * @param $sContentField content table field or field alias
  321. * @param $iInitiator initiator of the connection
  322. * @param $isMutual get mutual connections only
  323. * @return array of SQL string parts, for now 'join' part only is returned
  324. */
  325. public function getConnectedContentAsSQLParts ($sContentTable, $sContentField, $iInitiator, $isMutual = false)
  326. {
  327. return $this->_oQuery->getConnectedContentSQLParts($sContentTable, $sContentField, $iInitiator, $isMutual);
  328. }
  329. /**
  330. * Get necessary parts of SQL query to use connections in other queries
  331. * @param $sContentTable content table or alias
  332. * @param $sContentField content table field or field alias
  333. * @param $iContent content of the connection
  334. * @param $isMutual get mutual connections only
  335. * @return array of SQL string parts, for now 'join' part only is returned
  336. */
  337. public function getConnectedInitiatorsAsSQLParts ($sContentTable, $sContentField, $iContent, $isMutual = false)
  338. {
  339. return $this->_oQuery->getConnectedInitiatorsSQLParts($sContentTable, $sContentField, $iContent, $isMutual);
  340. }
  341. /**
  342. * Similar to getConnectionsAsArray, but for getCommonContentAsCondition, getConnectedContentAsCondition or getConnectedInitiatorsAsCondition methods
  343. * @see getConnectionsAsArray
  344. */
  345. public function getConnectionsAsCondition ($sContentType, $sContentField, $iId1, $iId2, $isMutual = false)
  346. {
  347. if (BX_CONNECTIONS_CONTENT_TYPE_COMMON == $sContentType)
  348. return $this->getCommonContentAsCondition($sContentField, $iId1, $iId2, $isMutual);
  349. if (BX_CONNECTIONS_CONTENT_TYPE_INITIATORS == $sContentType)
  350. $sMethod = 'getConnectedInitiatorsAsCondition';
  351. else
  352. $sMethod = 'getConnectedContentAsCondition';
  353. return $this->$sMethod($sContentField, $iId1, $isMutual);
  354. }
  355. /**
  356. * Get necessary condition array to use connections in search classes
  357. * @param $sContentField content table field name
  358. * @param $iInitiator initiator of the connection
  359. * @param $iMutual get mutual connections only
  360. * @return array of conditions, for now with 'restriction' and 'join' parts
  361. */
  362. public function getCommonContentAsCondition ($sContentField, $iInitiator1, $iInitiator2, $iMutual = false)
  363. {
  364. return array(
  365. 'restriction' => array (
  366. 'connections_' . $this->_sObject => array(
  367. 'value' => $iInitiator1,
  368. 'field' => 'initiator',
  369. 'operator' => '=',
  370. 'table' => 'c',
  371. ),
  372. 'connections_mutual_' . $this->_sObject => array(
  373. 'value' => $iMutual,
  374. 'field' => 'mutual',
  375. 'operator' => '=',
  376. 'table' => 'c',
  377. ),
  378. 'connections2_' . $this->_sObject => array(
  379. 'value' => $iInitiator2,
  380. 'field' => 'initiator',
  381. 'operator' => '=',
  382. 'table' => 'c2',
  383. ),
  384. 'connections2_mutual_' . $this->_sObject => array(
  385. 'value' => $iMutual,
  386. 'field' => 'mutual',
  387. 'operator' => '=',
  388. 'table' => 'c2',
  389. ),
  390. ),
  391. 'join' => array (
  392. 'connections_' . $this->_sObject => array(
  393. 'type' => 'INNER',
  394. 'table' => $this->_aObject['table'],
  395. 'table_alias' => 'c',
  396. 'mainField' => $sContentField,
  397. 'onField' => 'content',
  398. 'joinFields' => array(),
  399. ),
  400. 'connections2_' . $this->_sObject => array(
  401. 'type' => 'INNER',
  402. 'table' => $this->_aObject['table'],
  403. 'table_alias' => 'c2',
  404. 'mainTable' => 'c',
  405. 'mainField' => 'content',
  406. 'onField' => 'content',
  407. 'joinFields' => array(),
  408. ),
  409. ),
  410. );
  411. }
  412. /**
  413. * Get necessary condition array to use connections in search classes
  414. * @param $sContentField content table field name
  415. * @param $iInitiator initiator of the connection
  416. * @param $iMutual get mutual connections only
  417. * @return array of conditions, for now with 'restriction' and 'join' parts
  418. */
  419. public function getConnectedContentAsCondition ($sContentField, $iInitiator, $iMutual = false)
  420. {
  421. return array(
  422. 'restriction' => array (
  423. 'connections_' . $this->_sObject => array(
  424. 'value' => $iInitiator,
  425. 'field' => 'initiator',
  426. 'operator' => '=',
  427. 'table' => $this->_aObject['table'],
  428. ),
  429. 'connections_mutual_' . $this->_sObject => array(
  430. 'value' => $iMutual,
  431. 'field' => 'mutual',
  432. 'operator' => '=',
  433. 'table' => $this->_aObject['table'],
  434. ),
  435. ),
  436. 'join' => array (
  437. 'connections_' . $this->_sObject => array(
  438. 'type' => 'INNER',
  439. 'table' => $this->_aObject['table'],
  440. 'mainField' => $sContentField,
  441. 'onField' => 'content',
  442. 'joinFields' => array(),//'initiator'),
  443. ),
  444. ),
  445. );
  446. }
  447. /**
  448. * Get necessary condition array to use connections in search classes
  449. * @param $sContentField content table field name
  450. * @param $iInitiator initiator of the connection
  451. * @param $iMutual get mutual connections only
  452. * @return array of conditions, for now with 'restriction' and 'join' parts
  453. */
  454. public function getConnectedInitiatorsAsCondition ($sContentField, $iContent, $iMutual = false)
  455. {
  456. return array(
  457. 'restriction' => array (
  458. 'connections_' . $this->_sObject => array(
  459. 'value' => $iContent,
  460. 'field' => 'content',
  461. 'operator' => '=',
  462. 'table' => $this->_aObject['table'],
  463. ),
  464. 'connections_mutual_' . $this->_sObject => array(
  465. 'value' => $iMutual,
  466. 'field' => 'mutual',
  467. 'operator' => '=',
  468. 'table' => $this->_aObject['table'],
  469. ),
  470. ),
  471. 'join' => array (
  472. 'connections_' . $this->_sObject => array(
  473. 'type' => 'INNER',
  474. 'table' => $this->_aObject['table'],
  475. 'mainField' => $sContentField,
  476. 'onField' => 'initiator',
  477. 'joinFields' => array(),//'initiator'),
  478. ),
  479. ),
  480. );
  481. }
  482. /**
  483. * Check if initiator and content are connected.
  484. * In case if friends this function in conjunction with isMutual parameter can be used to check pending friend requests.
  485. * @param $iInitiator initiator of the connection
  486. * @param $iContent connected content or other profile id in case of friends
  487. * @return true - if content and initiator are connected or false - in all other cases
  488. */
  489. public function isConnected ($iInitiator, $iContent, $isMutual = false)
  490. {
  491. $oConnection = $this->_oQuery->getConnection ($iInitiator, $iContent);
  492. if (!$oConnection)
  493. return false;
  494. return false === $isMutual ? true : $oConnection['mutual'];
  495. }
  496. /**
  497. * Check if initiator and content are connected but connetion is not mutual, for checking pending connection requests.
  498. * This method makes sense only when type of connection is mutual.
  499. * @param $iInitiator initiator of the connection
  500. * @param $iContent connected content or other profile id in case of friends
  501. * @return true - if content and initiator are connected but connection is not mutual or false in all other cases
  502. */
  503. public function isConnectedNotMutual ($iInitiator, $iContent)
  504. {
  505. $oConnection = $this->_oQuery->getConnection ($iInitiator, $iContent);
  506. if (!$oConnection)
  507. return false;
  508. return $oConnection['mutual'] ? false : true;
  509. }
  510. /**
  511. * Must be called when some content is deleted which can have connections as 'content' or as 'initiator', to delete any associated data
  512. * @param $iId which can be as conetnt ot initiator
  513. * @return true if some connections were deleted
  514. */
  515. public function onDeleteInitiatorAndContent ($iId)
  516. {
  517. $b = $this->onDeleteInitiator ($iId);
  518. $b = $this->onDeleteContent ($iId) || $b;
  519. return $b;
  520. }
  521. /**
  522. * Must be called when some content is deleted which can have connections as 'initiator', to delete any associated data
  523. * @param $iIdInitiator initiator id
  524. * @return true if some connections were deleted
  525. */
  526. public function onDeleteInitiator ($iIdInitiator)
  527. {
  528. return $this->_oQuery->onDelete ($iIdInitiator, 'initiator');
  529. }
  530. /**
  531. * Must be called when some content is deleted which can have connections as 'content', to delete any associated data
  532. * @param $iIdInitiator initiator id
  533. * @return true if some connections were deleted
  534. */
  535. public function onDeleteContent ($iIdContent)
  536. {
  537. return $this->_oQuery->onDelete ($iIdContent, 'content');
  538. }
  539. /**
  540. * Must be called when module (which can have connections as 'content' or as 'initiator') is deleted, to delete any associated data.
  541. * This method call may be automated via @see BxBaseModGeneralInstaller::_aConnections property.
  542. * @param $sTable table name with data which have assiciations with the connection
  543. * @param $sFieldId id field name which is associated with the connection
  544. * @return number of deleted connections
  545. */
  546. public function onModuleDeleteInitiatorAndContent ($sTable, $sFieldId)
  547. {
  548. $iAffected = $this->onModuleDeleteInitiator ($sTable, $sFieldId);
  549. $iAffected += $this->onModuleDeleteContent ($sTable, $sFieldId);
  550. return $iAffected;
  551. }
  552. /**
  553. * Must be called when module (which can have connections as 'initiator') is deleted, to delete any associated data.
  554. * This method call may be automated via @see BxBaseModGeneralInstaller::_aConnections property.
  555. * @param $sTable table name with data which have assiciations with the connection
  556. * @param $sFieldId id field name which is associated with the connection
  557. * @return number of deleted connections
  558. */
  559. public function onModuleDeleteInitiator ($sTable, $sFieldId)
  560. {
  561. return $this->_oQuery->onModuleDelete ($sTable, $sFieldId, 'initiator');
  562. }
  563. /**
  564. * Must be called when module (which can have connections as 'content') is deleted, to delete any associated data.
  565. * This method call may be automated via @see BxBaseModGeneralInstaller::_aConnections property.
  566. * @param $sTable table name with data which have assiciations with the connection
  567. * @param $sFieldId id field name which is associated with the connection
  568. * @return number of deleted connections
  569. */
  570. public function onModuleDeleteContent ($sTable, $sFieldId)
  571. {
  572. return $this->_oQuery->onModuleDelete ($sTable, $sFieldId, 'content');
  573. }
  574. /**
  575. * 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.
  576. * This method call may be automated via @see BxBaseModGeneralInstaller::_aConnections property.
  577. * @param $sModuleName module name to delete connections for
  578. * @return number of deleted connections
  579. */
  580. public function onModuleProfileDeleteInitiatorAndContent ($sModuleName)
  581. {
  582. $iAffected = $this->onModuleProfileDeleteInitiator ($sModuleName);
  583. $iAffected += $this->onModuleProfileDeleteContent ($sModuleName);
  584. return $iAffected;
  585. }
  586. /**
  587. * Must be called when module (which can have connections as 'initiator' with 'sys_profiles' table) is deleted, to delete any associated data.
  588. * This method call may be automated via @see BxBaseModGeneralInstaller::_aConnections property.
  589. * @param $sModuleName module name to delete connections for
  590. * @return number of deleted connections
  591. */
  592. public function onModuleProfileDeleteInitiator ($sModuleName)
  593. {
  594. return $this->_oQuery->onModuleProfileDelete ($sModuleName, 'initiator');
  595. }
  596. /**
  597. * Must be called when module (which can have connections as 'content' with 'sys_profiles' table) is deleted, to delete any associated data.
  598. * This method call may be automated via @see BxBaseModGeneralInstaller::_aConnections property.
  599. * @param $sModuleName module name to delete connections for
  600. * @return number of deleted connections
  601. */
  602. public function onModuleProfileDeleteContent ($sModuleName)
  603. {
  604. return $this->_oQuery->onModuleProfileDelete ($sModuleName, 'content');
  605. }
  606. }
  607. /** @} */