10quality/php-calendar

PHP日历处理类。

v1.0.2 2019-05-08 00:45 UTC

This package is auto-updated.

Last update: 2024-08-27 12:58:48 UTC


README

Latest Stable Version Total Downloads License

PHP日历处理库。

注意: 此类不会输出/打印日历。

特性

  • 处理每月的周和日。
  • 可以附加数据。
  • 可以在任何自定义模板中渲染。

安装

使用composer,在项目中指定此依赖项

composer require 10quality/php-calendar

使用方法

以下示例将为当前月份构建日历

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();

打印

打印示例

<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>

其他属性或方法

为特定日期构建日历

$calendar = new Calendar('2017-01-25');
$calendar->build();

获取上个月和下个月的日期

$calendar = new Calendar('2017-01-25');
$calendar->nextMonthDate;
$calendar->prevMonthDate;

编码指南

PSR-4。

许可协议

The MIT License (MIT)

版权所有 (c) 2017 10Quality