Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
maddhatter committed May 21, 2015
2 parents 516e867 + fcf16f2 commit 554b04b
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 14 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor
composer.phar
composer.lock
.DS_Store
/vendor
composer.phar
composer.lock
.DS_Store
.idea/
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "maddhatter/laravel-fullcalendar",
"description": "Laravel helper for FullCalendar.io",
"license": "MIT",
"authors": [
{
"name": "Shawn Tunney",
Expand Down
36 changes: 33 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ $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)
'2015-02-14' //end time, must be a DateTime object or valid DateTime format (http://bit.ly/1z7QWbg),
1 //optional event ID
);
```
#### Implementing `Event` Interface
Expand All @@ -57,6 +58,12 @@ class EventModel extends Eloquent implements \MaddHatter\LaravelFullcalendar\Eve
{

protected $dates = ['start', 'end'];
/**
* Get the event's id number
*
* @return int
*/
public function getId();

/**
* Get the event's title
Expand Down Expand Up @@ -100,6 +107,27 @@ class EventModel extends Eloquent implements \MaddHatter\LaravelFullcalendar\Eve
}
```

#### `IdentifiableEvent` Interface

If you wish for your existing class to have event IDs, implement `\MaddHatter\LaravelFullcalendar\IdentifiableEvent` instead. This interface extends `\MaddHatter\LaravelFullcalendar\Event` to add a `getId()` method:

```php
class EventModel extends Eloquent implements \MaddHatter\LaravelFullcalendar\IdentifiableEvent
{

// Implement all Event methods ...

/**
* Get the event's ID
*
* @return int|string|null
*/
public function getId();

}

```

### 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/).

Expand All @@ -112,14 +140,16 @@ $events[] = \Calendar::event(
'Event One', //event title
false, //full day event?
'2015-02-11T0800', //start time (you can also use Carbon instead of DateTime)
'2015-02-12T0800' //end time (you can also use Carbon instead of DateTime)
'2015-02-12T0800', //end time (you can also use Carbon instead of DateTime)
0 //optionally, you can specify an event ID
);

$events[] = \Calendar::event(
"Valentine's Day", //event title
true, //full day event?
new \DateTime('2015-02-14'), //start time (you can also use Carbon instead of DateTime)
new \DateTime('2015-02-14') //end time (you can also use Carbon instead of DateTime)
new \DateTime('2015-02-14'), //end time (you can also use Carbon instead of DateTime)
'stringEventId' //optionally, you can specify an event ID
);

$eloquentEvent = EventModel::first(); //EventModel implements MaddHatter\LaravelFullcalendar\Event
Expand Down
7 changes: 4 additions & 3 deletions src/MaddHatter/LaravelFullcalendar/Calendar.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace MaddHatter\LaravelFullcalendar;

use ArrayAccess;
use DateTime;
use Illuminate\View\Factory;

Expand Down Expand Up @@ -145,11 +146,11 @@ public function addEvent(Event $event, array $customAttributes = [])
/**
* Add multiple events
*
* @param array $events
* @param array|ArrayAccess $events
* @param array $customAttributes
* @return $this
*/
public function addEvents(array $events, array $customAttributes = [])
public function addEvents($events, array $customAttributes = [])
{
foreach ($events as $event) {
$this->eventCollection->push($event, $customAttributes);
Expand Down Expand Up @@ -209,7 +210,7 @@ public function getCallbacks()
*
* @return string
*/
protected function getOptionsJson()
public function getOptionsJson()
{
$options = $this->getOptions();
$placeholders = $this->getCallbackPlaceholders();
Expand Down
1 change: 0 additions & 1 deletion src/MaddHatter/LaravelFullcalendar/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

interface Event
{

/**
* Get the event's title
*
Expand Down
8 changes: 8 additions & 0 deletions src/MaddHatter/LaravelFullcalendar/EventCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,20 @@ public function toArray()
private function convertToArray(Event $event, array $customAttributes = [])
{
return array_merge([
'id' => $this->getEventId($event),
'title' => $event->getTitle(),
'allDay' => $event->isAllDay(),
'start' => $event->getStart()->format('c'),
'end' => $event->getEnd()->format('c'),
], $customAttributes);
}

private function getEventId(Event $event)
{
if ($event instanceof IdentifiableEvent) {
return $event->getId();
}

return null;
}
}
13 changes: 13 additions & 0 deletions src/MaddHatter/LaravelFullcalendar/IdentifiableEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php namespace MaddHatter\LaravelFullcalendar;

interface IdentifiableEvent extends Event
{

/**
* Get the event's ID
*
* @return int|string|null
*/
public function getId();

}
23 changes: 20 additions & 3 deletions src/MaddHatter/LaravelFullcalendar/SimpleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
*
* @package MaddHatter\LaravelFullcalendar
*/
class SimpleEvent implements Event
class SimpleEvent implements IdentifiableEvent
{

/**
* @var
* @var string|int|null
*/
public $id;

/**
* @var string
*/
public $title;

Expand All @@ -37,13 +42,25 @@ class SimpleEvent implements Event
* @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
*/
public function __construct($title, $isAllDay, $start, $end)
public function __construct($title, $isAllDay, $start, $end, $id = null)
{
$this->title = $title;
$this->isAllDay = $isAllDay;
$this->start = $start instanceof DateTime ? $start : new DateTime($start);
$this->end = $start instanceof DateTime ? $end : new DateTime($end);
$this->id = $id;
}

/**
* Get the event's id number
*
* @return int
*/
public function getId()
{
return $this->id;
}

/**
Expand Down

0 comments on commit 554b04b

Please sign in to comment.