Installation
composer require edemy/agendabundle
Ensure eDemyFramework is installed as a dependency (this bundle is framework-specific).
Enable the Bundle
Add to config/bundles.php:
return [
// ...
Edemy\AgendaBundle\EdemyAgendaBundle::class => ['all' => true],
];
Basic Configuration Publish the default config:
php bin/console edemy:agenda:install
This creates a config/agenda.php with default settings (timezone, event types, etc.).
First Use Case: Creating an Event
Use the AgendaManager service in a controller:
use Edemy\AgendaBundle\Manager\AgendaManager;
class EventController extends AbstractController
{
public function createEvent(AgendaManager $agendaManager)
{
$event = $agendaManager->createEvent([
'title' => 'Team Meeting',
'start' => '2024-05-20T10:00:00',
'end' => '2024-05-20T11:00:00',
'type' => 'meeting',
]);
return $this->json($event);
}
}
Viewing Events
Use the AgendaListener to fetch events in templates:
{% for event in agenda.events %}
<div>{{ event.title }} ({{ event.start|date('Y-m-d H:i') }} - {{ event.end|date('H:i') }})</div>
{% endfor %}
Event CRUD Operations
AgendaManager::createEvent() with an associative array.AgendaManager::findEvent() and pass to updateEvent().AgendaManager::deleteEvent($eventId).Event Types and Categories
Define custom types in config/agenda.php:
'event_types' => [
'meeting' => ['label' => 'Meeting', 'color' => '#4CAF50'],
'task' => ['label' => 'Task', 'color' => '#2196F3'],
],
Use these in templates with Twig filters:
<span style="color: {{ event.type.color }}">{{ event.type.label }}</span>
Recurring Events Configure recurrence rules in the event array:
$event = $agendaManager->createEvent([
'title' => 'Weekly Sync',
'start' => '2024-05-20T09:00:00',
'end' => '2024-05-20T10:00:00',
'recurrence' => [
'frequency' => 'weekly',
'interval' => 1,
'end_date' => '2024-12-31',
],
]);
Integration with eDemy Framework
AgendaManager::getUserEvents($userId).$this->denyAccessUnlessGranted('ROLE_EDIT_AGENDA', $event);
API Endpoints Create a custom API controller to expose events:
class AgendaApiController extends AbstractController
{
public function getEvents(AgendaManager $agendaManager, Request $request)
{
$events = $agendaManager->getEvents(
$request->query->get('start'),
$request->query->get('end')
);
return $this->json($events);
}
}
Frontend Integration
Use the AgendaListener to pass events to Twig globally. For FullCalendar.js:
fetch('/api/agenda/events')
.then(response => response.json())
.then(events => {
calendar.addEventSource(events);
});
Command-Line Management Use the provided console commands:
# Clean expired events
php bin/console edemy:agenda:clean
# Export events to ICS
php bin/console edemy:agenda:export --user=1 --output=meeting.ics
Custom Event Fields
Extend the Event entity by overriding the bundle’s configuration:
# config/agenda.php
'event_fields' => [
'title',
'description',
'location', // Custom field
'priority', // Custom field
],
Notifications
Subscribe to the agenda.event.created event to trigger notifications:
use Edemy\AgendaBundle\Event\AgendaEvent;
$eventDispatcher->addListener('agenda.event.created', function (AgendaEvent $event) {
// Send email/notification
});
Timezone Mismatches
default_timezone in config/agenda.php to match your application’s timezone.$event->getStart()->setTimezone(new \DateTimeZone('UTC'))->format('c');
Recurrence Rule Quirks
spatie/calendar alongside it.php bin/console edemy:agenda:generate-recurrences --event=1
Database Schema Assumptions
edemy_agenda_events table. If you’ve customized the schema, override the AgendaManager to point to your table:
$agendaManager->setTableName('custom_agenda_events');
Caching Events
php bin/console cache:clear
Event Overlaps
if ($agendaManager->hasOverlappingEvents($newEvent)) {
throw new \RuntimeException('Event overlaps with existing events.');
}
Enable Verbose Logging
Set in config/agenda.php:
'debug' => true,
Logs will appear in var/log/dev.log.
Dump Event Data Use Laravel’s dumping tools:
\Symfony\Component\VarDumper\VarDumper::dump($agendaManager->getEvents());
Check Console Output
Run commands with -v for verbose output:
php bin/console edemy:agenda:clean -v
Custom Event Storage
Override the AgendaManager to use a custom repository:
$agendaManager->setRepository(new CustomAgendaRepository());
Event Subscribers
Extend the AgendaEvent class to add custom properties:
class CustomAgendaEvent extends \Edemy\AgendaBundle\Entity\Event
{
private $customField;
// Add getters/setters
}
Twig Extensions Add custom filters for event formatting:
$twig->addFilter(new \Twig\TwigFilter('format_event_time', function ($event) {
return $event->getStart()->format('g:i A');
}));
API Resources Use Laravel’s API Resources to transform events:
class EventResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->id,
'title' => $this->title,
'formatted_time' => $this->getFormattedTime(),
];
}
}
Testing
Mock the AgendaManager in tests:
$agendaManager = $this->createMock(AgendaManager::class);
$agendaManager->method('getEvents')->willReturn([$mockEvent]);
$this->app->instance(AgendaManager::class, $agendaManager);
How can I help you explore Laravel packages today?