BxBaseModProfileSearchResult.php 9.2 KB

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