BxBaseModGeneralCmtsSearchResult.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModGeneralCmtsSearchResult extends BxBaseModGeneralSearchResult
  12. {
  13. protected $sModule;
  14. protected $sModuleObjectComments;
  15. protected $aCommentsAddons;
  16. function __construct($sMode = '', $aParams = array())
  17. {
  18. parent::__construct($sMode, $aParams);
  19. $this->oModule = BxDolModule::getInstance($this->sModule);
  20. $this->sModuleObjectComments = $this->oModule->_oConfig->CNF['OBJECT_COMMENTS'];
  21. $this->aCommentsAddons = array();
  22. $this->aCurrent = array(
  23. 'name' => $this->sModule . '_cmts',
  24. 'module_name' => $this->sModule,
  25. 'object_metatags' => 'sys_cmts',
  26. 'title' => '',
  27. 'table' => $this->oModule->_oConfig->getDbPrefix() . 'cmts',
  28. 'ownFields' => array('cmt_id', 'cmt_object_id', 'cmt_author_id', 'cmt_text', 'cmt_time'),
  29. 'searchFields' => array('cmt_text'),
  30. 'restriction' => array(
  31. 'author' => array('value' => '', 'field' => 'cmt_author_id', 'operator' => '='),
  32. ),
  33. 'paginate' => array('start' => 0),
  34. 'sorting' => 'last',
  35. 'ident' => 'cmt_id',
  36. 'added' => 'cmt_time',
  37. );
  38. $this->_joinTableUniqueIds();
  39. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  40. }
  41. function displaySearchUnit($aData)
  42. {
  43. $oCmts = BxDolCmts::getObjectInstance($this->sModuleObjectComments, $aData['object_id']);
  44. $oCmts->addCssJs();
  45. if($this->_bLiveSearch) {
  46. $CNF = &$this->oModule->_oConfig->CNF;
  47. return $oCmts->getCommentLiveSearch($aData['id'], array(
  48. 'txt_sample_single' => isset($CNF['T']['txt_sample_comment_single']) ? $CNF['T']['txt_sample_comment_single'] : ''
  49. ));
  50. }
  51. else {
  52. if(!isset($this->aCommentsAddons[$aData['object_id']]))
  53. $this->aCommentsAddons[$aData['object_id']] = '';
  54. return $oCmts->getCommentSearch(isset($aData['cmt_id']) ? $aData['cmt_id'] : $aData['id'], $this->aCommentsAddons[$aData['object_id']]);
  55. }
  56. }
  57. function displayResultBlock ()
  58. {
  59. $sCode = '<ul class="cmts">' . parent::displayResultBlock() . '</ul>';
  60. if(!empty($this->aCommentsAddons) && is_array($this->aCommentsAddons))
  61. foreach($this->aCommentsAddons as $sCommentsAddon)
  62. $sCode .= $sCommentsAddon;
  63. return $sCode;
  64. }
  65. function getAlterOrder()
  66. {
  67. if($this->aCurrent['sorting'] == 'last')
  68. return array(
  69. 'order' => " ORDER BY `" . $this->aCurrent['table'] . "`.`cmt_time` DESC"
  70. );
  71. return array();
  72. }
  73. function decodeDataAPI ($a, $sMethod = 'getDataAPI')
  74. {
  75. $oContentInfo = $this->getContentInfoObject();
  76. foreach($a as $i => $r)
  77. $a[$i] = $oContentInfo->getContentInfoAPI($r['id']);
  78. return $a;
  79. }
  80. function decodeLsDataAPI ($aItems)
  81. {
  82. if(empty($aItems) || !is_array($aItems))
  83. return $aItems;
  84. $oCmts = BxDolCmts::getObjectInstance($this->sModuleObjectComments, 0, false);
  85. foreach($aItems as $i => $aItem) {
  86. $oCmts->init($aItem['object_id']);
  87. $aItems[$i] = $oCmts->getCommentStructure($aItem['id']);
  88. }
  89. return $aItems;
  90. }
  91. function _getPseud ()
  92. {
  93. return array(
  94. 'id' => 'cmt_id',
  95. 'object_id' => 'cmt_object_id',
  96. 'author' => 'cmt_author_id',
  97. 'text' => 'cmt_text',
  98. 'added' => 'cmt_time'
  99. );
  100. }
  101. protected function _joinTableUniqueIds()
  102. {
  103. $aCommentsSystem = BxDolCmtsQuery::getSystemBy(['type' => 'name', 'name' => $this->sModuleObjectComments]);
  104. if(empty($aCommentsSystem) || !is_array($aCommentsSystem))
  105. return;
  106. $sTableMain = $this->aCurrent['table'];
  107. $sTableUniqueIds = 'sys_cmts_ids';
  108. $sTableUniqueIdsAlias = 'tci';
  109. $this->aCurrent['restriction']['status_admin'] = [
  110. 'value' => 'active',
  111. 'field' => 'status_admin',
  112. 'operator' => '=',
  113. 'table' => $sTableUniqueIdsAlias
  114. ];
  115. $this->aCurrent['join']['unique_ids'] = [
  116. 'type' => 'INNER',
  117. 'table' => $sTableUniqueIds,
  118. 'table_alias' => $sTableUniqueIdsAlias,
  119. 'mainField' => 'cmt_id',
  120. 'on_sql' => "`{$sTableMain}`.`cmt_id`=`{$sTableUniqueIdsAlias}`.`cmt_id` AND `{$sTableUniqueIdsAlias}`.`system_id`='{$aCommentsSystem['ID']}' ",
  121. 'joinFields' => array('status_admin'),
  122. ];
  123. }
  124. }
  125. /** @} */