scortes/calendar

This package is abandoned and no longer maintained. No replacement package was suggested.

Monthly Event Calendar

v1.0.0 2015-08-24 09:54 UTC

This package is auto-updated.

Last update: 2021-05-23 20:36:00 UTC


README

License Latest Stable Version Dependency Status

Install

composer require scortes/calendar

Calendar

  1. Add events - every event needs to have date, content of event is completely up to you (it can be string, object, …)
  2. Optionally you can set min/max dates in dateStart/dateEnd. Otherwise they are automatically calculated.
  3. Display calendar, you can use helper function \Scortes\Calendar\HTML\monthsToTables for classic calendar.
// configure calendar
$request = new \Scortes\Calendar\CalendarRequest();
$request->dateStart = new DateTime('now - 2 month');
$request->dateEnd = null; // use max date from events
$request->events = [
    "now - 1 month" => 'Day in previous month',
    date('Y-n-') . 1 => 'First day in month',
    date('Y-n-') . 16 => '16th day in month',
    "now + 1 month" => 'Day in next month',
];
$request->addEvent(new DateTime('now + 2 months'), 'now + 2 months');

// build calendar
$calendar = Scortes\Calendar\createCalendar($request);

// display calendar
\Scortes\Calendar\HTML\monthsToTables(
    $calendar,
    array(
        'hideMonthsWithoutEvent' => true,
        'selectors' => array(
            'table' => ' class=calendar',
            'month' => ' id=currentMonth',
            'week' => ' id=currentWeek',
            'day' => ' id=today',
        ),
        'monthName' => function (Scortes\Calendar\Month\Month $month, $monthId) {
            return "<h3{$monthId}>Month {$month->monthNumber}/{$month->year}</h3>";
        },
        'day' => array(
            'withEvent' => function ($event, $currentDay) {
                return "<strong title='{$event}'>{$currentDay}</strong>";
            },
            'withoutEvent' => function ($currentDay) {
                return "<strong>{$currentDay}</strong>";
            },
            'empty' => '<td class="noDay">&nbsp;</td>'
        )
    )
);

Components

Calendar consist of two independent components:

Analyze months between two DateTimes

$dateStart = new DateTime('now - 1 month');
$dateEnd = new DateTime('now + 2 months');
$months = \Scortes\Calendar\createMonthsInterval($dateStart, $dateEnd);
Year Month Days Count Weeks Count First Day of Week First Week Number
2015 7 31 5 3 27
2015 8 31 6 6 31
2015 9 30 5 2 36
2015 10 31 5 4 40

### Data structure for events (trie separated by delimiter)

$events = new \Scortes\Calendar\Events\Events(' ');
$events->set('John', 'John');
$events->set('John Doe', 'John Doe');
$events->set('John Black', 'John Black');
$events->set('John Black', 'Another John Black');
$events->set('Paul Carter', 'Paul Carter');

$events->get('John Doe'); // John Doe
$events->get('John Black'); // [John Black, Another John Black]
$events->iterate('John'); // [John, John Doe, [John Black, Another John Black]]

Contributing

Contributions from others would be very much appreciated! Send pull request/issue. Thanks!

License

Copyright (c) 2015 Scortes. MIT Licensed, see LICENSE for details.