Passed
Push — master ( d6ccd5...f8a307 )
by
unknown
08:32
created

CalendarService::getClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: dangis
5
 * Date: 18.6.2
6
 * Time: 16.43
7
 */
8
9
namespace App\Service\Google;
10
11
use Google_Client;
12
use Google_Service_Calendar;
13
use Google_Service_Calendar_Event;
14
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
15
16
class CalendarService
17
{
18
    private $folderName;
19
20
    private $tokenStorage;
21
22
    public function __construct(TokenStorageInterface $tokenStorage)
23
    {
24
        $this->tokenStorage = $tokenStorage;
25
        $this->folderName = "Nagido-Files";
26
    }
27
28
    public function getClient()
29
    {
30
        $user = $this->tokenStorage->getToken()->getUser();
31
32
        //Create google client
33
        $client = new Google_Client();
34
        $client->setAccessToken($user->getGoogleAccessToken());
35
36
        //Set Drive Service
37
        return new Google_Service_Calendar($client);
38
    }
39
40
    public function setDate($date, $desc, $name) {
41
        $service = $this->getClient();
42
        $event = new Google_Service_Calendar_Event(array(
43
            'summary' => 'Nagido Document' . ' - ' . $name ,
44
            'description' => $desc,
45
            'start' => array(
46
                'dateTime' => $date,
47
                'timeZone' => 'Europe/Vilnius',
48
            ),
49
            'end' => array(
50
                'dateTime' => $date,
51
                'timeZone' => 'Europe/Vilnius',
52
            ),
53
            'reminders' => array(
54
                'useDefault' => FALSE,
55
                'overrides' => array(
56
                    array('method' => 'email', 'minutes' => 1)
57
                ),
58
            ),
59
            "colorId" => "6"
60
        ));
61
        $service->events->insert('primary', $event);
62
    }
63
}