event->name; switch ($eventName) { case 'OnAgendaBeforeRemove': $corePath = $modx->getOption('agenda.core_path', null, $modx->getOption('core_path') . 'components/agenda/'); $agenda = $modx->getService('agenda', 'Agenda', $corePath . 'model/agenda/', [ 'core_path' => $corePath ]); $eventId = $scriptProperties['id']; $className = $scriptProperties['className']; if (!$modx->loadClass('agenda.AgendaEvents', $agenda->getOption('modelPath'))) { $modx->log(xPDO::LOG_LEVEL_ERROR, 'Could not load AgendaEvents class!', '', 'AgendaCursusPreventRemove'); return; } if (!$modx->loadClass('agenda.AgendaEventDates', $agenda->getOption('modelPath'))) { $modx->log(xPDO::LOG_LEVEL_ERROR, 'Could not load AgendaEventDates class!', '', 'AgendaCursusPreventRemove'); return; } if ($eventId) { if ($className == 'AgendaEvents') { $c = $modx->newQuery('CursusEventParticipants'); $c->leftJoin('AgendaEventDates', 'AgendaEventDates', 'CursusEventParticipants.event_id = AgendaEventDates.id'); $c->where(['AgendaEventDates.event_id' => $eventId]); $count = $this->modx->getCount('CursusEventParticipants', $c); if ($count > 0) { $modx->event->_output = 'There are already repeating events booked for this event. Therefore, it is not possible to delete the event.'; } } elseif ($className == 'AgendaEventDates') { $participants = $modx->getObject('CursusEventParticipants', ['event_id' => $eventId]); if ($participants) { $modx->event->_output = 'The event repeat has already been booked. Therefore, it is not possible to delete it.'; } } } break; } return;