diff --git a/readme.md b/readme.md index 8ed4f74..1c78983 100644 --- a/readme.md +++ b/readme.md @@ -46,7 +46,10 @@ $event = \Calendar::event( true, //full day event? '2015-02-14', //start time, must be a DateTime object or valid DateTime format (http://bit.ly/1z7QWbg) '2015-02-14' //end time, must be a DateTime object or valid DateTime format (http://bit.ly/1z7QWbg), - 1 //optional event ID + 1, //optional event ID + [ + 'url' => 'http://full-calendar.io' + ] ); ``` #### Implementing `Event` Interface @@ -131,6 +134,55 @@ class EventModel extends Eloquent implements \MaddHatter\LaravelFullcalendar\Ide ``` +### Additional Event Parameters + +If you want to add [additional parameters](http://fullcalendar.io/docs/event_data/Event_Object) to your events, there are two options: + +#### Using `Calendar::event()` + +Pass an array of `'parameter' => 'value'` pairs as the 6th parameter to `Calendar::event()`: + +```php +$event = \Calendar::event( + "Valentine's Day", //event title + true, //full day event? + '2015-02-14', //start time, must be a DateTime object or valid DateTime format (http://bit.ly/1z7QWbg) + '2015-02-14' //end time, must be a DateTime object or valid DateTime format (http://bit.ly/1z7QWbg), + 1, //optional event ID + [ + 'url' => 'http://full-calendar.io', + //any other full-calendar supported parameters + ] +); + +``` + +#### Add an `getEventOptions` method to your event class + +```php + $this->background_color, + //etc + ]; + } + + //... +} + +``` + ### Create a Calendar To create a calendar, in your route or controller, create your event(s), then pass them to `Calendar::addEvent()` or `Calendar::addEvents()` (to add an array of events). `addEvent()` and `addEvents()` can be used fluently (chained together). Their second parameter accepts an array of valid [FullCalendar Event Object parameters](http://fullcalendar.io/docs/event_data/Event_Object/). diff --git a/src/MaddHatter/LaravelFullcalendar/Calendar.php b/src/MaddHatter/LaravelFullcalendar/Calendar.php index 2a850db..7fe98c4 100644 --- a/src/MaddHatter/LaravelFullcalendar/Calendar.php +++ b/src/MaddHatter/LaravelFullcalendar/Calendar.php @@ -67,12 +67,13 @@ public function __construct(Factory $view, EventCollection $eventCollection) * @param string $isAllDay * @param string|DateTime $start If string, must be valid datetime format: http://bit.ly/1z7QWbg * @param string|DateTime $end If string, must be valid datetime format: http://bit.ly/1z7QWbg - * @param string $id event Id + * @param string $id event Id + * @param array $options * @return SimpleEvent */ - public static function event($title, $isAllDay, $start, $end, $id = null) + public static function event($title, $isAllDay, $start, $end, $id = null, $options = []) { - return new SimpleEvent($title, $isAllDay, $start, $end, $id); + return new SimpleEvent($title, $isAllDay, $start, $end, $id, $options); } /** diff --git a/src/MaddHatter/LaravelFullcalendar/EventCollection.php b/src/MaddHatter/LaravelFullcalendar/EventCollection.php index 49d01e6..ea85f8c 100644 --- a/src/MaddHatter/LaravelFullcalendar/EventCollection.php +++ b/src/MaddHatter/LaravelFullcalendar/EventCollection.php @@ -32,13 +32,17 @@ public function toArray() private function convertToArray(Event $event, array $customAttributes = []) { - return array_merge([ + $eventArray = [ 'id' => $this->getEventId($event), 'title' => $event->getTitle(), 'allDay' => $event->isAllDay(), 'start' => $event->getStart()->format('c'), 'end' => $event->getEnd()->format('c'), - ], $customAttributes); + ]; + + $eventOptions = method_exists($event, 'getEventOptions') ? $event->getEventOptions() : []; + + return array_merge($eventArray, $eventOptions, $customAttributes); } private function getEventId(Event $event) diff --git a/src/MaddHatter/LaravelFullcalendar/SimpleEvent.php b/src/MaddHatter/LaravelFullcalendar/SimpleEvent.php index 3d9af95..e1c8973 100644 --- a/src/MaddHatter/LaravelFullcalendar/SimpleEvent.php +++ b/src/MaddHatter/LaravelFullcalendar/SimpleEvent.php @@ -37,20 +37,27 @@ class SimpleEvent implements IdentifiableEvent */ public $end; + /** + * @var array + */ + private $options; + /** * @param string $title * @param bool $isAllDay * @param string|DateTime $start If string, must be valid datetime format: http://bit.ly/1z7QWbg * @param string|DateTime $end If string, must be valid datetime format: http://bit.ly/1z7QWbg * @param int|string|null $id + * @param array $options */ - public function __construct($title, $isAllDay, $start, $end, $id = null) + public function __construct($title, $isAllDay, $start, $end, $id = null, $options = []) { $this->title = $title; $this->isAllDay = $isAllDay; $this->start = $start instanceof DateTime ? $start : new DateTime($start); - $this->end = $end instanceof DateTime ? $end : new DateTime($end); + $this->end = $start instanceof DateTime ? $end : new DateTime($end); $this->id = $id; + $this->options = $options; } /** @@ -102,4 +109,14 @@ public function getEnd() { return $this->end; } -} + + /** + * Get the optional event options + * + * @return array + */ + public function getEventOptions() + { + return $this->options; + } +} \ No newline at end of file