soockee/php-calendar 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

soockee/php-calendar

Composer 安装命令:

composer require soockee/php-calendar

包简介

A simple PHP class to generate calendars.

README 文档

README

A PHP class that makes generating calendars as easy as possible.

You can use the addEvent() or addEvents() methods to mark events on the generated calendar.

This is fully compatible with PHP 5 through tzo PHP 8.1+

Fork

This is a fork of benhall14/php-calendar

The additional features and modifications described in the next sections.

Multi-Cell Event Support

This implementation makes events span over multiple rows, if an event start and end date exceeds a single cells interval.

Dynamic Week View

The weekview is display based on current days date instead of fixed monday or sunday.

Installation via Composer

You can now install this class via composer.

$ composer require soockee/php-calendar

Remember to add the composer autoloader before using the class and use the correct namespace.

require 'vendor/autoload.php';

use soockee\phpCalendar\Calendar as Calendar;

Usage

Please make sure you have added the required classes.

Styling

You can apply styles in one of three ways:

  1. Using $calendar->stylesheet() after you have initialised a calendar;
    $calendar = new Calendar;
    $calendar->stylesheet();
  1. Using the calendar.css (or calendar.min.css) from the css directory;
    <link rel="stylesheet" type="text/css" href="css/calendar.min.css">
  1. Create your own stylesheet and add it to the head of your HTML document.

Draw a 'Month View' calendar

In its simplest form, use the following to create a calendar for current month. This will use all defaults (English, Week starting on Sunday, including stylesheet, printing to the page).

    (new Calendar)->display();

Or, you can break it down with full customisability:

    # create the calendar object
    $calendar = new Calendar;
    
    # change the weekly start date to "Monday"
    $calendar->useMondayStartingDate();
    
    # or revert to the default "Sunday"
    $calendar->useSundayStartingDate();
    
    # (optional) - if you want to use full day names instead of initials (ie, Sunday instead of S), apply the following:
    $calendar->useFullDayNames();
    
    # to revert to initials, use:
    $calendar->useInitialDayNames();

    # use the French locale, with days and month names being translated to French.
    $calendar->setLocale('fr_FR');
    # This uses the Carbon locales - https://carbon.nesbot.com/docs/#api-localization

    # add your own table class(es)
    $calendar->addTableClasses('class-1 class-2 class-3');
    # or using an array of classes.
    $calendar->addTableClasses(['class-1', 'class-2', 'class-3']);
    
    # (optional) - if you want to hide certain weekdays from the calendar, for example a calendar without weekends, you can use the following methods:
    $calendar->hideSaturdays() 		# This will hide Saturdays
    $calendar->hideSundays(); 		# This will hide Sundays
    $calendar->hideMondays(); 		# This will hide Mondays
    $calendar->hideTuesdays(); 		# This will hide Tuesdays
    $calendar->hideWednesdays();	# This will hide Wednesdays
    $calendar->hideThursdays();		# This will hide Thursdays
    $calendar->hideFridays();		# This will hide Fridays
    
    # (optional) - Translated Calendars - currently, there is only Spanish, but see "Translations" below for adding your own strings.
    $calendar->useSpanish(); 

    # if needed, add event
	$calendar->addEvent(
	    '2022-01-14',   # start date in either Y-m-d or Y-m-d H:i if you want to add a time.
	    '2022-01-14',   # end date in either Y-m-d or Y-m-d H:i if you want to add a time.
	    'My Birthday',  # event name text
	    true,           # should the date be masked - boolean default true
	    ['myclass', 'abc']   # (optional) additional classes in either string or array format to be included on the event days
	    ['event-class', 'abc']   # (optional) additional classes in either string or array format to be included on the event summary box
	);

    # or for multiple events

	$events = array();

	$events[] = array(
		'start' => '2022-01-14',
		'end' => '2022-01-14',
		'summary' => 'My Birthday',
		'mask' => true,
		'classes' => ['myclass', 'abc'],
        'event_box_classes' => ['event-box-1']
	);

	$events[] = array(
		'start' => '2022-12-25',
		'end' => '2022-12-25',
		'summary' => 'Christmas',
		'mask' => true
	);

	$calendar->addEvents($events);

    # finally, to draw a calendar    
    echo $calendar->draw(date('Y-m-d')); # draw this months calendar    

    # this can be repeated as many times as needed with different dates passed, such as:    
    echo $calendar->draw(date('Y-01-01')); # draw a calendar for January this year    
    echo $calendar->draw(date('Y-02-01')); # draw a calendar for February this year    
    echo $calendar->draw(date('Y-03-01')); # draw a calendar for March this year    
    echo $calendar->draw(date('Y-04-01')); # draw a calendar for April this year    
    echo $calendar->draw(date('Y-05-01')); # draw a calendar for May this year    
    echo $calendar->draw(date('Y-06-01')); # draw a calendar for June this year    
    
    # to use the pre-made color schemes, call the ->stylesheet() method and then pass the color choice to the draw method, such as:    
    echo $calendar->draw(date('Y-m-d'));            # print a (default) turquoise calendar    
    echo $calendar->draw(date('Y-m-d'), 'purple');  # print a purple calendar    
    echo $calendar->draw(date('Y-m-d'), 'pink');    # print a pink calendar    
    echo $calendar->draw(date('Y-m-d'), 'orange');  # print a orange calendar    
    echo $calendar->draw(date('Y-m-d'), 'yellow');  # print a yellow calendar    
    echo $calendar->draw(date('Y-m-d'), 'green');   # print a green calendar    
    echo $calendar->draw(date('Y-m-d'), 'grey');    # print a grey calendar    
    echo $calendar->draw(date('Y-m-d'), 'blue');    # print a blue calendar  
    
    # you can also call ->display(), which handles the echo'ing and adding the stylesheet.
    echo $calendar->display(date('Y-m-d')); # draw this months calendar    

