rafapaulino/calendar

1.1.4 2021-08-19 03:39 UTC

This package is auto-updated.

Last update: 2024-09-19 10:55:27 UTC


README

🡺 访问文档 🡸

Latest Stable Version Total Downloads Latest Unstable Version License Donate

这个包是什么以及它的作用是什么?

PHP日历是一个PHP包,可以从月份和年份参数生成日历,除此之外,还可以向日历中添加事件。

开始使用

1. 要求

2. 安装

  • composer require rafapaulino/calendar

3. 文档

您可以通过点击此处访问此包的文档

4. 代码示例

如何创建一个简单的日历

此包使用PHP创建日历,回调函数以字符串和数组格式存在。

生成日历的参数包括

  • month 月份,1到12。
  • year 日历的年份。
  • first day of week 日历开始的一周中的某一天。
  • full days 是否在日历上显示42天。

请参阅示例文件夹,了解如何轻松使用该类。

<?php
require '../vendor/autoload.php';

use Calendar\Calendar;

$calendar = new Calendar(
    1, //month
    2021, //year
    0, //first day of week 0-6
    true //show 42 days in calendar collumns
);
$month = $calendar->getMonth();
$year = $calendar->getYear();
$days = $calendar->getDays();
$daysWeek = $calendar->getDaysWeek();
?>
<table>
    <caption><?php echo $month->fullName; ?> <?php echo $year; ?></caption>
    <thead>
        <tr>
            <?php foreach($daysWeek as $week): ?>
                <th><?php echo $week->letter; ?></th>
            <?php endforeach; ?>
        </tr>
    </thead>
    <tbody>
        <?php 
            $loop = 0;
            foreach($days as $day):
                
        ?>
            <?php if ($loop == 0): ?><tr><?php endif; ?>
            
            <td class="<?php echo (($day->currentMonth)?'current':''); ?> <?php echo (($day->carbon->isToday() && $day->currentMonth)?'today':''); ?>"><?php echo $day->day; ?></td>

            <?php if ($loop == 6): ?></tr><?php endif; ?> 
        <?php 
            $loop++; 

            if ($loop > 6) $loop = 0;

            endforeach; 
        ?>
    </tbody>
</table>
<?php 
    if (($mes % 3) == 0): echo '<div style="clear:both;"></div>'; endif;

    endforeach; 
?>

向您的日历添加事件

<?php 
include 'vendor/autoload.php';

use Calendar\Calendar;
use Calendar\Events;

$calendar = new Calendar(1,2021, 0, true);
$events = new Events(1,2021);
$events->addEvent("My brother's birthday","2021-01-17",1);
$events->addEvent("Vacation","2021-01-01",9);
$month = $events->getMonth();
$year = $events->getYear();
$days = $events->getDays();
$daysWeek = $events->getDaysWeek();
?>
<table>
    <caption><?php echo $month->fullName; ?> <?php echo $year; ?></caption>
    <thead>
    <tr>
        <?php foreach($daysWeek as $week): ?>
            <th><?php echo $week->letter; ?></th>
        <?php endforeach; ?>
    </tr>
    </thead>
    <tbody>
    <?php
    $loop = 0;
    foreach($days as $day):

        ?>
        <?php if ($loop == 0): ?><tr><?php endif; ?>

        <td title="<?php echo ((count($day->events) > 0)? implode(", ",$day->events):''); ?>" class="<?php echo (($day->currentMonth)?'current':''); ?> <?php echo (($day->carbon->isToday() && $day->currentMonth)?'today':''); ?> <?php echo ((count($day->events) > 0)? 'events':''); ?>">
            <?php echo $day->day; ?>
        </td>

        <?php if ($loop == 6): ?></tr><?php endif; ?>
        <?php
        $loop++;

        if ($loop > 6) $loop = 0;

    endforeach;
    ?>
    </tbody>
</table>

特性

  • v1.1.4 我将事件添加到日历中。
  • v1.0.0 包创建和单元测试。

5. 示例

6. 支持

如果您需要任何支持,请检查我们的问题。您可以在那里提问或报告问题。

7. 致谢

创建者:Rafael Paulino