Skip to content

Commit

Permalink
Fix date format
Browse files Browse the repository at this point in the history
  • Loading branch information
tattali committed Apr 3, 2019
2 parents ddc28d8 + 3808f03 commit 10db3cc
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
CalendarBundle - jQuery Calendar bundle
CalendarBundle - FullCalendar.js integration
===========================================

[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/tattali/CalendarBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/tattali/CalendarBundle/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/tattali/CalendarBundle/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/tattali/CalendarBundle/?branch=master)
[![Build Status](https://scrutinizer-ci.com/g/tattali/CalendarBundle/badges/build.png?b=master)](https://scrutinizer-ci.com/g/tattali/CalendarBundle/build-status/master)
[![Total Downloads](https://poser.pugx.org/tattali/calendar-bundle/downloads)](https://packagist.org/packages/tattali/calendar-bundle)
[![Packagist](https://poser.pugx.org/tattali/calendar-bundle/version)](https://packagist.org/packages/tattali/calendar-bundle)
[![Latest Stable Version](https://poser.pugx.org/tattali/calendar-bundle/v/stable)](https://packagist.org/packages/tattali/calendar-bundle)

This bundle allow you to integrate [fullcalendar.js](http://fullcalendar.io/) library in your Symfony 4 project.
This bundle allow you to integrate [FullCalendar.js](http://fullcalendar.io/) library in your Symfony 4 project.

<p align="center">
<img src="https://user-images.githubusercontent.com/10502887/54887938-897a4d00-4e98-11e9-8db1-aff8c43aa6d3.png" alt="Calendar image">
</div>
</p>

* Symfony 3.4+ or Symfony 4.0+
* PHP v7.1+
Expand All @@ -35,7 +35,14 @@ The source of the documentation is stored in the `src/Resources/doc/` folder in
```sh
$ composer require tattali/calendar-bundle
```
The recipe will import the routes for you
(pending) The recipe will import the routes for you

Check the existence of the file `config/routes/calendar.yaml` or create it
```yaml
# config/routes/calendar.yaml
calendar:
resource: "@CalendarBundle/Resources/config/routing.yaml"
```
#### 2. Create the listener
You need to create a listener class to load your data into the calendar and register it as a service.
Expand All @@ -53,7 +60,7 @@ services:

Then, create the listener class to fill the calendar

See the [doctrine listener example](src/Resources/doc/doctrine-crud.md#4-use-an-event-listener-to-connect-all-of-this-together)
See the [doctrine listener example](src/Resources/doc/doctrine-crud.md#full-listener)

```php
// src/EventListener/CalendarListener.php
Expand Down Expand Up @@ -119,7 +126,7 @@ Add styles and js. Click [here](https://fullcalendar.io/download) to see other c
### Basic functionalities

You will probably want to customize the Calendar javascript to fit the needs of your application.
To do this, you can copy the following settings and modify them by consulting the [fullcalendar.js documentation](https://fullcalendar.io/docs). You can also look at the [options.ts](https://github.com/calendar/calendar/blob/master/src/core/options.ts) file as an option reference.
To do this, you can copy the following settings and modify them by consulting the [fullcalendar.js documentation](https://fullcalendar.io/docs). You can also look at the [options.ts](https://github.com/fullcalendar/fullcalendar/blob/master/src/core/options.ts) file as an option reference.
```js
document.addEventListener('DOMContentLoaded', () => {
var calendarEl = document.getElementById('calendar-holder');
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tattali/calendar-bundle",
"type": "symfony-bundle",
"description": "Provides event calendar for your Symfony 4 project. Compatible with Doctrine ORM & ODM, and custom storages.",
"description": "Provides event calendar for your Symfony 4 project. Compatible with Doctrine ORM & ODM, and API like Google Calendar.",
"keywords": ["fullcalendar", "calendar", "symfony", "symfony calendar"],
"homepage": "https://github.com/tattali/CalendarBundle",
"license": "MIT",
Expand Down
6 changes: 4 additions & 2 deletions src/Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class Event
{
const DATE_FORMAT = 'Y-m-d\\TH:i:s.u\\Z';

/**
* @var string
*/
Expand Down Expand Up @@ -134,12 +136,12 @@ public function toArray(): array
{
$event = [
'title' => $this->getTitle(),
'start' => $this->getStart()->format('Y-m-d\\TH:i:sP'),
'start' => $this->getStart()->format(self::DATE_FORMAT),
'allDay' => $this->isAllDay(),
];

if (null !== $this->getEnd()) {
$event['end'] = $this->getEnd()->format('Y-m-d\\TH:i:sP');
$event['end'] = $this->getEnd()->format(self::DATE_FORMAT);
}

return array_merge($event, $this->getOptions());
Expand Down
18 changes: 15 additions & 3 deletions src/Resources/doc/doctrine-crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@ This documentation assumes that doctrine is already installed.
```sh
$ composer require tattali/calendar-bundle
```
The recipe will import the routes for you
(pending) The recipe will import the routes for you

Check the existence of the file `config/routes/calendar.yaml` or create it
```yaml
# config/routes/calendar.yaml
calendar:
resource: "@CalendarBundle/Resources/config/routing.yaml"
```
### 2. Create the entity
Generate or create an entity with at least a *start date* and a *title*. You also can add an *end date*
```sh
# Symfony flex (Need the maker: `composer req --dev symfony/maker`)
# Symfony flex (Need the maker: `composer req --dev symfony/maker-bundle`)
$ php bin/console make:entity
```

Expand Down Expand Up @@ -140,7 +147,7 @@ You can now create or generate the CRUD of your entity

The following command will generate a `BookingController` with `index()`, `new()`, `show()`, `edit()` and `delete()` actions

And also the according `templates` and `form`
And also the according `templates` and `form` (You may need to install additional packages)
```sh
$ php bin/console make:crud Booking
```
Expand Down Expand Up @@ -194,6 +201,8 @@ services:
We now have to link the CRUD to the calendar by adding the `booking_show` route in each events

[TL;DR](#full-listener)

To do this create a listener with access to the router component and your entity repository
```php
// src/EventListener/CalendarListener.php
Expand Down Expand Up @@ -232,7 +241,10 @@ $bookingEvent->addOption(
);
```

#### Full listener

Full listener with `Booking` entity. Modify it to fit your needs.

```php
// src/EventListener/CalendarListener.php
<?php
Expand Down
4 changes: 2 additions & 2 deletions tests/Entity/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public function testItShouldConvertItsValuesInToArray()
$this->assertEquals(
[
'title' => $this->title,
'start' => $this->start->format('Y-m-d\\TH:i:sP'),
'start' => $this->start->format(Event::DATE_FORMAT),
'allDay' => $allDay,
'end' => $this->end->format('Y-m-d\\TH:i:sP'),
'end' => $this->end->format(Event::DATE_FORMAT),
$url => $urlValue,
],
$this->entity->toArray()
Expand Down

0 comments on commit 10db3cc

Please sign in to comment.