Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alrik11es/calendar

Calendar is a PHP calendar generator but in array, object or JSON format.
https://github.com/alrik11es/calendar

calendar composer php php-calendar-generator twig vuejs

Last synced: 24 days ago
JSON representation

Calendar is a PHP calendar generator but in array, object or JSON format.

Awesome Lists containing this project

README

        

Calendar [![Build Status](https://travis-ci.org/alrik11es/calendar.svg?branch=master)](https://travis-ci.org/alrik11es/calendar)
======================

[![Latest Stable Version](https://poser.pugx.org/alrik11es/calendar/v/stable.svg)](https://packagist.org/packages/alrik11es/calendar) [![Total Downloads](https://poser.pugx.org/alrik11es/calendar/downloads.svg)](https://packagist.org/packages/alrik11es/calendar) [![Latest Unstable Version](https://poser.pugx.org/alrik11es/calendar/v/unstable.svg)](https://packagist.org/packages/alrik11es/calendar) [![License](https://poser.pugx.org/alrik11es/calendar/license.svg)](https://packagist.org/packages/alrik11es/calendar)

Calendar is a PHP calendar structure generator in array, object or JSON format.

* [Installation](#installation)
* [Requirements](#requirements)
* [With composer](#with-composer)
* [How it works](#how-it-works)

## Motivation

Do you remember those long... long... hours trying to create a rendered calendar? Think about this, the main problem is that you have to generate the structure to do the rendering in your template engine, no matter what it is. So the thing here is I don't wanna give you a fully rendered calendar just the structure you need to do the render. How do you do the render... it's all on you.

Take a look to this example render:

![Calendar example](img/calendar.png "Calendar example")

## Installation

### Requirements

- Any flavour of PHP 5.6+ should do
- [optional] PHPUnit to execute the test suite

### With Composer

The easiest way to install the calendar is via [composer](http://getcomposer.org/). Create the following `composer.json` file and run the `php composer.phar install` command to install it.

```json
{
"require": {
"alrik11es/calendar": "0.1.*"
}
}
```

### No composer

Git clone this repo where you want and include/require all the src folder into your project.

## How it works
Lets get into business. Set up a calendar from today to 6 months into the future:

```php
$cal = new \SSC\Calendar();
$structure = $cal->getCalendar();

print_r($structure);
```

The output then is like the next one:

```
Array
(
[2014] => Array
(
[type] => year
[value] => 2014
[data] =>
[elements] => Array
(
[3] => Array
(
[type] => quarter
[value] => 3
[data] =>
[elements] => Array
(
[8] => Array
(
[type] => month
[value] => 8
[data] =>
[elements] => Array
(
[31] => Array
(
[type] => week
[value] => 31
[data] =>
[elements] => Array
(
[1] => Array
(
[type] => day
[value] => 1
[data] =>
[weekday] => 5
)
```

Then you just have to take it and render in your Twig or whatever... (Next one is the spanish way, but you can change to whatever you want)

```php




-


Mon
Tue
Wed
Thu
Fra
Sun
Sat

















```

# Bam! Calendar!

Oh BTW I can give you a Twig example Just for the record :P

```php
$cal = new \SSC\Calendar();
$cal->getConfig()->setInterval(new \DateInterval('P12M'));
$cal->day_callback = function($date){
$day = new \stdClass();
$day->has_passed = $date->getTimestamp()

Yeah, the Twig file...

```twig
{% for year in cal %}
{# You could add here the years #}
{% for quarter in year.elements %}
{% for month in quarter.elements %}



{{ year.value }} - {{ months_es[month.value] }}


L
M
X
J
V
S
D

{% for week in month.elements %}

{# You could add here the week number #}
{% for week_day in week_days%}

{% for day in week.elements %}
{% if day.weekday == week_day %}


{{ day.value }}

{% endif %}
{% endfor %}

{% endfor %}

{% endfor %}

{% endfor %}
{% endfor %}
{% endfor %}
```
# Vue.js

With the boom of this kind of libraries just like angular or react. I give you an example of how a render should look like. Obviously you will need to make the API part. But at least this is a good starting point.

```html






{{ year.value }} - {{ month.value }}


Mon
Tue
Wed
Thu
Fra
Sun
Sat





{{ day.value }}








export default {
data() {
return {
calendar: {},
}
},
methods: {
},
mounted() {
axios.get('/api/calendar').then(response => {
this.calendar = response.data;
console.log(this.calendar);
}).catch(e => {
});
}
}

.month{
float: left;
margin: 10px;
}

```