ecasanes/laravel-google-calendar-php-6

管理Google日历上的事件(兼容PHP 5.6.15及以上版本)

1.1.0 2017-04-26 13:05 UTC

This package is not auto-updated.

Last update: 2024-09-29 02:09:34 UTC


README

Latest Version on Packagist Software License Build Status SensioLabsInsight Quality Score StyleCI Total Downloads

此包使与Google日历协同工作变得轻松。一旦设置完成,您可以执行以下操作

use Spatie\GoogleCalendar\Event;

//create a new event
$event = new Event;

$event->name = 'A new event';
$event->startDateTime = Carbon\Carbon::now();
$event->endDateTime = Carbon\Carbon::now()->addHour();
$event->addAttendee(['email' => 'youremail@gmail.com']);
$event->addAttendee(['email' => 'anotherEmail@gmail.com']);

$event->save();

// get all future events on a calendar
$events = Event::get();

$firstEvent = $events->first();
$firstEvent->name = 'updated name';
$firstEvent->save();

// create a new event
Event::create([
   'name' => 'A new event'
   'startDateTime' => Carbon\Carbon::now(),
   'endDateTime' => Carbon\Carbon::now()->addHour(),
]);

// delete an event
$event->delete();

Spatie是一家位于比利时的安特卫普的网页设计公司。您可以在我们的网站上找到所有开源项目的概述这里

Postcardware

您可以使用此包(它MIT授权),但如果它进入您的生产环境,则必须向我们发送一张来自您家乡的明信片,并说明您正在使用我们的哪些包。

我们的地址是:Spatie,Samberstraat 69D,2060 安特卫普,比利时。

最佳明信片将在我们网站上的开源页面上发布。

安装

您可以通过Composer安装此包

composer require ecasanes/laravel-google-calendar-php-6

接下来必须注册服务提供者

'providers' => [
    ...
    Spatie\GoogleCalendar\GoogleCalendarServiceProvider::class,
];

可选地必须注册Spatie\GoogleCalendar\GoogleCalendarFacade

'aliases' => [
	...
    'GoogleCalendar' => Spatie\GoogleCalendar\GoogleCalendarFacade::class,
    ...
]

您必须使用以下命令发布配置

php artisan vendor:publish --provider="Spatie\GoogleCalendar\GoogleCalendarServiceProvider"

这将发布名为laravel-google-calendar.php的文件到您的配置目录,并包含以下内容

<?php

return [

    /**
     * Path to a json file containing the credentials of a Google Service account.
     */
    'client_secret_json' => storage_path('app/laravel-google-calendar/client_secret.json'),

    /**
     *  The id of the Google Calendar that will be used by default.
     */
    'calendar_id' => '',

];

阅读此博客文章,了解如何获取client_secret_jsoncalendar_id的正确值。

使用方法

获取事件

您可以通过调用Event::get();轻松获取所有事件,这将返回未来一年的所有事件。事件以Spatie\GoogleCalendar\Event对象的形式呈现。

函数的完整签名是

/**
 * @param \Carbon\Carbon|null $startDateTime
 * @param \Carbon\Carbon|null $endDateTime
 * @param array $queryParameters
 * @param string|null $calendarId
 *
 * @return \Illuminate\Support\Collection
 */
public static function get(Carbon $startDateTime = null, Carbon $endDateTime = null, array $queryParameters = [], string $calendarId = null) : Collection

您可以在$queryParameters中传递的参数列在Google日历API文档中关于list的说明上。

访问事件的开始和结束日期

您可以使用这些getter获取开始和结束日期作为Carbon实例

$events = Event::get();

$event[0]->startDate;
$event[0]->startDateTime;
$event[0]->endDate;
$event[0]->endDateTime;

创建一个事件

您可以直接new一个Spatie\GoogleCalendar\Event-对象

$event = new Event;

$event->name = 'A new event';
$event->startDateTime = Carbon\Carbon::now();
$event->endDateTime = Carbon\Carbon::now()->addHour();

$event->save();

您也可以调用静态方法create

Event::create([
   'name' => 'A new event',
   'startDateTime' => Carbon\Carbon::now(),
   'endDateTime' => Carbon\Carbon::now()->addHour(),
]);

这将创建一个具有特定开始和结束时间的事件。如果您想创建全天活动,必须使用startDateendDate而不是startDateTimeendDateTime

$event = new Event;

$event->name = 'A new full day event';
$event->startDate = Carbon\Carbon::now();
$event->endDate = Carbon\Carbon::now()->addDay();

$event->save();

获取单个事件

Google为每个单个事件分配一个唯一的ID。您可以通过使用get方法获取事件并获取Spatie\GoogleCalendar\Event-对象的id属性来获取此ID

// get the id of the first upcoming event in the calendar.
$calendarId = Event::get()->first()->id;

您可以使用此ID从Google获取单个事件

Event::find($calendarId);

更新一个事件

很简单,只需更改一些属性并调用save()

$event = Event::find($eventId);

$event->name = 'My updated title';
$event->save();

删除一个事件

很简单!

$event = Event::find($eventId);

$event->delete();

限制

Google日历API提供了许多选项。此包不支持所有这些选项。例如,无法使用此包正确管理重复事件。如果您坚持使用名称和日期创建事件,应该没问题。

变更日志

有关最近更改的更多信息,请参阅CHANGELOG

测试

$ composer test

贡献

有关详细信息,请参阅CONTRIBUTING

安全

如果您发现任何安全问题,请通过电子邮件发送至 freek@spatie.be,而不是使用问题跟踪器。

鸣谢

关于Spatie

Spatie是一家位于比利时的安特卫普的网页设计公司。您可以在我们的网站上找到所有开源项目的概述这里

许可证

MIT许可证(MIT)。更多信息请参阅 许可证文件