BxBaseProfileSearchResult.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. class BxBaseProfileSearchResult extends BxTemplSearchResult
  10. {
  11. protected $_bIsApi;
  12. protected $aUnitViews;
  13. protected $sUnitViewDefault;
  14. public function __construct($sMode = '', $aParams = [])
  15. {
  16. $this->_sMode = $sMode;
  17. $this->_aParams = $aParams;
  18. parent::__construct();
  19. $this->_bIsApi = bx_is_api();
  20. $this->aUnitViews = [
  21. 'unit' => 'unit_wo_cover.html',
  22. 'gallery' => 'unit_with_cover.html'
  23. ];
  24. if(!empty($aParams['unit_views']) && is_array($aParams['unit_views']))
  25. $this->aUnitViews = array_merge($this->aUnitViews, $aParams['unit_views']);
  26. $this->sUnitViewDefault = 'gallery';
  27. if(!empty($aParams['unit_view']))
  28. $this->sUnitViewDefault = $aParams['unit_view'];
  29. $this->sUnitTemplate = $this->aUnitViews[$this->sUnitViewDefault];
  30. $this->addContainerClass (array(
  31. 'bx-base-pofile-units-wrapper',
  32. 'bx-base-puw-' . str_replace('_' , '-', $this->sUnitViewDefault),
  33. 'bx-def-margin-sec-neg'
  34. ));
  35. $this->aCurrent = [
  36. 'name' => 'sys_search',
  37. 'module_name' => 'system',
  38. 'title' => '',
  39. 'table' => 'sys_profiles',
  40. 'ownFields' => ['id', 'account_id', 'type', 'content_id'],
  41. 'searchFields' => [],
  42. 'restriction' => [
  43. 'account_id' => ['value' => '', 'field' => 'account_id', 'operator' => '='],
  44. 'perofileStatus' => ['value' => 'active', 'field' => 'status', 'operator' => '='],
  45. 'perofileType' => ['value' => '', 'field' => 'type', 'operator' => '='],
  46. ],
  47. 'join' => [
  48. 'account' => [
  49. 'type' => 'INNER',
  50. 'table' => 'sys_accounts',
  51. 'mainField' => 'account_id',
  52. 'onField' => 'id',
  53. 'joinFields' => [],
  54. ],
  55. ],
  56. 'paginate' => ['start' => 0, 'perPage' => BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT],
  57. 'sorting' => 'last',
  58. 'ident' => 'id'
  59. ];
  60. if(!empty($this->_aParams['start']))
  61. $this->aCurrent['paginate']['forceStart'] = (int)$this->_aParams['start'];
  62. if(!empty($this->_aParams['per_page']))
  63. $this->aCurrent['paginate']['perPage'] = (int)$this->_aParams['per_page'];
  64. switch ($sMode) {
  65. case 'friends':
  66. $aParams = array_merge($aParams, [
  67. 'object' => 'sys_profiles_friends',
  68. 'type' => 'content',
  69. 'mutual' => true,
  70. 'profile2' => 0
  71. ]);
  72. if (!$this->_setConnectionsConditions($aParams))
  73. break;
  74. $this->aCurrent = array_merge($this->aCurrent, [
  75. 'title' => _t('_sys_page_title_browse_connections', BxDolProfile::getInstanceMagic($aParams['profile'])->getDisplayName()),
  76. 'api_request_url' => '/api.php?r=system/browse_friends/TemplServiceProfiles&params[]=' . $aParams['profile'] . '&params[]='
  77. ]);
  78. break;
  79. case 'friend_requests':
  80. $aParams = array_merge($aParams, [
  81. 'object' => 'sys_profiles_friends',
  82. 'type' => 'initiators',
  83. 'mutual' => 0,
  84. 'profile2' => 0
  85. ]);
  86. if (!$this->_setConnectionsConditions($aParams))
  87. break;
  88. $this->aCurrent = array_merge($this->aCurrent, [
  89. 'title' => _t('_sys_page_title_browse_connections', BxDolProfile::getInstanceMagic($aParams['profile'])->getDisplayName()),
  90. 'api_request_url' => '/api.php?r=system/browse_friend_requests/TemplServiceProfiles&params[]=' . $aParams['profile'] . '&params[]='
  91. ]);
  92. break;
  93. case 'friend_requested':
  94. $aParams = array_merge($aParams, [
  95. 'object' => 'sys_profiles_friends',
  96. 'type' => 'content',
  97. 'mutual' => 0,
  98. 'profile2' => 0
  99. ]);
  100. if (!$this->_setConnectionsConditions($aParams))
  101. break;
  102. $this->aCurrent = array_merge($this->aCurrent, [
  103. 'title' => _t('_sys_page_title_browse_connections', BxDolProfile::getInstanceMagic($aParams['profile'])->getDisplayName()),
  104. 'api_request_url' => '/api.php?r=system/browse_friend_requested/TemplServiceProfiles&params[]=' . $aParams['profile'] . '&params[]='
  105. ]);
  106. break;
  107. case 'subscriptions':
  108. $aParams = array_merge($aParams, [
  109. 'object' => 'sys_profiles_subscriptions',
  110. 'type' => 'content',
  111. 'mutual' => false,
  112. 'profile2' => 0
  113. ]);
  114. if (!$this->_setConnectionsConditions($aParams))
  115. break;
  116. $this->aCurrent = array_merge($this->aCurrent, [
  117. 'title' => _t('_sys_page_title_browse_connections', BxDolProfile::getInstanceMagic($aParams['profile'])->getDisplayName()),
  118. 'api_request_url' => '/api.php?r=system/browse_subscriptions/TemplServiceProfiles&params[]=' . $aParams['profile'] . '&params[]='
  119. ]);
  120. break;
  121. case 'subscribed_me':
  122. $aParams = array_merge($aParams, [
  123. 'object' => 'sys_profiles_subscriptions',
  124. 'type' => 'initiators',
  125. 'mutual' => false,
  126. 'profile2' => 0
  127. ]);
  128. if (!$this->_setConnectionsConditions($aParams))
  129. break;
  130. $this->aCurrent = array_merge($this->aCurrent, [
  131. 'title' => _t('_sys_page_title_browse_connections', BxDolProfile::getInstanceMagic($aParams['profile'])->getDisplayName()),
  132. 'api_request_url' => '/api.php?r=system/browse_subscribed_me/TemplServiceProfiles&params[]=' . $aParams['profile'] . '&params[]='
  133. ]);
  134. break;
  135. case 'members':
  136. $aParams = array_merge($aParams, [
  137. 'type' => 'content',
  138. 'mutual' => true,
  139. 'profile2' => 0
  140. ]);
  141. if (!$this->_setConnectionsConditions($aParams))
  142. break;
  143. $this->aCurrent = array_merge($this->aCurrent, [
  144. 'title' => _t('_sys_page_title_browse_connections', BxDolProfile::getInstanceMagic($aParams['profile'])->getDisplayName()),
  145. 'api_request_url' => '/api.php?r=system/browse_members/TemplServiceProfiles&params[]=' . $aParams['profile'] . '&params[]=' . $aParams['object'] . '&params[]='
  146. ]);
  147. break;
  148. case 'connections':
  149. if (!$this->_setConnectionsConditions($aParams))
  150. break;
  151. $oProfile = BxDolProfile::getInstance($aParams['profile']);
  152. $oProfile2 = isset($aParams['profile2']) ? BxDolProfile::getInstance($aParams['profile2']) : null;
  153. $bCommon = isset($aParams['type']) && $aParams['type'] == 'common';
  154. if($bCommon && $oProfile && $oProfile2)
  155. $this->aCurrent['title'] = _t('_sys_page_title_browse_connections_mutual', $oProfile->getDisplayName(), $oProfile2->getDisplayName());
  156. else if(!$bCommon && $oProfile)
  157. $this->aCurrent['title'] = _t('_sys_page_title_browse_connections', $oProfile->getDisplayName());
  158. $this->aCurrent['api_request_url'] = '/api.php?r=system/browse_connections/TemplServiceProfiles&params[]=' . $aParams['profile'] . '&params[]=';
  159. break;
  160. }
  161. }
  162. function displaySearchUnit ($aData)
  163. {
  164. $oProfile = BxDolProfile::getInstance($aData['id']);
  165. if(!$oProfile)
  166. return '';
  167. $aParams = $this->aUnitParams;
  168. if($this->_bIsApi)
  169. return $oProfile->getUnitAPI(0, $aParams);
  170. $aParams['template'] = substr($this->sUnitTemplate, 0, -5);
  171. return $oProfile->getUnit(0, $aParams);
  172. }
  173. function getAlterOrder()
  174. {
  175. $sType = is_array($this->aCurrent['sorting']) ? $this->aCurrent['sorting']['type'] : $this->aCurrent['sorting'];
  176. switch($sType) {
  177. case 'none':
  178. return [];
  179. case 'active':
  180. return ['order' => ' ORDER BY `sys_accounts`.`logged` DESC '];
  181. case 'last_connected':
  182. return ['order' => ' ORDER BY `' . $this->aCurrent['sorting']['table'] . '`.`added` DESC '];
  183. case 'last':
  184. default:
  185. return ['order' => ' ORDER BY `sys_accounts`.`added` DESC '];
  186. }
  187. }
  188. function decodeData ($a)
  189. {
  190. $aResult = [];
  191. foreach ($a as $index => $aItem)
  192. if(($oProfile = BxDolProfile::getInstance($aItem['id'])) !== false)
  193. $aResult[] = $oProfile->getUnitAPI();
  194. return $aResult;
  195. }
  196. protected function _setConnectionsConditions ($aParams)
  197. {
  198. $oConnection = isset($aParams['object']) ? BxDolConnection::getObjectInstance($aParams['object']) : false;
  199. if(!$oConnection || empty($aParams['profile']))
  200. return false;
  201. $sContentType = isset($aParams['type']) ? $aParams['type'] : BX_CONNECTIONS_CONTENT_TYPE_CONTENT;
  202. $isMutual = isset($aParams['mutual']) ? $aParams['mutual'] : false;
  203. $aConnection = $oConnection->getConnectionsAsCondition($sContentType, 'id', (int)$aParams['profile'], (int)$aParams['profile2'], $isMutual);
  204. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConnection['restriction']);
  205. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aConnection['join']);
  206. $this->aCurrent['sorting'] = [
  207. 'type' => 'last_connected',
  208. 'table' => current($aConnection['join'])['table']
  209. ];
  210. return true;
  211. }
  212. }
  213. /** @} */