run diz/thai-calendar

此包已被弃用,不再维护。未建议替代包。

泰语日历(也支持多语言)。

v2.0 2016-05-03 05:26 UTC

This package is auto-updated.

Last update: 2024-05-08 07:47:56 UTC


README

泰语日历(也支持多语言)。ปฏิทินภาษาไทย (และรองรับได้หลายภาษา).

Latest Stable Version License Total Downloads

此日历组件可以显示多种范围(如日、周、月、年)的日历。您可以在日历中添加事件或预约。要开始使用非常简单,只需设置一些类属性并显示即可。

用法

基本用法

在此示例中,仅显示日历,没有事件或预约,以便于理解。

// If you did not install it via Composer, you have to include/require these files.
require dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Rundiz' . DIRECTORY_SEPARATOR . 'Calendar' . DIRECTORY_SEPARATOR . 'Calendar.php';
require dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Rundiz' . DIRECTORY_SEPARATOR . 'Calendar' . DIRECTORY_SEPARATOR . 'Generators' . DIRECTORY_SEPARATOR . 'GeneratorInterface.php';
require dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Rundiz' . DIRECTORY_SEPARATOR . 'Calendar' . DIRECTORY_SEPARATOR . 'Generators' . DIRECTORY_SEPARATOR . 'GeneratorAbstractClass.php';
// The files below is calendar HTML generator. Choose just only one.
require dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Rundiz' . DIRECTORY_SEPARATOR . 'Calendar' . DIRECTORY_SEPARATOR . 'Generators' . DIRECTORY_SEPARATOR . 'Simple.php';
require dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Rundiz' . DIRECTORY_SEPARATOR . 'Calendar' . DIRECTORY_SEPARATOR . 'Generators' . DIRECTORY_SEPARATOR . 'Bootstrap3.php';

$Calendar = new \Rundiz\Calendar\Calendar();
// Set your base URL for links to other date/month/year in the same page.
$Calendar->base_url = (isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
// Set the viewing date to let calendar component knows that what is currently date you are looking at.
$Calendar->viewing_date = (isset($_GET['viewdate']) ? strip_tags($_GET['viewdate']) : date('Y-m-d'));
// Set first day of the week. You can ignore this property because it is set to 0 (Sunday) by default. Set to 0 for Sunday, 1 for Monday to 6 for Saturday.
$Calendar->first_day_of_week = 1;
// Display the calendar. 
// The first argument in this method is scope. You can set to 'day', 'week', 'month', 'year'.
// The second argument is the generator class name in case that you want something different.
echo $Calendar->display('day');
// Call to clear to clear and reset everything and make it ready to begins again.
$Calendar->clear();

使用其他生成器

$Calendar = new \Rundiz\Calendar\Calendar();
$Calendar->base_url = (isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$Calendar->viewing_date = (isset($_GET['viewdate']) ? strip_tags($_GET['viewdate']) : date('Y-m-d'));
// We already have 2 generators for you to use. 1 is Simple and 2 is Bootstrap3. Use its class name in second argument of display() method.
echo $Calendar->display('year', '\\Rundiz\\Calendar\\Generators\\Bootstrap3');
$Calendar->clear();

事件、预约

日、周、月、年范围的事件或预约始终使用相同的数组格式。让我们看看示例。

// Assume that today is 2016-05-02.
$events = array (
  array (
    'date_from' => '2016-05-02 00:00:00',
    'date_to' => '2016-05-03 01:00:00',
    'title' => 'Event today to tomorrow +1hr.',
  ),
  array (
    'date_from' => '2016-05-02 00:50:00',
    'date_to' => '2016-05-04 16:00:00',
    'title' => 'Event today to after tomorrow 00:50 to 16:00.',
  ),
  'special_event1' => array (
    'date_from' => '2016-05-03 10:00:00',
    'date_to' => '2016-05-03 15:00:00',
    'title' => 'Event tomorrow with special key name',
  ),
  array (
    'date_from' => '2016-05-03 11:00:00',
    'date_to' => '2016-05-03 15:00:00',
    'title' => 'Event tomorrow 11:00 to 15:00',
  ),
  array (
    'date_from' => '2016-05-03 23:40:00',
    'date_to' => '2016-05-04 02:30:00',
    'title' => 'Event tomorrow to after tomorrow 23:40 to 02:30',
  ),
  array (
    'date_from' => '2016-05-04 08:00:00',
    'date_to' => '2016-05-04 23:59:00',
    'title' => 'Event after tomorrow 08:00 to 23:59',
  ),
  array (
    'date_from' => '2016-05-14',
    'date_to' => '2016-05-14',
    'title' => 'Event next 12 days',
  ),
  array (
    'date_from' => '2016-05-28',
    'date_to' => '2016-06-02',
    'title' => 'Event 28 this month to next 5 days',
  ),
) ;

数组键 'date_from' 和 'date_to' 是必需的,键 'title' 是可选的。您可以在此数据中添加更多数组键,但您必须自己创建生成器以支持它。使用 setEvents() 方法将事件设置到日历中。

$Calendar = new \Rundiz\Calendar\Calendar();
$Calendar->base_url = (isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$Calendar->viewing_date = (isset($_GET['viewdate']) ? strip_tags($_GET['viewdate']) : date('Y-m-d'));
$Calendar->setEvents($events);
echo $Calendar->display('month');
$Calendar->clear();

自定义

更改区域设置

您可以将语言更改为使用其他语言(或区域设置)。为此,请调用 Calendar 类的 'locale' 属性。

$Calendar->locale = array('en_UK.utf8', 'en_UK', 'en');

有关区域设置的更多信息,请参阅 https://php.ac.cn/manual/en/function.setlocale.php

一周的第一天

您可以使用其他天作为一周的第一天,而不是星期日。将 'first_day_of_week' 属性设置为天数(0 = 星期日,1 = 星期一,2 = 星期二,...,6 = 星期六)

$Calendar->first_day_of_week = 3;// Wednesday as firstday of week.

佛教纪元(ปีพุทธศักราช)

您可以设置是否使用佛教纪元(BE)。您还可以更改佛教纪元和公历(AD)之间的年份差异。默认情况下,我们使用 543。

$Calendar->use_buddhist_era = true;// Set to false for not to use Buddhist era.
$Calendar->buddhist_era_offset = 543;
$Calendar->buddhist_era_offset_short = 43;// 2016 = 2559, 16 = 59.

屏幕截图

日范围日历

Day calendar

周范围日历

Week calendar

月范围日历

Month calendar

年范围日历

Year calendar