BxDolCmtsQuery.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  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. * @see BxDolCmts
  11. */
  12. class BxDolCmtsQuery extends BxDolDb
  13. {
  14. protected $_oMain;
  15. protected $_sTable;
  16. protected $_sTriggerTable;
  17. protected $_sTriggerFieldId;
  18. protected $_sTriggerFieldAuthor;
  19. protected $_sTriggerFieldTitle;
  20. protected $_sTriggerFieldComments;
  21. protected $_sTableFiles;
  22. protected $_sTableFiles2Entries;
  23. protected $_sTableIds;
  24. public function __construct(&$oMain)
  25. {
  26. $this->_sTableIds = BxDolCmts::$sTableIds;
  27. $this->_oMain = $oMain;
  28. $this->_sTableFiles = $this->_oMain->getTableNameImages();
  29. $this->_sTableFiles2Entries = $this->_oMain->getTableNameImages2Entries();
  30. $aSystem = $this->_oMain->getSystemInfo();
  31. $this->_sTable = $aSystem['table'];
  32. $this->_sTriggerTable = $aSystem['trigger_table'];
  33. $this->_sTriggerFieldId = $aSystem['trigger_field_id'];
  34. $this->_sTriggerFieldAuthor = $aSystem['trigger_field_author'];
  35. $this->_sTriggerFieldTitle = $aSystem['trigger_field_title'];
  36. $this->_sTriggerFieldComments = $aSystem['trigger_field_comments'];
  37. parent::__construct();
  38. }
  39. function getTableName ()
  40. {
  41. return $this->_sTable;
  42. }
  43. /**
  44. * @deprecated since version 10.0.0-B3 and can be removed in later versions.
  45. */
  46. function setTableNameFiles($sTable)
  47. {
  48. $this->_sTableFiles = $sTable;
  49. }
  50. /**
  51. * @deprecated since version 10.0.0-B3 and can be removed in later versions.
  52. */
  53. function setTableNameFiles2Entries($sTable)
  54. {
  55. $this->_sTableFiles2Entries = $sTable;
  56. }
  57. function getCommentsCountAll ($iId)
  58. {
  59. $sQuery = $this->prepare("SELECT `{$this->_sTriggerFieldComments}` FROM `{$this->_sTriggerTable}` WHERE `{$this->_sTriggerFieldId}` = ?", $iId);
  60. return (int)$this->getOne($sQuery);
  61. }
  62. function getCommentsCount ($iId, $iCmtVParentId = -1, $iAuthorId = 0, $sFilter = '')
  63. {
  64. $aBindings = array(
  65. 'cmt_object_id' => $iId
  66. );
  67. $sWhereClause = '';
  68. if((int)$iCmtVParentId >= 0) {
  69. $aBindings['cmt_vparent_id'] = $iCmtVParentId;
  70. $sWhereClause .= " AND `{$this->_sTable}`.`cmt_vparent_id` = :cmt_vparent_id";
  71. }
  72. $sJoinClause = '';
  73. switch($sFilter) {
  74. case BX_CMT_FILTER_FRIENDS:
  75. case BX_CMT_FILTER_SUBSCRIPTIONS:
  76. $oConnection = BxDolConnection::getObjectInstance($this->_oMain->getConnectionObject($sFilter));
  77. $aQueryParts = $oConnection->getConnectedContentAsSQLParts($this->_sTable, 'cmt_author_id', $iAuthorId);
  78. $sJoinClause .= ' ' . $aQueryParts['join'];
  79. break;
  80. case BX_CMT_FILTER_OTHERS:
  81. $aBindings['cmt_author_id'] = $iAuthorId;
  82. $sWhereClause .= " AND `{$this->_sTable}`.`cmt_author_id` <> :cmt_author_id";
  83. break;
  84. }
  85. $sQuery = "SELECT COUNT(*) FROM `{$this->_sTable}` $sJoinClause WHERE `{$this->_sTable}`.`cmt_object_id` = :cmt_object_id" . $sWhereClause;
  86. return (int)$this->getOne($sQuery, $aBindings);
  87. }
  88. function getComments ($iId, $iCmtVParentId = 0, $iAuthorId = 0, $sFilter = '', $aOrder = array(), $iStart = 0, $iCount = -1)
  89. {
  90. $aBindings = array(
  91. 'cmt_object_id' => $iId,
  92. 'system_id' => $this->_oMain->getSystemId()
  93. );
  94. $sFields = $sJoin = "";
  95. $sWhereParent = '';
  96. if((int)$iCmtVParentId >= 0) {
  97. $aBindings['cmt_vparent_id'] = $iCmtVParentId;
  98. $sWhereParent = " AND `{$this->_sTable}`.`cmt_vparent_id` = :cmt_vparent_id";
  99. }
  100. if(in_array($sFilter, array(BX_CMT_FILTER_FRIENDS, BX_CMT_FILTER_SUBSCRIPTIONS))) {
  101. $oConnection = BxDolConnection::getObjectInstance($this->_oMain->getConnectionObject($sFilter));
  102. $aQueryParts = $oConnection->getConnectedContentAsSQLParts($this->_sTable, 'cmt_author_id', $iAuthorId);
  103. $sJoin .= ' ' . $aQueryParts['join'];
  104. }
  105. $sOrder = " ORDER BY `{$this->_sTable}`.`cmt_time` ASC";
  106. if(isset($aOrder['by']) && isset($aOrder['way'])) {
  107. $aOrder['way'] = strtoupper(in_array($aOrder['way'], array(BX_CMT_ORDER_WAY_ASC, BX_CMT_ORDER_WAY_DESC)) ? $aOrder['way'] : BX_CMT_ORDER_WAY_ASC);
  108. switch($aOrder['by']) {
  109. case BX_CMT_ORDER_BY_DATE:
  110. $sOrder = " ORDER BY `{$this->_sTable}`.`cmt_time` " . $aOrder['way'];
  111. break;
  112. case BX_CMT_ORDER_BY_POPULAR:
  113. $oVote = $this->_oMain->getVoteObject(0);
  114. $oScore = $this->_oMain->getScoreObject(0);
  115. $aSortFields = array();
  116. if($oVote !== false) {
  117. array_push($aSortFields, '`' . $this->_sTableIds . '`.`votes`');
  118. }
  119. if($oScore !== false) {
  120. array_push($aSortFields, '`' . $this->_sTableIds . '`.`score`');
  121. }
  122. if (count($aSortFields) == 0)
  123. array_push($aSortFields, '`' . $this->_sTable . '`.`id`');
  124. $sOrder = " ORDER BY " . implode($aOrder['way'] . ', ', $aSortFields) . " " . $aOrder['way'];
  125. break;
  126. }
  127. }
  128. $sLimit = $iCount != -1 ? $this->prepareAsString(" LIMIT ?, ?", (int)$iStart, (int)$iCount) : '';
  129. $sQuery = "SELECT
  130. `{$this->_sTable}`.`cmt_id`,
  131. `{$this->_sTableIds}`.`id` AS `cmt_unique_id`,
  132. `{$this->_sTable}`.`cmt_parent_id`,
  133. `{$this->_sTable}`.`cmt_vparent_id`,
  134. `{$this->_sTable}`.`cmt_object_id`,
  135. `{$this->_sTable}`.`cmt_author_id`,
  136. `{$this->_sTable}`.`cmt_level`,
  137. `{$this->_sTable}`.`cmt_text`,
  138. `{$this->_sTable}`.`cmt_replies`,
  139. `{$this->_sTable}`.`cmt_time`
  140. $sFields
  141. FROM `{$this->_sTable}`
  142. LEFT JOIN `{$this->_sTableIds}` ON (`{$this->_sTable}`.`cmt_id` = `{$this->_sTableIds}`.`cmt_id` AND `{$this->_sTableIds}`.`system_id` = :system_id)
  143. $sJoin
  144. WHERE `{$this->_sTable}`.`cmt_object_id` = :cmt_object_id" . $sWhereParent . $sOrder . $sLimit;
  145. return $this->getAll($sQuery, $aBindings);
  146. }
  147. function getCommentsBy($aParams = array())
  148. {
  149. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query', 1 => array()));
  150. $sSelectClause = $sJoinClause = $sWhereClause = $sOrderClause = $sLimitClause = "";
  151. $sSelectClause = "
  152. `{$this->_sTable}`.`cmt_id`,
  153. `{$this->_sTable}`.`cmt_parent_id`,
  154. `{$this->_sTable}`.`cmt_vparent_id`,
  155. `{$this->_sTable}`.`cmt_object_id`,
  156. `{$this->_sTable}`.`cmt_author_id`,
  157. `{$this->_sTable}`.`cmt_level`,
  158. `{$this->_sTable}`.`cmt_text`,
  159. `{$this->_sTable}`.`cmt_replies`,
  160. `{$this->_sTable}`.`cmt_time`";
  161. if(isset($aParams['object_id'])) {
  162. $aMethod['params'][1]['cmt_object_id'] = (int)$aParams['object_id'];
  163. $sWhereClause .= " AND `{$this->_sTable}`.`cmt_object_id` = :cmt_object_id";
  164. }
  165. switch($aParams['type']) {
  166. case 'id':
  167. $aMethod['name'] = 'getRow';
  168. $aMethod['params'][1]['id'] = (int)$aParams['id'];
  169. $sWhereClause .= " AND `{$this->_sTable}`.`cmt_id` = :id";
  170. break;
  171. case 'latest':
  172. if(!empty($aParams['author'])) {
  173. $aMethod['params'][1]['cmt_author_id'] = (int)$aParams['author'];
  174. $sWhereClause .= " AND `{$this->_sTable}`.`cmt_author_id` " . (isset($aParams['others']) && (int)$aParams['others'] == 1 ? "<>" : "=") . " :cmt_author_id";
  175. }
  176. $sOrderClause = "`{$this->_sTable}`.`cmt_time` DESC";
  177. $sLimitClause = "";
  178. if(isset($aParams['per_page']))
  179. $sLimitClause = $this->prepareAsString("?, ?", $aParams['start'], $aParams['per_page']);
  180. break;
  181. case 'object_id':
  182. $aMethod['params'][1]['cmt_object_id'] = (int)$aParams['object_id'];
  183. $sWhereClause .= " AND `{$this->_sTable}`.`cmt_object_id` = :cmt_object_id";
  184. $sOrderClause = "`{$this->_sTable}`.`cmt_time` ASC";
  185. $sLimitClause = "";
  186. if(isset($aParams['per_page']))
  187. $sLimitClause = $this->prepareAsString("?, ?", $aParams['start'], $aParams['per_page']);
  188. break;
  189. case 'search_ids':
  190. $aMethod['name'] = 'getColumn';
  191. $sSelectClause = "`{$this->_sTable}`.`cmt_id`";
  192. if (!empty($aParams['start']) && !empty($aParams['per_page']))
  193. $sLimitClause = $this->prepareAsString("?, ?", $aParams['start'], $aParams['per_page']);
  194. elseif (!empty($aParams['per_page']))
  195. $sLimitClause = $this->prepareAsString("?", $aParams['per_page']);
  196. $sWhereConditions = "1";
  197. foreach($aParams['search_params'] as $sSearchParam => $aSearchParam) {
  198. $sSearchValue = "";
  199. switch ($aSearchParam['operator']) {
  200. case 'like':
  201. $sSearchValue = " LIKE " . $this->escape("%" . $aSearchParam['value'] . "%");
  202. break;
  203. case 'in':
  204. $sSearchValue = " IN (" . $this->implode_escape($aSearchParam['value']) . ")";
  205. break;
  206. case 'and':
  207. $iResult = 0;
  208. if (is_array($aSearchParam['value']))
  209. foreach ($aSearchParam['value'] as $iValue)
  210. $iResult |= pow (2, $iValue - 1);
  211. else
  212. $iResult = (int)$aSearchParam['value'];
  213. $sSearchValue = " & " . $iResult . "";
  214. break;
  215. default:
  216. $sSearchValue = " " . $aSearchParam['operator'] . " :" . $sSearchParam;
  217. $aMethod['params'][1][$sSearchParam] = $aSearchParam['value'];
  218. }
  219. $sWhereConditions .= " AND `{$this->_sTable}`.`" . $sSearchParam . "`" . $sSearchValue;
  220. }
  221. $sWhereClause .= " AND (" . $sWhereConditions . ")";
  222. $sOrderClause .= "`{$this->_sTable}`.`cmt_time` ASC";
  223. break;
  224. case 'all_ids':
  225. $aMethod['name'] = 'getColumn';
  226. $sSelectClause = "`{$this->_sTable}`.`cmt_id`";
  227. $sOrderClause = "`{$this->_sTable}`.`cmt_time` ASC";
  228. break;
  229. }
  230. if(!empty($sOrderClause))
  231. $sOrderClause = 'ORDER BY ' . $sOrderClause;
  232. if(!empty($sLimitClause))
  233. $sLimitClause = 'LIMIT ' . $sLimitClause;
  234. $aMethod['params'][0] = "SELECT " . $sSelectClause . " FROM `{$this->_sTable}` " . $sJoinClause . " WHERE 1 " . $sWhereClause . " " . $sOrderClause . " " . $sLimitClause;
  235. return call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  236. }
  237. function getComment ($iId, $iCmtId)
  238. {
  239. $sFields = $sJoin = "";
  240. $oVote = $this->_oMain->getVoteObject($iCmtId);
  241. if($oVote !== false) {
  242. $aSql = $oVote->getSqlParts($this->_sTableIds, 'id');
  243. $sFields .= $aSql['fields'];
  244. $sJoin .= $aSql['join'];
  245. }
  246. $sQuery = $this->prepare("SELECT
  247. `{$this->_sTable}`.`cmt_id`,
  248. `{$this->_sTableIds}`.`id` AS `cmt_unique_id`,
  249. `{$this->_sTable}`.`cmt_parent_id`,
  250. `{$this->_sTable}`.`cmt_vparent_id`,
  251. `{$this->_sTable}`.`cmt_object_id`,
  252. `{$this->_sTable}`.`cmt_author_id`,
  253. `{$this->_sTable}`.`cmt_level`,
  254. `{$this->_sTable}`.`cmt_text`,
  255. `{$this->_sTable}`.`cmt_replies`,
  256. `{$this->_sTable}`.`cmt_time`
  257. $sFields
  258. FROM `{$this->_sTable}`
  259. LEFT JOIN `{$this->_sTableIds}` ON (`{$this->_sTable}`.`cmt_id` = `{$this->_sTableIds}`.`cmt_id` AND `{$this->_sTableIds}`.`system_id` = ?)
  260. $sJoin
  261. WHERE `{$this->_sTable}`.`cmt_object_id` = ? AND `{$this->_sTable}`.`cmt_id` = ?
  262. LIMIT 1", $this->_oMain->getSystemId(), $iId, $iCmtId);
  263. return $this->getRow($sQuery);
  264. }
  265. function getCommentSimple ($iId, $iCmtId)
  266. {
  267. $sQuery = $this->prepare("SELECT * FROM {$this->_sTable} AS `c` WHERE `cmt_object_id` = ? AND `cmt_id` = ? LIMIT 1", $iId, $iCmtId);
  268. return $this->getRow($sQuery);
  269. }
  270. function removeComment ($iId, $iCmtId, $iCmtParentId)
  271. {
  272. $sQuery = $this->prepare("DELETE FROM {$this->_sTable} WHERE `cmt_object_id` = ? AND `cmt_id` = ? LIMIT 1", $iId, $iCmtId);
  273. if (!$this->query($sQuery))
  274. return false;
  275. if($iCmtParentId)
  276. $this->updateRepliesCount($iCmtParentId, -1);
  277. return true;
  278. }
  279. function saveImages($iSystemId, $iCmtId, $iImageId)
  280. {
  281. $sQuery = $this->prepare("INSERT IGNORE INTO `{$this->_sTableFiles2Entries}` SET `system_id`=?, `cmt_id`=?, `image_id`=?", $iSystemId, $iCmtId, $iImageId);
  282. return (int)$this->query($sQuery) > 0;
  283. }
  284. function getFiles($iSystemId, $iCmtId, $iId = false)
  285. {
  286. $aBindings = array(
  287. 'system_id' => $iSystemId
  288. );
  289. $sJoin = "";
  290. $sWhere = " AND `tf2e`.`system_id` = :system_id ";
  291. if($iCmtId !== false) {
  292. $aBindings['cmt_id'] = $iCmtId;
  293. $sWhere .= " AND `tf2e`.`cmt_id` = :cmt_id ";
  294. }
  295. if($iId !== false) {
  296. $aBindings['cmt_object_id'] = $iId;
  297. $sWhere .= " AND `te`.`cmt_object_id` = :cmt_object_id";
  298. $sJoin .= " INNER JOIN `{$this->_sTable}` AS `te` ON (`tf2e`.`cmt_id` = `te`.`cmt_id`) ";
  299. }
  300. $sQuery = "SELECT
  301. `tf2e`.*,
  302. `tf`.`file_name` AS `file_name`,
  303. `tf`.`mime_type` AS `mime_type`,
  304. `tf`.`size` AS `size`
  305. FROM `{$this->_sTableFiles2Entries}` AS `tf2e`
  306. LEFT JOIN `{$this->_sTableFiles}` AS `tf` ON (`tf2e`.`image_id` = `tf`.`id`) " . $sJoin . "
  307. WHERE 1 " . $sWhere;
  308. return $this->getAll($sQuery, $aBindings);
  309. }
  310. function deleteImages($iSystemId, $iCmtId)
  311. {
  312. $aBindings = array(
  313. 'system_id' => $iSystemId
  314. );
  315. $sWhereAddon = "";
  316. if ($iCmtId !== false) {
  317. $aBindings['cmt_id'] = $iCmtId;
  318. $sWhereAddon = " AND `cmt_id` = :cmt_id ";
  319. }
  320. return $this->query("DELETE FROM `{$this->_sTableFiles2Entries}` WHERE `system_id` = :system_id" . $sWhereAddon, $aBindings);
  321. }
  322. function updateRepliesCount($iCmtId, $iCount)
  323. {
  324. $sQuery = $this->prepare("UPDATE `{$this->_sTable}` SET `cmt_replies`=`cmt_replies`+? WHERE `cmt_id`=? LIMIT 1", $iCount, $iCmtId);
  325. return $this->query($sQuery);
  326. }
  327. function deleteAuthorComments ($iAuthorId, &$aFiles = null, &$aCmtIds = null)
  328. {
  329. $aSystem = $this->_oMain->getSystemInfo();
  330. $isDelOccured = 0;
  331. $sQuery = $this->prepare("SELECT `cmt_id`, `cmt_parent_id` FROM {$this->_sTable} WHERE `cmt_author_id` = ? AND `cmt_replies` = 0", $iAuthorId);
  332. $a = $this->getAll ($sQuery);
  333. foreach ($a as $r) {
  334. $sQuery = $this->prepare("DELETE FROM {$this->_sTable} WHERE `cmt_id` = ?", $r['cmt_id']);
  335. $this->query ($sQuery);
  336. $sQuery = $this->prepare("UPDATE {$this->_sTable} SET `cmt_replies` = `cmt_replies` - 1 WHERE `cmt_id` = ?", $r['cmt_parent_id']);
  337. $this->query ($sQuery);
  338. $aFilesMore = $this->convertImagesArray($this->getFiles($aSystem['system_id'], $r['cmt_id']));
  339. $this->deleteImages($aSystem['system_id'], $r['cmt_id']);
  340. if ($aFilesMore && null !== $aFiles)
  341. $aFiles = array_merge($aFiles, $aFilesMore);
  342. if (null !== $aCmtIds)
  343. $aCmtIds[] = $r['cmt_id'];
  344. $isDelOccured = 1;
  345. }
  346. $sQuery = $this->prepare("UPDATE {$this->_sTable} SET `cmt_author_id` = 0 WHERE `cmt_author_id` = ? AND `cmt_replies` != 0", $iAuthorId);
  347. $this->query ($sQuery);
  348. if ($isDelOccured)
  349. $this->query ("OPTIMIZE TABLE {$this->_sTable}");
  350. }
  351. function deleteObjectComments ($iObjectId, &$aFilesReturn = null, &$aCmtIds = null)
  352. {
  353. $aSystem = $this->_oMain->getSystemInfo();
  354. $aFiles = $this->convertImagesArray($this->getFiles($aSystem['system_id'], false, $iObjectId));
  355. if ($aFiles) {
  356. $sQuery = $this->prepare("DELETE FROM {$this->_sTableFiles2Entries} WHERE `system_id` = ? AND `image_id` IN(" . $this->implode_escape($aFiles) . ")", $aSystem['system_id']);
  357. $this->query($sQuery);
  358. }
  359. if (null !== $aCmtIds) {
  360. $sQuery = $this->prepare("SELECT `cmt_id` FROM {$this->_sTable} WHERE `cmt_object_id` = ?", $iObjectId);
  361. $aCmtIds = $this->getColumn ($sQuery);
  362. }
  363. $sQuery = $this->prepare("DELETE FROM {$this->_sTable} WHERE `cmt_object_id` = ?", $iObjectId);
  364. $this->query ($sQuery);
  365. $this->query ("OPTIMIZE TABLE {$this->_sTable}");
  366. if (null !== $aFilesReturn)
  367. $aFilesReturn = $aFiles;
  368. }
  369. function deleteAll ($iSystemId, &$aFiles = null, &$aCmtIds = null)
  370. {
  371. // get files
  372. if (null !== $aFiles)
  373. $aFiles = $this->convertImagesArray($this->getFiles($iSystemId, false));
  374. // delete files
  375. $this->deleteImages($iSystemId, false);
  376. if (null !== $aCmtIds)
  377. $aCmtIds = $this->getColumn ("SELECT `cmt_id` FROM {$this->_sTable}");
  378. // delete comments
  379. $sQuery = $this->prepare("TRUNCATE TABLE {$this->_sTable}");
  380. $this->query ($sQuery);
  381. }
  382. function deleteCmtIds ($iSystemId, $iCmtId)
  383. {
  384. $sQuery = $this->prepare("DELETE FROM {$this->_sTableIds} WHERE `system_id` = ? AND `cmt_id` = ?", $iSystemId, $iCmtId);
  385. return $this->query ($sQuery);
  386. }
  387. function getObjectAuthorId($iId)
  388. {
  389. $sQuery = $this->prepare("SELECT `{$this->_sTriggerFieldAuthor}` FROM `{$this->_sTriggerTable}` WHERE `{$this->_sTriggerFieldId}` = ? LIMIT 1", $iId);
  390. return $this->getOne($sQuery);
  391. }
  392. function getObjectTitle($iId)
  393. {
  394. $sQuery = $this->prepare("SELECT `{$this->_sTriggerFieldTitle}` FROM `{$this->_sTriggerTable}` WHERE `{$this->_sTriggerFieldId}` = ? LIMIT 1", $iId);
  395. return $this->getOne($sQuery);
  396. }
  397. function updateTriggerTable($iId, $iCount)
  398. {
  399. $sQuery = $this->prepare("UPDATE `{$this->_sTriggerTable}` SET `{$this->_sTriggerFieldComments}` = ? WHERE `{$this->_sTriggerFieldId}` = ? LIMIT 1", $iCount, $iId);
  400. return $this->query($sQuery);
  401. }
  402. function getUniqId($iSystemId, $iCmtId, $iAuthorId = 0)
  403. {
  404. $sQuery = $this->prepare("SELECT `id` FROM `{$this->_sTableIds}` WHERE `system_id` = ? AND `cmt_id` = ?", $iSystemId, $iCmtId);
  405. if($iUniqId = $this->getOne($sQuery))
  406. return $iUniqId;
  407. if(empty($iAuthorId))
  408. $iAuthorId = bx_get_logged_profile_id();
  409. $sQuery = $this->prepare("INSERT INTO `{$this->_sTableIds}` SET `system_id` = ?, `cmt_id` = ?, `author_id` = ?", $iSystemId, $iCmtId, $iAuthorId);
  410. if(!$this->query($sQuery))
  411. return false;
  412. return $this->lastId();
  413. }
  414. protected function convertImagesArray($a)
  415. {
  416. if (!$a || !is_array($a))
  417. return array();
  418. $aFiles = array ();
  419. foreach ($a as $aFile)
  420. $aFiles[] = $aFile['image_id'];
  421. return $aFiles;
  422. }
  423. }
  424. /** @} */