BxBaseModGroupsTemplate.php 6.0 KB

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