BxBaseProfileSearchResult.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. parent::__construct();
  17. $this->_bIsApi = bx_is_api();
  18. $this->aUnitViews = [
  19. 'unit' => 'unit_wo_cover.html',
  20. 'gallery' => 'unit_with_cover.html'
  21. ];
  22. if(!empty($aParams['unit_views']) && is_array($aParams['unit_views']))
  23. $this->aUnitViews = array_merge($this->aUnitViews, $aParams['unit_views']);
  24. $this->sUnitViewDefault = 'gallery';
  25. if(!empty($aParams['unit_view']))
  26. $this->sUnitViewDefault = $aParams['unit_view'];
  27. $this->sUnitTemplate = $this->aUnitViews[$this->sUnitViewDefault];
  28. $this->addContainerClass (array(
  29. 'bx-base-pofile-units-wrapper',
  30. 'bx-base-puw-' . str_replace('_' , '-', $this->sUnitViewDefault),
  31. 'bx-def-margin-sec-neg'
  32. ));
  33. $this->aCurrent = [
  34. 'name' => 'sys_search',
  35. 'module_name' => 'system',
  36. 'title' => '',
  37. 'table' => 'sys_profiles',
  38. 'ownFields' => ['id', 'account_id', 'type', 'content_id'],
  39. 'searchFields' => [],
  40. 'restriction' => [
  41. 'account_id' => ['value' => '', 'field' => 'account_id', 'operator' => '='],
  42. 'perofileStatus' => ['value' => 'active', 'field' => 'status', 'operator' => '='],
  43. 'perofileType' => ['value' => '', 'field' => 'type', 'operator' => '='],
  44. ],
  45. 'join' => [
  46. 'account' => [
  47. 'type' => 'INNER',
  48. 'table' => 'sys_accounts',
  49. 'mainField' => 'account_id',
  50. 'onField' => 'id',
  51. 'joinFields' => [],
  52. ],
  53. ],
  54. 'paginate' => ['start' => 0],
  55. 'sorting' => 'last',
  56. 'ident' => 'id'
  57. ];
  58. switch ($sMode) {
  59. case 'connections':
  60. if (!$this->_setConnectionsConditions($aParams))
  61. break;
  62. $oProfile = BxDolProfile::getInstance($aParams['profile']);
  63. $oProfile2 = isset($aParams['profile2']) ? BxDolProfile::getInstance($aParams['profile2']) : null;
  64. $bCommon = isset($aParams['type']) && $aParams['type'] == 'common';
  65. if($bCommon && $oProfile && $oProfile2)
  66. $this->aCurrent['title'] = _t('_sys_page_title_browse_connections_mutual', $oProfile->getDisplayName(), $oProfile2->getDisplayName());
  67. else if(!$bCommon && $oProfile)
  68. $this->aCurrent['title'] = _t('_sys_page_title_browse_connections', $oProfile->getDisplayName());
  69. break;
  70. }
  71. }
  72. function displaySearchUnit ($aData)
  73. {
  74. $oProfile = BxDolProfile::getInstance($aData['id']);
  75. if(!$oProfile)
  76. return '';
  77. if($this->_bIsApi)
  78. return $oProfile->getUnitAPI();
  79. return $oProfile->getUnit(0, ['template' => substr($this->sUnitTemplate, 0, -5)]);
  80. }
  81. function getAlterOrder()
  82. {
  83. $sType = is_array($this->aCurrent['sorting']) ? $this->aCurrent['sorting']['type'] : $this->aCurrent['sorting'];
  84. switch($sType) {
  85. case 'none':
  86. return [];
  87. case 'active':
  88. return ['order' => ' ORDER BY `sys_accounts`.`logged` DESC '];
  89. case 'last_connected':
  90. return ['order' => ' ORDER BY `' . $this->aCurrent['sorting']['table'] . '`.`added` DESC '];
  91. case 'last':
  92. default:
  93. return ['order' => ' ORDER BY `sys_accounts`.`added` DESC '];
  94. }
  95. }
  96. function decodeData ($a)
  97. {
  98. $aResult = [];
  99. foreach ($a as $index => $aItem)
  100. if(($oProfile = BxDolProfile::getInstance($aItem['id'])) !== false)
  101. $aResult[] = $oProfile->getUnitAPI();
  102. return $aResult;
  103. }
  104. protected function _setConnectionsConditions ($aParams)
  105. {
  106. $oConnection = isset($aParams['object']) ? BxDolConnection::getObjectInstance($aParams['object']) : false;
  107. if(!$oConnection || empty($aParams['profile']))
  108. return false;
  109. $sContentType = isset($aParams['type']) ? $aParams['type'] : BX_CONNECTIONS_CONTENT_TYPE_CONTENT;
  110. $isMutual = isset($aParams['mutual']) ? $aParams['mutual'] : false;
  111. $aConnection = $oConnection->getConnectionsAsCondition($sContentType, 'id', (int)$aParams['profile'], (int)$aParams['profile2'], $isMutual);
  112. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConnection['restriction']);
  113. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aConnection['join']);
  114. $this->aCurrent['sorting'] = [
  115. 'type' => 'last_connected',
  116. 'table' => current($aConnection['join'])['table']
  117. ];
  118. return true;
  119. }
  120. }
  121. /** @} */