BxDolConnection.php 26 KB

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