forked from nelkasovic/laravel-full-calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 236927b
Showing
14 changed files
with
894 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/vendor | ||
composer.phar | ||
composer.lock | ||
.DS_Store | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: php | ||
|
||
php: | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- hhvm | ||
|
||
before_script: | ||
- travis_retry composer self-update | ||
- travis_retry composer install --prefer-source --no-interaction --dev | ||
|
||
script: phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "qlick/laravel-full-calendar", | ||
"description": "Laravel helper for FullCalendar.io. Fork of https://github.com/maddhatter/laravel-fullcalendar", | ||
"authors": [ | ||
{ | ||
"name": "Qlick by Nermin Elkasovic", | ||
"email": "[email protected]", | ||
"homepage": "https://qlick.ch", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": "^7.1", | ||
"illuminate/database": "5.7.*|5.8.*|^6.0", | ||
"illuminate/support": "5.7.*|5.8.*|^6.0" | ||
}, | ||
"license": "MIT", | ||
"homepage": "https://github.com/nelkasovic/laravel-full-calendar", | ||
"support": { | ||
"email": "[email protected]", | ||
"issues": "https://github.com/nelkasovic/laravel-full-calendar/issues", | ||
"wiki": "https://github.com/nelkasovic/laravel-full-calendar/wiki", | ||
"source": "https://github.com/nelkasovic/laravel-full-calendar", | ||
"docs": "https://github.com/nelkasovic/laravel-full-calendar" | ||
}, | ||
"autoload": { | ||
"App\\": "app/", | ||
"psr-4": { | ||
"Qlick\\LaravelFullcalendar": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Qlick\\LaravelFullcalendar\\ServiceProvider" | ||
], | ||
"aliases": { | ||
"Calendar": "Qlick\\LaravelFullcalendar\\Facades\\Calendar" | ||
} | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,262 @@ | ||
# Laravel 5 Full Calendar Helper | ||
|
||
[![Latest Stable Version](https://poser.pugx.org/maddhatter/laravel-fullcalendar/v/stable)](https://packagist.org/packages/maddhatter/laravel-fullcalendar) [![Total Downloads](https://poser.pugx.org/maddhatter/laravel-fullcalendar/downloads)](https://packagist.org/packages/maddhatter/laravel-fullcalendar) [![Latest Unstable Version](https://poser.pugx.org/maddhatter/laravel-fullcalendar/v/unstable)](https://packagist.org/packages/maddhatter/laravel-fullcalendar) [![License](https://poser.pugx.org/maddhatter/laravel-fullcalendar/license)](https://packagist.org/packages/maddhatter/laravel-fullcalendar) | ||
|
||
***For Laravel 4.2: use the [laravel-4 branch](https://github.com/maddhatter/laravel-fullcalendar/tree/laravel-4)*** | ||
|
||
This is a simple helper package to make generating [http://fullcalendar.io](http://fullcalendar.io) in Laravel apps easier. | ||
|
||
## Installing | ||
Require the package with composer using the following command: | ||
|
||
composer require maddhatter/laravel-fullcalendar | ||
|
||
Or add the following to your composer.json's require section and `composer update` | ||
|
||
```json | ||
"require": { | ||
"maddhatter/laravel-fullcalendar": "~1.0" | ||
} | ||
``` | ||
|
||
### Laravel 5.4 (and earlier) | ||
|
||
Register the service provider in your `app.php` config file: | ||
|
||
```php | ||
MaddHatter\LaravelFullcalendar\ServiceProvider::class, | ||
``` | ||
|
||
And optionally create an alias: | ||
|
||
```php | ||
'Calendar' => MaddHatter\LaravelFullcalendar\Facades\Calendar::class, | ||
|
||
``` | ||
|
||
### Laravel 5.5+ | ||
The provider and `Calendar` alias will be registered automatically. | ||
|
||
You will also need to include [fullcalendar.io](http://fullcalendar.io/)'s files in your HTML. | ||
|
||
## Usage | ||
|
||
### Creating Events | ||
|
||
#### Using `event()`: | ||
The simpliest way to create an event is to pass the event information 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' | ||
] | ||
); | ||
``` | ||
#### Implementing `Event` Interface | ||
|
||
Alternatively, you can use an existing class and have it implement `MaddHatter\LaravelFullcalendar\Event`. An example of an Eloquent model that implements the `Event` interface: | ||
|
||
```php | ||
class EventModel extends Eloquent implements \MaddHatter\LaravelFullcalendar\Event | ||
{ | ||
|
||
protected $dates = ['start', 'end']; | ||
|
||
/** | ||
* Get the event's id number | ||
* | ||
* @return int | ||
*/ | ||
public function getId() { | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* Get the event's title | ||
* | ||
* @return string | ||
*/ | ||
public function getTitle() | ||
{ | ||
return $this->title; | ||
} | ||
|
||
/** | ||
* Is it an all day event? | ||
* | ||
* @return bool | ||
*/ | ||
public function isAllDay() | ||
{ | ||
return (bool)$this->all_day; | ||
} | ||
|
||
/** | ||
* Get the start time | ||
* | ||
* @return DateTime | ||
*/ | ||
public function getStart() | ||
{ | ||
return $this->start; | ||
} | ||
|
||
/** | ||
* Get the end time | ||
* | ||
* @return DateTime | ||
*/ | ||
public function getEnd() | ||
{ | ||
return $this->end; | ||
} | ||
} | ||
``` | ||
|
||
#### `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(); | ||
|
||
} | ||
|
||
``` | ||
|
||
### 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 | ||
<?php | ||
class CalendarEvent extends \Illuminate\Database\Eloquent\Model implements \MaddHatter\LaravelFullcalendar\Event | ||
{ | ||
//... | ||
|
||
/** | ||
* Optional FullCalendar.io settings for this event | ||
* | ||
* @return array | ||
*/ | ||
public function getEventOptions() | ||
{ | ||
return [ | ||
'color' => $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/). | ||
|
||
#### Sample Controller code: | ||
|
||
```php | ||
$events = []; | ||
|
||
$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) | ||
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) | ||
'stringEventId' //optionally, you can specify an event ID | ||
); | ||
|
||
$eloquentEvent = EventModel::first(); //EventModel implements MaddHatter\LaravelFullcalendar\Event | ||
|
||
$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 | ||
])->setCallbacks([ //set fullcalendar callback options (will not be JSON encoded) | ||
'viewRender' => 'function() {alert("Callbacks!");}' | ||
]); | ||
|
||
return view('hello', compact('calendar')); | ||
``` | ||
|
||
|
||
#### Sample View | ||
|
||
Then to display, add the following code to your View: | ||
|
||
```html | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script> | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.js"></script> | ||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.css"/> | ||
|
||
|
||
<style> | ||
/* ... */ | ||
</style> | ||
</head> | ||
<body> | ||
{!! $calendar->calendar() !!} | ||
{!! $calendar->script() !!} | ||
</body> | ||
</html> | ||
``` | ||
**Note:** The output from `calendar()` and `script()` must be non-escaped, so use `{!!` and `!!}` (or whatever you've configured your Blade compiler's raw tag directives as). | ||
|
||
The `script()` can be placed anywhere after `calendar()`, and must be after fullcalendar was included. | ||
|
||
This will generate (in February 2015): | ||
|
||
![](http://i.imgur.com/qjgVhCY.png) |
Oops, something went wrong.