BxDolConnection.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  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. if (!$iContent || !$iInitiator)
  179. return array ('err' => true, 'msg' => _t('_sys_conn_err_input_data_is_not_defined'));
  180. if (!$this->$sMethod((int)$iInitiator, (int)$iContent)) {
  181. if ($isMutual && BX_CONNECTIONS_TYPE_MUTUAL == $this->_sType && $this->isConnected((int)$iInitiator, (int)$iContent, false) && !$this->isConnected((int)$iInitiator, (int)$iContent, true))
  182. return array ('err' => true, 'msg' => _t('_sys_conn_err_connection_is_awaiting_confirmation'));
  183. return array ('err' => true, 'msg' => _t($sErrorKey));
  184. }
  185. return array ('err' => false, 'msg' => _t('_sys_conn_msg_success'));
  186. }
  187. public function outputActionResult ($mixed, $sFormat = 'json')
  188. {
  189. switch ($sFormat) {
  190. case 'json':
  191. default:
  192. header('Content-Type: application/json; charset=utf-8');
  193. echo json_encode($mixed);
  194. }
  195. exit;
  196. }
  197. /**
  198. * Add new connection.
  199. * @param $iInitiator initiator of the connection, in most cases some profile id
  200. * @param $iContent content to make connection to, in most cases some content id, or other profile id in case of friends
  201. * @return true - if connection was added, false - if connection already exists or error occured
  202. */
  203. public function addConnection ($iInitiator, $iContent)
  204. {
  205. $iMutual = 0;
  206. if (!$this->_oQuery->addConnection((int)$iInitiator, (int)$iContent, $iMutual))
  207. return false;
  208. bx_alert($this->_sObject, 'connection_added', 0, getLoggedId(), array(
  209. 'initiator' => (int)$iInitiator,
  210. 'content' => (int)$iContent,
  211. 'mutual' => (int)$iMutual,
  212. 'object' => $this,
  213. ));
  214. return true;
  215. }
  216. /**
  217. * Remove connection.
  218. * @param $iInitiator initiator of the connection
  219. * @param $iContent connected content or other profile id in case of friends
  220. * @return true - if connection was removed, false - if connection isn't exist or error occured
  221. */
  222. public function removeConnection ($iInitiator, $iContent)
  223. {
  224. if (!($aConnection = $this->_oQuery->getConnection((int)$iInitiator, (int)$iContent))) // connection doesn't exist
  225. return false;
  226. if (!$this->_oQuery->removeConnection((int)$iInitiator, (int)$iContent))
  227. return false;
  228. bx_alert($this->_sObject, 'connection_removed', 0, getLoggedId(), array(
  229. 'initiator' => (int)$iInitiator,
  230. 'content' => (int)$iContent,
  231. 'mutual' => isset($aConnection['mutual']) ? $aConnection['mutual'] : 0,
  232. 'object' => $this,
  233. ));
  234. return true;
  235. }
  236. /**
  237. * Compound function, which calls getCommonContent, getConnectedContent or getConnectedInitiators depending on $sContentType
  238. * @param $sContentType content type to get BX_CONNECTIONS_CONTENT_TYPE_CONTENT, BX_CONNECTIONS_CONTENT_TYPE_INITIATORS or BX_CONNECTIONS_CONTENT_TYPE_COMMON
  239. * @param $iId1 one content or initiator
  240. * @param $iId2 second content or initiator only in case of BX_CONNECTIONS_CONTENT_TYPE_COMMON content type
  241. * @param $isMutual get mutual connections only
  242. * @return array of available connections
  243. */
  244. public function getConnectionsAsArray ($sContentType, $iId1, $iId2, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  245. {
  246. if (BX_CONNECTIONS_CONTENT_TYPE_COMMON == $sContentType)
  247. return $this->getCommonContent($iId1, $iId2, $isMutual, $iStart, $iLimit, $iOrder);
  248. if (BX_CONNECTIONS_CONTENT_TYPE_INITIATORS == $sContentType)
  249. $sMethod = 'getConnectedInitiators';
  250. else
  251. $sMethod = 'getConnectedContent';
  252. return $this->$sMethod($iId1, $isMutual, $iStart, $iLimit, $iOrder);
  253. }
  254. /**
  255. * Get common content IDs between two initiators
  256. * @param $iInitiator1 one initiator
  257. * @param $iInitiator2 second initiator
  258. * @param $isMutual get mutual connections only
  259. * @return array of available connections
  260. */
  261. public function getCommonContent ($iInitiator1, $iInitiator2, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  262. {
  263. return $this->_oQuery->getCommonContent($iInitiator1, $iInitiator2, $isMutual, $iStart, $iLimit, $iOrder);
  264. }
  265. /**
  266. * Get connected content IDs
  267. * @param $iInitiator initiator of the connection
  268. * @param $isMutual get mutual connections only
  269. * @return array of available connections
  270. */
  271. public function getConnectedContent ($iInitiator, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  272. {
  273. return $this->_oQuery->getConnectedContent($iInitiator, $isMutual, $iStart, $iLimit, $iOrder);
  274. }
  275. /**
  276. * Get connected initiators IDs
  277. * @param $iContent content of the connection
  278. * @param $isMutual get mutual connections only
  279. * @return array of available connections
  280. */
  281. public function getConnectedInitiators ($iContent, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  282. {
  283. return $this->_oQuery->getConnectedInitiators($iContent, $isMutual, $iStart, $iLimit, $iOrder);
  284. }
  285. /**
  286. * Similar to getConnectionsAsArray, but for getCommonContentAsSQLParts, getConnectedContentAsSQLParts or getConnectedInitiatorsAsSQLParts methods
  287. * @see getConnectionsAsArray
  288. */
  289. public function getConnectionsAsSQLParts ($sContentType, $sContentTable, $sContentField, $iId1, $iId2, $isMutual = false)
  290. {
  291. if (BX_CONNECTIONS_CONTENT_TYPE_COMMON == $sContentType)
  292. return $this->getCommonContentAsSQLParts($sContentTable, $sContentField, $iId1, $iId2, $isMutual);
  293. if (BX_CONNECTIONS_CONTENT_TYPE_INITIATORS == $sContentType)
  294. $sMethod = 'getConnectedInitiatorsAsSQLParts';
  295. else
  296. $sMethod = 'getConnectedContentAsSQLParts';
  297. return $this->$sMethod($sContentTable, $sContentField, $iId1, $isMutual);
  298. }
  299. /**
  300. * Get necessary parts of SQL query to use connections in other queries
  301. * @param $sContentTable content table or alias
  302. * @param $sContentField content table field or field alias
  303. * @param $iInitiator initiator of the connection
  304. * @param $isMutual get mutual connections only
  305. * @return array of SQL string parts, for now 'join' part only is returned
  306. */
  307. public function getCommonContentAsSQLParts ($sContentTable, $sContentField, $iInitiator1, $iInitiator2, $isMutual = false)
  308. {
  309. return $this->_oQuery->getCommonContentSQLParts($sContentTable, $sContentField, $iInitiator1, $iInitiator2, $isMutual);
  310. }
  311. /**
  312. * Get necessary parts of SQL query to use connections in other queries
  313. * @param $sContentTable content table or alias
  314. * @param $sContentField content table field or field alias
  315. * @param $iInitiator initiator of the connection
  316. * @param $isMutual get mutual connections only
  317. * @return array of SQL string parts, for now 'join' part only is returned
  318. */
  319. public function getConnectedContentAsSQLParts ($sContentTable, $sContentField, $iInitiator, $isMutual = false)
  320. {
  321. return $this->_oQuery->getConnectedContentSQLParts($sContentTable, $sContentField, $iInitiator, $isMutual);
  322. }
  323. /**
  324. * Get necessary parts of SQL query to use connections in other queries
  325. * @param $sContentTable content table or alias
  326. * @param $sContentField content table field or field alias
  327. * @param $iContent content of the connection
  328. * @param $isMutual get mutual connections only
  329. * @return array of SQL string parts, for now 'join' part only is returned
  330. */
  331. public function getConnectedInitiatorsAsSQLParts ($sContentTable, $sContentField, $iContent, $isMutual = false)
  332. {
  333. return $this->_oQuery->getConnectedInitiatorsSQLParts($sContentTable, $sContentField, $iContent, $isMutual);
  334. }
  335. /**
  336. * Similar to getConnectionsAsArray, but for getCommonContentAsCondition, getConnectedContentAsCondition or getConnectedInitiatorsAsCondition methods
  337. * @see getConnectionsAsArray
  338. */
  339. public function getConnectionsAsCondition ($sContentType, $sContentField, $iId1, $iId2, $isMutual = false)
  340. {
  341. if (BX_CONNECTIONS_CONTENT_TYPE_COMMON == $sContentType)
  342. return $this->getCommonContentAsCondition($sContentField, $iId1, $iId2, $isMutual);
  343. if (BX_CONNECTIONS_CONTENT_TYPE_INITIATORS == $sContentType)
  344. $sMethod = 'getConnectedInitiatorsAsCondition';
  345. else
  346. $sMethod = 'getConnectedContentAsCondition';
  347. return $this->$sMethod($sContentField, $iId1, $isMutual);
  348. }
  349. /**
  350. * Get necessary condition array to use connections in search classes
  351. * @param $sContentField content table field name
  352. * @param $iInitiator initiator of the connection
  353. * @param $iMutual get mutual connections only
  354. * @return array of conditions, for now with 'restriction' and 'join' parts
  355. */
  356. public function getCommonContentAsCondition ($sContentField, $iInitiator1, $iInitiator2, $iMutual = false)
  357. {
  358. return array(
  359. 'restriction' => array (
  360. 'connections_' . $this->_sObject => array(
  361. 'value' => $iInitiator1,
  362. 'field' => 'initiator',
  363. 'operator' => '=',
  364. 'table' => 'c',
  365. ),
  366. 'connections_mutual_' . $this->_sObject => array(
  367. 'value' => $iMutual,
  368. 'field' => 'mutual',
  369. 'operator' => '=',
  370. 'table' => 'c',
  371. ),
  372. 'connections2_' . $this->_sObject => array(
  373. 'value' => $iInitiator2,
  374. 'field' => 'initiator',
  375. 'operator' => '=',
  376. 'table' => 'c2',
  377. ),
  378. 'connections2_mutual_' . $this->_sObject => array(
  379. 'value' => $iMutual,
  380. 'field' => 'mutual',
  381. 'operator' => '=',
  382. 'table' => 'c2',
  383. ),
  384. ),
  385. 'join' => array (
  386. 'connections_' . $this->_sObject => array(
  387. 'type' => 'INNER',
  388. 'table' => $this->_aObject['table'],
  389. 'table_alias' => 'c',
  390. 'mainField' => $sContentField,
  391. 'onField' => 'content',
  392. 'joinFields' => array(),
  393. ),
  394. 'connections2_' . $this->_sObject => array(
  395. 'type' => 'INNER',
  396. 'table' => $this->_aObject['table'],
  397. 'table_alias' => 'c2',
  398. 'mainTable' => 'c',
  399. 'mainField' => 'content',
  400. 'onField' => 'content',
  401. 'joinFields' => array(),
  402. ),
  403. ),
  404. );
  405. }
  406. /**
  407. * Get necessary condition array to use connections in search classes
  408. * @param $sContentField content table field name
  409. * @param $iInitiator initiator of the connection
  410. * @param $iMutual get mutual connections only
  411. * @return array of conditions, for now with 'restriction' and 'join' parts
  412. */
  413. public function getConnectedContentAsCondition ($sContentField, $iInitiator, $iMutual = false)
  414. {
  415. return array(
  416. 'restriction' => array (
  417. 'connections_' . $this->_sObject => array(
  418. 'value' => $iInitiator,
  419. 'field' => 'initiator',
  420. 'operator' => '=',
  421. 'table' => $this->_aObject['table'],
  422. ),
  423. 'connections_mutual_' . $this->_sObject => array(
  424. 'value' => $iMutual,
  425. 'field' => 'mutual',
  426. 'operator' => '=',
  427. 'table' => $this->_aObject['table'],
  428. ),
  429. ),
  430. 'join' => array (
  431. 'connections_' . $this->_sObject => array(
  432. 'type' => 'INNER',
  433. 'table' => $this->_aObject['table'],
  434. 'mainField' => $sContentField,
  435. 'onField' => 'content',
  436. 'joinFields' => array(),//'initiator'),
  437. ),
  438. ),
  439. );
  440. }
  441. /**
  442. * Get necessary condition array to use connections in search classes
  443. * @param $sContentField content table field name
  444. * @param $iInitiator initiator of the connection
  445. * @param $iMutual get mutual connections only
  446. * @return array of conditions, for now with 'restriction' and 'join' parts
  447. */
  448. public function getConnectedInitiatorsAsCondition ($sContentField, $iContent, $iMutual = false)
  449. {
  450. return array(
  451. 'restriction' => array (
  452. 'connections_' . $this->_sObject => array(
  453. 'value' => $iContent,
  454. 'field' => 'content',
  455. 'operator' => '=',
  456. 'table' => $this->_aObject['table'],
  457. ),
  458. 'connections_mutual_' . $this->_sObject => array(
  459. 'value' => $iMutual,
  460. 'field' => 'mutual',
  461. 'operator' => '=',
  462. 'table' => $this->_aObject['table'],
  463. ),
  464. ),
  465. 'join' => array (
  466. 'connections_' . $this->_sObject => array(
  467. 'type' => 'INNER',
  468. 'table' => $this->_aObject['table'],
  469. 'mainField' => $sContentField,
  470. 'onField' => 'initiator',
  471. 'joinFields' => array(),//'initiator'),
  472. ),
  473. ),
  474. );
  475. }
  476. /**
  477. * Check if initiator and content are connected.
  478. * In case if friends this function in conjunction with isMutual parameter can be used to check pending friend requests.
  479. * @param $iInitiator initiator of the connection
  480. * @param $iContent connected content or other profile id in case of friends
  481. * @return true - if content and initiator are connected or false - in all other cases
  482. */
  483. public function isConnected ($iInitiator, $iContent, $isMutual = false)
  484. {
  485. $oConnection = $this->_oQuery->getConnection ($iInitiator, $iContent);
  486. if (!$oConnection)
  487. return false;
  488. return false === $isMutual ? true : $oConnection['mutual'];
  489. }
  490. /**
  491. * Check if initiator and content are connected but connetion is not mutual, for checking pending connection requests.
  492. * This method makes sense only when type of connection is mutual.
  493. * @param $iInitiator initiator of the connection
  494. * @param $iContent connected content or other profile id in case of friends
  495. * @return true - if content and initiator are connected but connection is not mutual or false in all other cases
  496. */
  497. public function isConnectedNotMutual ($iInitiator, $iContent)
  498. {
  499. $oConnection = $this->_oQuery->getConnection ($iInitiator, $iContent);
  500. if (!$oConnection)
  501. return false;
  502. return $oConnection['mutual'] ? false : true;
  503. }
  504. /**
  505. * Must be called when some content is deleted which can have connections as 'content' or as 'initiator', to delete any associated data
  506. * @param $iId which can be as conetnt ot initiator
  507. * @return true if some connections were deleted
  508. */
  509. public function onDeleteInitiatorAndContent ($iId)
  510. {
  511. $b = $this->onDeleteInitiator ($iId);
  512. $b = $this->onDeleteContent ($iId) || $b;
  513. return $b;
  514. }
  515. /**
  516. * Must be called when some content is deleted which can have connections as 'initiator', to delete any associated data
  517. * @param $iIdInitiator initiator id
  518. * @return true if some connections were deleted
  519. */
  520. public function onDeleteInitiator ($iIdInitiator)
  521. {
  522. return $this->_oQuery->onDelete ($iIdInitiator, 'initiator');
  523. }
  524. /**
  525. * Must be called when some content is deleted which can have connections as 'content', to delete any associated data
  526. * @param $iIdInitiator initiator id
  527. * @return true if some connections were deleted
  528. */
  529. public function onDeleteContent ($iIdContent)
  530. {
  531. return $this->_oQuery->onDelete ($iIdContent, 'content');
  532. }
  533. /**
  534. * Must be called when module (which can have connections as 'content' or as 'initiator') is deleted, to delete any associated data.
  535. * This method call may be automated via @see BxBaseModGeneralInstaller::_aConnections property.
  536. * @param $sTable table name with data which have assiciations with the connection
  537. * @param $sFieldId id field name which is associated with the connection
  538. * @return number of deleted connections
  539. */
  540. public function onModuleDeleteInitiatorAndContent ($sTable, $sFieldId)
  541. {
  542. $iAffected = $this->onModuleDeleteInitiator ($sTable, $sFieldId);
  543. $iAffected += $this->onModuleDeleteContent ($sTable, $sFieldId);
  544. return $iAffected;
  545. }
  546. /**
  547. * Must be called when module (which can have connections as 'initiator') is deleted, to delete any associated data.
  548. * This method call may be automated via @see BxBaseModGeneralInstaller::_aConnections property.
  549. * @param $sTable table name with data which have assiciations with the connection
  550. * @param $sFieldId id field name which is associated with the connection
  551. * @return number of deleted connections
  552. */
  553. public function onModuleDeleteInitiator ($sTable, $sFieldId)
  554. {
  555. return $this->_oQuery->onModuleDelete ($sTable, $sFieldId, 'initiator');
  556. }
  557. /**
  558. * Must be called when module (which can have connections as 'content') is deleted, to delete any associated data.
  559. * This method call may be automated via @see BxBaseModGeneralInstaller::_aConnections property.
  560. * @param $sTable table name with data which have assiciations with the connection
  561. * @param $sFieldId id field name which is associated with the connection
  562. * @return number of deleted connections
  563. */
  564. public function onModuleDeleteContent ($sTable, $sFieldId)
  565. {
  566. return $this->_oQuery->onModuleDelete ($sTable, $sFieldId, 'content');
  567. }
  568. /**
  569. * 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.
  570. * This method call may be automated via @see BxBaseModGeneralInstaller::_aConnections property.
  571. * @param $sModuleName module name to delete connections for
  572. * @return number of deleted connections
  573. */
  574. public function onModuleProfileDeleteInitiatorAndContent ($sModuleName)
  575. {
  576. $iAffected = $this->onModuleProfileDeleteInitiator ($sModuleName);
  577. $iAffected += $this->onModuleProfileDeleteContent ($sModuleName);
  578. return $iAffected;
  579. }
  580. /**
  581. * Must be called when module (which can have connections as 'initiator' with 'sys_profiles' table) is deleted, to delete any associated data.
  582. * This method call may be automated via @see BxBaseModGeneralInstaller::_aConnections property.
  583. * @param $sModuleName module name to delete connections for
  584. * @return number of deleted connections
  585. */
  586. public function onModuleProfileDeleteInitiator ($sModuleName)
  587. {
  588. return $this->_oQuery->onModuleProfileDelete ($sModuleName, 'initiator');
  589. }
  590. /**
  591. * Must be called when module (which can have connections as 'content' with 'sys_profiles' table) is deleted, to delete any associated data.
  592. * This method call may be automated via @see BxBaseModGeneralInstaller::_aConnections property.
  593. * @param $sModuleName module name to delete connections for
  594. * @return number of deleted connections
  595. */
  596. public function onModuleProfileDeleteContent ($sModuleName)
  597. {
  598. return $this->_oQuery->onModuleProfileDelete ($sModuleName, 'content');
  599. }
  600. }
  601. /** @} */