BxBaseModGroupsTemplate.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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->_bLetterAvatar = false;
  22. $this->_iUnitCharsSummary = 50;
  23. $this->_sUnitClassWoCover = $this->_sUnitClass; //--- Save default 'Unit' class (from BxBaseModProfileTemplate) as 'Unit W\O Cover' class here.
  24. $this->_sUnitClassWithCover .= ' bx-base-groups-unit-with-cover';
  25. $this->_sUnitClass = $this->_sUnitClassWithCover;
  26. $this->_sUnitClassWoInfo .= ' bx-base-groups-unit-wo-info';
  27. $this->_sUnitClassWoInfoShowCase .= ' bx-base-groups-unit-wo-info bx-base-groups-unit-wo-info-showcase';
  28. $this->_sUnitClassShowCase .= ' bx-base-groups-unit-with-cover bx-base-groups-unit-showcase';
  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. $aParams['show_badge'] = false;
  58. return parent::prepareCover($aData, $aParams);
  59. }
  60. public function getPopupSetRole($aRoles, $iProfileId, $iProfileRole)
  61. {
  62. $sJsObject = $this->_oConfig->getJsObject('main');
  63. $sHtmlIdPrefix = str_replace('_', '-', $this->_oConfig->getName()) . '-role';
  64. $aTmplVarsRoles = array();
  65. foreach($aRoles as $iRole => $sRole)
  66. $aTmplVarsRoles[] = array(
  67. 'id' => $sHtmlIdPrefix . '-' . $iRole,
  68. 'value' => $iRole,
  69. 'onclick' => $sJsObject . '.onClickSetRoleMulti(this, ' . $iProfileId . ', ' . $iRole . ')',
  70. 'title' => $sRole,
  71. 'bx_if:show_checked' => array(
  72. 'condition' => $iRole != 0 && $iProfileRole & (1 << ($iRole - 1)),
  73. 'content' => array()
  74. )
  75. );
  76. return $this->parseHtmlByName('set_role_popup.html', array(
  77. 'bx_repeat:roles' => $aTmplVarsRoles
  78. ));
  79. }
  80. public function getPopupQuestionnaire($iContentId, $iProfileId)
  81. {
  82. $aAnswers = $this->_oModule->_oDb->getQuestions(['sample' => 'answers', 'content_id' => $iContentId, 'profile_id' => $iProfileId]);
  83. if(empty($aAnswers) || !is_array($aAnswers))
  84. return $this->_bIsApi ? [] : '';
  85. $aTmplVarsAnswers = [];
  86. foreach($aAnswers as $aAnswer)
  87. $aTmplVarsAnswers[] = [
  88. 'question' => $aAnswer['question'],
  89. 'answer' => $aAnswer['answer'],
  90. ];
  91. if($this->_bIsApi)
  92. return $aTmplVarsAnswers;
  93. return $this->parseHtmlByName('popup_qnr_answers.html', ['bx_repeat:answers' => $aTmplVarsAnswers]);
  94. }
  95. protected function _getUnitClass($aData, $sTemplateName = 'unit.html')
  96. {
  97. $CNF = &$this->_oConfig->CNF;
  98. $sResult = '';
  99. switch($sTemplateName) {
  100. case 'unit_wo_cover.html':
  101. $sResult = $this->_sUnitClassWoCover;
  102. break;
  103. default:
  104. $sResult = parent::_getUnitClass($aData, $sTemplateName);
  105. }
  106. return $sResult . ' ' . str_replace('_', '-', $this->_oConfig->getName()) . '-unit-' . $aData[$CNF['FIELD_ID']];
  107. }
  108. protected function _getUnitSize($aData, $sTemplateName = 'unit.html')
  109. {
  110. $sResult = '';
  111. switch($sTemplateName) {
  112. case 'unit.html':
  113. case 'unit_with_cover.html':
  114. $sResult = 'ava';
  115. break;
  116. default:
  117. $sResult = $this->_sUnitSizeDefault;
  118. break;
  119. }
  120. return $sResult;
  121. }
  122. protected function _isUnitThumb($aData, $sTemplateName = 'unit.html')
  123. {
  124. $bResult = true;
  125. switch($sTemplateName) {
  126. case 'unit.html':
  127. case 'unit_with_cover.html':
  128. $bResult = !$this->_oConfig->isUseCoverAsThumb();
  129. break;
  130. }
  131. return $bResult;
  132. }
  133. protected function _isUnitBadge($aData, $sTemplateName = 'unit.html')
  134. {
  135. return false;
  136. }
  137. function _image ($sField, $sTranscodeObject, $sNoImage, $aData, $bSubstituteNoImage = true)
  138. {
  139. $CNF = &$this->_oConfig->CNF;
  140. if($sField == $CNF['FIELD_PICTURE'] && $this->_oConfig->isUseCoverAsThumb())
  141. $sField = $CNF['FIELD_COVER'];
  142. return parent::_image($sField, $sTranscodeObject, $sNoImage, $aData, $bSubstituteNoImage);
  143. }
  144. }
  145. /** @} */