BxShopifySearchResult.php 5.6 KB

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