10quality / php-calendar
PHP calendar handler class.
v1.0.2
2019-05-08 00:45 UTC
Requires
- php: >=5.2
- fisharebest/ext-calendar: dev-master
Requires (Dev)
- phpunit/phpunit: 4.4.*
This package is auto-updated.
Last update: 2024-10-27 13:16:08 UTC
README
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.
Installation
With composer, make the dependecy required in your project:
composer require 10quality/php-calendar
Usage
The following example will build the calendar for the current month:
use TenQuality\Utility\Calendar; $calendar = new Calendar(); $calendar->build();
Attaching data
// 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
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>
Other properties or methods
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;
Coding guidelines
PSR-4.
LICENSE
The MIT License (MIT)
Copyright (c) 2017 10Quality.