BxFilesSearchResult.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 Files Files
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxFilesSearchResult extends BxBaseModTextSearchResult
  12. {
  13. function __construct($sMode = '', $aParams = array())
  14. {
  15. parent::__construct($sMode, $aParams);
  16. $this->aCurrent = array(
  17. 'name' => 'bx_files',
  18. 'module_name' => 'bx_files',
  19. 'object_metatags' => 'bx_files',
  20. 'title' => _t('_bx_files_page_title_browse'),
  21. 'table' => 'bx_files_main',
  22. 'ownFields' => array('id', 'file_id', 'title', 'desc', 'author', 'added'),
  23. 'searchFields' => array(),
  24. 'restriction' => array(
  25. 'author' => array('value' => '', 'field' => 'author', 'operator' => '='),
  26. 'status' => array('value' => 'active', 'field' => 'status', 'operator' => '='),
  27. ),
  28. 'paginate' => array('perPage' => getParam('bx_files_per_page_browse'), 'start' => 0),
  29. 'sorting' => 'last',
  30. 'rss' => array(
  31. 'title' => '',
  32. 'link' => '',
  33. 'image' => '',
  34. 'profile' => 0,
  35. 'fields' => array (
  36. 'Guid' => 'link',
  37. 'Link' => 'link',
  38. 'Title' => 'title',
  39. 'DateTimeUTS' => 'added',
  40. 'Desc' => 'desc',
  41. ),
  42. ),
  43. 'ident' => 'id',
  44. );
  45. $this->sFilterName = 'bx_files_filter';
  46. $this->oModule = $this->getMain();
  47. $this->aCurrent['searchFields'] = explode(',', getParam($this->oModule->_oConfig->CNF['PARAM_SEARCHABLE_FIELDS']));
  48. $oProfileAuthor = null;
  49. $CNF = &$this->oModule->_oConfig->CNF;
  50. switch ($sMode) {
  51. case 'group_author':
  52. case 'author':
  53. if(!$this->_updateCurrentForAuthor($sMode, $aParams, $oProfileAuthor)) {
  54. $this->isError = true;
  55. break;
  56. }
  57. break;
  58. case 'favorite':
  59. if(!$this->_updateCurrentForFavorite($sMode, $aParams, $oProfileAuthor)) {
  60. $this->isError = true;
  61. break;
  62. }
  63. break;
  64. case 'public':
  65. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  66. $this->aCurrent['title'] = _t('_bx_files_page_title_browse_recent');
  67. $this->aCurrent['rss']['link'] = 'modules/?r=files/rss/' . $sMode;
  68. break;
  69. case 'popular':
  70. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_POPULAR']);
  71. $this->aCurrent['title'] = _t('_bx_files_page_title_browse_popular');
  72. $this->aCurrent['rss']['link'] = 'modules/?r=files/rss/' . $sMode;
  73. $this->aCurrent['sorting'] = 'popular';
  74. break;
  75. case 'updated':
  76. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_UPDATED']);
  77. $this->aCurrent['title'] = _t('_bx_files_page_title_browse_updated');
  78. $this->aCurrent['rss']['link'] = 'modules/?r=files/rss/' . $sMode;
  79. $this->aCurrent['sorting'] = 'updated';
  80. break;
  81. case '': // search results
  82. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  83. $this->aCurrent['title'] = _t('_bx_files');
  84. $this->aCurrent['paginate']['perPage'] = 3;
  85. unset($this->aCurrent['rss']);
  86. break;
  87. default:
  88. $sMode = '';
  89. $this->isError = true;
  90. }
  91. $this->processReplaceableMarkers($oProfileAuthor);
  92. if ('group_author' != $sMode)
  93. $this->addConditionsForPrivateContent($CNF, $oProfileAuthor);
  94. }
  95. function getAlterOrder()
  96. {
  97. $aSql = array();
  98. switch ($this->aCurrent['sorting']) {
  99. case 'last':
  100. $aSql['order'] = ' ORDER BY `bx_files_main`.`added` DESC';
  101. break;
  102. case 'updated':
  103. $aSql['order'] = ' ORDER BY `bx_files_main`.`changed` DESC';
  104. break;
  105. case 'popular':
  106. $aSql['order'] = ' ORDER BY `bx_files_main`.`views` DESC';
  107. break;
  108. }
  109. return $aSql;
  110. }
  111. }
  112. /** @} */