BxBaseModProfileSearchResult.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 _setAccountConfirmationConditions($aParams)
  58. {
  59. $sConfirmationType = getParam('sys_account_confirmation_type');
  60. $bHideUnconfirmed = getParam('sys_account_hide_unconfirmed_accounts') == 'on';
  61. if($sConfirmationType == BX_ACCOUNT_CONFIRMATION_NONE || !$bHideUnconfirmed)
  62. return;
  63. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], array(
  64. 'account_confirmed_email' => array('value' => '', 'field' => 'email_confirmed', 'operator' => '=', 'table' => 'sys_accounts'),
  65. 'account_confirmed_phone' => array('value' => '', 'field' => 'phone_confirmed', 'operator' => '=', 'table' => 'sys_accounts'),
  66. ));
  67. switch($sConfirmationType) {
  68. case BX_ACCOUNT_CONFIRMATION_EMAIL:
  69. $this->aCurrent['restriction']['account_confirmed_email']['value'] = 1;
  70. break;
  71. case BX_ACCOUNT_CONFIRMATION_PHONE:
  72. $this->aCurrent['restriction']['account_confirmed_phone']['value'] = 1;
  73. break;
  74. case BX_ACCOUNT_CONFIRMATION_EMAIL_PHONE:
  75. $this->aCurrent['restriction']['account_confirmed_email']['value'] = 1;
  76. $this->aCurrent['restriction']['account_confirmed_phone']['value'] = 1;
  77. break;
  78. }
  79. }
  80. protected function _setConnectionsConditions ($aParams)
  81. {
  82. $oConnection = isset($aParams['object']) ? BxDolConnection::getObjectInstance($aParams['object']) : false;
  83. if (!$oConnection || !isset($aParams['profile']) || !(int)$aParams['profile'])
  84. return false;
  85. $sContentType = isset($aParams['type']) ? $aParams['type'] : BX_CONNECTIONS_CONTENT_TYPE_CONTENT;
  86. $isMutual = isset($aParams['mutual']) ? $aParams['mutual'] : false;
  87. $a = $oConnection->getConnectionsAsCondition ($sContentType, 'id', (int)$aParams['profile'], (int)$aParams['profile2'], $isMutual);
  88. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $a['restriction']);
  89. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $a['join']);
  90. return true;
  91. }
  92. protected function _setConditionsForRecommended ()
  93. {
  94. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  95. $a = $oConnection->getConnectedContentAsSQLPartsExt ($this->aCurrent['table'], '', '');
  96. $aTmp = array(
  97. 'recommended' => array(
  98. 'type' => 'LEFT',
  99. 'table' => $a['join']['table'],
  100. 'mainField' => 'id` AND ' . bx_get_logged_profile_id() . ' = `' . $a['join']['table'] . '`.`initiator',
  101. 'onField' => 'content',
  102. 'joinFields' => array(),
  103. )
  104. );
  105. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aTmp);
  106. if (isset($this->aCurrent['restriction_sql']))
  107. $this->aCurrent['restriction_sql'] .= ' AND `' . $a['join']['table'] . '`.`initiator` IS NULL AND ' . bx_get_logged_profile_id() . ' <> `sys_profiles`.`id` ' ;
  108. else
  109. $this->aCurrent['restriction_sql'] = ' AND `' . $a['join']['table'] . '`.`initiator` IS NULL AND ' . bx_get_logged_profile_id() . ' <> `sys_profiles`.`id` ' ;
  110. }
  111. protected function _setAclConditions ($aParams)
  112. {
  113. $oAcl = BxDolAcl::getInstance();
  114. if(!$oAcl || empty($aParams['level']))
  115. return false;
  116. if(!is_array($aParams['level']))
  117. $aParams['level'] = array($aParams['level']);
  118. $this->aCurrent['title'] = array();
  119. foreach($aParams['level'] as $iLevelId) {
  120. $aInfo = $oAcl->getMembershipInfo($iLevelId);
  121. if(empty($aInfo) || !is_array($aInfo))
  122. continue;
  123. $this->aCurrent['title'][] = _t($aInfo['name']);
  124. }
  125. $aCondition = $oAcl->getContentByLevelAsCondition('id', $aParams['level']);
  126. $this->aCurrent['restriction_sql'] = (!empty($this->aCurrent['restriction_sql']) ? $this->aCurrent['restriction_sql'] : '') . $aCondition['restriction_sql'];
  127. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aCondition['restriction']);
  128. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aCondition['join']);
  129. return true;
  130. }
  131. protected function _setFavoriteConditions($sMode, $aParams, &$oProfileAuthor)
  132. {
  133. $CNF = &$this->oModule->_oConfig->CNF;
  134. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['user']);
  135. if(!$oProfileAuthor)
  136. return false;
  137. $iProfileAuthor = $oProfileAuthor->id();
  138. $oFavorite = $this->oModule->getObjectFavorite();
  139. if(!$oFavorite->isPublic() && $iProfileAuthor != bx_get_logged_profile_id())
  140. return false;
  141. $aConditions = $oFavorite->getConditionsTrack($CNF['TABLE_ENTRIES'], 'id', $iProfileAuthor);
  142. if(!empty($aConditions) && is_array($aConditions)) {
  143. if(empty($this->aCurrent['restriction']) || !is_array($this->aCurrent['restriction']))
  144. $this->aCurrent['restriction'] = array();
  145. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions['restriction']);
  146. if(empty($this->aCurrent['join']) || !is_array($this->aCurrent['join']))
  147. $this->aCurrent['join'] = array();
  148. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aConditions['join']);
  149. }
  150. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_VIEW_FAVORITES'] . '&profile_id={profile_id}';
  151. $this->aCurrent['title'] = _t($CNF['T']['txt_browse_favorites']);
  152. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  153. return true;
  154. }
  155. function getItemPerPageInShowCase ()
  156. {
  157. $iPerPageInShowCase = parent::getItemPerPageInShowCase();
  158. $CNF = &$this->oModule->_oConfig->CNF;
  159. if ($this->bRecommendedView && isset($CNF['PARAM_PER_PAGE_BROWSE_RECOMMENDED'])){
  160. $iPerPageInShowCase = getParam($CNF['PARAM_PER_PAGE_BROWSE_RECOMMENDED']);
  161. }
  162. return $iPerPageInShowCase;
  163. }
  164. function displayResultBlock ()
  165. {
  166. $this->oModule->_oTemplate->addJs(array('modules/base/profile/js/|searchresult.js'));
  167. return parent::displayResultBlock ();
  168. }
  169. }
  170. /** @} */