BxPersonsSearchResult.php 9.0 KB

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