BxBaseModProfileSearchResult.php 7.5 KB

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