BxTimelineSearchResult.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 Timeline Timeline
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. require_once('BxTimelineModule.php');
  12. class BxTimelineSearchResult extends BxBaseModNotificationsSearchResult
  13. {
  14. function __construct($sMode = '', $aParams = array())
  15. {
  16. parent::__construct($sMode, $aParams);
  17. $this->aCurrent = array(
  18. 'name' => 'bx_timeline',
  19. 'module_name' => 'bx_timeline',
  20. 'object_metatags' => 'bx_timeline',
  21. 'title' => _t('_bx_timeline_page_title_browse'),
  22. 'table' => 'bx_timeline_events',
  23. 'ownFields' => array('id', 'owner_id', 'type', 'action', 'object_id', 'object_privacy_view', 'content', 'title', 'description', 'views', 'rate', 'votes', 'rrate', 'rvotes', 'score', 'sc_up', 'sc_down', 'comments', 'reports', 'reposts', 'date', 'status', 'status_admin', 'pinned', 'sticked', 'promoted'),
  24. 'searchFields' => array(),
  25. 'restriction' => array(
  26. 'internal' => array('value' => 'timeline_common_post', 'field' => 'type', 'operator' => '='),
  27. 'status' => array('value' => BX_TIMELINE_STATUS_ACTIVE, 'field' => 'status', 'operator' => '='),
  28. 'status_admin' => array('value' => BX_TIMELINE_STATUS_ACTIVE, 'field' => 'status_admin', 'operator' => '='),
  29. 'active' => array('value' => '1', 'field' => 'active', 'operator' => '='),
  30. ),
  31. 'paginate' => array('perPage' => getParam('bx_timeline_events_per_page'), 'start' => 0),
  32. 'sorting' => 'last',
  33. 'ident' => 'id',
  34. 'added' => 'date'
  35. );
  36. $this->sFilterName = 'bx_timeline_filter';
  37. $this->oModule = $this->getMain();
  38. $CNF = &$this->oModule->_oConfig->CNF;
  39. $sSearchFields = getParam($CNF['PARAM_SEARCHABLE_FIELDS']);
  40. $this->aCurrent['searchFields'] = !empty($sSearchFields) ? explode(',', $sSearchFields) : '';
  41. switch ($sMode) {
  42. case '': // search results
  43. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  44. $this->aCurrent['title'] = _t('_bx_timeline');
  45. unset($this->aCurrent['paginate']['perPage'], $this->aCurrent['rss']);
  46. break;
  47. default:
  48. $sMode = '';
  49. $this->isError = true;
  50. }
  51. $this->setProcessPrivateContent(false);
  52. }
  53. function displayResultBlock ()
  54. {
  55. $sResult = parent::displayResultBlock();
  56. if(empty($sResult))
  57. return $sResult;
  58. return $this->oModule->_oTemplate->getSearchBlock($sResult);
  59. }
  60. function getAlterOrder()
  61. {
  62. $aSql = array();
  63. switch ($this->aCurrent['sorting']) {
  64. case 'last':
  65. $aSql['order'] = ' ORDER BY `bx_timeline_events`.`date` DESC';
  66. break;
  67. }
  68. return $aSql;
  69. }
  70. function decodeLsDataAPI ($aItems)
  71. {
  72. if(empty($aItems) || !is_array($aItems))
  73. return $aItems;
  74. $oMenuActions = false;
  75. if(!($oMenuActions = BxDolMenu::getObjectInstance($this->oModule->_oConfig->getObject('menu_item_actions_all'))))
  76. $oMenuActions = BxDolMenu::getObjectInstance($this->oModule->_oConfig->getObject('menu_item_actions'));
  77. $oMenuManage = BxDolMenu::getObjectInstance($this->oModule->_oConfig->getObject('menu_item_manage'));
  78. $aResults = [];
  79. foreach($aItems as $aItem) {
  80. $sItem = $this->oModule->_oTemplate->getPost($aItem);
  81. if(empty($sItem))
  82. continue;
  83. $aItem = array_merge($aItem, [
  84. 'menu_actions' => $oMenuActions,
  85. 'menu_manage' => $oMenuManage
  86. ]);
  87. $aResults[] = $this->oModule->_oTemplate->getPostApi($aItem);
  88. }
  89. return $aResults;
  90. }
  91. }
  92. /** @} */