BxBaseProfileSearchResult.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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],
  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 'subscriptions':
  80. $aParams = array_merge($aParams, [
  81. 'object' => 'sys_profiles_subscriptions',
  82. 'type' => 'content',
  83. 'mutual' => false,
  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_subscriptions/TemplServiceProfiles&params[]=' . $aParams['profile'] . '&params[]='
  91. ]);
  92. break;
  93. case 'subscribed_me':
  94. $aParams = array_merge($aParams, [
  95. 'object' => 'sys_profiles_subscriptions',
  96. 'type' => 'initiators',
  97. 'mutual' => false,
  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_subscribed_me/TemplServiceProfiles&params[]=' . $aParams['profile'] . '&params[]='
  105. ]);
  106. break;
  107. case 'members':
  108. $aParams = array_merge($aParams, [
  109. 'type' => 'content',
  110. 'mutual' => true,
  111. 'profile2' => 0
  112. ]);
  113. if (!$this->_setConnectionsConditions($aParams))
  114. break;
  115. $this->aCurrent = array_merge($this->aCurrent, [
  116. 'title' => _t('_sys_page_title_browse_connections', BxDolProfile::getInstanceMagic($aParams['profile'])->getDisplayName()),
  117. 'api_request_url' => '/api.php?r=system/browse_members/TemplServiceProfiles&params[]=' . $aParams['profile'] . '&params[]=' . $aParams['object'] . '&params[]='
  118. ]);
  119. break;
  120. case 'connections':
  121. if (!$this->_setConnectionsConditions($aParams))
  122. break;
  123. $oProfile = BxDolProfile::getInstance($aParams['profile']);
  124. $oProfile2 = isset($aParams['profile2']) ? BxDolProfile::getInstance($aParams['profile2']) : null;
  125. $bCommon = isset($aParams['type']) && $aParams['type'] == 'common';
  126. if($bCommon && $oProfile && $oProfile2)
  127. $this->aCurrent['title'] = _t('_sys_page_title_browse_connections_mutual', $oProfile->getDisplayName(), $oProfile2->getDisplayName());
  128. else if(!$bCommon && $oProfile)
  129. $this->aCurrent['title'] = _t('_sys_page_title_browse_connections', $oProfile->getDisplayName());
  130. $this->aCurrent['api_request_url'] = '/api.php?r=system/browse_connections/TemplServiceProfiles&params[]=' . $aParams['profile'] . '&params[]=';
  131. break;
  132. }
  133. }
  134. function displaySearchUnit ($aData)
  135. {
  136. $oProfile = BxDolProfile::getInstance($aData['id']);
  137. if(!$oProfile)
  138. return '';
  139. $aParams = $this->aUnitParams;
  140. if($this->_bIsApi)
  141. return $oProfile->getUnitAPI(0, $aParams);
  142. $aParams['template'] = substr($this->sUnitTemplate, 0, -5);
  143. return $oProfile->getUnit(0, $aParams);
  144. }
  145. function getAlterOrder()
  146. {
  147. $sType = is_array($this->aCurrent['sorting']) ? $this->aCurrent['sorting']['type'] : $this->aCurrent['sorting'];
  148. switch($sType) {
  149. case 'none':
  150. return [];
  151. case 'active':
  152. return ['order' => ' ORDER BY `sys_accounts`.`logged` DESC '];
  153. case 'last_connected':
  154. return ['order' => ' ORDER BY `' . $this->aCurrent['sorting']['table'] . '`.`added` DESC '];
  155. case 'last':
  156. default:
  157. return ['order' => ' ORDER BY `sys_accounts`.`added` DESC '];
  158. }
  159. }
  160. function decodeData ($a)
  161. {
  162. $aResult = [];
  163. foreach ($a as $index => $aItem)
  164. if(($oProfile = BxDolProfile::getInstance($aItem['id'])) !== false)
  165. $aResult[] = $oProfile->getUnitAPI();
  166. return $aResult;
  167. }
  168. protected function _setConnectionsConditions ($aParams)
  169. {
  170. $oConnection = isset($aParams['object']) ? BxDolConnection::getObjectInstance($aParams['object']) : false;
  171. if(!$oConnection || empty($aParams['profile']))
  172. return false;
  173. $sContentType = isset($aParams['type']) ? $aParams['type'] : BX_CONNECTIONS_CONTENT_TYPE_CONTENT;
  174. $isMutual = isset($aParams['mutual']) ? $aParams['mutual'] : false;
  175. $aConnection = $oConnection->getConnectionsAsCondition($sContentType, 'id', (int)$aParams['profile'], (int)$aParams['profile2'], $isMutual);
  176. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConnection['restriction']);
  177. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aConnection['join']);
  178. $this->aCurrent['sorting'] = [
  179. 'type' => 'last_connected',
  180. 'table' => current($aConnection['join'])['table']
  181. ];
  182. return true;
  183. }
  184. }
  185. /** @} */