Skip to content

carlescliment/calendar-bundle

Repository files navigation

CalendarBundle

Build Status

The CalendarBundle gives you a built-in calendar for managing events without relying on third-parties like Google. It comes with four different default views; agenda, by day, by week and by month. If you need greater customizations, you can use the bundle as a simple calendar API and build your own logic on it.

Installation

1. Update your vendors

Add this line to your composer.json

"require": {
    "carlescliment/calendar-bundle": "dev-master"
}

Execute php composer.phar update carlescliment/calendar-bundle

2. Load the bundle in app/AppKernel.php

$bundles = array(
    // ...
    new BladeTester\CalendarBundle\BladeTesterCalendarBundle(),
);

3. Update your routing:

// ...

BladeTesterCalendarBundle:
    resource: "@BladeTesterCalendarBundle/Resources/config/routing.yml"
    prefix:   /

4. Create your calendar bundle

Create a new bundle extending BladeTesterCalendarBundle

namespace Your\OwnCalendarBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class YourOwnCalendarBundle extends Bundle
{

   public function getParent()
    {
        return 'BladeTesterCalendarBundle';
    }
}

WARNING: If your bundle includes its own routing file, remember to delete it or completely override the parent bundle paths.

Add it to AppKernel.

    $bundles = array(
        // ...
        new Your\OwnCalendarBundle\YourOwnCalendarBundle(),
    );

5. Update the schema

php app/console doctrine:schema:update --force

6. Install the assets

php app/console assets:install

Using the calendar

Go to http://www.example.com/calendar and enjoy :)

Customizing the bundle

If you want to override the bundle default views to use your design and markup, please follow the next steps.

1. Override the default base template

Copy the template in Resources/views/Base/base.html.twig into your own bundle and modify it to extend your base template.

2. Add the assets to your base template

<script type="text/javascript" src="{{ asset('bundles/bladetestercalendar/js/jquery-1.9.1.min.js') }}"></script>
<link rel="stylesheet" href="{{ asset('bundles/bladetestercalendar/css/calendar.css') }}" />
<script type="text/javascript" src="{{ asset('bundles/bladetestercalendar/js/calendar.js') }}"></script>

Note: remove the line including jquery if your template already includes it.

How to override the default entities

You can define your own entities. First, create your custom entity:

namespace Your\OwnCalendarBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use BladeTester\CalendarBundle\Entity\Event as BaseEvent;


/**
 * @ORM\Entity(repositoryClass="BladeTester\CalendarBundle\Repository\EventRepository")
 * @ORM\Table(name="events")
 */
class Event extends BaseEvent
{
  // ... your implementation goes here
}

Then modify your app/config/config.yml

    blade_tester_calendar:
        driver: doctrine/orm
        engine: twig
        classes:
            event:
                entity: Your\OwnBundle\Entity\Event
            category:
                entity: Your\OwnBundle\Entity\EventCategory

Extending the behaviour

It is easy to extend the behaviour of this bundle by using inheritance in your models and entities. If it is not enough, you can register listeners to the calendar events.

Pre-persist event

Dispatched whenever an item is about to be created in the database.

    your_own_calendar_listener:
        class: Your\OwnCalendarBundle\Event\CalendarListener
        tags:
          - { name: kernel.event_listener, event: calendar.pre-persist, method: onPrePersist }
namespace Your\OwnCalendarBundle\Event;

use BladeTester\CalendarBundle\Event\CalendarEvent;

class CalendarListener {

    public function onPrePersist(CalendarEvent $event) {
        $event_model = $event->getEvent();
        // do whatever with the object before persisting it.
    }
}

Post-add event

Dispatched after an item is added to the database.

    your_own_calendar_listener:
        class: Your\OwnCalendarBundle\Event\CalendarListener
        tags:
          - { name: kernel.event_listener, event: calendar.post-add, method: onPostAdd }

Post-update event

Dispatched after an item is updated.

    your_own_calendar_listener:
        class: Your\OwnCalendarBundle\Event\CalendarListener
        tags:
          - { name: kernel.event_listener, event: calendar.post-update, method: onPostUpdate }

Testing

CalendarBundle contains unitary and functional tests. Download the bundle, create the database according to the travis.yml file and configure the access settings in src/BladeTester/CalendarBundle/Tests/App/parameters.ini. Run the following command:

cd /path/to/calendar-bundle
composer update
php vendor/bin/phpunit

Credits

Contribute and feedback

Any feedback and contribution will be very appreciated.

About

A bundle for managing calendars in Symfony 2

Resources

Stars

Watchers

Forks

Packages

No packages published