dhtmlx / scheduler-helper
dhtmlxScheduler中处理重复事件的辅助工具。
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-09-14 16:29:27 UTC
README
需求
- PHP>=5.4 (PDO~)
- MySQL, PostgreSQL, Sqlite等。
安装
- composer 'dhtmlx/scheduler-helper'
或者
- 直接从以下仓库下载文件 'git@github.com:DHTMLX/scheduler-helper-php.git'
require_once "./SchedulerHelper.php"; use DHTMLX_Scheduler\Helper;
如何使用
为了创建一个辅助对象,您应该调用类构造函数 DHTMLX_Scheduler\Helper([$connectorDataArray]):
$helper = new Helper( array( "dbsm" => "mysql", // optional, "mysql" by default "host" => "localhost", // optional, "localhost" by default "db_name" => "scheduler_helper_db", "user" => "root", "password" => "root", "table_name" => "events_rec" // name of the table that contains data of recurring events ) );
在辅助工具中定义了一套标准的字段,用于处理表格。
helper::FLD_ID => "event_id", helper::FLD_START_DATE => "start_date", helper::FLD_END_DATE => "end_date", helper::FLD_TEXT => "text", helper::FLD_RECURRING_TYPE => "rec_type", helper::FLD_PARENT_ID => "event_pid", helper::FLD_LENGTH => "event_length"
为了重新定义辅助工具并创建新字段,您应该使用方法 'setFieldsNames([$fieldsDataArray])'
$helper->setFieldsNames(array( $helper::FLD_RECURRING_TYPE => "my_recurring_type_field", // redefining the field 'FLD_RECURRING_TYPE'. "my_property_field" // initialization of a new field ));
要获取已设置的仅字段,只需在函数 'setFieldsNames([$fieldsDataArray], true)' 中的第二个参数设置 'true' 即可。
$helper->setFieldsNames(array( $helper::FLD_RECURRING_TYPE => "my_recurring_type_field", // redefining the field 'FLD_RECURRING_TYPE'. "my_property_field" // initialization of a new field ), true);
要设置是否考虑服务器时区,您应使用 server_date 配置(默认为 false)。如果为 true,则辅助工具将使用服务器时间,否则将使用从数据库获取的日期。
$helper->config["server_date"] = true;
要设置重复发生日期是否保存在UTC中,可以使用 "occurrence_timestamp_in_utc" 配置(默认为 false)。如果为 true,则辅助工具将按UTC处理异常日期。
$helper->config["occurrence_timestamp_in_utc"] = true;
要保存数据到数据库,请使用方法 'saveData([dataArray])'
// To save data of the field 'FLD_RECURRING_TYPE', you can use a data array or a string in the format 'week_2_____1,3#10'. $newRecurringTypeArray = array( "each" => "week", "step" => 2, "days_of_week" => "monday,wednesday", // if the field 'week_number' is set, the field 'days_of_week' must contain only one value // "week_number" => 2, "repeat" => 10 ); $helper->saveData(array( // $helper::FLD_ID => "20", // if you pass this field for saving, data in the database will be updated by this value, otherwise new data will be written $helper::FLD_RECURRING_TYPE => $newRecurringTypeArray, $helper::FLD_START_DATE => "2015-09-30 00:00:00", $helper::FLD_END_DATE => $helper->getRecurringEndDateStr($newRecurringTypeArray, "2015-09-30 00:00:00", 500), // to count the end date of the recurring series, you can use the function 'getRecurringEndDateStr' $helper::FLD_LENGTH => 500, "my_property_field" => "Any data..." // new fields defined by the user must be presented in this way ));
要删除数据库中的数据,应使用方法 'deleteById([ID])'
$helper->deleteById(48); // will delete data by the field 'FLD_ID'.
要获取重复事件的详细信息,请使用方法 'getData([$startDateStr], [$endDateStr])'
$helper->getData("2015-02-10 09:00:00", "2020-01-02 07:00:00"); // The function will return recurring events from the defined range taking into account exclusion of events series // The result will look as follows: //array( // array( // "start_date" => "2015-02-13 00:00:00", // "end_date" => "2015-02-15 00:00:00", // "text" => "Second Friday", // ... // ), // .... //);
#####测试
为了运行测试
-
按照以下说明安装 PHPUnit https://phpunit.de/manual/current/en/installation.html
-
在 tests/TestConfig.php 中配置数据库设置
-
进入仓库文件夹并执行
phpunit --bootstrap SchedulerHelper.php tests/SchedulerHelperTest
许可证
MIT许可证
版权(c)2015 DHTMLX
特此授予任何获得本软件及其相关文档副本(“软件”)的人免费使用软件的权利,不受任何限制,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,以及允许向软件提供方提供软件的人以这样做,前提是以下条件
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。