BxBaseModGroupsSearchResult.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 BaseGroups Base classes for groups modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModGroupsSearchResult extends BxBaseModProfileSearchResult
  12. {
  13. public function __construct($sMode = '', $aParams = array())
  14. {
  15. if (!isset($aParams['unit_views'])) {
  16. if (!is_array($aParams))
  17. $aParams = [];
  18. $aParams['unit_views'] = array('gallery' => 'unit.html', 'showcase' => 'unit_with_cover_showcase.html');
  19. }
  20. parent::__construct($sMode, $aParams);
  21. }
  22. function displayResultBlock()
  23. {
  24. $this->oModule->_oTemplate->addJs(['modules/base/groups/js/|main.js', 'main.js']);
  25. return $this->oModule->_oTemplate->getJsCode('main', [
  26. 'sModule' => $this->oModule->getName()
  27. ], [
  28. 'wrap' => true,
  29. 'mask' => "if(window['{object}'] == undefined) window['{object}'] = new {class}({params});"
  30. ]) . parent::displayResultBlock();
  31. }
  32. protected function addConditionsForPrivateContent($CNF, $oProfile, $aCustomGroup = array())
  33. {
  34. if(empty($CNF['OBJECT_PRIVACY_VIEW']))
  35. return;
  36. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  37. if(!$oPrivacy)
  38. return;
  39. parent::addConditionsForPrivateContent($CNF, $oProfile, array_merge($aCustomGroup, $oPrivacy->getPartiallyVisiblePrivacyGroups()));
  40. }
  41. protected function addConditionsForAuthorStatus($CNF)
  42. {
  43. return;
  44. }
  45. protected function addConditionsForCf($CNF)
  46. {
  47. if(empty($CNF['FIELD_CF']))
  48. return;
  49. $oCf = BxDolContentFilter::getInstance();
  50. if(!$oCf->isEnabled())
  51. return;
  52. $aConditions = $oCf->getConditions($this->aCurrent['join']['profile']['table'], $CNF['FIELD_CF']);
  53. if(!empty($aConditions) && is_array($aConditions))
  54. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions);
  55. }
  56. protected function _setAuthorConditions($sMode, $aParams, &$oProfileAuthor)
  57. {
  58. $CNF = &$this->oModule->_oConfig->CNF;
  59. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['author']);
  60. if (!$oProfileAuthor)
  61. return false;
  62. $iProfileAuthor = $oProfileAuthor->id();
  63. $this->aCurrent['restriction']['owner']['value'] = $iProfileAuthor;
  64. if(!empty($aParams['per_page']))
  65. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  66. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_JOINED_ENTRIES'] . '&profile_id={profile_id}';
  67. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  68. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  69. return true;
  70. }
  71. protected function _setFavoriteConditions($sMode, $aParams, &$oProfileAuthor)
  72. {
  73. $CNF = &$this->oModule->_oConfig->CNF;
  74. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['user']);
  75. if (!$oProfileAuthor)
  76. return false;
  77. $iListId = 0;
  78. if(isset($aParams['list_id']))
  79. $iListId = (int)$aParams['list_id'];
  80. $iProfileAuthor = $oProfileAuthor->id();
  81. $oFavorite = $this->oModule->getObjectFavorite();
  82. if(!$oFavorite || (!$oFavorite->isPublic() && $iProfileAuthor != bx_get_logged_profile_id()))
  83. return false;
  84. $aConditions = $oFavorite->getConditionsTrack($CNF['TABLE_ENTRIES'], 'id', $iProfileAuthor, $iListId);
  85. if(!empty($aConditions) && is_array($aConditions)) {
  86. if(empty($this->aCurrent['restriction']) || !is_array($this->aCurrent['restriction']))
  87. $this->aCurrent['restriction'] = array();
  88. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions['restriction']);
  89. if(empty($this->aCurrent['join']) || !is_array($this->aCurrent['join']))
  90. $this->aCurrent['join'] = array();
  91. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aConditions['join']);
  92. }
  93. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_JOINED_ENTRIES'] . '&profile_id={profile_id}';
  94. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  95. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  96. return true;
  97. }
  98. protected function _updateCurrentForContext($sMode, $aParams, &$oProfileContext)
  99. {
  100. $CNF = &$this->oModule->_oConfig->CNF;
  101. $oProfileContext = BxDolProfile::getInstance((int)$aParams['context']);
  102. if (!$oProfileContext)
  103. return false;
  104. $iProfileIdContext = $oProfileContext->id();
  105. $this->aCurrent['restriction']['context'] = array(
  106. 'value' => -$iProfileIdContext,
  107. 'field' => $CNF['FIELD_ALLOW_VIEW_TO'],
  108. 'operator' => '=',
  109. 'table' => $CNF['TABLE_ENTRIES']
  110. );
  111. if(!empty($aParams['per_page']))
  112. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  113. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_ENTRIES_BY_CONTEXT'] . '&profile_id={profile_id}';
  114. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_context']);
  115. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileIdContext;
  116. return true;
  117. }
  118. }
  119. /** @} */