質問編集履歴
8
コントローラを追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -290,6 +290,10 @@
|
|
290
290
|
|
291
291
|
{
|
292
292
|
|
293
|
+
/***このメソッド内で予定更新時のときに登録された予定を取得する必要があると予測 **/
|
294
|
+
|
295
|
+
|
296
|
+
|
293
297
|
$this->config = $config['google'];
|
294
298
|
|
295
299
|
|
@@ -326,7 +330,7 @@
|
|
326
330
|
|
327
331
|
{
|
328
332
|
|
329
|
-
dd($event); /
|
333
|
+
dd($event); /*** 確認 ***/
|
330
334
|
|
331
335
|
return $this->service->events->insert($this->calendar_id, $event);
|
332
336
|
|
@@ -346,7 +350,7 @@
|
|
346
350
|
|
347
351
|
{
|
348
352
|
|
349
|
-
dd($event); /
|
353
|
+
dd($event); /***確認***/
|
350
354
|
|
351
355
|
return $this->service->events->update($this->calendar_id, $event->getId(), $event);
|
352
356
|
|
@@ -355,3 +359,147 @@
|
|
355
359
|
}
|
356
360
|
|
357
361
|
```
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
コントローラ
|
370
|
+
|
371
|
+
```ここに言語を入力
|
372
|
+
|
373
|
+
<?php
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
namespace App\Http\Controllers;
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
use App\Services\GoogleCalendarService;
|
382
|
+
|
383
|
+
use Illuminate\Http\Request;
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
class CalendarController extends Controller
|
388
|
+
|
389
|
+
{
|
390
|
+
|
391
|
+
private $service;
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
/**
|
396
|
+
|
397
|
+
* CalendarController constructor.
|
398
|
+
|
399
|
+
* @param GoogleCalendarService $service
|
400
|
+
|
401
|
+
*/
|
402
|
+
|
403
|
+
public function __construct(GoogleCalendarService $service)
|
404
|
+
|
405
|
+
{
|
406
|
+
|
407
|
+
$this->service = $service;
|
408
|
+
|
409
|
+
}
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
/**
|
414
|
+
|
415
|
+
* @param Request $request
|
416
|
+
|
417
|
+
*/
|
418
|
+
|
419
|
+
public function store(Request $request)
|
420
|
+
|
421
|
+
{
|
422
|
+
|
423
|
+
$this->service->addEvent($this->makeGoogleEvent($request));
|
424
|
+
|
425
|
+
}
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
/**
|
430
|
+
|
431
|
+
* @param Request $request
|
432
|
+
|
433
|
+
*/
|
434
|
+
|
435
|
+
public function update(Request $request)
|
436
|
+
|
437
|
+
{
|
438
|
+
|
439
|
+
$this->service->updateEvent($this->makeGoogleEvent($request));
|
440
|
+
|
441
|
+
}
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
/**
|
446
|
+
|
447
|
+
* @param Request $request
|
448
|
+
|
449
|
+
* @return \Google_Service_Calendar_Event
|
450
|
+
|
451
|
+
*/
|
452
|
+
|
453
|
+
private function makeGoogleEvent(Request $request)
|
454
|
+
|
455
|
+
{
|
456
|
+
|
457
|
+
/*** ここでイベント更新時の時にもインスタンス化しているのが原因だと考えています。 ***/
|
458
|
+
|
459
|
+
$google_event = new \Google_Service_Calendar_Event();
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
if ($request->has('event_id')) {
|
464
|
+
|
465
|
+
$google_event->setId($request->event_id);
|
466
|
+
|
467
|
+
}
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
$google_event->setSummary($request->title);
|
472
|
+
|
473
|
+
$google_event->setDescription($request->memo);
|
474
|
+
|
475
|
+
$google_event->setColorId('1');
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
$start = new \Google_Service_Calendar_EventDateTime();
|
480
|
+
|
481
|
+
$start->setTimeZone('Asia/Tokyo');
|
482
|
+
|
483
|
+
$start->setDateTime($request->startdate . ' ' . $request->starttime);
|
484
|
+
|
485
|
+
$google_event->setStart($start);
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
$end = new \Google_Service_Calendar_EventDateTime();
|
490
|
+
|
491
|
+
$end->setTimeZone('Asia/Tokyo');
|
492
|
+
|
493
|
+
$end->setDateTime($request['enddate'] . ' ' . $request['endtime']);
|
494
|
+
|
495
|
+
$google_event->setEnd($end);
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
return $google_event;
|
500
|
+
|
501
|
+
}
|
502
|
+
|
503
|
+
}
|
504
|
+
|
505
|
+
```
|
7
追記をしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -199,3 +199,159 @@
|
|
199
199
|
}
|
200
200
|
|
201
201
|
```
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
追記
|
210
|
+
|
211
|
+
app/Services/GoogleCalendarService.php
|
212
|
+
|
213
|
+
```ここに言語を入力
|
214
|
+
|
215
|
+
<?php
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
namespace App\Services;
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
use Google\Exception;
|
224
|
+
|
225
|
+
use Google_Client;
|
226
|
+
|
227
|
+
use Google_Service_Calendar;
|
228
|
+
|
229
|
+
use Google_Service_Calendar_Event;
|
230
|
+
|
231
|
+
use Illuminate\Config\Repository;
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
class GoogleCalendarService
|
236
|
+
|
237
|
+
{
|
238
|
+
|
239
|
+
/**
|
240
|
+
|
241
|
+
* @var array
|
242
|
+
|
243
|
+
*/
|
244
|
+
|
245
|
+
private $config;
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
/**
|
250
|
+
|
251
|
+
* @var Google_Client
|
252
|
+
|
253
|
+
*/
|
254
|
+
|
255
|
+
private $client;
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
/**
|
260
|
+
|
261
|
+
* @var Google_Service_Calendar
|
262
|
+
|
263
|
+
*/
|
264
|
+
|
265
|
+
private $service;
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
/**
|
270
|
+
|
271
|
+
* @var
|
272
|
+
|
273
|
+
*/
|
274
|
+
|
275
|
+
private $calendar_id;
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
/**
|
280
|
+
|
281
|
+
* GoogleCalendarService constructor.
|
282
|
+
|
283
|
+
* @param Repository $config
|
284
|
+
|
285
|
+
* @throws Exception
|
286
|
+
|
287
|
+
*/
|
288
|
+
|
289
|
+
public function __construct(Repository $config)
|
290
|
+
|
291
|
+
{
|
292
|
+
|
293
|
+
$this->config = $config['google'];
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
$this->client = new Google_Client();
|
298
|
+
|
299
|
+
$this->client->setApplicationName($this->config['app_name']);
|
300
|
+
|
301
|
+
$this->client->setScopes(Google_Service_Calendar::CALENDAR_EVENTS);
|
302
|
+
|
303
|
+
$this->client->setAuthConfig(storage_path('app/google-calendar/auth.json'));
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
$this->service = new Google_Service_Calendar($this->client);
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
$this->calendar_id = $this->config['calendar_id'];
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
/**
|
318
|
+
|
319
|
+
* @param Google_Service_Calendar_Event $event
|
320
|
+
|
321
|
+
* @return Google_Service_Calendar_Event
|
322
|
+
|
323
|
+
*/
|
324
|
+
|
325
|
+
public function addEvent(Google_Service_Calendar_Event $event): Google_Service_Calendar_Event
|
326
|
+
|
327
|
+
{
|
328
|
+
|
329
|
+
dd($event); //確認
|
330
|
+
|
331
|
+
return $this->service->events->insert($this->calendar_id, $event);
|
332
|
+
|
333
|
+
}
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
/**
|
338
|
+
|
339
|
+
* @param Google_Service_Calendar_Event $event
|
340
|
+
|
341
|
+
* @return Google_Service_Calendar_Event
|
342
|
+
|
343
|
+
*/
|
344
|
+
|
345
|
+
public function updateEvent(Google_Service_Calendar_Event $event): Google_Service_Calendar_Event
|
346
|
+
|
347
|
+
{
|
348
|
+
|
349
|
+
dd($event); //確認
|
350
|
+
|
351
|
+
return $this->service->events->update($this->calendar_id, $event->getId(), $event);
|
352
|
+
|
353
|
+
}
|
354
|
+
|
355
|
+
}
|
356
|
+
|
357
|
+
```
|
6
追記をしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
[PHPからGoogleカレンダーに予定を追加・変更・削除する](https://jipulog.com/google-calendar-php/)
|
18
18
|
|
19
|
-
|
19
|
+
使っているAPIはgooglecalendarAPIです。
|
20
20
|
|
21
21
|
```
|
22
22
|
|
5
参考サイトのリンクを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,6 +10,12 @@
|
|
10
10
|
|
11
11
|
宜しくお願い致します。
|
12
12
|
|
13
|
+
参考にしたサイト
|
14
|
+
|
15
|
+
[Google Calendar API を用いてLaravelアプリから予定を追加する手順](https://qiita.com/sakashin10291029/items/c5f7540ab6a32283b619)
|
16
|
+
|
17
|
+
[PHPからGoogleカレンダーに予定を追加・変更・削除する](https://jipulog.com/google-calendar-php/)
|
18
|
+
|
13
19
|
|
14
20
|
|
15
21
|
```
|
4
インデントを直しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,15 +14,11 @@
|
|
14
14
|
|
15
15
|
```
|
16
16
|
|
17
|
-
class CalenderEventsController extends Controller
|
17
|
+
class CalenderEventsController extends Controller{
|
18
|
-
|
19
|
-
{
|
20
18
|
|
21
19
|
//googleカレンダー APIインスタンス作成
|
22
20
|
|
23
|
-
|
21
|
+
public function getClient(){
|
24
|
-
|
25
|
-
{
|
26
22
|
|
27
23
|
|
28
24
|
|
@@ -50,51 +46,49 @@
|
|
50
46
|
|
51
47
|
|
52
48
|
|
53
|
-
//登録処理
|
49
|
+
//登録処理
|
54
50
|
|
55
|
-
public function store(Request $request){
|
51
|
+
public function store(Request $request){
|
56
52
|
|
57
|
-
|
53
|
+
/** googleカレンダーとの連携処理 **/
|
58
54
|
|
59
55
|
|
60
56
|
|
61
|
-
|
57
|
+
$client = $this->getClient();
|
62
58
|
|
63
|
-
|
59
|
+
$service = new Google_Service_Calendar($client);
|
64
60
|
|
65
|
-
|
61
|
+
$calendarId = env('GOOGLE_CALENDAR_ID');
|
62
|
+
|
63
|
+
$google_event = new Google_Service_Calendar_Event();
|
66
64
|
|
67
65
|
|
68
66
|
|
67
|
+
//件名
|
68
|
+
|
69
|
-
|
69
|
+
$google_event->setSummary($request['title']);
|
70
70
|
|
71
71
|
|
72
72
|
|
73
|
-
|
73
|
+
//内容
|
74
74
|
|
75
|
-
|
75
|
+
$google_event->setDescription($request['memo']);
|
76
76
|
|
77
77
|
|
78
78
|
|
79
|
-
|
79
|
+
//色
|
80
80
|
|
81
|
-
|
81
|
+
$google_event->setColorId("1");
|
82
82
|
|
83
83
|
|
84
84
|
|
85
|
-
|
85
|
+
//開始時間
|
86
86
|
|
87
|
-
|
87
|
+
$start = new Google_Service_Calendar_EventDateTime();
|
88
88
|
|
89
|
-
|
89
|
+
$start->setDateTime($request['startdate']. 'T'.$request['starttime'] . '+09:00');
|
90
90
|
|
91
|
-
//開始時間
|
92
|
-
|
93
|
-
$start = new Google_Service_Calendar_EventDateTime();
|
94
|
-
|
95
|
-
$start->setDateTime($request['startdate']. 'T'.$request['starttime'] . '+09:00');
|
96
|
-
|
97
|
-
|
91
|
+
$google_event->setStart($start);
|
98
92
|
|
99
93
|
|
100
94
|
|
@@ -102,33 +96,33 @@
|
|
102
96
|
|
103
97
|
|
104
98
|
|
105
|
-
|
99
|
+
//終了時間
|
106
100
|
|
107
|
-
|
101
|
+
$end = new Google_Service_Calendar_EventDateTime();
|
108
102
|
|
109
|
-
|
103
|
+
$end->setDateTime($request['enddate']. 'T'.$request['endtime'] . '+09:00');
|
110
104
|
|
111
|
-
|
105
|
+
$google_event->setEnd($end);
|
112
106
|
|
113
107
|
|
114
108
|
|
115
|
-
|
109
|
+
//グーグルカレンダーに予定反映
|
116
110
|
|
117
|
-
|
111
|
+
$result = $service->events->insert($calendarId,$google_event);
|
118
112
|
|
119
113
|
|
120
114
|
|
121
|
-
|
115
|
+
//イベントIDを取得する
|
122
116
|
|
123
|
-
|
117
|
+
$google_event_id = $result->getId();
|
124
118
|
|
125
|
-
}
|
119
|
+
}
|
126
120
|
|
127
121
|
|
128
122
|
|
129
|
-
//変更処理
|
123
|
+
//変更処理
|
130
124
|
|
131
|
-
public function update(Request request){
|
125
|
+
public function update(Request request){
|
132
126
|
|
133
127
|
$client = $this->getClient();
|
134
128
|
|
@@ -194,7 +188,7 @@
|
|
194
188
|
|
195
189
|
$result = $service->events->update($calendarId,$google_event_id,$google_event);
|
196
190
|
|
197
|
-
}
|
191
|
+
}
|
198
192
|
|
199
193
|
}
|
200
194
|
|
3
間違えているところがあったので修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -50,7 +50,7 @@
|
|
50
50
|
|
51
51
|
|
52
52
|
|
53
|
-
登録処理
|
53
|
+
//登録処理
|
54
54
|
|
55
55
|
public function store(Request $request){
|
56
56
|
|
2
クラス名を追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,7 +14,11 @@
|
|
14
14
|
|
15
15
|
```
|
16
16
|
|
17
|
+
class CalenderEventsController extends Controller
|
18
|
+
|
19
|
+
{
|
20
|
+
|
17
|
-
//googleカレンダー APIインスタンス作成
|
21
|
+
//googleカレンダー APIインスタンス作成
|
18
22
|
|
19
23
|
public function getClient()
|
20
24
|
|
@@ -46,9 +50,9 @@
|
|
46
50
|
|
47
51
|
|
48
52
|
|
49
|
-
登録処理
|
53
|
+
登録処理
|
50
|
-
|
54
|
+
|
51
|
-
public function store(Request $request){
|
55
|
+
public function store(Request $request){
|
52
56
|
|
53
57
|
/** googleカレンダーとの連携処理 **/
|
54
58
|
|
@@ -118,80 +122,80 @@
|
|
118
122
|
|
119
123
|
$google_event_id = $result->getId();
|
120
124
|
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
//変更処理
|
130
|
+
|
131
|
+
public function update(Request request){
|
132
|
+
|
133
|
+
$client = $this->getClient();
|
134
|
+
|
135
|
+
$service = new Google_Service_Calendar($client);
|
136
|
+
|
137
|
+
$calendarId = env('GOOGLE_CALENDAR_ID');
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
$google_event_id = ここに登録時のイベントIDを持ってきたい
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
$google_event = new Google_Service_Calendar_Event();
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
//件名
|
152
|
+
|
153
|
+
$google_event->setSummary($request['title']);
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
//内容
|
158
|
+
|
159
|
+
$google_event->setDescription($request['memo']);
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
//色
|
164
|
+
|
165
|
+
$google_event->setColorId("1");
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
//開始時間
|
170
|
+
|
171
|
+
$start = new Google_Service_Calendar_EventDateTime();
|
172
|
+
|
173
|
+
$start->setDateTime($request['startdate']. 'T'.$request['starttime'] . '+09:00');
|
174
|
+
|
175
|
+
$google_event->setStart($start);
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
//終了時間
|
184
|
+
|
185
|
+
$end = new Google_Service_Calendar_EventDateTime();
|
186
|
+
|
187
|
+
$end->setDateTime($request['enddate']. 'T'.$request['endtime'] . '+09:00');
|
188
|
+
|
189
|
+
$google_event->setEnd($end);
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
//グーグルカレンダーに予定反映
|
194
|
+
|
195
|
+
$result = $service->events->update($calendarId,$google_event_id,$google_event);
|
196
|
+
|
197
|
+
}
|
198
|
+
|
121
199
|
}
|
122
200
|
|
123
|
-
|
124
|
-
|
125
|
-
//変更処理
|
126
|
-
|
127
|
-
public function update(Request request){
|
128
|
-
|
129
|
-
$client = $this->getClient();
|
130
|
-
|
131
|
-
$service = new Google_Service_Calendar($client);
|
132
|
-
|
133
|
-
$calendarId = env('GOOGLE_CALENDAR_ID');
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
$google_event_id = ここに登録時のイベントIDを持ってきたい
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
$google_event = new Google_Service_Calendar_Event();
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
//件名
|
148
|
-
|
149
|
-
$google_event->setSummary($request['title']);
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
//内容
|
154
|
-
|
155
|
-
$google_event->setDescription($request['memo']);
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
//色
|
160
|
-
|
161
|
-
$google_event->setColorId("1");
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
//開始時間
|
166
|
-
|
167
|
-
$start = new Google_Service_Calendar_EventDateTime();
|
168
|
-
|
169
|
-
$start->setDateTime($request['startdate']. 'T'.$request['starttime'] . '+09:00');
|
170
|
-
|
171
|
-
$google_event->setStart($start);
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
//終了時間
|
180
|
-
|
181
|
-
$end = new Google_Service_Calendar_EventDateTime();
|
182
|
-
|
183
|
-
$end->setDateTime($request['enddate']. 'T'.$request['endtime'] . '+09:00');
|
184
|
-
|
185
|
-
$google_event->setEnd($end);
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
//グーグルカレンダーに予定反映
|
190
|
-
|
191
|
-
$result = $service->events->update($calendarId,$google_event_id,$google_event);
|
192
|
-
|
193
|
-
}
|
194
|
-
|
195
|
-
|
196
|
-
|
197
201
|
```
|
1
間違えているところがあったので修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,7 +34,7 @@
|
|
34
34
|
|
35
35
|
|
36
36
|
|
37
|
-
$client->setAuthConfig(storage_path('app/google-calendar/
|
37
|
+
$client->setAuthConfig(storage_path('app/google-calendar/'JSONファイル'));
|
38
38
|
|
39
39
|
|
40
40
|
|
@@ -134,13 +134,13 @@
|
|
134
134
|
|
135
135
|
|
136
136
|
|
137
|
-
$google_event_id =
|
137
|
+
$google_event_id = ここに登録時のイベントIDを持ってきたい
|
138
138
|
|
139
139
|
|
140
140
|
|
141
141
|
$google_event = new Google_Service_Calendar_Event();
|
142
142
|
|
143
|
-
|
143
|
+
|
144
144
|
|
145
145
|
|
146
146
|
|
@@ -188,20 +188,10 @@
|
|
188
188
|
|
189
189
|
//グーグルカレンダーに予定反映
|
190
190
|
|
191
|
-
|
191
|
+
$result = $service->events->update($calendarId,$google_event_id,$google_event);
|
192
192
|
|
193
193
|
}
|
194
194
|
|
195
195
|
|
196
196
|
|
197
197
|
```
|
198
|
-
|
199
|
-
登録処理の時に書いてある
|
200
|
-
|
201
|
-
//イベントIDを取得する
|
202
|
-
|
203
|
-
$google_event_id = $result->getId();
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
このgoogle_event_idの値を変更処理の時に宣言し、使用したいのですがどのようにすればよいかわかりません。
|