arturgrigio/google-laravel-calendar-2 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

arturgrigio/google-laravel-calendar-2

Composer 安装命令:

composer require arturgrigio/google-laravel-calendar-2

包简介

Manage events on a Google Calendar

README 文档

README

This package is originally by Spatie. It was using Google API 1.1.7, but I couldn't get the key to work properly, so I ended up reimplementing the $client with OAuth2. Here is an example of what you can do with the repo:

use Arturgrigio\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->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();

Installation

You can install the package via composer:

composer require arturgrigio/google-laravel-calendar-2

Next up the service provider must be registered:

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

Optionally the Spatie\GoogleCalendar\GoogleCalendarFacade must be registered:

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

You must publish the configuration with this command:

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

This will publish file called laravel-google-calendar.php in your config-directory with this contents:

<?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' => '',

    /**
     *  This is where google will save the credentials
     */
    'credentials_path' => storage_path('app/laravel-google-calendar/calendar-php-quickstart.json'),
    
];

You'll need a OAuth Client ID client_secret_xxxx...xxx.json from your google dev console.

Usage

Getting events

You can fetch all events by simply calling Event::get(); this will return all events of the coming year. An event comes in the form of a Spatie\GoogleCalendar\Event object.

The fill signature of the function is:

/**
 * @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

The parameters you can pass in $querParameters are listed on the documentation on list at the Google Calendar API docs.

Creating an event

You can just new up a Arturgrigio\GoogleCalendar\Event-object

$event = new Event;

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

$event->save();

You can also call create statically:

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

This will create an event with a specific start and end time. If you want to create a full day event you must use startDate and endDate instead of startDateTime and endDateTime.

$event = new Event;

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

$event->save();

Getting a single event

Google assigns a unique id to every single event. You can get this id by getting events using the get method and getting the id property on a Arturgrigio\GoogleCalendar\Event-object:

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

You can use this id to fetch a single event from Google:

Event::find($calendarId)

Updating an event

Easy, just change some properties and call save():

$event = Event::find($eventId)

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

Deleting an event

Nothing to it!

$event = Event::find($eventId)

$event->delete()

Limitations

The Google Calendar API provides many options. This package doesn't support all of them. For instance recurring events cannot be managed properly with this package. If you stick to creating events with a name and a date you should be fine.

Testing

$ composer test

Credits

License

The MIT License (MIT). Please see License File for more information.

arturgrigio/google-laravel-calendar-2 适用场景与选型建议

arturgrigio/google-laravel-calendar-2 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.73k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2016 年 09 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「event」 「oauth」 「schedule」 「calendar」 「google」 「laravel-google-calendar」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 arturgrigio/google-laravel-calendar-2 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 arturgrigio/google-laravel-calendar-2 我们能提供哪些服务?
定制开发 / 二次开发

基于 arturgrigio/google-laravel-calendar-2 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.73k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-09-14