falco442/cake-google-calendar

此包已被废弃,不再维护。没有建议的替代包。

CakePHP 2.x 的 Google 日历插件

v1.1.2 2017-03-06 13:26 UTC

This package is not auto-updated.

Last update: 2022-02-01 13:05:49 UTC


README

这是一个简单的 CakePHP 插件,用于 Google 日历,仍在开发中。目前,它可以

  • 在 Google 日历中创建事件
  • 获取 Google 用户的日历列表

安装

手动安装

下载 .zip 文件并将其解压到您的 app/Plugin 文件夹中,将主文件夹重命名为 "GoogleCalendar"

使用 Git 克隆

转到 app/Plugin 文件夹并执行以下命令

git clone https://github.com/falco442/CakePHP-GoogleCalendarPlugin.git GoogleCalendar

使用 Composer

使用 Composer 安装 CakePHP 2.x(遵循此说明)后,您可以使用以下命令安装插件

composer require falco442/cake-google-calendar

用法

加载组件

AppController.php 中的 Components 中加载 GoogleCalendar

public $components = array(
    ...,
    'GoogleCalendar.GoogleCalendar'=>array(
       'id'=>'your-Google-App-id',
        'secret'=>'your-Google-App-secret'        
    )
);

这将加载插件中的组件。

创建事件

如果您想在 Google 日历中创建事件,只需使用 insertEvent() 函数,并传递两个参数:事件数据的数组,以及创建事件的用户 Google id(Google 邮箱)

$this->GoogleCalendar->insertEvent($googleAccountID, $event);

其中事件应为一个数组,形式如下

$event = array(
    'start'=>'2014-12-31 22:00:00',
    'end'=>'2015-01-01 03:30:00',
    'summary'=>'New Years Eve Dinner',
    'description'=>'We will have a great party!!',
    'location'=>'Via Nazionale 6 Roma'
);

该函数返回 Google 返回的事件 id

获取用户的日历列表

要获取用户的日历列表,只需使用 getCalendarList() 函数,该函数接受一个唯一参数:我们想要获取日历列表的用户的 Google 账户 ID

$this->GoogleCalendar->getCalendarList($googleAccountID);

该函数返回一个包含 $googleAccountID 的日历列表的数组。

额外

映射事件字段

如果您不想每次都映射事件字段(可能是因为您的事件表字段名称与 Google 日历事件字段名称不匹配),您可以在 AppController.php 中传递映射参数

public $components = array(
    ...,
    'GoogleCalendar.GoogleCalendar'=>array(
       'id'=>'your-Google-App-id',
        'secret'=>'your-Google-App-secret',
        'eventMap'=>array(
            'summary'=>'event_title',
            'description'=>'event_description'
            'location'=>'event_address',
            'start'=>'start_datetime',
            'end'=>'end_datetime'
        )
    )
);

更改时区

注意,事件的开始和日期仅接受 datetime 格式,并且默认使用时区将 datetime 格式化并发送到 Google 日历。

默认时区为Europe/Rome,但您可以通过AppController.php进行更改。

public $components = array(
    ...,
    'GoogleCalendar.GoogleCalendar'=>array(
        'id'=>'your-Google-App-id',
        'secret'=>'your-Google-App-secret',
        'timeZone'=>'your-Time-Zone-code'
    )
);

您可以在此处找到PHP支持的时区列表。