BxSpacesSearchResult.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. * @defdroup Spaces Spaces
  7. * @indroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxSpacesSearchResult extends BxBaseModGroupsSearchResult
  12. {
  13. function __construct($sMode = '', $aParams = false)
  14. {
  15. parent::__construct($sMode, $aParams);
  16. $this->aCurrent = array(
  17. 'name' => 'bx_spaces',
  18. 'module_name' => 'bx_spaces',
  19. 'object_metatags' => 'bx_spaces',
  20. 'title' => _t('_bx_spaces_page_title_browse'),
  21. 'table' => 'sys_profiles',
  22. 'tableSearch' => 'bx_spaces_data',
  23. 'ownFields' => array(),
  24. 'searchFields' => array(),
  25. 'restriction' => array(
  26. 'account_id' => array('value' => '', 'field' => 'account_id', 'operator' => '='),
  27. 'perofileStatus' => array('value' => 'active', 'field' => 'status', 'operator' => '='),
  28. 'perofileType' => array('value' => 'bx_spaces', 'field' => 'type', 'operator' => '='),
  29. 'owner' => array('value' => '', 'field' => 'author', 'operator' => '=', 'table' => 'bx_spaces_data'),
  30. 'category' => array('value' => '', 'field' => 'space_cat', 'operator' => '=', 'table' => 'bx_spaces_data'),
  31. 'featured' => array('value' => '', 'field' => 'featured', 'operator' => '<>', 'table' => 'bx_spaces_data'),
  32. 'status' => array('value' => 'active', 'field' => 'status', 'operator' => '=', 'table' => 'bx_spaces_data'),
  33. 'statusAdmin' => array('value' => 'active', 'field' => 'status_admin', 'operator' => '=', 'table' => 'bx_spaces_data'),
  34. ),
  35. 'join' => array (
  36. 'profile' => array(
  37. 'type' => 'INNER',
  38. 'table' => 'bx_spaces_data',
  39. 'mainField' => 'content_id',
  40. 'onField' => 'id',
  41. 'joinFields' => array('id', 'space_name', 'picture', 'cover', 'cover_data', 'added', 'author', 'allow_view_to'),
  42. ),
  43. 'account' => array(
  44. 'type' => 'INNER',
  45. 'table' => 'sys_accounts',
  46. 'mainField' => 'account_id',
  47. 'onField' => 'id',
  48. 'joinFields' => array(),
  49. ),
  50. ),
  51. 'paginate' => array('perPage' => getParam('bx_spaces_per_page_browse'), 'start' => 0),
  52. 'sorting' => 'last',
  53. 'rss' => array(
  54. 'title' => '',
  55. 'link' => '',
  56. 'image' => '',
  57. 'profile' => 0,
  58. 'fields' => array (
  59. 'Guid' => 'link',
  60. 'Link' => 'link',
  61. 'Title' => 'space_name',
  62. 'DateTimeUTS' => 'added',
  63. 'Desc' => 'space_name',
  64. 'Image' => 'picture',
  65. ),
  66. ),
  67. 'ident' => 'id'
  68. );
  69. $this->sFilterName = 'bx_spaces_data_filter';
  70. $this->oModule = $this->getMain();
  71. $CNF = &$this->oModule->_oConfig->CNF;
  72. $sSearchFields = getParam($CNF['PARAM_SEARCHABLE_FIELDS']);
  73. $this->aCurrent['searchFields'] = !empty($sSearchFields) ? explode(',', $sSearchFields) : '';
  74. $oJoinedProfile = null;
  75. $bProcessConditionsForPrivateContent = true;
  76. switch ($sMode) {
  77. case 'created_entries':
  78. $this->_setAuthorConditions($sMode, $aParams, $oJoinedProfile);
  79. break;
  80. case 'joined_entries':
  81. $oJoinedProfile = null;
  82. if(!$this->_updateCurrentForJoinedEntries($sMode, $aParams, $oJoinedProfile))
  83. break;
  84. $bProcessConditionsForPrivateContent = false;
  85. if(!$this->aCurrent['title'])
  86. $this->aCurrent['title'] = _t('_bx_spaces_page_title_joined_entries');
  87. break;
  88. case 'connections':
  89. if ($this->_setConnectionsConditions($aParams)) {
  90. $bProcessConditionsForPrivateContent = false;
  91. $oProfile = BxDolProfile::getInstance($aParams['profile']);
  92. $oProfile2 = isset($aParams['profile2']) ? BxDolProfile::getInstance($aParams['profile2']) : null;
  93. if (isset($aParams['type']) && $aParams['type'] == 'common' && $oProfile && $oProfile2)
  94. $this->aCurrent['title'] = _t('_bx_spaces_page_title_browse_connections_mutual', $oProfile->getDisplayName(), $oProfile2->getDisplayName());
  95. elseif ((!isset($aParams['type']) || $aParams['type'] != 'common') && $oProfile)
  96. $this->aCurrent['title'] = _t('_bx_spaces_page_title_browse_connections', $oProfile->getDisplayName());
  97. $this->aCurrent['rss']['link'] = 'modules/?r=spaces/rss/' . $sMode . '/' . $aParams['object'] . '/' . $aParams['type'] . '/' . (int)$aParams['profile'] . '/' . (int)$aParams['profile2'] . '/' . (int)$aParams['mutual'];
  98. }
  99. break;
  100. case 'favorite':
  101. $this->_setFavoriteConditions($sMode, $aParams, $oJoinedProfile);
  102. break;
  103. case 'recent':
  104. $this->aCurrent['rss']['link'] = 'modules/?r=spaces/rss/' . $sMode;
  105. $this->aCurrent['title'] = _t('_bx_spaces_page_title_browse_recent');
  106. $this->aCurrent['sorting'] = 'last';
  107. $this->sBrowseUrl = 'page.php?i=spaces-home';
  108. break;
  109. case 'featured':
  110. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  111. $this->aCurrent['title'] = _t('_bx_spaces_page_title_browse_featured');
  112. $this->aCurrent['restriction']['featured']['value'] = '0';
  113. $this->aCurrent['rss']['link'] = 'modules/?r=spaces/rss/' . $sMode;
  114. $this->aCurrent['sorting'] = 'featured';
  115. break;
  116. case 'recommended':
  117. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  118. $this->aCurrent['title'] = _t('_bx_spaces_page_title_browse_recommended');
  119. $this->aCurrent['restriction']['featured']['value'] = '0';
  120. $this->aCurrent['rss']['link'] = 'modules/?r=spaces/rss/' . $sMode;
  121. $this->aCurrent['sorting'] = 'recommended';
  122. $this->_setConditionsForRecommended();
  123. break;
  124. case 'top':
  125. $this->aCurrent['rss']['link'] = 'modules/?r=spaces/rss/' . $sMode;
  126. $this->aCurrent['title'] = _t('_bx_spaces_page_title_browse_top');
  127. $this->aCurrent['sorting'] = 'top';
  128. $this->sBrowseUrl = 'page.php?i=spaces-top';
  129. break;
  130. case 'top_level':
  131. $this->aCurrent['restriction']['level'] = array('value' => '0', 'field' => 'level', 'operator' => '=', 'table' => 'bx_spaces_data');
  132. break;
  133. case 'category':
  134. $iCategory = (int)$aParams['category'];
  135. $this->addMarkers([
  136. 'category_id' => $iCategory,
  137. 'category_name' => BxDolCategory::getObjectInstance($CNF['OBJECT_CATEGORY'])->getCategoryTitle($iCategory),
  138. ]);
  139. $this->aCurrent['restriction']['category']['value'] = $iCategory;
  140. $this->sBrowseUrl = $CNF['URL_CATEGORY'] . '&category={category_id}';
  141. $this->aCurrent['title'] = _t('_bx_spaces_page_title_browse_category');
  142. $this->aCurrent['rss']['link'] = 'modules/?r=spaces/rss/' . $sMode . '/' . $iCategory;
  143. break;
  144. case 'multi_category':
  145. $sCategory = $aParams['category'];
  146. $this->addMarkers([
  147. 'category' => $sCategory
  148. ]);
  149. $this->setCategoryObject('multi');
  150. $this->setCustomSearchCondition(['keyword' => $sCategory]);
  151. $this->sBrowseUrl = $CNF['URL_MULTI_CATEGORY'] . '&category={category}';
  152. $this->aCurrent['title'] = _t('_bx_spaces_page_title_browse_category');
  153. break;
  154. case '': // search results
  155. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  156. $this->aCurrent['title'] = _t('_bx_spaces');
  157. unset($this->aCurrent['paginate']['perPage'], $this->aCurrent['rss']);
  158. break;
  159. default:
  160. $this->isError = true;
  161. }
  162. if ($bProcessConditionsForPrivateContent) {
  163. $this->addConditionsForPrivateContent($CNF, $oJoinedProfile);
  164. $this->addCustomConditions($CNF, $oJoinedProfile, $sMode, $aParams);
  165. }
  166. $this->sCenterContentUnitSelector = false;
  167. }
  168. function getAlterOrder()
  169. {
  170. switch ($this->aCurrent['sorting']) {
  171. case 'featured':
  172. return array('order' => ' ORDER BY `bx_spaces_data`.`featured` DESC ');
  173. case 'recommended':
  174. return array('order' => ' ORDER BY RAND() ');
  175. case 'none':
  176. return array();
  177. case 'top':
  178. return array('order' => ' ORDER BY `bx_spaces_data`.`views` DESC ');
  179. case 'last':
  180. default:
  181. return array('order' => ' ORDER BY `bx_spaces_data`.`added` DESC ');
  182. }
  183. }
  184. function _getPseud ()
  185. {
  186. return array(
  187. 'id' => 'id',
  188. 'space_name' => 'space_name',
  189. 'added' => 'added',
  190. 'author' => 'author',
  191. 'picture' => 'picture',
  192. );
  193. }
  194. }
  195. /** @} */