Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Agendabundle Laravel Package

edemy/agendabundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require edemy/agendabundle
    

    Ensure eDemyFramework is installed as a dependency (this bundle is framework-specific).

  2. Enable the Bundle Add to config/bundles.php:

    return [
        // ...
        Edemy\AgendaBundle\EdemyAgendaBundle::class => ['all' => true],
    ];
    
  3. 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.).

  4. 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);
        }
    }
    
  5. 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 %}
    

Implementation Patterns

Core Workflows

  1. Event CRUD Operations

    • Create: Use AgendaManager::createEvent() with an associative array.
    • Update: Fetch via AgendaManager::findEvent() and pass to updateEvent().
    • Delete: AgendaManager::deleteEvent($eventId).
  2. 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>
    
  3. 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',
        ],
    ]);
    
  4. Integration with eDemy Framework

    • User-Specific Events: Use AgendaManager::getUserEvents($userId).
    • Permissions: Leverage eDemy’s security system to restrict event access:
      $this->denyAccessUnlessGranted('ROLE_EDIT_AGENDA', $event);
      
  5. 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);
        }
    }
    

Integration Tips

  1. 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);
        });
    
  2. 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
    
  3. 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
    ],
    
  4. 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
    });
    

Gotchas and Tips

Pitfalls

  1. Timezone Mismatches

    • Always set the default_timezone in config/agenda.php to match your application’s timezone.
    • Debug issues with:
      $event->getStart()->setTimezone(new \DateTimeZone('UTC'))->format('c');
      
  2. Recurrence Rule Quirks

    • The bundle uses a simplified recurrence system. For complex rules (e.g., "every other Tuesday"), consider using a library like spatie/calendar alongside it.
    • Test recurrence logic with:
      php bin/console edemy:agenda:generate-recurrences --event=1
      
  3. Database Schema Assumptions

    • The bundle assumes a edemy_agenda_events table. If you’ve customized the schema, override the AgendaManager to point to your table:
      $agendaManager->setTableName('custom_agenda_events');
      
  4. Caching Events

    • The bundle caches events by default. Clear the cache after bulk operations:
      php bin/console cache:clear
      
  5. Event Overlaps

    • The bundle does not validate overlaps by default. Add validation in your controller:
      if ($agendaManager->hasOverlappingEvents($newEvent)) {
          throw new \RuntimeException('Event overlaps with existing events.');
      }
      

Debugging Tips

  1. Enable Verbose Logging Set in config/agenda.php:

    'debug' => true,
    

    Logs will appear in var/log/dev.log.

  2. Dump Event Data Use Laravel’s dumping tools:

    \Symfony\Component\VarDumper\VarDumper::dump($agendaManager->getEvents());
    
  3. Check Console Output Run commands with -v for verbose output:

    php bin/console edemy:agenda:clean -v
    

Extension Points

  1. Custom Event Storage Override the AgendaManager to use a custom repository:

    $agendaManager->setRepository(new CustomAgendaRepository());
    
  2. Event Subscribers Extend the AgendaEvent class to add custom properties:

    class CustomAgendaEvent extends \Edemy\AgendaBundle\Entity\Event
    {
        private $customField;
    
        // Add getters/setters
    }
    
  3. 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');
    }));
    
  4. 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(),
            ];
        }
    }
    
  5. Testing Mock the AgendaManager in tests:

    $agendaManager = $this->createMock(AgendaManager::class);
    $agendaManager->method('getEvents')->willReturn([$mockEvent]);
    $this->app->instance(AgendaManager::class, $agendaManager);
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware