Calendar handler library for PHP.
NOTE: This class will not echo / print the calendar.
Features:
- Handles monthly weeks and days.
- Ability to attach data.
- Able to be render in any custom template.
With composer, make the dependecy required in your project:
composer require 10quality/php-calendar
The following example will build the calendar for the current month:
use TenQuality\Utility\Calendar;
$calendar = new Calendar();
$calendar->build();
// Example
$data = array();
$data[] = $obj; // Either ARRAY or OBJECT
$calendar = new Calendar();
$calendar->data = $data;
// Array column or object filed containing the date related to each data row
$calendar->dataDateFiled = 'dateCreated';
// Build
$calendar->build();
Printing example:
<table>
<thead>
<tr>
<?php foreach ($calendar->headers as $header) : ?>
<th><?php echo $header ?></th>
<?php endforeach ?>
</tr>
</thead>
<tbody>
<?php foreach ($calendar->weeks as $week) : ?>
<tr>
<?php foreach ($week->days as $day) : ?>
<td>
<h2><?php echo $day->number ?></h2>
<?php foreach ($day->data as $row) : ?>
<!--TODO: What ever needs to be done with data-->
<?php endforeach ?>
</td>
<?php endforeach ?>
</tr>
<?php endforeach ?>
</tbody>
</table>
Build calendar for a specific date:
$calendar = new Calendar('2017-01-25');
$calendar->build();
Get previous and next month dates:
$calendar = new Calendar('2017-01-25');
$calendar->nextMonthDate;
$calendar->prevMonthDate;
PSR-4.
The MIT License (MIT)
Copyright (c) 2017 10Quality.