Skip to content

Commit

Permalink
Backport custom fullcalendar settings
Browse files Browse the repository at this point in the history
  • Loading branch information
maddhatter committed Mar 13, 2015
1 parent 082f658 commit c3f1c4f
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 13 deletions.
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ $eloquentEvent = EventModel::first(); //EventModel implements MaddHatter\Laravel
$calendar = Calendar::addEvents($events) //add an array with addEvents
->addEvent($eloquentEvent, [ //set custom color fo this event
'color' => '#800',
]);
])->setOptions([ //set fullcalendar options
'firstDay' => 1
]);

return View::make('hello', compact('calendar'));
```
Expand Down
62 changes: 61 additions & 1 deletion src/MaddHatter/LaravelFullcalendar/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ class Calendar
*/
protected $id;

/**
* Default options array
*
* @var array
*/
protected $defaultOptions = [
'header' => [
'left' => 'prev,next today',
'center' => 'title',
'right' => 'month,agendaWeek,agendaDay',
],
'eventLimit' => true,
];

/**
* User defined options
*
* @var array
*/
protected $userOptions = [];

/**
* @param Factory $view
* @param EventCollection $eventCollection
Expand Down Expand Up @@ -62,9 +83,11 @@ public function calendar()
*/
public function script()
{
$options = $this->getOptionsJson();

return $this->view->make('fullcalendar::script', [
'id' => $this->getId(),
'events' => $this->eventCollection->toJson(),
'options' => $options,
]);
}

Expand Down Expand Up @@ -127,4 +150,41 @@ public function addEvents(array $events, array $customAttributes = [])

return $this;
}

/**
* Set fullcalendar options
*
* @param array $options
* @return $this
*/
public function setOptions(array $options)
{
$this->userOptions = $options;

return $this;
}

/**
* Get the fullcalendar options (not including the events list)
*
* @return array
*/
public function getOptions()
{
return array_merge($this->defaultOptions, $this->userOptions);
}

/**
* Get options+events JSON
*
* @return array
*/
protected function getOptionsJson()
{
$options = $this->getOptions();

$options['events'] = $this->eventCollection->toArray();

return json_encode($options);
}
}
10 changes: 8 additions & 2 deletions src/MaddHatter/LaravelFullcalendar/EventCollection.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php namespace MaddHatter\LaravelFullcalendar;
<?php namespace MaddHatter\LaravelFullcalendar;

use Illuminate\Support\Collection;

class EventCollection {
class EventCollection
{

/**
* @var Collection
Expand All @@ -24,6 +25,11 @@ public function toJson()
return $this->events->toJson();
}

public function toArray()
{
return $this->events->toArray();
}

private function convertToArray(Event $event, array $customAttributes = [])
{
return array_merge([
Expand Down
10 changes: 1 addition & 9 deletions src/views/script.blade.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
<script>
$('#calendar-{{ $id }}').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
eventLimit: true,
events: {{ $events }}
});
$('#calendar-{{ $id }}').fullCalendar({{ $options }});
</script>

0 comments on commit c3f1c4f

Please sign in to comment.