BxEventsModule.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  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. use Spatie\CalendarLinks\Link;
  12. /**
  13. * Events profiles module.
  14. */
  15. class BxEventsModule extends BxBaseModGroupsModule implements iBxDolCalendarService
  16. {
  17. function __construct(&$aModule)
  18. {
  19. parent::__construct($aModule);
  20. $CNF = &$this->_oConfig->CNF;
  21. $this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
  22. $CNF['FIELD_TIMEZONE'],
  23. $CNF['FIELD_JOIN_CONFIRMATION'],
  24. $CNF['FIELD_REMINDER']
  25. ));
  26. }
  27. public function actionCalendarSync($iContentId = 0)
  28. {
  29. $aContentInfo = (int)$iContentId ? $this->_oDb->getContentInfoById((int)$iContentId) : null;
  30. if (!$aContentInfo) {
  31. $this->_oTemplate->displayPageNotFound();
  32. exit;
  33. }
  34. if (CHECK_ACTION_RESULT_ALLOWED !== $this->checkAllowedView($aContentInfo)) {
  35. $this->_oTemplate->displayAccessDenied();
  36. exit;
  37. }
  38. $CNF = $this->_oConfig->CNF;
  39. if (!isset($aContentInfo['date_start']) || !$aContentInfo['date_start'] || !isset($aContentInfo['date_end']) || !$aContentInfo['date_end'] || !$aContentInfo[$CNF['FIELD_TIMEZONE']] || empty($CNF['OBJECT_METATAGS'])) {
  40. $this->_oTemplate->displayPageNotFound();
  41. exit;
  42. }
  43. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  44. $sLocation = $oMetatags && $oMetatags->locationsIsEnabled() ? $oMetatags->locationsString($aContentInfo[$CNF['FIELD_ID']], false) : '';
  45. $oDateStart = new DateTime('@' . $aContentInfo['date_start']);
  46. $oDateEnd = new DateTime('@' . ($aContentInfo['date_end'] > $aContentInfo['repeat_stop'] ? $aContentInfo['date_end'] : $aContentInfo['repeat_stop']));
  47. $oTz = new DateTimeZone($aContentInfo[$CNF['FIELD_TIMEZONE']]);
  48. $oDateStart->setTimezone($oTz);
  49. $oDateEnd->setTimezone($oTz);
  50. $oICalLink = $oDateStart && $oDateEnd ? Link::create(
  51. $aContentInfo[$CNF['FIELD_TITLE']],
  52. $oDateStart,
  53. $oDateEnd
  54. ) : null;
  55. if ($sLocation)
  56. $oICalLink->address($sLocation);
  57. $s = $oICalLink->ics();
  58. if (!preg_match('/^data:([a-zA-Z0-9\/]+);charset=[a-zA-Z0-9]+;base64,(.*)$/', $s, $m)) {
  59. $this->_oTemplate->displayErrorOccured();
  60. exit;
  61. }
  62. header('Content-type: ' . $m[1] . '; charset=utf-8');
  63. header('Content-Disposition: inline; filename="event.ics"');
  64. echo base64_decode($m[2]);
  65. }
  66. public function actionCalendarData()
  67. {
  68. // check permissions
  69. $aSQLPart = array();
  70. $iContentId = (int)bx_get('event');
  71. $iContextId = (int)bx_get('context_id');
  72. if ($iContentId) {
  73. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  74. if (CHECK_ACTION_RESULT_ALLOWED !== $this->checkAllowedView($aContentInfo)) {
  75. $this->_oTemplate->displayAccessDenied();
  76. exit;
  77. }
  78. $aSQLPart = array();
  79. }
  80. else {
  81. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  82. if($iContextId){
  83. if (!$this->serviceIsEnableForContext($iContextId)){
  84. exit;
  85. }
  86. else{
  87. $aSQLPart = $oPrivacy ? $oPrivacy->getContentByGroupAsSQLPart(- $iContextId) : array();
  88. }
  89. }
  90. else{
  91. $aSQLPart = $oPrivacy ? $oPrivacy->getContentPublicAsSQLPart(0, $oPrivacy->getPartiallyVisiblePrivacyGroups()) : array();
  92. }
  93. }
  94. // get entries
  95. $aEntries = $this->_oDb->getEntriesByDate(bx_get('start'), bx_get('end'), bx_get('event'), $aSQLPart);
  96. bx_alert($this->getName(), 'calendar_data', 0, false, array(
  97. 'event' => $iContentId,
  98. 'context_id' => $iContextId,
  99. 'start' => bx_get('start'),
  100. 'end' => bx_get('end'),
  101. 'sql_part' => &$aSQLPart,
  102. 'data' => &$aEntries,
  103. ));
  104. header('Content-Type: application/json; charset=utf-8');
  105. echo json_encode($aEntries);
  106. }
  107. public function serviceIsIcalExportAvaliable($iContentId)
  108. {
  109. return true;
  110. $aContentInfo = $iContentId ? $this->_oDb->getContentInfoById($iContentId) : false;
  111. if ($aContentInfo)
  112. return false;
  113. return $aContentInfo['date_start'] && $aContentInfo['date_end'];
  114. }
  115. public function serviceGetCalendarEntries($iProfileId)
  116. {
  117. $CNF = &$this->_oConfig->CNF;
  118. $oConn = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  119. $aData = $oConn->getConnectedContent($iProfileId);
  120. $aData2 = array(0);
  121. foreach($aData as $iProfileId2){
  122. $oProfile = BxDolProfile::getInstance($iProfileId2);
  123. array_push($aData2, $oProfile->getContentId());
  124. }
  125. $aSQLPart['where'] = " AND `bx_events_data`.`id` IN(" . implode(',', $aData2) . ")";
  126. return $this->_oDb->getEntriesByDate(bx_get('start'), bx_get('end'), null, $aSQLPart);
  127. }
  128. public function serviceGetSafeServices()
  129. {
  130. $a = parent::serviceGetSafeServices();
  131. return array_merge($a, array (
  132. 'BrowsePastProfiles' => '',
  133. 'Calendar' => '',
  134. ));
  135. }
  136. /**
  137. * @page service Service Calls
  138. * @section bx_events Events
  139. * @subsection bx_events-browse Browse
  140. * @subsubsection bx_events-browse_upcoming_profiles browse_upcoming_profiles
  141. *
  142. * @code bx_srv('bx_events', 'browse_upcoming_profiles', [...]); @endcode
  143. *
  144. * Browse upcoming events
  145. *
  146. * @param $bDisplayEmptyMsg show "empty" message or not if nothing found
  147. * @param $bAjaxPaginate use AJAX paginate or not
  148. *
  149. * @see BxEventsModule::serviceBrowseUpcomingProfiles
  150. */
  151. /**
  152. * @ref bx_events-browse_upcoming_profiles "browse_upcoming_profiles"
  153. */
  154. public function serviceBrowseUpcomingProfiles ($aParams = false)
  155. {
  156. $bDisplayEmptyMsg = false;
  157. if(isset($aParams['empty_message'])) {
  158. $bDisplayEmptyMsg = (bool)$aParams['empty_message'];
  159. unset($aParams['empty_message']);
  160. }
  161. $bAjaxPaginate = true;
  162. if(isset($aParams['ajax_paginate'])) {
  163. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  164. unset($aParams['ajax_paginate']);
  165. }
  166. return $this->_serviceBrowse ('upcoming', $aParams, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  167. }
  168. /**
  169. * @page service Service Calls
  170. * @section bx_events Events
  171. * @subsection bx_events-browse Browse
  172. * @subsubsection bx_events-browse_upcoming_connected_profiles browse_upcoming_connected_profiles
  173. *
  174. * @code bx_srv('bx_events', 'browse_upcoming_connected_profiles', [...]); @endcode
  175. *
  176. * Browse upcoming connected (followed) events
  177. *
  178. * @param $bDisplayEmptyMsg show "empty" message or not if nothing found
  179. * @param $bAjaxPaginate use AJAX paginate or not
  180. *
  181. * @see BxEventsModule::serviceBrowseUpcomingConnectedProfiles
  182. */
  183. /**
  184. * @ref bx_events-browse_upcoming_connected_profiles "browse_upcoming_connected_profiles"
  185. */
  186. public function serviceBrowseUpcomingConnectedProfiles ($aParams = false)
  187. {
  188. if(!is_array($aParams) || empty($aParams['object']) || empty($aParams['profile']))
  189. return '';
  190. $bDisplayEmptyMsg = false;
  191. if(isset($aParams['empty_message'])) {
  192. $bDisplayEmptyMsg = (bool)$aParams['empty_message'];
  193. unset($aParams['empty_message']);
  194. }
  195. $bAjaxPaginate = true;
  196. if(isset($aParams['ajax_paginate'])) {
  197. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  198. unset($aParams['ajax_paginate']);
  199. }
  200. $aDefaults = array(
  201. 'type' => 'content',
  202. 'mutual' => false,
  203. 'profile2' => 0
  204. );
  205. return $this->_serviceBrowse ('upcoming_connected', array_merge($aDefaults, $aParams), BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  206. }
  207. /**
  208. * @page service Service Calls
  209. * @section bx_events Events
  210. * @subsection bx_events-browse Browse
  211. * @subsubsection bx_events-browse_past_profiles browse_past_profiles
  212. *
  213. * @code bx_srv('bx_events', 'browse_past_profiles', [...]); @endcode
  214. *
  215. * Browse past events
  216. *
  217. * @param $bDisplayEmptyMsg show "empty" message or not if nothing found
  218. * @param $bAjaxPaginate use AJAX paginate or not
  219. *
  220. * @see BxEventsModule::serviceBrowsePastProfiles
  221. */
  222. /**
  223. * @ref bx_events-browse_past_profiles "browse_past_profiles"
  224. */
  225. public function serviceBrowsePastProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = true)
  226. {
  227. return $this->_serviceBrowse ('past', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  228. }
  229. /**
  230. * @page service Service Calls
  231. * @section bx_events Events
  232. * @subsection bx_events-browse Browse
  233. * @subsubsection bx_events-browse_past_profiles browse_past_profiles_by_params
  234. *
  235. * @code bx_srv('bx_events', 'browse_past_profiles_by_params', [...]); @endcode
  236. *
  237. * Browse past events
  238. *
  239. * @param $aParams array with all parameters
  240. *
  241. * @see BxEventsModule::serviceBrowsePastProfilesByParams
  242. */
  243. /**
  244. * @ref bx_events-browse_past_profiles_by_params "browse_past_profiles_by_params"
  245. */
  246. public function serviceBrowsePastProfilesByParams ($aParams)
  247. {
  248. $bDisplayEmptyMsg = false;
  249. if(isset($aParams['empty_message'])) {
  250. $bDisplayEmptyMsg = (bool)$aParams['empty_message'];
  251. unset($aParams['empty_message']);
  252. }
  253. $bAjaxPaginate = true;
  254. if(isset($aParams['ajax_paginate'])) {
  255. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  256. unset($aParams['ajax_paginate']);
  257. }
  258. return $this->_serviceBrowse ('past', $aParams, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  259. }
  260. /**
  261. * @page service Service Calls
  262. * @section bx_events Events
  263. * @subsection bx_events-page_blocks Page Blocks
  264. * @subsubsection bx_events-calendar calendar
  265. *
  266. * @code bx_srv('bx_events', 'calendar', [...]); @endcode
  267. *
  268. * Shows event or events calendar
  269. *
  270. * @param $aData additional data to point which events to show, leave empty to show all events, specify event's ID in 'event' array key to show calendar for one event only, specify context's ID in 'context_id' array key to show calendar for one context events only. If only one event is specified then it will show calendar only if it's repeating event.
  271. * @param $sTemplate template to use to show calendar, or leave empty for default template, possible options: calendar.html, calendar_compact.html
  272. * @return HTML string with calendar to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML. On error empty string is returned.
  273. *
  274. * @see BxEventsModule::serviceCalendar
  275. */
  276. /**
  277. * @ref bx_events-calendar "calendar"
  278. */
  279. public function serviceCalendar($aData = array(), $sTemplate = 'calendar.html')
  280. {
  281. if(isset($aData['context_id']) && !$this->serviceIsEnableForContext($aData['context_id']))
  282. return '';
  283. $oCalendar = new BxTemplCalendar([
  284. 'eventSources' => [
  285. bx_append_url_params(BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'calendar_data', $aData),
  286. ],
  287. ], $this->_oTemplate);
  288. $this->_oTemplate->addCss(['main.css']);
  289. return $oCalendar->display($sTemplate);
  290. }
  291. /**
  292. * @page service Service Calls
  293. * @section bx_events Events
  294. * @subsection bx_events-other Other
  295. * @subsubsection bx_events-process_reminders process_reminders
  296. *
  297. * @code bx_srv('bx_events', 'process_reminders'); @endcode
  298. *
  299. * Send remiders to event's participants.
  300. *
  301. * It must be processed once every hour for the proper processing.
  302. * @return nothing
  303. *
  304. * @see BxEventsModule::serviceProcessReminders
  305. */
  306. /**
  307. * @ref bx_events-process_reminders "process_reminders"
  308. */
  309. public function serviceProcessReminders()
  310. {
  311. $CNF = &$this->_oConfig->CNF;
  312. $iNow = time();
  313. $bUseIn = $this->_oConfig->isInternalNotifications();
  314. $sModule = $this->getName();
  315. // get all events for today and tomorrow, since the max reminder is 24 hours
  316. $aEntries = $this->_oDb->getEntriesByDate('@' . time(), '@' . (time() + 3600 * getParam('bx_events_reminder_interval')));
  317. foreach($aEntries as $aEntry) {
  318. $aReminders = $bUseIn ? [$aEntry['reminder']] : [24, 1];
  319. if(!$aReminders)
  320. continue;
  321. $oEventProfile = BxDolProfile::getInstanceByContentAndType($aEntry[$CNF['FIELD_ID']], $sModule);
  322. if(!$oEventProfile)
  323. continue;
  324. $iEventProfileId = $oEventProfile->id();
  325. foreach($aReminders as $iReminder) {
  326. $iTimestamp = $aEntry['start_utc'] - (3600 * $iReminder);
  327. if($iNow <= ($iTimestamp - 3600) || $iNow >= $iTimestamp)
  328. continue;
  329. if($bUseIn)
  330. $this->sendReminders($aEntry);
  331. bx_alert($sModule, 'reminder', $aEntry[$CNF['FIELD_ID']], $iEventProfileId, array(
  332. 'object_author_id' => $iEventProfileId,
  333. 'reminder' => $iReminder
  334. ));
  335. }
  336. }
  337. }
  338. public function serviceGetNotificationsData()
  339. {
  340. $CNF = &$this->_oConfig->CNF;
  341. $aResults = parent::serviceGetNotificationsData();
  342. $sModule = $this->_aModule['name'];
  343. $aSettingsTypes = ['follow_context'];
  344. $aResults['handlers'] = array_merge($aResults['handlers'], [
  345. ['group' => $sModule . '_reminder', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'reminder', 'module_name' => $sModule, 'module_method' => 'get_notifications_reminder', 'module_class' => 'Module', 'module_event_privacy' => $CNF['OBJECT_PRIVACY_VIEW_NOTIFICATION_EVENT']],
  346. ]);
  347. $aResults['settings'] = array_merge($aResults['settings'], [
  348. ['group' => 'reminder', 'unit' => $sModule, 'action' => 'reminder', 'types' => $aSettingsTypes],
  349. ]);
  350. $aResults['alerts'] = array_merge($aResults['alerts'], [
  351. ['unit' => $sModule, 'action' => 'reminder'],
  352. ]);
  353. return $aResults;
  354. }
  355. public function serviceGetNotificationsInsertData($oAlert, $aHandler, $aDataItems)
  356. {
  357. if($oAlert->sAction != 'reminder' || empty($aDataItems) || !is_array($aDataItems) || empty($oAlert->aExtras['reminder']))
  358. return $aDataItems;
  359. foreach($aDataItems as $iIndex => $aDataItem) {
  360. $aContent = [];
  361. if(!empty($aDataItem['content']))
  362. $aContent = unserialize($aDataItem['content']);
  363. $aContent['reminder'] = (int)$oAlert->aExtras['reminder'];
  364. $aDataItems[$iIndex]['content'] = serialize($aContent);
  365. }
  366. return $aDataItems;
  367. }
  368. public function serviceGetNotificationsReminder($aEvent)
  369. {
  370. $CNF = &$this->_oConfig->CNF;
  371. if(!isset($aEvent['content']['reminder']))
  372. return [];
  373. $iContentId = (int)$aEvent['object_id'];
  374. $oEventProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  375. if(!$oEventProfile)
  376. return [];
  377. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  378. if(empty($aContentInfo) || !is_array($aContentInfo))
  379. return [];
  380. return [
  381. 'entry_sample' => $CNF['T']['txt_sample_single'],
  382. 'entry_url' => bx_absolute_url(str_replace(BX_DOL_URL_ROOT, '', $oEventProfile->getUrl()), '{bx_url_root}'),
  383. 'entry_caption' => $oEventProfile->getDisplayName(),
  384. 'entry_author' => $oEventProfile->id(),
  385. 'lang_key' => '_bx_events_txt_ntfs_reminder_' . $aEvent['content']['reminder']
  386. ];
  387. }
  388. /**
  389. * @page service Service Calls
  390. * @section bx_events Events
  391. * @subsection bx_events-internal Internal
  392. * @subsubsection bx_events-get_timeline_post get_timeline_post
  393. *
  394. * @code bx_srv('bx_events', 'get_timeline_post', [...]); @endcode
  395. *
  396. * Get Timeline post. It's needed for Timeline module.
  397. *
  398. * @param $aEvent timeline event array from Timeline module
  399. * @return array in special format which is needed specifically for Timeline module to display the data.
  400. *
  401. * @see BxEventsModule::serviceGetTimelinePost
  402. */
  403. /**
  404. * @ref bx_events-get_timeline_post "get_timeline_post"
  405. */
  406. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  407. {
  408. $a = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  409. if($a === false)
  410. return false;
  411. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  412. if(empty($aContentInfo) || !is_array($aContentInfo))
  413. return $a;
  414. $CNF = $this->_oConfig->CNF;
  415. $oDateStart = date_create('@' . $aContentInfo['date_start']);
  416. if ($oDateStart)
  417. $oDateStart->setTimezone(new DateTimeZone($aContentInfo['timezone'] ? $aContentInfo['timezone'] : 'UTC'));
  418. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  419. $sLocationString = $oMetatags ? $oMetatags->locationsString($aContentInfo[$CNF['FIELD_ID']], false) : false;
  420. $a['content']['raw'] = $this->_oTemplate->parseHtmlByName('timeline_post.html', [
  421. 'title' => $a['content']['title'],
  422. 'title_attr' => bx_html_attribute($a['content']['title']),
  423. 'url' => $a['content']['url'],
  424. 'bx_if:date' => [
  425. 'condition' => $oDateStart,
  426. 'content' => [
  427. 'date' => $oDateStart ? bx_time_js($aContentInfo['date_start'], BX_FORMAT_DATE_TIME, true) : '',
  428. 'date_c' => $oDateStart->format('c'),
  429. ]],
  430. 'bx_if:location' => array(
  431. 'condition' => !!$sLocationString,
  432. 'content' => array('location' => $sLocationString),
  433. ),
  434. ]);
  435. return $a;
  436. }
  437. public function actionIntervals()
  438. {
  439. $sAction = bx_get('a');
  440. $sMethodName = 'subaction' . ucfirst($sAction);
  441. if (!method_exists($this, $sMethodName)) {
  442. $this->_oTemplate->pageNotFound();
  443. return;
  444. }
  445. $this->$sMethodName();
  446. }
  447. public function subactionRestore($iContentId = 0)
  448. {
  449. if (!$iContentId)
  450. $iContentId = (int)bx_get('c');
  451. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  452. if (
  453. ($aContentInfo && CHECK_ACTION_RESULT_ALLOWED !== $this->checkAllowedEdit ($aContentInfo))
  454. ||
  455. (!$aContentInfo && CHECK_ACTION_RESULT_ALLOWED !== $this->checkAllowedAdd ())
  456. ) {
  457. $this->_oTemplate->displayAccessDenied();
  458. exit;
  459. }
  460. $a = $this->_oDb->getIntervals($iContentId);
  461. foreach ($a as $iIntervalId => $r) {
  462. $a[$iIntervalId]['file_id'] = $r['interval_id'];
  463. $a[$iIntervalId]['repeat_stop'] = bx_process_output ($r['repeat_stop'], BX_DATA_DATE_TS);
  464. }
  465. if ('json' == bx_get('f')) {
  466. header('Content-type: text/html; charset=utf-8');
  467. echo json_encode($a);
  468. }
  469. }
  470. public function subactionDelete()
  471. {
  472. header('Content-type: text/html; charset=utf-8');
  473. $iIntervalId = (int)bx_get('id');
  474. if (!($aContentInfo = $this->_oDb->getContentInfoByIntervalId($iIntervalId))) {
  475. echo _t('_sys_request_page_not_found_cpt');
  476. }
  477. elseif (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedEdit ($aContentInfo))) {
  478. echo $sMsg;
  479. }
  480. elseif (!$this->_oDb->deleteIntervalById($iIntervalId)) {
  481. echo _t('_sys_txt_error_occured');
  482. }
  483. else {
  484. echo 'ok';
  485. }
  486. }
  487. public function checkAllowedIcalExport ($aDataEntry, $isPerformAction = false)
  488. {
  489. return $aDataEntry['date_start'] && $aDataEntry['date_end'] ? CHECK_ACTION_RESULT_ALLOWED : _t('_sys_txt_access_denied');
  490. }
  491. /**
  492. * Send reminder to event's paritcipants
  493. * @param $aContentInfo content info
  494. * @return number of sent reminders
  495. */
  496. protected function sendReminders($aContentInfo)
  497. {
  498. $CNF = $this->_oConfig->CNF;
  499. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  500. if (!$oConnection)
  501. return false;
  502. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aContentInfo[$CNF['FIELD_ID']], $this->getName());
  503. if (!$oGroupProfile)
  504. return false;
  505. $aParticipants = $oConnection->getConnectedInitiators($oGroupProfile->id(), true);
  506. if (!$aParticipants)
  507. return true;
  508. $oDateBegin = new DateTime();
  509. $oDateBegin->setTimestamp($aContentInfo['start_utc']);
  510. $oDateBegin->setTimezone(new DateTimeZone($aContentInfo['timezone'] ? $aContentInfo['timezone'] : 'UTC'));
  511. $sEntryBegin = $oDateBegin->format('r');
  512. $sEntryBeginShort = date(getParam('bx_events_short_date_format'), $oDateBegin->getTimestamp());
  513. $oDateBegin->setTimezone(new DateTimeZone('UTC'));
  514. $sEntryBeginUTC = $oDateBegin->format('c');
  515. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  516. $sLocationString = $oMetatags->locationsString($aContentInfo[$CNF['FIELD_ID']], false);
  517. $iCounter = 0;
  518. foreach ($aParticipants as $iProfileId) {
  519. $b = sendMailTemplate($CNF['EMAIL_REMINDER'], 0, $iProfileId, array(
  520. 'EntryUrl' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']])),
  521. 'EntryTitle' => $aContentInfo['title'],
  522. 'EntryBegin' => $sEntryBegin,
  523. 'EntryBeginShort' => $sEntryBeginShort,
  524. 'EntryBeginUTC' => $sEntryBeginUTC,
  525. 'EntryLocation' => $sLocationString ? _t('_bx_events_email_reminder_location', $sLocationString) : '',
  526. ), BX_EMAIL_NOTIFY);
  527. $iCounter += $b ? 1 : 0;
  528. }
  529. return $iCounter;
  530. }
  531. }
  532. /** @} */