Skip to content

Commit

Permalink
Handle group classes in validator
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk committed May 9, 2024
1 parent 5ffd5b4 commit 1ac4f60
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
10 changes: 1 addition & 9 deletions src/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use DateTime;
use DateTimeZone;
use Iterator;
use JuniWalk\Calendar\Entity\Activity;
use JuniWalk\Calendar\Entity\Legend;
use JuniWalk\Calendar\Entity\Options;
use JuniWalk\Calendar\Enums\View;
Expand Down Expand Up @@ -327,14 +326,7 @@ private function fetchEvents(DateTime $start, DateTime $end, DateTimeZone $timeZ
$source = $sources[$event->getSource()];

try {
/** @var Activity */
$event = $validator->validate($event, $source);

if (isset($event->groupId)) {
$event->classNames[] = 'fc-group-'.$event->groupId;
}

$events[$key] = $event;
$events[$key] = $validator->validate($event, $source);

} catch (Throwable $e) {
Debugger::log($e);
Expand Down
7 changes: 6 additions & 1 deletion src/EventValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace JuniWalk\Calendar;

use DateTime;
use JuniWalk\Calendar\Entity\Activity;
use JuniWalk\Calendar\Enums\Day;
use JuniWalk\Calendar\Exceptions\EventInvalidException;
use Nette\Schema\Expect;
Expand Down Expand Up @@ -41,12 +42,16 @@ public function validate(Event $event, Source $source): object
$event->setEnd($end->modify('midnight next day'));
}

/** @var Event */
/** @var Activity */
$event = $this->processor->process(
$this->schema[$event::class],
$event->jsonSerialize(),
);

if (isset($event->groupId)) {
$event->classNames[] = 'fc-group-'.$event->groupId;
}

if ($event->getSource() <> $source->getName()) {
throw new EventInvalidException('Event\'s source property has to match its source name.');
}
Expand Down

0 comments on commit 1ac4f60

Please sign in to comment.