1
0

BxBaseModGeneralCmtsSearchResult.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  38. }
  39. function getMain()
  40. {
  41. return BxDolModule::getInstance($this->sModule);
  42. }
  43. function displaySearchUnit($aData)
  44. {
  45. $oCmts = BxDolCmts::getObjectInstance($this->sModuleObjectComments, $aData['object_id']);
  46. $oCmts->addCssJs();
  47. if($this->_bLiveSearch) {
  48. $CNF = &$this->oModule->_oConfig->CNF;
  49. return $oCmts->getCommentLiveSearch($aData['id'], array(
  50. 'txt_sample_single' => isset($CNF['T']['txt_sample_comment_single']) ? $CNF['T']['txt_sample_comment_single'] : ''
  51. ));
  52. }
  53. else {
  54. if(!isset($this->aCommentsAddons[$aData['object_id']]))
  55. $this->aCommentsAddons[$aData['object_id']] = '';
  56. return $oCmts->getCommentSearch(isset($aData['cmt_id']) ? $aData['cmt_id'] : $aData['id'], $this->aCommentsAddons[$aData['object_id']]);
  57. }
  58. }
  59. function displayResultBlock ()
  60. {
  61. $sCode = '<ul class="cmts">' . parent::displayResultBlock() . '</ul>';
  62. if(!empty($this->aCommentsAddons) && is_array($this->aCommentsAddons))
  63. foreach($this->aCommentsAddons as $sCommentsAddon)
  64. $sCode .= $sCommentsAddon;
  65. return $sCode;
  66. }
  67. function getAlterOrder()
  68. {
  69. if($this->aCurrent['sorting'] == 'last')
  70. return array(
  71. 'order' => " ORDER BY `" . $this->aCurrent['table'] . "`.`cmt_time` DESC"
  72. );
  73. return array();
  74. }
  75. function _getPseud ()
  76. {
  77. return array(
  78. 'id' => 'cmt_id',
  79. 'object_id' => 'cmt_object_id',
  80. 'author' => 'cmt_author_id',
  81. 'text' => 'cmt_text',
  82. 'added' => 'cmt_time'
  83. );
  84. }
  85. }
  86. /** @} */