BxEventsTemplate.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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, 'order_by' => $this->_bIsApi ? 'date_start' : '']);
  25. if(empty($aSessions) || !is_array($aSessions))
  26. return '';
  27. $aTmplVarsSession = [];
  28. foreach($aSessions as $aSession) {
  29. $aTmplVarsSession[] = [
  30. 'title' => bx_process_output($aSession['title']),
  31. 'description' => bx_process_output($aSession['description'], BX_DATA_HTML),
  32. 'date_start' => $this->_bIsApi ? $aSession['date_start'] : bx_time_js($aSession['date_start'], BX_FORMAT_DATE_TIME, true),
  33. 'date_end' => $this->_bIsApi ? $aSession['date_end'] : bx_time_js($aSession['date_end'], BX_FORMAT_DATE_TIME, true),
  34. ];
  35. }
  36. if($this->_bIsApi)
  37. return [bx_api_get_block('simple_list', $aTmplVarsSession)];
  38. return $this->parseHtmlByName('entry-sessions.html', [
  39. 'bx_repeat:sessions' => $aTmplVarsSession
  40. ]);
  41. }
  42. function unitVars ($aData, $isCheckPrivateContent = true, $mixedTemplate = false, $aParams = array())
  43. {
  44. $aVars = parent::unitVars ($aData, $isCheckPrivateContent, $mixedTemplate, $aParams);
  45. $CNF = &$this->_oConfig->CNF;
  46. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  47. $aContentInfo = $this->getModule()->_oDb->getContentInfoById($aData[$CNF['FIELD_ID']]);
  48. $oDateStart = date_create('@' . $aContentInfo['date_start']);
  49. if ($oDateStart)
  50. $oDateStart->setTimezone(new DateTimeZone($aContentInfo['timezone'] ? $aContentInfo['timezone'] : 'UTC'));
  51. $oDateEnd = date_create('@' . $aContentInfo['date_end']);
  52. if ($oDateEnd)
  53. $oDateEnd->setTimezone(new DateTimeZone($aContentInfo['timezone'] ? $aContentInfo['timezone'] : 'UTC'));
  54. $isPublic = CHECK_ACTION_RESULT_ALLOWED === $this->getModule()->checkAllowedView($aData) || $oPrivacy->isPartiallyVisible($aData[$CNF['FIELD_ALLOW_VIEW_TO']]);
  55. if ($isPublic) {
  56. $aVars['bx_if:info']['content']['members'] = $oDateStart->format(getParam($CNF['PARAM_FORMAT_DATE']));
  57. }
  58. return array_merge($aVars, array(
  59. 'date_start' => $aData['date_start'] ? $aData['date_start'] : '',
  60. 'date_start_f' => $oDateStart ? bx_time_js($oDateStart->getTimestamp(), BX_FORMAT_DATE_TIME, true) : '',
  61. 'date_end' => $aData['date_end'] ? $aData['date_end'] : '',
  62. 'date_end_f' => $oDateEnd ? bx_time_js($oDateEnd->getTimestamp(), BX_FORMAT_DATE_TIME, true) : '',
  63. ));
  64. }
  65. protected function _getBrowsingFiltersContent($aParams)
  66. {
  67. $sModule = $this->_oConfig->getName();
  68. $sJsObject = $this->_oConfig->getJsObject('main');
  69. $aForm = [
  70. 'form_attrs' => [
  71. 'id' => $sModule . '_filters_' . $aParams['mode'],
  72. 'action' => ''
  73. ],
  74. 'params' => [
  75. 'db' => [
  76. 'table' => '',
  77. 'key' => '',
  78. 'uri' => '',
  79. 'uri_title' => '',
  80. 'submit_name' => ''
  81. ],
  82. 'module' => $sModule,
  83. 'object' => $sModule . '_filters',
  84. 'display' => $sModule . '_filters_apply',
  85. 'view_mode' => 0,
  86. ],
  87. 'inputs' => [
  88. 'by_location' => [
  89. 'name' => 'by_location',
  90. 'type' => 'location',
  91. 'caption' => _t('_bx_events_form_filters_input_by_location'),
  92. 'manual_input' => true,
  93. 'minimized' => true
  94. ],
  95. 'by_date' => [
  96. 'name' => 'by_date',
  97. 'type' => 'radio_set',
  98. 'caption' => _t('_bx_events_form_filters_input_by_date'),
  99. 'values' => [
  100. ['key' => 'all', 'value' => _t('_bx_events_form_filters_input_by_date_all')],
  101. ['key' => 'today', 'value' => _t('_bx_events_form_filters_input_by_date_today')],
  102. ['key' => 'tomorrow', 'value' => _t('_bx_events_form_filters_input_by_date_tomorrow')],
  103. ['key' => 'weekend', 'value' => _t('_bx_events_form_filters_input_by_date_weekend')],
  104. ['key' => 'this_week', 'value' => _t('_bx_events_form_filters_input_by_date_this_week')],
  105. ['key' => 'next_week', 'value' => _t('_bx_events_form_filters_input_by_date_next_week')],
  106. ['key' => 'this_month', 'value' => _t('_bx_events_form_filters_input_by_date_this_month')],
  107. ['key' => 'date_range', 'value' => _t('_bx_events_form_filters_input_by_date_date_range')],
  108. ],
  109. 'value' => 'all',
  110. 'attrs' => ['onchange' => $sJsObject . '.onChangeBrowsingFiltersByDate(this)'],
  111. 'dv_thd' => 1
  112. ],
  113. 'date_start' => [
  114. 'name' => 'date_start',
  115. 'type' => 'datepicker',
  116. 'tr_attrs' => ['class' => 'date-range date-start', 'style' => 'display:none']
  117. ],
  118. 'date_end' => [
  119. 'name' => 'date_end',
  120. 'type' => 'datepicker',
  121. 'tr_attrs' => ['class' => 'date-range date-end', 'style' => 'display:none']
  122. ],
  123. 'timezone' => [
  124. 'name' => 'timezone',
  125. 'type' => 'hidden',
  126. 'value' => ''
  127. ],
  128. 'controls' => [
  129. 'name' => 'controls',
  130. 'type' => 'input_set',
  131. [
  132. 'name' => 'apply',
  133. 'type' => 'button',
  134. 'value' => _t('_bx_events_form_filters_input_do_apply'),
  135. 'attrs' => ['onclick' => $sJsObject . '.applyBrowsingFilter(this, ' . json_encode($aParams) . ')']
  136. ], [
  137. 'name' => 'cancel',
  138. 'type' => 'button',
  139. 'value' => _t('_Cancel'),
  140. 'attrs' => [
  141. 'class' => 'bx-def-margin-sec-left',
  142. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()"
  143. ]
  144. ],
  145. ],
  146. ]
  147. ];
  148. $oForm = new BxTemplFormView($aForm);
  149. if($this->_bIsApi)
  150. return $oForm->getCodeAPI();
  151. $sIncludes = '';
  152. $sIncludes .= $this->addCss(['filters.css'], true);
  153. $sIncludes .= $this->addJs(['moment-timezone-with-data-1970-2030.min.js'], true);
  154. return $sIncludes . $oForm->getCode(true);
  155. }
  156. }
  157. /** @} */