BxSpacesTemplate.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. * @defdroup Spaces Spaces
  7. * @indroup UnaModules
  8. *
  9. * @{
  10. */
  11. /*
  12. * Spaces module representation.
  13. */
  14. class BxSpacesTemplate extends BxBaseModGroupsTemplate
  15. {
  16. function __construct(&$oConfig, &$oDb)
  17. {
  18. $this->MODULE = 'bx_spaces';
  19. parent::__construct($oConfig, $oDb);
  20. }
  21. public function entryChilds($aData, $aParams = [])
  22. {
  23. $aChild = $this->_oModule->_oDb->getChildEntriesIdByProfileId($aData['profile_id']);
  24. if(count($aChild) == 0)
  25. return false;
  26. if(!isset($aParams['template']))
  27. $aParams['template'] = 'unit_wo_cover';
  28. return $this->parseHtmlByName('entry-childs.html', [
  29. 'content' => $this->getBrowseQuick($aChild, $aParams['template'])
  30. ]);
  31. }
  32. public function entryParent($aData, $aParams = [])
  33. {
  34. $CNF = $this->_oConfig->CNF;
  35. $iParentPid = (int)$aData[$CNF['FIELD_PARENT']];
  36. if($iParentPid == 0)
  37. return false;
  38. $aParent = $this->_oDb->getContentInfoByProfileId($iParentPid);
  39. if(empty($aParent) || !is_array($aParent) || $aParent[$CNF['FIELD_STATUS']] != 'active' || $aParent[$CNF['FIELD_STATUS_ADMIN']] != 'active')
  40. return false;
  41. if(!isset($aParams['template']))
  42. $aParams['template'] = 'unit_wo_cover';
  43. return $this->parseHtmlByName('entry-parent.html', [
  44. 'content' => $this->getBrowseQuick([$aData[$CNF['FIELD_PARENT']]], $aParams['template'])
  45. ]);
  46. }
  47. public function entryRating($aData)
  48. {
  49. $CNF = &$this->getModule()->_oConfig->CNF;
  50. $sVotes = '';
  51. if(($oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_STARS'], $aData['id']))) {
  52. $sVotes = $oVotes->getElementBlock(['show_counter' => true, 'show_legend' => true]);
  53. if(!empty($sVotes))
  54. $sVotes = $this->parseHtmlByName('entry-rating.html', [
  55. 'content' => $sVotes,
  56. ]);
  57. }
  58. return $sVotes;
  59. }
  60. protected function _getBrowsingFiltersContent($aParams)
  61. {
  62. $sModule = $this->_oConfig->getName();
  63. $sJsObject = $this->_oConfig->getJsObject('main');
  64. $sForm = $sModule . '_filters_' . $aParams['mode'];
  65. $aForm = [
  66. 'form_attrs' => [
  67. 'id' => $sForm,
  68. 'name' => $sForm,
  69. 'action' => ''
  70. ],
  71. 'params' => [
  72. 'db' => [
  73. 'table' => '',
  74. 'key' => '',
  75. 'uri' => '',
  76. 'uri_title' => '',
  77. 'submit_name' => ''
  78. ],
  79. 'browse' => $aParams,
  80. 'module' => $sModule,
  81. 'object' => $sModule . '_filters',
  82. 'display' => $sModule . '_filters_apply',
  83. 'view_mode' => 0,
  84. ],
  85. 'inputs' => [
  86. 'controls' => [
  87. 'name' => 'controls',
  88. 'type' => 'input_set',
  89. [
  90. 'name' => 'apply',
  91. 'type' => 'button',
  92. 'value' => _t('_bx_spaces_form_filters_input_do_apply'),
  93. 'attrs' => ['onclick' => $sJsObject . '.applyBrowsingFilter(this, ' . json_encode($aParams) . ')']
  94. ], [
  95. 'name' => 'cancel',
  96. 'type' => 'button',
  97. 'value' => _t('_Cancel'),
  98. 'attrs' => [
  99. 'class' => 'bx-def-margin-sec-left',
  100. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()"
  101. ]
  102. ],
  103. ],
  104. ]
  105. ];
  106. $oForm = new BxTemplFormView($aForm);
  107. if($this->_bIsApi)
  108. return [
  109. 'name' => $oForm->getName(),
  110. 'data' => $oForm->getCodeAPI()
  111. ];
  112. $sIncludes = '';
  113. $sIncludes .= $this->addCss(['filters.css'], true);
  114. return $sIncludes . $oForm->getCode(true);
  115. }
  116. private function getBrowseQuick($aProfiles, $sTemplate = 'unit_wo_cover')
  117. {
  118. $sRv = '';
  119. foreach ($aProfiles as $iProfileId) {
  120. $oProfile = BxDolProfile::getInstance($iProfileId);
  121. if(!$oProfile)
  122. continue;
  123. $sRv .= $oProfile->getUnit(false, array('template' => $sTemplate));
  124. }
  125. return $sRv;
  126. }
  127. }
  128. /** @} */