Скрипт календаря для php

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

A simple PHP class to generate calendars. Easy to populate, the calendar shows events by passing in an array.

License

benhall14/php-calendar

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

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 to PHP 8.1+

Installation via Composer

You can now install this class via composer.

$ composer require benhall14/php-calendar 

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

require 'vendor/autoload.php'; use benhall14\phpCalendar\Calendar as Calendar; 

Please make sure you have added the required classes.

You can apply styles in one of three ways:

$calendar = new Calendar; $calendar->stylesheet();
link rel pl-s">stylesheet" type pl-s">text/css" href pl-s">css/calendar.min.css">

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

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(); # 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 ); # or for multiple events $events = array(); $events[] = array( 'start' => '2022-01-14', 'end' => '2022-01-14', 'summary' => 'My Birthday', 'mask' => true, 'classes' => ['myclass', 'abc'] ); $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

Читайте также:  Import java math pow

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.

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

We now ship with both English and Spanish translations, with more coming soon. Alternatively, you can add your own custom string translations for both the days and months using the following:

# This will set up the days - simply copy/paste the code below and replace the Spanish initials and full-day names with your own. (NB - Leave the keys in English) $calendar->setDays([ 'sunday' => [ 'initials' => 'D', 'full' => 'Domingo' ], 'monday' => [ 'initials' => 'L', 'full' => 'Lunes', ], 'tuesday' => [ 'initials' => 'M', 'full' => 'Martes', ], 'wednesday' => [ 'initials' => 'X', 'full' => 'Miércoles', ], 'thursday' => [ 'initials' => 'J', 'full' => 'Jueves', ], 'friday' => [ 'initials' => 'V', 'full' => 'Viernes', ], 'saturday' => [ 'initials' => 'S', 'full' => 'Sábado', ], ]); # To add custom month names, simply copy/paste the code below and replace the Spanish month names with your own strings. (NB - Leave the keys in English) $calendar->setMonths([ 'january' => 'Enero', 'february' => 'Febrero', 'march' => 'Marzo', 'april' => 'Abril', 'may' => 'Mayo', 'june' => 'Junio', 'july' => 'Julio', 'august' => 'Agosto', 'september' => 'Septiembre', 'october' => 'Octubre', 'november' => 'Noviembre', 'december' => 'Diciembre' ]);

If you want to help with translations, use the code in the useSpanish() method as a guide, and open a pull-request.

Читайте также:  Merge excel files python

Fully tested to work with PHP 5.3, 5.5, 5.6, 7.0, 7.1, 7.2, 7.3 and 8.1

PHP DateTime

Licensed under the MIT license

If you find this project helpful or useful in any way, please consider getting me a cup of coffee — It’s really appreciated 🙂

About

A simple PHP class to generate calendars. Easy to populate, the calendar shows events by passing in an array.

Источник

Календарь на PHP

PHP-класс для вывода календаря на месяц, год или любой другой интервал с возможностью выделить отдельные даты и вывести к ним подсказки.

class Calendar < /** * Вывод календаря на один месяц. */ public static function getMonth($month, $year, $events = array()) < $months = array( 1 =>'Январь', 2 => 'Февраль', 3 => 'Март', 4 => 'Апрель', 5 => 'Май', 6 => 'Июнь', 7 => 'Июль', 8 => 'Август', 9 => 'Сентябрь', 10 => 'Октябрь', 11 => 'Ноябрь', 12 => 'Декабрь' ); $month = intval($month); $out = ' 
'; $day_week = date('N', mktime(0, 0, 0, $month, 1, $year)); $day_week--; $out.= ''; for ($x = 0; $x '; > $days_counter = 0; $days_month = date('t', mktime(0, 0, 0, $month, 1, $year)); for ($day = 1; $day elseif (time() > strtotime($day . '.' . $month . '.' . $year)) < $class = 'last'; >else < $class = ''; >$event_show = false; $event_text = array(); if (!empty($events)) < foreach ($events as $date =>$text) < $date = explode('.', $date); if (count($date) == 3) < $y = explode(' ', $date[2]); if (count($y) == 2) < $date[2] = $y[0]; >if ($day == intval($date[0]) && $month == intval($date[1]) && $year == $date[2]) < $event_show = true; $event_text[] = $text; >> elseif (count($date) == 2) < if ($day == intval($date[0]) && $month == intval($date[1])) < $event_show = true; $event_text[] = $text; >> elseif ($day == intval($date[0])) < $event_show = true; $event_text[] = $text; >> > if ($event_show) < $out.= ''; > else < $out.= ''; > if ($day_week == 6) < $out.= ''; if (($days_counter + 1) != $days_month) < $out.= ''; > $day_week = -1; > $day_week++; $days_counter++; > $out .= '
Пн Вт Ср Чт Пт Сб Вс
' . $day; if (!empty($event_text)) < $out.= '
', $event_text) . '
'; > $out.= '
' . $day . '
'; return $out; > /** * Вывод календаря на несколько месяцев. */ public static function getInterval($start, $end, $events = array()) < $curent = explode('.', $start); $curent[0] = intval($curent[0]); $end = explode('.', $end); $end[0] = intval($end[0]); $begin = true; $out = '
$curent[0]++; if ($curent[0] == 13) < $curent[0] = 1; $curent[1]++; >> while ($begin == true); $out .= '
'; return $out; > >
.calendar-item < width: 200px; display: inline-block; vertical-align: top; margin: 0 16px 20px; font: 14px/1.2 Arial, sans-serif; >.calendar-head < text-align: center; padding: 5px; font-weight: 700; font-size: 14px; >.calendar-item table < border-collapse: collapse; width: 100%; >.calendar-item th < font-size: 12px; padding: 6px 7px; text-align: center; color: #888; font-weight: normal; >.calendar-item td < font-size: 13px; padding: 6px 5px; text-align: center; border: 1px solid #ddd; >.calendar-item tr th:nth-child(6), .calendar-item tr th:nth-child(7), .calendar-item tr td:nth-child(6), .calendar-item tr td:nth-child(7) < color: #e65a5a; >.calendar-day.last < color: #999 !important; >.calendar-day.today < font-weight: bold; >.calendar-day.event < background: #ffe2ad; position: relative; cursor: pointer; >.calendar-day.event:hover .calendar-popup < display: block; >.calendar-popup < display: none; position: absolute; top: 40px; left: 0; min-width: 200px; padding: 15px; background: #fff; text-align: left; font-size: 13px; z-index: 100; box-shadow: 0 0 10px rgba(0,0,0,0.5); color: #000; >.calendar-popup:before

Далее приведены варианты использования класса и живые примеры.

Читайте также:  Using php in linux

Календарь на месяц

Вывод календаря на текущий месяц:

echo Calendar::getMonth(date('n'), date('Y'));

Источник

Оцените статью