BxEventsTemplate.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 Events Events
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /*
  12. * Groups module representation.
  13. */
  14. class BxEventsTemplate extends BxBaseModGroupsTemplate
  15. {
  16. function __construct(&$oConfig, &$oDb)
  17. {
  18. $this->MODULE = 'bx_events';
  19. parent::__construct($oConfig, $oDb);
  20. }
  21. public function getBlockSessions($iContentId)
  22. {
  23. $CNF = &$this->_oConfig->CNF;
  24. $aSessions = $this->_oDb->getSessions(['sample' => 'event_id', 'event_id' => $iContentId]);
  25. if(empty($aSessions) || !is_array($aSessions))
  26. return '';
  27. $sFormatDateTime = getParam($CNF['PARAM_FORMAT_DATETIME']);
  28. $sFormatDate = getParam($CNF['PARAM_FORMAT_DATE']);
  29. $sFormatTime = getParam($CNF['PARAM_FORMAT_TIME']);
  30. $aTmplVarsSession = [];
  31. foreach($aSessions as $aSession) {
  32. $sDate = '';
  33. if(date('d', $aSession['date_start']) == date('d', $aSession['date_end']))
  34. $sDate = date($sFormatDate, $aSession['date_start']) . ' ' . date($sFormatTime, $aSession['date_start']) . ' - ' . date($sFormatTime, $aSession['date_end']);
  35. else
  36. $sDate = date($sFormatDateTime, $aSession['date_start']) . ' - ' . date($sFormatDateTime, $aSession['date_end']);
  37. $aTmplVarsSession[] = [
  38. 'title' => bx_process_output($aSession['title']),
  39. 'date_time' => $sDate,
  40. ];
  41. }
  42. return $this->parseHtmlByName('entry-sessions.html', [
  43. 'bx_repeat:sessions' => $aTmplVarsSession
  44. ]);
  45. }
  46. function unitVars ($aData, $isCheckPrivateContent = true, $mixedTemplate = false, $aParams = array())
  47. {
  48. $aVars = parent::unitVars ($aData, $isCheckPrivateContent, $mixedTemplate, $aParams);
  49. $CNF = &$this->_oConfig->CNF;
  50. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  51. $aContentInfo = $this->getModule()->_oDb->getContentInfoById($aData[$CNF['FIELD_ID']]);
  52. $oDateStart = date_create('@' . $aContentInfo['date_start']);
  53. if ($oDateStart)
  54. $oDateStart->setTimezone(new DateTimeZone($aContentInfo['timezone'] ? $aContentInfo['timezone'] : 'UTC'));
  55. $oDateEnd = date_create('@' . $aContentInfo['date_end']);
  56. if ($oDateEnd)
  57. $oDateEnd->setTimezone(new DateTimeZone($aContentInfo['timezone'] ? $aContentInfo['timezone'] : 'UTC'));
  58. $isPublic = CHECK_ACTION_RESULT_ALLOWED === $this->getModule()->checkAllowedView($aData) || $oPrivacy->isPartiallyVisible($aData[$CNF['FIELD_ALLOW_VIEW_TO']]);
  59. if ($isPublic) {
  60. $aVars['bx_if:info']['content']['members'] = $oDateStart->format(getParam($CNF['PARAM_FORMAT_DATE']));
  61. }
  62. return array_merge($aVars, array(
  63. 'date_start' => $aData['date_start'] ? $aData['date_start'] : '',
  64. 'date_start_f' => $oDateStart ? bx_time_js($oDateStart->getTimestamp(), BX_FORMAT_DATE_TIME, true) : '',
  65. 'date_end' => $aData['date_end'] ? $aData['date_end'] : '',
  66. 'date_end_f' => $oDateEnd ? bx_time_js($oDateEnd->getTimestamp(), BX_FORMAT_DATE_TIME, true) : '',
  67. ));
  68. }
  69. protected function _getBrowsingFiltersContent($aParams)
  70. {
  71. $sJsObject = $this->_oConfig->getJsObject('main');
  72. $sMode = $aParams['mode'];
  73. $aForm = [
  74. 'inputs' => [
  75. 'by_date' => [
  76. 'name' => 'by_date',
  77. 'type' => 'radio_set',
  78. 'caption' => _t('_bx_events_form_filters_input_by_date'),
  79. 'values' => [
  80. ['key' => 'all', 'value' => _t('_bx_events_form_filters_input_by_date_all')],
  81. ['key' => 'today', 'value' => _t('_bx_events_form_filters_input_by_date_today')],
  82. ['key' => 'tomorrow', 'value' => _t('_bx_events_form_filters_input_by_date_tomorrow')],
  83. ['key' => 'weekend', 'value' => _t('_bx_events_form_filters_input_by_date_weekend')],
  84. ['key' => 'this_week', 'value' => _t('_bx_events_form_filters_input_by_date_this_week')],
  85. ['key' => 'next_week', 'value' => _t('_bx_events_form_filters_input_by_date_next_week')],
  86. ['key' => 'this_month', 'value' => _t('_bx_events_form_filters_input_by_date_this_month')],
  87. ['key' => 'date_range', 'value' => _t('_bx_events_form_filters_input_by_date_date_range')],
  88. ],
  89. 'value' => 'all',
  90. 'attrs' => ['onchange' => $sJsObject . '.onChangeBrowsingFiltersByDate(this)'],
  91. 'dv_thd' => 1
  92. ],
  93. 'date_start' => [
  94. 'name' => 'date_start',
  95. 'type' => 'datepicker',
  96. 'tr_attrs' => ['class' => 'date-range date-start', 'style' => 'display:none']
  97. ],
  98. 'date_end' => [
  99. 'name' => 'date_end',
  100. 'type' => 'datepicker',
  101. 'tr_attrs' => ['class' => 'date-range date-end', 'style' => 'display:none']
  102. ],
  103. 'controls' => [
  104. 'name' => 'controls',
  105. 'type' => 'input_set',
  106. [
  107. 'name' => 'apply',
  108. 'type' => 'button',
  109. 'value' => _t('_bx_events_form_filters_input_do_apply'),
  110. 'attrs' => ['onclick' => $sJsObject . '.applyBrowsingFilter(this, ' . json_encode($aParams) . ')']
  111. ], [
  112. 'name' => 'cancel',
  113. 'type' => 'button',
  114. 'value' => _t('_Cancel'),
  115. 'attrs' => [
  116. 'class' => 'bx-def-margin-sec-left',
  117. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()"
  118. ]
  119. ],
  120. ],
  121. ]
  122. ];
  123. $oForm = new BxTemplFormView($aForm);
  124. return $oForm->getCode(true);
  125. }
  126. }
  127. /** @} */