BxEventsModule.php 23 KB

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