BxDolConnectionQuery.php 20 KB

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