2017 © Pedro Peláez
 

symfony-bundle calendar

This bundle allows you to integrate the jQuery FullCalendar plugin into your Symfony3 application.

image

palo2583/calendar

This bundle allows you to integrate the jQuery FullCalendar plugin into your Symfony3 application.

  • Wednesday, February 14, 2018
  • by palo2583
  • Repository
  • 0 Watchers
  • 0 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 140 % Grown

The README.md

CalendarBundle - jQuery FullCalendar bundle.

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

This bundle allows you to integrate the jQuery FullCalendar plugin into your Symfony2 application., (*2)

Once installed, this bundle will use event listeners to load events from any bundle in your application., (*3)

!!! based on adesigns/calendar-bundle !!!, (*4)

Installation

Before installing, please note that this bundle has a dependency on the FOSJsRouting bundle to expose the calendar AJAX event loader route. Please ensure that the FOSJsRouting bundle is installed and configured before continuing., (*5)

Through Composer (Symfony 2.1+):

Add the following lines in your composer.json file:, (*6)

composer require adesigns/calendar-bundle

Register the bundle in app/AppKernel.php:, (*7)

``` php // app/AppKernel.php, (*8)

public function registerBundles() { return array( // ... new ADesigns\CalendarBundle\ADesignsCalendarBundle(), ); }, (*9)


Register the routing in `app/config/routing.yml`: ``` yml # app/config/routing.yml adesigns_calendar: resource: "@ADesignsCalendarBundle/Resources/config/routing.xml"

Publish the assets:, (*10)

$ php app/console assets:install web

Usage

Add the required stylesheet and javascripts to your layout:, (*11)

Stylesheet:, (*12)

<link rel="stylesheet" href="{{ asset('bundles/adesignscalendar/css/fullcalendar/fullcalendar.css') }}" />

Javascript:, (*13)

<script type="text/javascript" src="{{ asset('bundles/adesignscalendar/js/jquery/jquery.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('bundles/adesignscalendar/js/fullcalendar/fullcalendar.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('bundles/adesignscalendar/js/calendar-settings.js') }}"></script>

Then, in the template where you wish to display the calendar, add the following twig:, (*14)

{% include 'ADesignsCalendarBundle::calendar.html.twig' %}

Adding Events

The best part about this bundle is that you can add events to the calendar from any part of your application. The calendar loads events via AJAX, and dispatches an event to load calendar events from your application., (*15)

When a request is made to load events for a given start/end time, the bundle dispatches a calendar.load_events event. Adding event listeners is an easy 2 step process, (*16)

Create an Event Listener class in your bundle:, (*17)

``` php // src/Acme/DemoBundle/EventListener/CalendarEventListener.php, (*18)

namespace Acme\DemoBundle\EventListener;, (*19)

use ADesigns\CalendarBundle\Event\CalendarEvent; use ADesigns\CalendarBundle\Entity\EventEntity; use Doctrine\ORM\EntityManager;, (*20)

class CalendarEventListener { private $entityManager;, (*21)

public function __construct(EntityManager $entityManager)
{
    $this->entityManager = $entityManager;
}

public function loadEvents(CalendarEvent $calendarEvent)
{
    $startDate = $calendarEvent->getStartDatetime();
    $endDate = $calendarEvent->getEndDatetime();

    // The original request so you can get filters from the calendar
    // Use the filter in your query for example

    $request = $calendarEvent->getRequest();
    $filter = $request->get('filter');


    // load events using your custom logic here,
    // for instance, retrieving events from a repository

    $companyEvents = $this->entityManager->getRepository('AcmeDemoBundle:MyCompanyEvents')
                      ->createQueryBuilder('company_events')
                      ->where('company_events.event_datetime BETWEEN :startDate and :endDate')
                      ->setParameter('startDate', $startDate->format('Y-m-d H:i:s'))
                      ->setParameter('endDate', $endDate->format('Y-m-d H:i:s'))
                      ->getQuery()->getResult();

    // $companyEvents and $companyEvent in this example
    // represent entities from your database, NOT instances of EventEntity
    // within this bundle.
    //
    // Create EventEntity instances and populate it's properties with data
    // from your own entities/database values.

    foreach($companyEvents as $companyEvent) {

        // create an event with a start/end time, or an all day event
        if ($companyEvent->getAllDayEvent() === false) {
            $eventEntity = new EventEntity($companyEvent->getTitle(), $companyEvent->getStartDatetime(), $companyEvent->getEndDatetime());
        } else {
            $eventEntity = new EventEntity($companyEvent->getTitle(), $companyEvent->getStartDatetime(), null, true);
        }

        //optional calendar event settings
        $eventEntity->setAllDay(true); // default is false, set to true if this is an all day event
        $eventEntity->setBgColor('#FF0000'); //set the background color of the event's label
        $eventEntity->setFgColor('#FFFFFF'); //set the foreground color of the event's label
        $eventEntity->setUrl('http://www.google.com'); // url to send user to when event label is clicked
        $eventEntity->setCssClass('my-custom-class'); // a custom class you may want to apply to event labels

        //finally, add the event to the CalendarEvent for displaying on the calendar
        $calendarEvent->addEvent($eventEntity);
    }
}

}, (*22)


Additional properties and customization of each event on the calendar can be found in the Entity/EventEntity class. Then, add the listener to your services: ``` xml <container xmlns="http://symfony.com/schema/dic/services"> <services> <service id="acme.demobundle.calendar_listener" class="Acme\DemoBundle\EventListener\CalendarEventListener"> <argument type="service" id="doctrine.orm.entity_manager" /> <tag name="kernel.event_listener" event="calendar.load_events" method="loadEvents" /> </service> </services> </container>

And that's it! When the ADesignsCalendarBundle::calendar.html.twig template is rendered, any events within the current month/day/year will be pulled from your application., (*23)

Extending the Calendar Javascript

You may want to customize the FullCalendar javascript to meet your applications needs. In order to do this, you can copy the calendar-settings.js in Resources/public/js, and modify it to fit your needs. For instance, you can pass custom filters to your event listeners by adding extra parameters in the eventSources method:, (*24)

javascript eventSources: [ { url: Routing.generate('fullcalendar_loader'), type: 'POST', // A way to add custom filters to your event listeners data: { filter: 'my_custom_filter_param' }, error: function() { //alert('There was an error while fetching Google Calendar!'); } } ], (*25)

The Versions

14/02 2018
28/07 2014

1.2-beta

1.2.0.0-beta http://github.com/adesigns/calendar-bundle

This bundle allows you to integrate the jQuery FullCalendar plugin into your Symfony2 application.

  Sources   Download

MIT

The Requires

 

by Mike Yudin

calendar fullcalendar jquery calendar

24/04 2014

1.1

1.1.0.0 http://github.com/adesigns/calendar-bundle

This bundle allows you to integrate the jQuery FullCalendar plugin into your Symfony2 application.

  Sources   Download

MIT

The Requires

 

by Mike Yudin

calendar fullcalendar jquery calendar

08/06 2013

1.0

1.0.0.0 http://github.com/adesigns/calendar-bundle

This bundle allows you to integrate the jQuery FullCalendar plugin into your Symfony2 application.

  Sources   Download

MIT

The Requires

 

by Mike Yudin

calendar fullcalendar jquery calendar