BxBaseModGroupsTemplate.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. /*
  12. * Groups module representation.
  13. */
  14. class BxBaseModGroupsTemplate extends BxBaseModProfileTemplate
  15. {
  16. protected $_iUnitCharsSummary;
  17. protected $_sUnitClassWoCover;
  18. function __construct(&$oConfig, &$oDb)
  19. {
  20. parent::__construct($oConfig, $oDb);
  21. $this->_iUnitCharsSummary = 50;
  22. $this->_sUnitClassWoCover = $this->_sUnitClass; //--- Save default 'Unit' class (from BxBaseModProfileTemplate) as 'Unit W\O Cover' class here.
  23. $this->_sUnitClassWithCover .= ' bx-base-groups-unit-with-cover';
  24. $this->_sUnitClass = $this->_sUnitClassWithCover;
  25. $this->_sUnitClassWoInfo .= ' bx-base-groups-unit-wo-info';
  26. $this->_sUnitClassWoInfoShowCase .= ' bx-base-groups-unit-wo-info bx-base-groups-unit-wo-info-showcase';
  27. $this->_sUnitClassShowCase .= ' bx-base-groups-unit-with-cover bx-base-groups-unit-showcase';
  28. $this->_bLetterAvatar = !$this->_oConfig->isUseCoverAsThumb();
  29. }
  30. public function addLocationBase()
  31. {
  32. parent::addLocationBase();
  33. $this->addLocation('mod_groups', BX_DIRECTORY_PATH_MODULES . 'base' . DIRECTORY_SEPARATOR . 'groups' . DIRECTORY_SEPARATOR, BX_DOL_URL_MODULES . 'base/groups/');
  34. }
  35. function unitVars ($aData, $isCheckPrivateContent = true, $mixedTemplate = false, $aParams = array())
  36. {
  37. $aVars = parent::unitVars ($aData, $isCheckPrivateContent, $mixedTemplate, $aParams);
  38. $CNF = &$this->_oConfig->CNF;
  39. $oProfile = BxDolProfile::getInstance($aData[$CNF['FIELD_AUTHOR']]);
  40. if (!$oProfile)
  41. $oProfile = BxDolProfileUndefined::getInstance();
  42. $aVars['title'] = (boolean)$aVars['public'] ? bx_process_output($aData[$CNF['FIELD_NAME']]) : _t($CNF['T']['txt_private_group']);
  43. $aVars['description'] = '';
  44. if(!empty($CNF['FIELD_TEXT']) && !empty($aData[$CNF['FIELD_TEXT']]) && (boolean)$aVars['public'])
  45. $aVars['description'] = strmaxtextlen(strip_tags($aData[$CNF['FIELD_TEXT']]), $this->_iUnitCharsSummary);
  46. $aVars['author'] = $oProfile->getDisplayName();
  47. $aVars['author_url'] = $oProfile->getUrl();
  48. $aVars['author_icon'] = $oProfile->getIcon();
  49. $aVars['author_thumb'] = $oProfile->getThumb();
  50. $aVars['author_avatar'] = $oProfile->getAvatar();
  51. return $aVars;
  52. }
  53. function prepareCover($aData, $aParams = [])
  54. {
  55. if($this->_oConfig->isUseCoverAsThumb())
  56. $aParams['show_avatar'] = false;
  57. return parent::prepareCover($aData, $aParams);
  58. }
  59. public function getPopupSetRole($aRoles, $iProfileId, $iProfileRole)
  60. {
  61. if ($this->_bIsApi){
  62. $aTmplVarsRoles = array();
  63. foreach($aRoles as $iRole => $sRole){
  64. $aTmplVarsRoles[] = [
  65. 'value' => $iRole,
  66. 'label' => $sRole,
  67. ];
  68. }
  69. return ['values' => $aTmplVarsRoles, 'value' => $iProfileRole];
  70. }
  71. $sJsObject = $this->_oConfig->getJsObject('main');
  72. $sHtmlIdPrefix = str_replace('_', '-', $this->_oConfig->getName()) . '-role';
  73. $aTmplVarsRoles = array();
  74. foreach($aRoles as $iRole => $sRole)
  75. $aTmplVarsRoles[] = array(
  76. 'id' => $sHtmlIdPrefix . '-' . $iRole,
  77. 'value' => $iRole,
  78. 'onclick' => $sJsObject . '.onClickSetRoleMulti(this, ' . $iProfileId . ', ' . $iRole . ')',
  79. 'title' => $sRole,
  80. 'bx_if:show_checked' => array(
  81. 'condition' => $iRole != 0 && $iProfileRole & (1 << ($iRole - 1)),
  82. 'content' => array()
  83. )
  84. );
  85. return $this->parseHtmlByName('set_role_popup.html', array(
  86. 'bx_repeat:roles' => $aTmplVarsRoles
  87. ));
  88. }
  89. public function getPopupQuestionnaire($iContentId, $iProfileId)
  90. {
  91. $aAnswers = $this->_oModule->_oDb->getQuestions(['sample' => 'answers', 'content_id' => $iContentId, 'profile_id' => $iProfileId]);
  92. if(empty($aAnswers) || !is_array($aAnswers))
  93. return $this->_bIsApi ? [] : '';
  94. $aTmplVarsAnswers = [];
  95. foreach($aAnswers as $aAnswer)
  96. $aTmplVarsAnswers[] = [
  97. 'question' => $aAnswer['question'],
  98. 'answer' => $aAnswer['answer'],
  99. ];
  100. if($this->_bIsApi)
  101. return $aTmplVarsAnswers;
  102. return $this->parseHtmlByName('popup_qnr_answers.html', ['bx_repeat:answers' => $aTmplVarsAnswers]);
  103. }
  104. public function getTimelineCardRecommendations($aParams)
  105. {
  106. $CNF = &$this->_oConfig->CNF;
  107. $sModule = $this->_oConfig->getName();
  108. $iProfileId = 0;
  109. if(!($iProfileId = bx_get_logged_profile_id()))
  110. return $this->_bIsApi ? [] : '';
  111. $oRecommendation = false;
  112. if(($sKey = 'OBJECT_RECOMMENDATIONS_FANS') && (empty($CNF[$sKey]) || !($oRecommendation = BxDolRecommendation::getObjectInstance($CNF[$sKey]))))
  113. return $this->_bIsApi ? [] : '';
  114. $sId = 'rc' . ((int)($aParams['start'] ?? 0) + (int)($aParams['event_index'] ?? 0));
  115. if($this->_bIsApi) {
  116. $aResult = [];
  117. if(($aCode = $oRecommendation->getCodeAPI($iProfileId, ['showcase' => true])) && is_array($aCode))
  118. $aResult = [
  119. 'id' => $sId,
  120. 'type' => 'timeline_recommendations',
  121. 'module' => $sModule,
  122. 'title' => _t($sModule . '_timeline_recommendations'),
  123. 'content' => array_merge($aCode, [
  124. 'page_url' => bx_api_get_relative_url(BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME'])),
  125. ])
  126. ];
  127. return $aResult;
  128. }
  129. $sCode = $oRecommendation->getCode($iProfileId, ['showcase' => true]);
  130. if(!$sCode)
  131. return '';
  132. return $this->parseHtmlByName('timeline_post_recommendation.html', [
  133. 'html_id' => $this->_oConfig->getHtmlIds('timeline_card_recommendations') . $sId,
  134. 'class' => str_replace('_', '-', $sModule),
  135. 'code' => $sCode
  136. ]) . $this->addCss(['timeline.css'], true);
  137. }
  138. protected function _getUnitClass($aData, $sTemplateName = 'unit.html')
  139. {
  140. $CNF = &$this->_oConfig->CNF;
  141. $sResult = '';
  142. switch($sTemplateName) {
  143. case 'unit_wo_cover.html':
  144. $sResult = $this->_sUnitClassWoCover;
  145. break;
  146. default:
  147. $sResult = parent::_getUnitClass($aData, $sTemplateName);
  148. }
  149. return $sResult . ' ' . str_replace('_', '-', $this->_oConfig->getName()) . '-unit-' . $aData[$CNF['FIELD_ID']];
  150. }
  151. protected function _getUnitSize($aData, $sTemplateName = 'unit.html')
  152. {
  153. $sResult = '';
  154. switch($sTemplateName) {
  155. case 'unit.html':
  156. case 'unit_with_cover.html':
  157. $sResult = 'ava';
  158. break;
  159. default:
  160. $sResult = $this->_sUnitSizeDefault;
  161. break;
  162. }
  163. return $sResult;
  164. }
  165. protected function _isUnitThumb($aData, $sTemplateName = 'unit.html')
  166. {
  167. $bResult = true;
  168. switch($sTemplateName) {
  169. case 'unit.html':
  170. case 'unit_with_cover.html':
  171. $bResult = !$this->_oConfig->isUseCoverAsThumb();
  172. break;
  173. }
  174. return $bResult;
  175. }
  176. function _image ($sField, $sTranscodeObject, $sNoImage, $aData, $bSubstituteNoImage = true)
  177. {
  178. $CNF = &$this->_oConfig->CNF;
  179. if($sField == $CNF['FIELD_PICTURE'] && $this->_oConfig->isUseCoverAsThumb())
  180. $sField = $CNF['FIELD_COVER'];
  181. return parent::_image($sField, $sTranscodeObject, $sNoImage, $aData, $bSubstituteNoImage);
  182. }
  183. protected function _isTemplateWithMeta(string $sTemplateName = 'unit.html'): bool
  184. {
  185. $bResult = parent::_isTemplateWithMeta($sTemplateName);
  186. if (!$bResult && 'unit.html' == $sTemplateName)
  187. $bResult = true;
  188. return $bResult;
  189. }
  190. }
  191. /** @} */