Last active
October 22, 2025 10:21
-
-
Save jenswittmann/c03690fa8129c637c0a5df5d83d28a47 to your computer and use it in GitHub Desktop.
Prevents booked Cursus dates from being accidentally deleted via the Agenda CMP. See documentation: https://docs.treehillstudio.de/en/agenda/08_System_Events/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @package agenda | |
| * @subpackage plugin | |
| */ | |
| namespace TreehillStudio\Agenda\Plugins\Events; | |
| use TreehillStudio\Agenda\Agenda; | |
| use TreehillStudio\Agenda\Plugins\Plugin; | |
| use xPDO; | |
| use xPDOObject; | |
| /** | |
| * Skeleton class for OnAgendaBeforeRemove event | |
| */ | |
| class OnAgendaBeforeRemove extends Plugin | |
| { | |
| /** @var Agenda $agenda */ | |
| public $agenda; | |
| public function process() | |
| { | |
| $corePath = $this->modx->getOption('agenda.core_path', null, $this->modx->getOption('core_path') . 'components/agenda/'); | |
| $this->agenda = $this->modx->getService('agenda', Agenda::class, $corePath . 'model/agenda/', [ | |
| 'core_path' => $corePath | |
| ]); | |
| $eventId = $this->scriptProperties['id']; | |
| $className = $this->scriptProperties['className']; | |
| /** @var xPDOObject $object */ | |
| $object = &$this->scriptProperties['object']; | |
| if (!$this->modx->loadClass('agenda.AgendaEvents', $this->agenda->getOption('modelPath'))) { | |
| $this->modx->log(xPDO::LOG_LEVEL_ERROR, 'Could not load AgendaEvents class!', '', 'OnAgendaBeforeSave'); | |
| } else { | |
| $this->modx->loadClass('agenda.AgendaEvents', $this->agenda->getOption('modelPath')); | |
| } | |
| if ($eventId) { | |
| if ($className == 'AgendaEvents') { | |
| $c = $this->modx->newQuery('CursusEventParticipants'); | |
| $c->leftJoin('AgendaEventDates', 'AgendaEventDates', 'CursusEventParticipants.event_id = AgendaEventDates.id'); | |
| $c->where(['AgendaEventDates.event_id' => $eventId]); | |
| $participants = $this->modx->getCollection('CursusEventParticipants', $c); | |
| if (count($participants) > 0) { | |
| $this->modx->event->_output = 'Es wurden bereits Wiederholungen dieses Termins gebucht. Das komplette Löschen des Termins ist daher nicht möglich.'; | |
| } | |
| } | |
| if ($className == 'AgendaEventDates') { | |
| $participants = $this->modx->getObject('CursusEventParticipants', ['event_id' => $eventId]); | |
| if ($participants) { | |
| $this->modx->event->_output = 'Termin wurde bereits gebucht.'; | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment