BxDolConnectionQuery.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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. * Database queries for Connection objects.
  11. * @see BxDolConnection
  12. */
  13. class BxDolConnectionQuery extends BxDolDb
  14. {
  15. protected $_aObject;
  16. protected $_sTable;
  17. protected $_sType;
  18. protected $_sTriggerTable;
  19. protected $_sTriggerFieldId;
  20. protected $_sTriggerFieldCount;
  21. public function __construct($aObject)
  22. {
  23. parent::__construct();
  24. $this->_aObject = $aObject;
  25. $this->_sTable = $aObject['table'];
  26. $this->_sType = $aObject['type'];
  27. $this->_sTriggerTable = $aObject['trigger_table'];
  28. $this->_sTriggerFieldId = $aObject['trigger_field_id'];
  29. $this->_sTriggerFieldCount = $aObject['trigger_field_count'];
  30. }
  31. static public function getConnectionObject ($sObject)
  32. {
  33. $oDb = BxDolDb::getInstance();
  34. $sQuery = $oDb->prepare("SELECT * FROM `sys_objects_connection` WHERE `object` = ?", $sObject);
  35. $aObject = $oDb->getRow($sQuery);
  36. if (!$aObject || !is_array($aObject))
  37. return false;
  38. return $aObject;
  39. }
  40. public function getCommonContentSQLParts ($sContentTable, $sContentField, $iInitiator1, $iInitiator2, $isMutual = false)
  41. {
  42. $sWhereJoin1 = $this->prepareAsString(" AND `c`.`initiator` = ?", $iInitiator1);
  43. $sWhereJoin2 = $this->prepareAsString(" AND `c2`.`initiator` = ?", $iInitiator2);
  44. if (false !== $isMutual) {
  45. $sWhereJoin1 .= $this->prepareAsString(" AND `c`.`mutual` = ?", $isMutual);
  46. $sWhereJoin2 .= $this->prepareAsString(" AND `c2`.`mutual` = ?", $isMutual);
  47. }
  48. $sJoin = "";
  49. if($this->_aObject['profile_content'])
  50. $sJoin = " INNER JOIN `sys_profiles` AS `cp1` ON (`cp1`.`id` = `c`.`content` AND `cp1`.`status` = 'active') INNER JOIN `sys_profiles` AS `cp2` ON (`cp2`.`id` = `c2`.`content` AND `cp2`.`status` = 'active')";
  51. return [
  52. 'join' => "INNER JOIN `{$this->_sTable}` AS `c` ON (`c`.`content` = `$sContentTable`.`$sContentField` $sWhereJoin1) INNER JOIN `{$this->_sTable}` AS `c2` ON (`c2`.`content` = `c`.`content` $sWhereJoin2)" . $sJoin,
  53. ];
  54. }
  55. public function getConnectedContentSQLParts ($sContentTable, $sContentField, $iInitiator, $isMutual = false)
  56. {
  57. $aResult = $this->getConnectedContentSQLPartsExt($sContentTable, $sContentField, $iInitiator, $isMutual);
  58. $aFields = [];
  59. foreach($aResult['fields'] as $sFieldAlias => $aField)
  60. $aFields[$sFieldAlias] = "`" . $aField['table_alias'] . "`.`" . $aField['name'] . "`";
  61. $sJoin = "";
  62. if($this->_aObject['profile_content'])
  63. $sJoin = " INNER JOIN `sys_profiles` AS `cp` ON (`cp`.`id` = `{$aResult['join']['table_alias']}`.`content` AND `cp`.`status` = 'active')";
  64. return [
  65. 'fields' => $aFields,
  66. 'join' => $aResult['join']['type'] . " JOIN `" . $aResult['join']['table'] . "` AS `" . $aResult['join']['table_alias'] . "` ON (" . $aResult['join']['condition'] . ")" . $sJoin,
  67. ];
  68. }
  69. public function getConnectedContentSQLPartsExt ($sContentTable, $sContentField, $iInitiator, $isMutual = false)
  70. {
  71. $sWhere = $this->prepareAsString(" AND `c`.`initiator` = ?", $iInitiator);
  72. if(false !== $isMutual)
  73. $sWhere .= $this->prepareAsString(" AND `c`.`mutual` = ?", $isMutual);
  74. return array(
  75. 'fields' => array(
  76. 'added' => array('table_alias' => 'c', 'name' => 'added')
  77. ),
  78. 'join' => array(
  79. 'type' => 'INNER',
  80. 'table' => $this->_sTable,
  81. 'table_alias' => 'c',
  82. 'condition' => "`c`.`content` = `" . $sContentTable . "`.`" . $sContentField . "`" . $sWhere
  83. )
  84. );
  85. }
  86. public function getConnectedContentSQLPartsMultiple ($sContentTable, $sContentField, $sInitiatorTable, $sInitiatorField, $isMutual = false)
  87. {
  88. $sOn = "";
  89. if (false !== $isMutual)
  90. $sOn .= $this->prepareAsString(" AND `c`.`mutual` = ?", $isMutual);
  91. return array(
  92. 'join' => "INNER JOIN `{$this->_sTable}` AS `c` ON (`c`.`content` = `$sContentTable`.`$sContentField` $sOn)",
  93. 'where' => " AND `c`.`initiator` = `$sInitiatorTable`.`$sInitiatorField`"
  94. );
  95. }
  96. public function getConnectedInitiatorsSQLParts ($sInitiatorTable, $sInitiatorField, $iContent, $isMutual = false)
  97. {
  98. $aResult = $this->getConnectedInitiatorsSQLPartsExt($sInitiatorTable, $sInitiatorField, $iContent, $isMutual);
  99. $sJoin = '';
  100. if($this->_aObject['profile_initiator'])
  101. $sJoin = " INNER JOIN `sys_profiles` AS `cp` ON (`cp`.`id` = `{$aResult['join']['table_alias']}`.`initiator` AND `cp`.`status` = 'active')";
  102. return [
  103. 'join' => $aResult['join']['type'] . " JOIN `" . $aResult['join']['table'] . "` AS `" . $aResult['join']['table_alias'] . "` ON (" . $aResult['join']['condition'] . ")" . $sJoin,
  104. ];
  105. }
  106. public function getConnectedInitiatorsSQLPartsExt ($sInitiatorTable, $sInitiatorField, $iContent, $isMutual = false)
  107. {
  108. $sWhere = $this->prepareAsString(" AND `c`.`content` = ?", $iContent);
  109. if(false !== $isMutual)
  110. $sWhere .= $this->prepareAsString(" AND `c`.`mutual` = ?", $isMutual);
  111. return array(
  112. 'join' => array(
  113. 'type' => 'INNER',
  114. 'table' => $this->_sTable,
  115. 'table_alias' => 'c',
  116. 'condition' => "`c`.`initiator` = `" . $sInitiatorTable . "`.`" . $sInitiatorField . "`" . $sWhere
  117. )
  118. );
  119. }
  120. public function getConnectedInitiatorsSQLPartsMultiple ($sInitiatorTable, $sInitiatorField, $sContentTable, $sContentField, $isMutual = false)
  121. {
  122. $sOn = "";
  123. if(false !== $isMutual)
  124. $sOn .= $this->prepareAsString(" AND `c`.`mutual` = ?", $isMutual);
  125. return array(
  126. 'join' => "INNER JOIN `{$this->_sTable}` AS `c` ON (`c`.`initiator` = `$sInitiatorTable`.`$sInitiatorField` $sOn)",
  127. 'where' => " AND `c`.`content` = `$sContentTable`.`$sContentField`"
  128. );
  129. }
  130. public function getCommonContent($iInitiator1, $iInitiator2, $isMutual, $iStart, $iLimit, $iOrder)
  131. {
  132. $aBindings = [
  133. 'initiator1' => $iInitiator1,
  134. 'initiator2' => $iInitiator2,
  135. ];
  136. $sWhereJoin = "";
  137. if($isMutual !== false) {
  138. $aBindings['mutual'] = $isMutual;
  139. $sWhereJoin = " AND `c2`.`mutual` = :mutual";
  140. }
  141. $sJoin = "INNER JOIN `" . $this->_sTable . "` AS `c2` ON (`c2`.`initiator` = :initiator2 AND `c`.`content` = `c2`.`content` $sWhereJoin)";
  142. if($this->_aObject['profile_content'])
  143. $sJoin .= "INNER JOIN `sys_profiles` AS `p1` ON (`p1`.`id` = `c`.`content` AND `p1`.`status` = 'active') INNER JOIN `sys_profiles` AS `p2` ON (`p2`.`id` = `c2`.`content` AND `p2`.`status` = 'active')";
  144. $sWhere = " AND `c`.`initiator` = :initiator1";
  145. return $this->getColumn($this->_getConnectionsQuery($sWhere, $sJoin, '`c`.`content`', $isMutual, $iStart, $iLimit, $iOrder), $aBindings);
  146. }
  147. public function getConnectedContent ($iInitiator, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  148. {
  149. $sWhere = " AND `c`.`initiator` = :initiator";
  150. $sJoin = $this->_aObject['profile_content'] ? "INNER JOIN `sys_profiles` `p` ON `p`.`id` = `c`.`content` AND `p`.`status` = 'active'" : '';
  151. $sQuery = $this->_getConnectionsQuery($sWhere, $sJoin, '`c`.`content`', $isMutual, $iStart, $iLimit, $iOrder);
  152. return $this->getColumn($sQuery, array(
  153. 'initiator' => $iInitiator
  154. ));
  155. }
  156. public function getConnectedContentByType ($iInitiator, $mixedType, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  157. {
  158. $mixedType = is_array($mixedType) ? $mixedType : array($mixedType);
  159. $sWhere = " AND `c`.`initiator` = :initiator";
  160. $sJoin = $this->_aObject['profile_content'] ? 'INNER JOIN `sys_profiles` `p` ON `p`.`id` = `c`.`content` AND `p`.`status` = \'active\' AND `p`.`type` IN (' . $this->implode_escape($mixedType) . ')' : '';
  161. $sQuery = $this->_getConnectionsQuery($sWhere, $sJoin, '`c`.`content`', $isMutual, $iStart, $iLimit, $iOrder);
  162. return $this->getColumn($sQuery, array(
  163. 'initiator' => $iInitiator,
  164. ));
  165. }
  166. public function getConnectedContentSince ($iInitiator, $iDate, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  167. {
  168. $sWhere = " AND `c`.`initiator` = :initiator AND `c`.`added` >= :date";
  169. $sJoin = $this->_aObject['profile_content'] ? 'INNER JOIN `sys_profiles` `p` ON `p`.`id` = `c`.`content` AND `p`.`status` = \'active\'' : '';
  170. $sQuery = $this->_getConnectionsQuery($sWhere, $sJoin, '`c`.`content`', $isMutual, $iStart, $iLimit, $iOrder);
  171. return $this->getColumn($sQuery, [
  172. 'initiator' => $iInitiator,
  173. 'date' => $iDate
  174. ]);
  175. }
  176. public function getConnectedInitiators ($iContent, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  177. {
  178. $sWhere = " AND `c`.`content` = :content";
  179. $sJoin = $this->_aObject['profile_initiator'] ? 'INNER JOIN `sys_profiles` `p` ON `p`.`id` = `c`.`initiator` AND `p`.`status` = \'active\'' : '';
  180. $sQuery = $this->_getConnectionsQuery($sWhere, $sJoin, '`c`.`initiator`', $isMutual, $iStart, $iLimit, $iOrder);
  181. return $this->getColumn($sQuery, array(
  182. 'content' => $iContent
  183. ));
  184. }
  185. public function getConnectedInitiatorsByType ($iContent, $mixedType, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  186. {
  187. $mixedType = is_array($mixedType) ? $mixedType : array($mixedType);
  188. $sWhere = " AND `c`.`content` = :content";
  189. $sJoin = $this->_aObject['profile_initiator'] ? 'INNER JOIN `sys_profiles` `p` ON `p`.`id` = `c`.`initiator` AND `p`.`status` = \'active\' AND `p`.`type` IN (' . $this->implode_escape($mixedType) . ')' : '';
  190. $sQuery = $this->_getConnectionsQuery($sWhere, $sJoin, '`c`.`initiator`', $isMutual, $iStart, $iLimit, $iOrder);
  191. return $this->getColumn($sQuery, array(
  192. 'content' => $iContent,
  193. ));
  194. }
  195. public function getConnectedInitiatorsSince ($iContent, $iDate, $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  196. {
  197. $sWhere = " AND `c`.`content` = :content AND `c`.`added` >= :date";
  198. $sJoin = $this->_aObject['profile_initiator'] ? 'INNER JOIN `sys_profiles` `p` ON `p`.`id` = `c`.`initiator` AND `p`.`status` = \'active\'' : '';
  199. $sQuery = $this->_getConnectionsQuery($sWhere, $sJoin, '`c`.`initiator`', $isMutual, $iStart, $iLimit, $iOrder);
  200. return $this->getColumn($sQuery, [
  201. 'content' => $iContent,
  202. 'date' => $iDate
  203. ]);
  204. }
  205. protected function _getConnectionsQuery ($sWhere, $sJoin = '', $sFields = '*', $isMutual = false, $iStart = 0, $iLimit = BX_CONNECTIONS_LIST_LIMIT, $iOrder = BX_CONNECTIONS_ORDER_NONE)
  206. {
  207. $sOrder = $this->_getOrderClause($iOrder, '`c`');
  208. $sWhere .= (false !== $isMutual) ? $this->prepareAsString(" AND `c`.`mutual` = ?", $isMutual) : '';
  209. $sLimit = "";
  210. if($iLimit != BX_CONNECTIONS_LIST_NO_LIMIT)
  211. $sLimit = $this->prepareAsString("LIMIT ?, ?", $iStart, $iLimit);
  212. return "SELECT $sFields FROM `" . $this->_sTable . "` AS `c` $sJoin WHERE 1 $sWhere $sOrder $sLimit";
  213. }
  214. public function getCommonContentCount($iInitiator1, $iInitiator2, $isMutual)
  215. {
  216. $aBindings = [
  217. 'initiator1' => $iInitiator1,
  218. 'initiator2' => $iInitiator2
  219. ];
  220. $sWhereJoin = "";
  221. if($isMutual !== false) {
  222. $aBindings['mutual'] = $isMutual;
  223. $sWhereJoin = " AND `c2`.`mutual` = :mutual";
  224. }
  225. $sJoin = "INNER JOIN `" . $this->_sTable . "` AS `c2` ON (`c2`.`initiator` = :initiator2 AND `c`.`content` = `c2`.`content` $sWhereJoin)";
  226. if($this->_aObject['profile_content'])
  227. $sJoin .= "INNER JOIN `sys_profiles` AS `p1` ON (`p1`.`id` = `c`.`content` AND `p1`.`status` = 'active') INNER JOIN `sys_profiles` AS `p2` ON (`p2`.`id` = `c2`.`content` AND `p2`.`status` = 'active')";
  228. $sWhere = " AND `c`.`initiator` = :initiator1";
  229. return $this->getOne($this->_getConnectionsQueryCount($sWhere, $sJoin, $isMutual, '`c`.`content`'), $aBindings);
  230. }
  231. public function getConnectedContentCount ($iInitiator, $isMutual = false, $iFromDate = 0)
  232. {
  233. return $this->getConnectedContentCountExt($iInitiator, $isMutual, ['from_date' => $iFromDate]);
  234. }
  235. public function getConnectedContentCountExt ($iInitiator, $isMutual = false, $aParams = [])
  236. {
  237. $sJoin = $this->_aObject['profile_content'] ? 'INNER JOIN `sys_profiles` `p` ON `p`.`id` = `c`.`content` AND `p`.`status` = \'active\'' : '';
  238. $sWhere = $this->prepareAsString(" AND `c`.`initiator` = ?", $iInitiator);
  239. if(isset($aParams['from_date']) && ($iFromDate = (int)$aParams['from_date']) > 0)
  240. $sWhere .= $this->prepareAsString(" AND `c`.`added` > ?", $iFromDate);
  241. if(!empty($aParams['by_type']) && is_array($aParams['by_type']) && $this->_aObject['profile_content'])
  242. $sWhere .= " AND `p`.`type` IN (" . $this->implode_escape($aParams['by_type']) . ")";
  243. $sQuery = $this->_getConnectionsQueryCount($sWhere, $sJoin, $isMutual);
  244. return $this->getOne($sQuery);
  245. }
  246. public function getConnectedInitiatorsCount ($iContent, $isMutual = false)
  247. {
  248. $sJoin = $this->_aObject['profile_initiator'] ? 'INNER JOIN `sys_profiles` `p` ON `p`.`id` = `c`.`initiator` AND `p`.`status` = \'active\'' : '';
  249. $sWhere = $this->prepareAsString(" AND `c`.`content` = ?", $iContent);
  250. $sQuery = $this->_getConnectionsQueryCount($sWhere, $sJoin, $isMutual);
  251. return $this->getOne($sQuery);
  252. }
  253. protected function _getConnectionsQueryCount ($sWhere, $sJoin = '', $isMutual = false, $sFields = '`c`.`id`')
  254. {
  255. $sWhere .= (false !== $isMutual) ? $this->prepareAsString(" AND `c`.`mutual` = ?", $isMutual) : '';
  256. return "SELECT COUNT(" . $sFields . ") FROM `" . $this->_sTable . "` AS `c` $sJoin WHERE 1 $sWhere";
  257. }
  258. protected function _getOrderClause ($iOrder = BX_CONNECTIONS_ORDER_NONE, $sTable = '')
  259. {
  260. if ($sTable)
  261. $sTable .= '.';
  262. $sOrder = '';
  263. switch ($iOrder) {
  264. case BX_CONNECTIONS_ORDER_ADDED_ASC:
  265. $sOrder = "ORDER BY {$sTable}`added` ASC";
  266. break;
  267. case BX_CONNECTIONS_ORDER_ADDED_DESC:
  268. $sOrder = "ORDER BY {$sTable}`added` DESC";
  269. break;
  270. }
  271. return $sOrder;
  272. }
  273. public function getConnection ($iInitiator, $iContent)
  274. {
  275. $sQuery = $this->prepare("SELECT * FROM `" . $this->_sTable . "` WHERE `initiator` = ? AND `content` = ?", $iInitiator, $iContent);
  276. return $this->fromMemory('BxDolConnectionQuery::getConnection' . $this->_sTable . $iInitiator . '_' . $iContent, 'getRow', $sQuery);
  277. }
  278. public function getConnectionById ($iId)
  279. {
  280. $sQuery = $this->prepare("SELECT * FROM `" . $this->_sTable . "` WHERE `id` = ?", $iId);
  281. return $this->fromMemory('BxDolConnectionQuery::getConnectionById' . $this->_sTable . $iId, 'getRow', $sQuery);
  282. }
  283. public function addConnection ($iInitiator, $iContent, &$iMutualParam = null)
  284. {
  285. if ($this->getConnection($iInitiator, $iContent)) // connection already exists
  286. return false;
  287. $aBindings = array();
  288. $iMutual = 0;
  289. $sMutualField = '';
  290. if (BX_CONNECTIONS_TYPE_MUTUAL == $this->_sType) {
  291. $aConnectionMutual = $this->getConnection($iContent, $iInitiator);
  292. $iMutual = $aConnectionMutual ? 1 : 0;
  293. $sMutualField = ", `mutual` = :mutual";
  294. $aBindings['mutual'] = $iMutual;
  295. }
  296. $sQuery = $this->prepare("INSERT IGNORE INTO `" . $this->_sTable . "` SET `initiator` = :initiator, `content` = :content, `added` = :added" . $sMutualField);
  297. if (!$this->query($sQuery, array_merge($aBindings, array('initiator' => $iInitiator, 'content' => $iContent, 'added' => time()))))
  298. return false;
  299. if ($iMutual) // in case of mutual connection update 'mutual' field
  300. $this->updateConnectionMutual($iContent, $iInitiator, $iMutual);
  301. if (null !== $iMutualParam)
  302. $iMutualParam = $iMutual;
  303. $this->cleanMemory('BxDolConnectionQuery::getConnection' . $this->_sTable . $iInitiator . '_' . $iContent);
  304. return true;
  305. }
  306. public function updateConnection ($iInitiator, $iContent, $aSet)
  307. {
  308. if(empty($aSet) || !is_array($aSet))
  309. return false;
  310. $sQuery = $this->prepare("UPDATE `" . $this->_sTable . "` SET " . $this->arrayToSQL($aSet) . " WHERE `initiator` = ? AND `content` = ?", $iInitiator, $iContent);
  311. if ($bResult = $this->query($sQuery))
  312. $this->cleanMemory('BxDolConnectionQuery::getConnection' . $this->_sTable . $iInitiator . '_' . $iContent);
  313. return $bResult;
  314. }
  315. public function updateConnectionMutual ($iInitiator, $iContent, $iMutual)
  316. {
  317. $sQuery = $this->prepare("UPDATE `" . $this->_sTable . "` SET `mutual` = ? WHERE `initiator` = ? AND `content` = ?", $iMutual, $iInitiator, $iContent);
  318. if ($bResult = $this->query($sQuery))
  319. $this->cleanMemory('BxDolConnectionQuery::getConnection' . $this->_sTable . $iInitiator . '_' . $iContent);
  320. return $bResult;
  321. }
  322. public function updateConnectionTriggerTableValue($iObjectId, $iValue)
  323. {
  324. return (int)$this->query("UPDATE `{$this->_sTriggerTable}` SET `{$this->_sTriggerFieldCount}` = `{$this->_sTriggerFieldCount}` + :count WHERE `{$this->_sTriggerFieldId}` = :id", [
  325. 'id' => $iObjectId,
  326. 'count' => (int)$iValue
  327. ]) > 0;
  328. }
  329. public function removeConnection ($iInitiator, $iContent)
  330. {
  331. if (!($aConnection = $this->getConnection($iInitiator, $iContent))) // connection doesn't exist
  332. return true;
  333. $sQuery = $this->prepare("DELETE FROM `" . $this->_sTable . "` WHERE `initiator` = ? AND `content` = ?", $iInitiator, $iContent);
  334. if (!$this->res($sQuery))
  335. return false;
  336. $this->cleanMemory('BxDolConnectionQuery::getConnection' . $this->_sTable . $iInitiator . '_' . $iContent);
  337. if (BX_CONNECTIONS_TYPE_MUTUAL == $this->_sType && $aConnection['mutual'])
  338. $this->removeConnection($iContent, $iInitiator);
  339. return true;
  340. }
  341. public function onDelete ($iId, $sField = 'initiator')
  342. {
  343. $sQuery = $this->prepare("DELETE FROM `{$this->_sTable}` WHERE `$sField` = ?", $iId);
  344. return $this->query($sQuery);
  345. }
  346. public function onModuleDelete ($sTable, $sFieldId, $sField = 'initiator')
  347. {
  348. return $this->onModuleDeleteCustom ($sTable, $sFieldId, $sField);
  349. }
  350. public function onModuleProfileDelete ($sModuleName, $sField = 'initiator')
  351. {
  352. return $this->onModuleDeleteCustom ('sys_profiles', 'id', $sField, $this->prepareAsString(" AND `sys_profiles`.`type` = ? ", $sModuleName));
  353. }
  354. protected function onModuleDeleteCustom ($sTable, $sFieldId, $sField = 'initiator', $sWhere = '')
  355. {
  356. $sQuery = $this->prepare("DELETE `" . $this->_sTable . "` FROM `" . $this->_sTable . "` INNER JOIN `{$sTable}` WHERE `" . $this->_sTable . "`.`$sField` = `{$sTable}`.`{$sFieldId}` " . $sWhere);
  357. return $this->query($sQuery);
  358. }
  359. }
  360. /** @} */