BxWorkspacesSearchResult.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 Workspaces Workspaces
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxWorkspacesSearchResult extends BxBaseModProfileSearchResult
  12. {
  13. function __construct($sMode = '', $aParams = false)
  14. {
  15. parent::__construct($sMode, $aParams);
  16. $this->aCurrent = array(
  17. 'name' => 'bx_workspaces',
  18. 'module_name' => 'bx_workspaces',
  19. 'object_metatags' => 'bx_workspaces',
  20. 'title' => _t('_bx_workspaces_page_title_browse'),
  21. 'table' => 'sys_profiles',
  22. 'tableSearch' => 'bx_workspaces_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_workspaces', 'field' => 'type', 'operator' => '='),
  29. 'owner' => array('value' => '', 'field' => 'author', 'operator' => '=', 'table' => 'bx_workspaces_data'),
  30. 'featured' => array('value' => '', 'field' => 'featured', 'operator' => '<>', 'table' => 'bx_workspaces_data'),
  31. 'online' => array('value' => '', 'field' => 'date', 'operator' => '>', 'table' => 'sys_sessions'),
  32. ),
  33. 'join' => array (
  34. 'profile' => array(
  35. 'type' => 'INNER',
  36. 'table' => 'bx_workspaces_data',
  37. 'mainField' => 'content_id',
  38. 'onField' => 'id',
  39. 'joinFields' => array('id', 'added', 'author', 'allow_view_to'),
  40. ),
  41. 'account' => array(
  42. 'type' => 'INNER',
  43. 'table' => 'sys_accounts',
  44. 'mainField' => 'account_id',
  45. 'onField' => 'id',
  46. 'joinFields' => array(),
  47. ),
  48. ),
  49. 'paginate' => array('perPage' => getParam('bx_workspaces_per_page_browse'), 'start' => 0),
  50. 'sorting' => 'active',
  51. 'rss' => array(
  52. 'title' => '',
  53. 'link' => '',
  54. 'image' => '',
  55. 'profile' => 0,
  56. 'fields' => array (
  57. 'Guid' => 'link',
  58. 'Link' => 'link',
  59. 'DateTimeUTS' => 'added',
  60. ),
  61. ),
  62. 'ident' => 'id'
  63. );
  64. $this->sFilterName = 'bx_workspaces_filter';
  65. $this->oModule = $this->getMain();
  66. $CNF = &$this->oModule->_oConfig->CNF;
  67. $sSearchFields = getParam($CNF['PARAM_SEARCHABLE_FIELDS']);
  68. $this->aCurrent['searchFields'] = !empty($sSearchFields) ? explode(',', $sSearchFields) : '';
  69. $this->_setAccountConfirmationConditions($aParams);
  70. switch ($sMode) {
  71. case 'connections':
  72. if ($this->_setConnectionsConditions($aParams)) {
  73. $oProfile = BxDolProfile::getInstance($aParams['profile']);
  74. $oProfile2 = isset($aParams['profile2']) ? BxDolProfile::getInstance($aParams['profile2']) : null;
  75. if (isset($aParams['type']) && $aParams['type'] == 'common' && $oProfile && $oProfile2)
  76. $this->aCurrent['title'] = _t('_bx_workspaces_page_title_browse_connections_mutual', $oProfile->getDisplayName(), $oProfile2->getDisplayName());
  77. elseif ((!isset($aParams['type']) || $aParams['type'] != 'common') && $oProfile)
  78. $this->aCurrent['title'] = _t('_bx_workspaces_page_title_browse_connections', $oProfile->getDisplayName());
  79. $this->aCurrent['rss']['link'] = 'modules/?r=workspaces/rss/' . $sMode . '/' . $aParams['object'] . '/' . $aParams['type'] . '/' . (int)$aParams['profile'] . '/' . (int)$aParams['profile2'] . '/' . (int)$aParams['mutual'];
  80. }
  81. break;
  82. case 'familiar':
  83. if($this->_setFamiliarConnectionsConditions($aParams)) {
  84. $this->aCurrent['title'] = _t('_bx_workspaces_page_title_browse_familiar');
  85. unset($this->aCurrent['rss']);
  86. }
  87. break;
  88. case 'acl':
  89. if ($this->_setAclConditions($aParams)) {
  90. $this->aCurrent['title'] = _t('_bx_workspaces_page_title_browse_by_acl', implode(', ', $this->aCurrent['title']));
  91. unset($this->aCurrent['rss']);
  92. }
  93. break;
  94. case 'favorite':
  95. $oProfileAuthor = null;
  96. if(!$this->_setFavoriteConditions($sMode, $aParams, $oProfileAuthor)) {
  97. $this->isError = true;
  98. break;
  99. }
  100. break;
  101. case 'recent':
  102. $this->aCurrent['rss']['link'] = 'modules/?r=workspaces/rss/' . $sMode;
  103. $this->aCurrent['title'] = _t('_bx_workspaces_page_title_browse_recent');
  104. $this->aCurrent['sorting'] = 'last';
  105. $this->sBrowseUrl = 'page.php?i=workspaces-home';
  106. break;
  107. case 'featured':
  108. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  109. $this->aCurrent['title'] = _t('_bx_workspaces_page_title_browse_featured');
  110. $this->aCurrent['restriction']['featured']['value'] = '0';
  111. $this->aCurrent['rss']['link'] = 'modules/?r=workspaces/rss/' . $sMode;
  112. $this->aCurrent['sorting'] = 'featured';
  113. break;
  114. case 'recommended':
  115. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  116. $this->aCurrent['title'] = _t('_bx_groups_page_title_browse_recommended');
  117. $this->aCurrent['restriction']['featured']['value'] = '0';
  118. $this->aCurrent['rss']['link'] = 'modules/?r=groups/rss/' . $sMode;
  119. $this->aCurrent['sorting'] = 'recommended';
  120. $this->_setConditionsForRecommended();
  121. break;
  122. case 'active':
  123. $this->aCurrent['rss']['link'] = 'modules/?r=workspaces/rss/' . $sMode;
  124. $this->aCurrent['title'] = _t('_bx_workspaces_page_title_browse_active');
  125. $this->aCurrent['sorting'] = 'active';
  126. $this->sBrowseUrl = 'page.php?i=workspaces-active';
  127. break;
  128. case 'online':
  129. $this->aCurrent['rss']['link'] = 'modules/?r=workspaces/rss/' . $sMode;
  130. $this->aCurrent['title'] = _t('_bx_workspaces_page_title_browse_online');
  131. $this->aCurrent['restriction']['online']['value'] = time() - 60 * (int)getParam('sys_account_online_time');
  132. $this->aCurrent['restriction_sql'] = ' AND `sys_accounts`.`profile_id`=`sys_profiles`.`id`';
  133. $this->aCurrent['join']['session'] = array(
  134. 'type' => 'INNER',
  135. 'table' => 'sys_sessions',
  136. 'mainField' => 'account_id',
  137. 'onField' => 'user_id',
  138. 'joinFields' => array('date'),
  139. 'groupTable' => $this->aCurrent['table'],
  140. 'groupField' => 'id'
  141. );
  142. $this->aCurrent['sorting'] = 'online';
  143. $this->sBrowseUrl = 'page.php?i=workspaces-online';
  144. break;
  145. case '': // search results
  146. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  147. $this->aCurrent['title'] = _t('_bx_workspaces');
  148. unset($this->aCurrent['paginate']['perPage'], $this->aCurrent['rss']);
  149. break;
  150. default:
  151. $this->isError = true;
  152. }
  153. $this->sCenterContentUnitSelector = false;
  154. }
  155. function getAlterOrder()
  156. {
  157. switch ($this->aCurrent['sorting']) {
  158. case 'featured':
  159. return array('order' => ' ORDER BY `bx_workspaces_data`.`featured` DESC ');
  160. case 'recommended':
  161. return array('order' => ' ORDER BY RAND() ');
  162. case 'none':
  163. return array();
  164. case 'active':
  165. return array('order' => ' ORDER BY `sys_accounts`.`logged` DESC ');
  166. case 'online':
  167. return array('order' => ' ORDER BY `sys_sessions`.`date` DESC ');
  168. case 'last':
  169. default:
  170. return array('order' => ' ORDER BY `bx_workspaces_data`.`added` DESC ');
  171. }
  172. }
  173. function _getPseud ()
  174. {
  175. return array(
  176. 'id' => 'id',
  177. 'fullname' => 'fullname',
  178. 'added' => 'added',
  179. 'author' => 'author',
  180. 'picture' => 'picture',
  181. );
  182. }
  183. }
  184. /** @} */