BxBaseModGeneralCmtsSearchResult.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 = $this->getMain();
  20. $this->sModuleObjectComments = $this->oModule->_oConfig->CNF['OBJECT_COMMENTS'];
  21. $this->aCommentsAddons = array();
  22. $this->aCurrent = array(
  23. 'name' => $this->oModule->_oConfig->getName() . '_cmts',
  24. 'module_name' => $this->oModule->_oConfig->getName(),
  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. );
  37. $this->_joinTableUniqueIds();
  38. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  39. }
  40. function getMain()
  41. {
  42. return BxDolModule::getInstance($this->sModule);
  43. }
  44. function displaySearchUnit($aData)
  45. {
  46. $oCmts = BxDolCmts::getObjectInstance($this->sModuleObjectComments, $aData['object_id']);
  47. $oCmts->addCssJs();
  48. if($this->_bLiveSearch) {
  49. $CNF = &$this->oModule->_oConfig->CNF;
  50. return $oCmts->getCommentLiveSearch($aData['id'], array(
  51. 'txt_sample_single' => isset($CNF['T']['txt_sample_comment_single']) ? $CNF['T']['txt_sample_comment_single'] : ''
  52. ));
  53. }
  54. else {
  55. if(!isset($this->aCommentsAddons[$aData['object_id']]))
  56. $this->aCommentsAddons[$aData['object_id']] = '';
  57. return $oCmts->getCommentSearch(isset($aData['cmt_id']) ? $aData['cmt_id'] : $aData['id'], $this->aCommentsAddons[$aData['object_id']]);
  58. }
  59. }
  60. function displayResultBlock ()
  61. {
  62. $sCode = '<ul class="cmts">' . parent::displayResultBlock() . '</ul>';
  63. if(!empty($this->aCommentsAddons) && is_array($this->aCommentsAddons))
  64. foreach($this->aCommentsAddons as $sCommentsAddon)
  65. $sCode .= $sCommentsAddon;
  66. return $sCode;
  67. }
  68. function getAlterOrder()
  69. {
  70. if($this->aCurrent['sorting'] == 'last')
  71. return array(
  72. 'order' => " ORDER BY `" . $this->aCurrent['table'] . "`.`cmt_time` DESC"
  73. );
  74. return array();
  75. }
  76. function decodeDataAPI ($a)
  77. {
  78. $oContentInfo = $this->getContentInfoObject();
  79. foreach($a as $i => $r) {
  80. if(isset($r['author']))
  81. $a[$i]['author_data'] = BxDolProfile::getData($r['author']);
  82. $a[$i]['url'] = bx_api_get_relative_url($oContentInfo->getContentLink($r['id']));
  83. }
  84. return $a;
  85. }
  86. function _getPseud ()
  87. {
  88. return array(
  89. 'id' => 'cmt_id',
  90. 'object_id' => 'cmt_object_id',
  91. 'author' => 'cmt_author_id',
  92. 'text' => 'cmt_text',
  93. 'added' => 'cmt_time'
  94. );
  95. }
  96. protected function _joinTableUniqueIds()
  97. {
  98. $aCommentsSystem = BxDolCmtsQuery::getSystemBy(['type' => 'name', 'name' => $this->sModuleObjectComments]);
  99. if(empty($aCommentsSystem) || !is_array($aCommentsSystem))
  100. return;
  101. $sTableMain = $this->aCurrent['table'];
  102. $sTableUniqueIds = 'sys_cmts_ids';
  103. $sTableUniqueIdsAlias = 'tci';
  104. $this->aCurrent['restriction']['status_admin'] = [
  105. 'value' => 'active',
  106. 'field' => 'status_admin',
  107. 'operator' => '=',
  108. 'table' => $sTableUniqueIdsAlias
  109. ];
  110. $this->aCurrent['join']['unique_ids'] = [
  111. 'type' => 'INNER',
  112. 'table' => $sTableUniqueIds,
  113. 'table_alias' => $sTableUniqueIdsAlias,
  114. 'mainField' => 'cmt_id',
  115. 'on_sql' => "`{$sTableMain}`.`cmt_id`=`{$sTableUniqueIdsAlias}`.`cmt_id` AND `{$sTableUniqueIdsAlias}`.`system_id`='{$aCommentsSystem['ID']}' ",
  116. 'joinFields' => array('status_admin'),
  117. ];
  118. }
  119. }
  120. /** @} */