BxAdsSearchResult.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 Ads Ads
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxAdsSearchResult extends BxBaseModTextSearchResult
  12. {
  13. protected $sModule;
  14. function __construct($sMode = '', $aParams = array())
  15. {
  16. parent::__construct($sMode, $aParams);
  17. $this->sModule = 'bx_ads';
  18. $this->oModule = BxDolModule::getInstance($this->sModule);
  19. $CNF = &$this->oModule->_oConfig->CNF;
  20. $this->aCurrent = array(
  21. 'name' => $this->sModule,
  22. 'module_name' => $this->sModule,
  23. 'object_metatags' => $CNF['OBJECT_METATAGS'],
  24. 'title' => _t('_bx_ads_page_title_browse'),
  25. 'table' => $CNF['TABLE_ENTRIES'],
  26. 'ownFields' => array('id', 'title', 'text', 'thumb', 'author', 'added'),
  27. 'searchFields' => array(),
  28. 'restriction' => array(
  29. 'author' => array('value' => '', 'field' => 'author', 'operator' => '='),
  30. 'featured' => array('value' => '', 'field' => 'featured', 'operator' => '<>'),
  31. 'category' => array('value' => '', 'field' => 'category', 'operator' => '='),
  32. 'status' => array('value' => 'active', 'field' => 'status', 'operator' => '='),
  33. 'statusAdmin' => array('value' => 'active', 'field' => 'status_admin', 'operator' => '='),
  34. ),
  35. 'paginate' => array('perPage' => getParam('bx_ads_per_page_browse'), 'start' => 0),
  36. 'sorting' => 'last',
  37. 'rss' => array(
  38. 'title' => '',
  39. 'link' => '',
  40. 'image' => '',
  41. 'profile' => 0,
  42. 'fields' => array (
  43. 'Guid' => 'link',
  44. 'Link' => 'link',
  45. 'Title' => 'title',
  46. 'DateTimeUTS' => 'added',
  47. 'Desc' => 'text',
  48. 'Image' => 'thumb'
  49. ),
  50. ),
  51. 'ident' => 'id',
  52. );
  53. $this->sFilterName = 'bx_ads_filter';
  54. $sSearchFields = getParam($CNF['PARAM_SEARCHABLE_FIELDS']);
  55. $this->aCurrent['searchFields'] = !empty($sSearchFields) ? explode(',', $sSearchFields) : '';
  56. $oProfileAuthor = null;
  57. switch ($sMode) {
  58. case 'author':
  59. if(!$this->_updateCurrentForAuthor($sMode, $aParams, $oProfileAuthor))
  60. $this->isError = true;
  61. break;
  62. case 'context':
  63. if(!$this->_updateCurrentForContext($sMode, $aParams, $oProfileAuthor))
  64. $this->isError = true;
  65. break;
  66. case 'favorite':
  67. if(!$this->_updateCurrentForFavorite($sMode, $aParams, $oProfileAuthor))
  68. $this->isError = true;
  69. break;
  70. case 'public':
  71. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  72. $this->aCurrent['title'] = _t('_bx_ads_page_title_browse_recent');
  73. $this->aCurrent['rss']['link'] = 'modules/?r=ads/rss/' . $sMode;
  74. break;
  75. case 'featured':
  76. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  77. $this->aCurrent['title'] = _t('_bx_ads_page_title_browse_featured');
  78. $this->aCurrent['restriction']['featured']['value'] = '0';
  79. $this->aCurrent['rss']['link'] = 'modules/?r=ads/rss/' . $sMode;
  80. $this->aCurrent['sorting'] = 'featured';
  81. break;
  82. case 'popular':
  83. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_POPULAR']);
  84. $this->aCurrent['title'] = _t('_bx_ads_page_title_browse_popular');
  85. $this->aCurrent['rss']['link'] = 'modules/?r=ads/rss/' . $sMode;
  86. $this->aCurrent['sorting'] = 'popular';
  87. break;
  88. case 'updated':
  89. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_UPDATED']);
  90. $this->aCurrent['title'] = _t('_bx_ads_page_title_browse_updated');
  91. $this->aCurrent['rss']['link'] = 'modules/?r=ads/rss/' . $sMode;
  92. $this->aCurrent['sorting'] = 'updated';
  93. break;
  94. case 'category':
  95. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_CATEGORIES']);
  96. if(!empty($aParams['category']))
  97. $this->aCurrent['restriction']['category']['value'] = $aParams['category'];
  98. $this->aCurrent['title'] = _t('_bx_ads_page_title_browse_category');
  99. $this->aCurrent['rss']['link'] = 'modules/?r=ads/rss/' . $sMode;
  100. $this->aCurrent['sorting'] = 'last';
  101. break;
  102. case '': // search results
  103. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  104. $this->aCurrent['title'] = _t('_bx_ads');
  105. unset($this->aCurrent['paginate']['perPage'], $this->aCurrent['rss']);
  106. break;
  107. default:
  108. $sMode = '';
  109. $this->isError = true;
  110. }
  111. $this->processReplaceableMarkers($oProfileAuthor);
  112. $this->addConditionsForPrivateContent($CNF, $oProfileAuthor);
  113. $this->addCustomConditions($CNF, $oProfileAuthor, $sMode, $aParams);
  114. }
  115. function getAlterOrder()
  116. {
  117. $CNF = &$this->oModule->_oConfig->CNF;
  118. $aSql = array();
  119. switch ($this->aCurrent['sorting']) {
  120. case 'last':
  121. $aSql['order'] = ' ORDER BY `' . $CNF['TABLE_ENTRIES'] . '`.`added` DESC';
  122. break;
  123. case 'featured':
  124. $aSql['order'] = ' ORDER BY `' . $CNF['TABLE_ENTRIES'] . '`.`featured` DESC';
  125. break;
  126. case 'updated':
  127. $aSql['order'] = ' ORDER BY `' . $CNF['TABLE_ENTRIES'] . '`.`changed` DESC';
  128. break;
  129. case 'popular':
  130. $aSql['order'] = ' ORDER BY `' . $CNF['TABLE_ENTRIES'] . '`.`views` DESC';
  131. break;
  132. }
  133. return $aSql;
  134. }
  135. }
  136. /** @} */