| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup UnaBaseView UNA Base Representation Classes
- * @{
- */
- class BxBaseProfileSearchResult extends BxTemplSearchResult
- {
- protected $_bIsApi;
- protected $aUnitViews;
- protected $sUnitViewDefault;
- public function __construct($sMode = '', $aParams = [])
- {
- $this->_sMode = $sMode;
- $this->_aParams = $aParams;
- parent::__construct();
- $this->_bIsApi = bx_is_api();
- $this->aUnitViews = [
- 'unit' => 'unit_wo_cover.html',
- 'gallery' => 'unit_with_cover.html'
- ];
- if(!empty($aParams['unit_views']) && is_array($aParams['unit_views']))
- $this->aUnitViews = array_merge($this->aUnitViews, $aParams['unit_views']);
- $this->sUnitViewDefault = 'gallery';
- if(!empty($aParams['unit_view']))
- $this->sUnitViewDefault = $aParams['unit_view'];
- $this->sUnitTemplate = $this->aUnitViews[$this->sUnitViewDefault];
- $this->addContainerClass (array(
- 'bx-base-pofile-units-wrapper',
- 'bx-base-puw-' . str_replace('_' , '-', $this->sUnitViewDefault),
- 'bx-def-margin-sec-neg'
- ));
- $aProfileModules = bx_srv('system', 'get_modules_by_type', ['profile']);
- $aProfileModulesNames = array_map(function($item) {
- return $item['name'];
- }, $aProfileModules);
-
- $this->aCurrent = [
- 'name' => 'sys_search',
- 'module_name' => 'system',
- 'title' => '',
- 'table' => 'sys_profiles',
- 'ownFields' => ['id', 'account_id', 'type', 'content_id'],
- 'searchFields' => [],
- 'restriction' => [
- 'account_id' => ['value' => '', 'field' => 'account_id', 'operator' => '='],
- 'perofileStatus' => ['value' => 'active', 'field' => 'status', 'operator' => '='],
- 'perofileType' => ['value' => $aProfileModulesNames, 'field' => 'type', 'operator' => 'in'],
- ],
- 'join' => [
- 'account' => [
- 'type' => 'INNER',
- 'table' => 'sys_accounts',
- 'mainField' => 'account_id',
- 'onField' => 'id',
- 'joinFields' => [],
- ],
- ],
- 'paginate' => ['start' => 0, 'perPage' => BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT],
- 'sorting' => 'last',
- 'ident' => 'id'
- ];
- if(!empty($this->_aParams['start']))
- $this->aCurrent['paginate']['forceStart'] = (int)$this->_aParams['start'];
- if(!empty($this->_aParams['per_page']))
- $this->aCurrent['paginate']['perPage'] = (int)$this->_aParams['per_page'];
- switch ($sMode) {
- case 'friends':
- $aParams = array_merge($aParams, [
- 'object' => 'sys_profiles_friends',
- 'type' => 'content',
- 'mutual' => true,
- 'profile2' => 0
- ]);
-
- if (!$this->_setConnectionsConditions($aParams))
- break;
- $this->aCurrent = array_merge($this->aCurrent, [
- 'title' => _t('_sys_page_title_browse_connections', BxDolProfile::getInstanceMagic($aParams['profile'])->getDisplayName()),
- 'api_request_url' => '/api.php?r=system/browse_friends/TemplServiceProfiles¶ms[]=' . $aParams['profile'] . '¶ms[]='
- ]);
- break;
- case 'friend_requests':
- $aParams = array_merge($aParams, [
- 'object' => 'sys_profiles_friends',
- 'type' => 'initiators',
- 'mutual' => 0,
- 'profile2' => 0
- ]);
-
- if (!$this->_setConnectionsConditions($aParams))
- break;
- $this->aCurrent = array_merge($this->aCurrent, [
- 'title' => _t('_sys_page_title_browse_connections', BxDolProfile::getInstanceMagic($aParams['profile'])->getDisplayName()),
- 'api_request_url' => '/api.php?r=system/browse_friend_requests/TemplServiceProfiles¶ms[]=' . $aParams['profile'] . '¶ms[]='
- ]);
- break;
-
- case 'friend_requested':
- $aParams = array_merge($aParams, [
- 'object' => 'sys_profiles_friends',
- 'type' => 'content',
- 'mutual' => 0,
- 'profile2' => 0
- ]);
-
- if (!$this->_setConnectionsConditions($aParams))
- break;
- $this->aCurrent = array_merge($this->aCurrent, [
- 'title' => _t('_sys_page_title_browse_connections', BxDolProfile::getInstanceMagic($aParams['profile'])->getDisplayName()),
- 'api_request_url' => '/api.php?r=system/browse_friend_requested/TemplServiceProfiles¶ms[]=' . $aParams['profile'] . '¶ms[]='
- ]);
- break;
-
- case 'subscriptions':
- $aParams = array_merge($aParams, [
- 'object' => 'sys_profiles_subscriptions',
- 'type' => 'content',
- 'mutual' => false,
- 'profile2' => 0
- ]);
- if (!$this->_setConnectionsConditions($aParams))
- break;
- $this->aCurrent = array_merge($this->aCurrent, [
- 'title' => _t('_sys_page_title_browse_connections', BxDolProfile::getInstanceMagic($aParams['profile'])->getDisplayName()),
- 'api_request_url' => '/api.php?r=system/browse_subscriptions/TemplServiceProfiles¶ms[]=' . $aParams['profile'] . '¶ms[]='
- ]);
- break;
-
- case 'subscribed_me':
- $aParams = array_merge($aParams, [
- 'object' => 'sys_profiles_subscriptions',
- 'type' => 'initiators',
- 'mutual' => false,
- 'profile2' => 0
- ]);
- if (!$this->_setConnectionsConditions($aParams))
- break;
- $this->aCurrent = array_merge($this->aCurrent, [
- 'title' => _t('_sys_page_title_browse_connections', BxDolProfile::getInstanceMagic($aParams['profile'])->getDisplayName()),
- 'api_request_url' => '/api.php?r=system/browse_subscribed_me/TemplServiceProfiles¶ms[]=' . $aParams['profile'] . '¶ms[]='
- ]);
- break;
- case 'members':
- $aParams = array_merge($aParams, [
- 'type' => 'content',
- 'mutual' => true,
- 'profile2' => 0
- ]);
- if (!$this->_setConnectionsConditions($aParams))
- break;
- $this->aCurrent = array_merge($this->aCurrent, [
- 'title' => _t('_sys_page_title_browse_connections', BxDolProfile::getInstanceMagic($aParams['profile'])->getDisplayName()),
- 'api_request_url' => '/api.php?r=system/browse_members/TemplServiceProfiles¶ms[]=' . $aParams['profile'] . '¶ms[]=' . $aParams['object'] . '¶ms[]='
- ]);
- break;
- case 'connections':
- if (!$this->_setConnectionsConditions($aParams))
- break;
- $oProfile = BxDolProfile::getInstance($aParams['profile']);
- $oProfile2 = isset($aParams['profile2']) ? BxDolProfile::getInstance($aParams['profile2']) : null;
- $bCommon = isset($aParams['type']) && $aParams['type'] == 'common';
- if($bCommon && $oProfile && $oProfile2)
- $this->aCurrent['title'] = _t('_sys_page_title_browse_connections_mutual', $oProfile->getDisplayName(), $oProfile2->getDisplayName());
- else if(!$bCommon && $oProfile)
- $this->aCurrent['title'] = _t('_sys_page_title_browse_connections', $oProfile->getDisplayName());
- $this->aCurrent['api_request_url'] = '/api.php?r=system/browse_connections/TemplServiceProfiles¶ms[]=' . $aParams['profile'] . '¶ms[]=';
- break;
- }
- }
- function displaySearchUnit ($aData)
- {
- $oProfile = BxDolProfile::getInstance($aData['id']);
- if(!$oProfile)
- return '';
- $aParams = $this->aUnitParams;
- if($this->_bIsApi)
- return $oProfile->getUnitAPI(0, $aParams);
- $aParams['template'] = substr($this->sUnitTemplate, 0, -5);
- return $oProfile->getUnit(0, $aParams);
- }
- function getAlterOrder()
- {
- $sType = is_array($this->aCurrent['sorting']) ? $this->aCurrent['sorting']['type'] : $this->aCurrent['sorting'];
- switch($sType) {
- case 'none':
- return [];
- case 'active':
- return ['order' => ' ORDER BY `sys_accounts`.`logged` DESC '];
- case 'last_connected':
- return ['order' => ' ORDER BY `' . $this->aCurrent['sorting']['table'] . '`.`added` DESC '];
- case 'last':
- default:
- return ['order' => ' ORDER BY `sys_accounts`.`added` DESC '];
- }
- }
- function decodeDataAPI($a)
- {
- $aResult = [];
- foreach ($a as $index => $aItem)
- if(($oProfile = BxDolProfile::getInstance($aItem['id'])) !== false)
- $aResult[] = $oProfile->getUnitAPI();
- return $aResult;
- }
- protected function _setConnectionsConditions ($aParams)
- {
- $oConnection = isset($aParams['object']) ? BxDolConnection::getObjectInstance($aParams['object']) : false;
- if(!$oConnection || empty($aParams['profile']))
- return false;
- $sContentType = isset($aParams['type']) ? $aParams['type'] : BX_CONNECTIONS_CONTENT_TYPE_CONTENT;
- $isMutual = isset($aParams['mutual']) ? $aParams['mutual'] : false;
- $aConnection = $oConnection->getConnectionsAsCondition($sContentType, 'id', (int)$aParams['profile'], (int)$aParams['profile2'], $isMutual);
- $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConnection['restriction']);
- $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aConnection['join']);
- $this->aCurrent['sorting'] = [
- 'type' => 'last_connected',
- 'table' => current($aConnection['join'])['table']
- ];
- return true;
- }
- }
- /** @} */
|