BxBaseModProfileSearchResult.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. function getRssUnitImage (&$a, $sField)
  33. {
  34. $CNF = &$this->oModule->_oConfig->CNF;
  35. if(empty($sField) || empty($a[$sField]))
  36. return '';
  37. $sTranscoder = '';
  38. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_PICTURE']))
  39. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_PICTURE'];
  40. else if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']))
  41. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_GALLERY'];
  42. else
  43. return '';
  44. $oTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  45. if(!$oTranscoder)
  46. return '';
  47. return $oTranscoder->getFileUrl($a[$sField]);
  48. }
  49. protected function _setConnectionsConditions ($aParams)
  50. {
  51. $oConnection = isset($aParams['object']) ? BxDolConnection::getObjectInstance($aParams['object']) : false;
  52. if (!$oConnection || !isset($aParams['profile']) || !(int)$aParams['profile'])
  53. return false;
  54. $sContentType = isset($aParams['type']) ? $aParams['type'] : BX_CONNECTIONS_CONTENT_TYPE_CONTENT;
  55. $isMutual = isset($aParams['mutual']) ? $aParams['mutual'] : false;
  56. $a = $oConnection->getConnectionsAsCondition ($sContentType, 'id', (int)$aParams['profile'], (int)$aParams['profile2'], $isMutual);
  57. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $a['restriction']);
  58. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $a['join']);
  59. return true;
  60. }
  61. protected function _setConditionsForRecommended ()
  62. {
  63. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  64. $a = $oConnection->getConnectedContentAsSQLPartsExt ($this->aCurrent['table'], '', '');
  65. $aTmp = array(
  66. 'recommended' => array(
  67. 'type' => 'LEFT',
  68. 'table' => $a['join']['table'],
  69. 'mainField' => 'id` AND ' . bx_get_logged_profile_id() . ' = `' . $a['join']['table'] . '`.`initiator',
  70. 'onField' => 'content',
  71. 'joinFields' => array(),
  72. )
  73. );
  74. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aTmp);
  75. if (isset($this->aCurrent['restriction_sql']))
  76. $this->aCurrent['restriction_sql'] .= ' AND `' . $a['join']['table'] . '`.`initiator` IS NULL AND ' . bx_get_logged_profile_id() . ' <> `sys_profiles`.`id` ' ;
  77. else
  78. $this->aCurrent['restriction_sql'] = ' AND `' . $a['join']['table'] . '`.`initiator` IS NULL AND ' . bx_get_logged_profile_id() . ' <> `sys_profiles`.`id` ' ;
  79. }
  80. protected function _setAclConditions ($aParams)
  81. {
  82. $oAcl = BxDolAcl::getInstance();
  83. if(!$oAcl || empty($aParams['level']))
  84. return false;
  85. if(!is_array($aParams['level']))
  86. $aParams['level'] = array($aParams['level']);
  87. $this->aCurrent['title'] = array();
  88. foreach($aParams['level'] as $iLevelId) {
  89. $aInfo = $oAcl->getMembershipInfo($iLevelId);
  90. if(empty($aInfo) || !is_array($aInfo))
  91. continue;
  92. $this->aCurrent['title'][] = _t($aInfo['name']);
  93. }
  94. $aCondition = $oAcl->getContentByLevelAsCondition('id', $aParams['level']);
  95. $this->aCurrent['restriction_sql'] = (!empty($this->aCurrent['restriction_sql']) ? $this->aCurrent['restriction_sql'] : '') . $aCondition['restriction_sql'];
  96. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aCondition['restriction']);
  97. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aCondition['join']);
  98. return true;
  99. }
  100. protected function _setFavoriteConditions($sMode, $aParams, &$oProfileAuthor)
  101. {
  102. $CNF = &$this->oModule->_oConfig->CNF;
  103. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['user']);
  104. if(!$oProfileAuthor)
  105. return false;
  106. $iProfileAuthor = $oProfileAuthor->id();
  107. $oFavorite = $this->oModule->getObjectFavorite();
  108. if(!$oFavorite->isPublic() && $iProfileAuthor != bx_get_logged_profile_id())
  109. return false;
  110. $aConditions = $oFavorite->getConditionsTrack($CNF['TABLE_ENTRIES'], 'id', $iProfileAuthor);
  111. if(!empty($aConditions) && is_array($aConditions)) {
  112. if(empty($this->aCurrent['restriction']) || !is_array($this->aCurrent['restriction']))
  113. $this->aCurrent['restriction'] = array();
  114. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions['restriction']);
  115. if(empty($this->aCurrent['join']) || !is_array($this->aCurrent['join']))
  116. $this->aCurrent['join'] = array();
  117. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aConditions['join']);
  118. }
  119. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_VIEW_FAVORITES'] . '&profile_id={profile_id}';
  120. $this->aCurrent['title'] = _t($CNF['T']['txt_browse_favorites']);
  121. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  122. return true;
  123. }
  124. function getItemPerPageInShowCase ()
  125. {
  126. $iPerPageInShowCase = parent::getItemPerPageInShowCase();
  127. $CNF = &$this->oModule->_oConfig->CNF;
  128. if ($this->bRecommendedView && isset($CNF['PARAM_PER_PAGE_BROWSE_RECOMMENDED'])){
  129. $iPerPageInShowCase = getParam($CNF['PARAM_PER_PAGE_BROWSE_RECOMMENDED']);
  130. }
  131. return $iPerPageInShowCase;
  132. }
  133. function displayResultBlock ()
  134. {
  135. $this->oModule->_oTemplate->addJs(array('modules/base/profile/js/|searchresult.js'));
  136. return parent::displayResultBlock ();
  137. }
  138. }
  139. /** @} */