BxBaseModProfileSearchResult.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModProfileSearchResult extends BxBaseModGeneralSearchResult
  12. {
  13. protected $bRecommendedView = false;
  14. public function __construct($sMode = '', $aParams = array())
  15. {
  16. parent::__construct($sMode, $aParams);
  17. $this->aUnitViews = array('gallery' => 'unit_with_cover.html', 'showcase' => 'unit_with_cover_showcase.html');
  18. if (!empty($aParams['unit_views']))
  19. $this->aUnitViews = $aParams['unit_views'];
  20. if (!empty($aParams['unit_view']))
  21. $this->sUnitViewDefault = $aParams['unit_view'];
  22. $this->sUnitTemplate = $this->aUnitViews[$this->sUnitViewDefault];
  23. $this->sCenterContentUnitSelector = '.bx-base-pofile-unit';
  24. $this->addContainerClass (array('bx-def-margin-sec-lefttopright-neg', 'bx-base-pofile-units-wrapper', 'bx-def-margin-sec-bottom-neg'));
  25. if ('unit_with_cover_showcase.html' == $this->sUnitTemplate){
  26. $this->bShowcaseView = true;
  27. $this->removeContainerClass ('bx-def-margin-bottom-neg');
  28. }
  29. if ($sMode == 'recommended')
  30. $this->bRecommendedView=true;
  31. }
  32. protected function _setConnectionsConditions ($aParams)
  33. {
  34. $oConnection = isset($aParams['object']) ? BxDolConnection::getObjectInstance($aParams['object']) : false;
  35. if (!$oConnection || !isset($aParams['profile']) || !(int)$aParams['profile'])
  36. return false;
  37. $sContentType = isset($aParams['type']) ? $aParams['type'] : BX_CONNECTIONS_CONTENT_TYPE_CONTENT;
  38. $isMutual = isset($aParams['mutual']) ? $aParams['mutual'] : false;
  39. $a = $oConnection->getConnectionsAsCondition ($sContentType, 'id', (int)$aParams['profile'], (int)$aParams['profile2'], $isMutual);
  40. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $a['restriction']);
  41. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $a['join']);
  42. return true;
  43. }
  44. protected function _setConditionsForRecommended ()
  45. {
  46. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  47. $a = $oConnection->getConnectedContentAsSQLPartsExt ($this->aCurrent['table'], '', '');
  48. $aTmp = array(
  49. 'recommended' => array(
  50. 'type' => 'LEFT',
  51. 'table' => $a['join']['table'],
  52. 'mainField' => 'id` AND ' . bx_get_logged_profile_id() . ' = `' . $a['join']['table'] . '`.`initiator',
  53. 'onField' => 'content',
  54. 'joinFields' => array(),
  55. )
  56. );
  57. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aTmp);
  58. if (isset($this->aCurrent['restriction_sql']))
  59. $this->aCurrent['restriction_sql'] .= ' AND `' . $a['join']['table'] . '`.`initiator` IS NULL';
  60. else
  61. $this->aCurrent['restriction_sql'] = ' AND `' . $a['join']['table'] . '`.`initiator` IS NULL';
  62. }
  63. protected function _setAclConditions ($aParams)
  64. {
  65. $oAcl = BxDolAcl::getInstance();
  66. if(!$oAcl || empty($aParams['level']))
  67. return false;
  68. if(!is_array($aParams['level']))
  69. $aParams['level'] = array($aParams['level']);
  70. $this->aCurrent['title'] = array();
  71. foreach($aParams['level'] as $iLevelId) {
  72. $aInfo = $oAcl->getMembershipInfo($iLevelId);
  73. if(empty($aInfo) || !is_array($aInfo))
  74. continue;
  75. $this->aCurrent['title'][] = _t($aInfo['name']);
  76. }
  77. $aCondition = $oAcl->getContentByLevelAsCondition('id', $aParams['level']);
  78. $this->aCurrent['restriction_sql'] = (!empty($this->aCurrent['restriction_sql']) ? $this->aCurrent['restriction_sql'] : '') . $aCondition['restriction_sql'];
  79. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aCondition['restriction']);
  80. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aCondition['join']);
  81. return true;
  82. }
  83. protected function _setFavoriteConditions($sMode, $aParams, &$oProfileAuthor)
  84. {
  85. $CNF = &$this->oModule->_oConfig->CNF;
  86. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['user']);
  87. if(!$oProfileAuthor)
  88. return false;
  89. $iProfileAuthor = $oProfileAuthor->id();
  90. $oFavorite = $this->oModule->getObjectFavorite();
  91. if(!$oFavorite->isPublic() && $iProfileAuthor != bx_get_logged_profile_id())
  92. return false;
  93. $aConditions = $oFavorite->getConditionsTrack($CNF['TABLE_ENTRIES'], 'id', $iProfileAuthor);
  94. if(!empty($aConditions) && is_array($aConditions)) {
  95. if(empty($this->aCurrent['restriction']) || !is_array($this->aCurrent['restriction']))
  96. $this->aCurrent['restriction'] = array();
  97. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions['restriction']);
  98. if(empty($this->aCurrent['join']) || !is_array($this->aCurrent['join']))
  99. $this->aCurrent['join'] = array();
  100. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aConditions['join']);
  101. }
  102. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_VIEW_FAVORITES'] . '&profile_id={profile_id}';
  103. $this->aCurrent['title'] = _t($CNF['T']['txt_browse_favorites']);
  104. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  105. return true;
  106. }
  107. function getItemPerPageInShowCase ()
  108. {
  109. $iPerPageInShowCase = parent::getItemPerPageInShowCase();
  110. $CNF = &$this->oModule->_oConfig->CNF;
  111. if ($this->bRecommendedView && isset($CNF['PARAM_PER_PAGE_BROWSE_RECOMMENDED'])){
  112. $iPerPageInShowCase = getParam($CNF['PARAM_PER_PAGE_BROWSE_RECOMMENDED']);
  113. }
  114. return $iPerPageInShowCase;
  115. }
  116. }
  117. /** @} */