Draw a 'Week View' calendar

Instead of a 'month view' calendar, you can now render as a 'week view'. To do this, simply use ->useWeekView(). Remember, when adding events to a week-view calendar, you need to include the time too (see events above).

    $events = array();

    $events[] = array(
        'start' => '2022-01-14 14:40',
        'end' => '2022-01-14 15:10',
        'summary' => 'My Birthday',
        'mask' => true,
        'classes' => ['myclass', 'abc']
    );

    $events[] = array(
        'start' => '2022-11-04 14:00',
        'end' => '2022-11-04 18:30',
        'summary' => 'Event 1',
        'mask' => true
    );
    $events[] = array(
        'start' => '2022-11-04 14:00',
        'end' => '2022-11-04 18:30',
        'summary' => 'Event 2',
        'mask' => true
    );

    $calendar = new Calendar;

    $calendar->addEvents($events)->setTimeFormat('00:00', '00:00', 10)->useWeekView()->display(date('Y-m-d'), 'green');

You can change the start/end times of the day, along with the time interval by using the ->setTimeFormat method:

    $calendar->setTimeFormat('00:00', '00:00', 10)->useWeekView()->display(date('Y-m-d'), 'green');
    # This will print a week view calendar with 10 minute slots from midnight to midnight - ie. 00:00, 00:10, 00:20 and so on.

Monday Start Date

You can now change the weekly start date from a Sunday to a Monday. To activate this, simple use the useMondayStartingDate() method before you 'draw'.

    $calendar = new Calendar;
    $calendar->useMondayStartingDate();
    $calendar->display(date('Y-m-d'), 'green');

Translated Calendars

We now use automatically from the date and the setLocale() method. If you use ->setLocale('fr_FR'), then the days and month names will be French. For more information on the Carbon localization, see https://carbon.nesbot.com/docs/#api-localization

Credits

Requirements

Carbon

License

Copyright (c) 2016-2022 Benjamin Hall, ben@conobe.co.uk https://conobe.co.uk

Copyright (c) 2025 Simon Stockhause simon.stockhause@dampfzeit.com https://dampfzeit.com

Licensed under the MIT license

soockee/php-calendar 适用场景与选型建议

soockee/php-calendar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「time」 「date」 「calendar」 「calendars」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 soockee/php-calendar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 soockee/php-calendar 我们能提供哪些服务?
定制开发 / 二次开发

基于 soockee/php-calendar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 34
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-02