adesigns / calendar-bundle

This bundle allows you to integrate the jQuery FullCalendar plugin into your Symfony2 application.
MIT License
97 stars 60 forks source link

Support for non-standard event fields #19

Closed marcaube closed 10 years ago

marcaube commented 10 years ago

FullCalendar supports non-standard event fields, so that we can add a custom values to our events.

I extended your EventEntity class to implement this. Is this a feature you'd like to add ?

I'd like to discuss structure, naming and such before sending a PR.

<?php

namespace Acme\CalendarBundle\Entity;

use ADesigns\CalendarBundle\Entity\EventEntity as BaseEvent;

/**
 * Extends the ADesigns' Event functionality with support for custom fields
 */
class Event extends BaseEvent
{
    /**
     * Non-standard fields
     *
     * @var array
     */
    protected $otherFields = array();

    /**
     * @param string $name
     * @param string $value
     */
    public function addField($name, $value)
    {
        $this->otherFields[$name] = $value;
    }

    /**
     * @param string $name
     */
    public function removeField($name)
    {
        if (!array_key_exists($name, $this->otherFields)) {
            return;
        }

        unset($this->otherFields[$name]);
    }

    /**
     * {@inheritDoc}
     */
    public function toArray()
    {
        $event = parent::toArray();

        foreach ($this->otherFields as $field => $value) {
            $event[$field] = $value;
        }

        return $event;
    }
}
mikeyudin commented 10 years ago

This seems like a nice feature to have at our disposal. The change looks pretty straightforward.

The naming looks fine, IMO. Since these fields are optional, should be able to amend EventEntity without any BC breaks.

Do you have time to do the PR? Extra points if you could throw in a new test case for EventEntity! =)

marcaube commented 10 years ago

There you go