-
Notifications
You must be signed in to change notification settings - Fork 2
/
sheets.php
69 lines (55 loc) · 1.92 KB
/
sheets.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
require_once __DIR__ . '/vendor/autoload.php';
$client = new Google_Client();
$client->setApplicationName('Google Sheets and PHP');
$client->setScopes([Google_Service_Sheets::SPREADSHEETS]);
$client->setAccessType('offline');
$client->setAuthConfig(__DIR__ . '/credentials.json');
$sheet_service = new Google_Service_Sheets($client);
$spreadsheetIds = [
'CC' => "15Ts37hFoveRIf9SP8gUWeTlBgxCIUOp4VtednMRWTI8",
'CN' => "1BcAy1cV2mKADshW8NdV0ps_AaRCNpmR467YbyZpdYos",
'CS' => "11MEvrd_feBGgEGcwewRSFxChaW2S6uS3DG5ZjG434BE",
'USJ' => "1i4bbKzQNWYRV7RO-hZxU2BWn4WI68Zk_KBMjZtCpDOM",
'Kandy' => "1wzPZy9iKgPNPCcMlTZ8a_EroraxoczhqhfIBeW8mbcs",
'Ruhuna' => "1eyayItK2U7Xy2uLsCUokhVxuvtrDYUAqpOYH3Zu_m1I",
'SLIIT' => "1PB0BhWJ17vgKcHOybvm3GFEXGmY8AYeototr21x_59A",
'NSBM' => "1gIJX6jbhigc1duSh3Fc1aFaPCV04_Zf9AUWBAIjXsVo",
'NIBM' => "1R_1T8dbqc7chHjSjY_a8V1r1mkKlA7KzrDRGHoMn_L8",
'Rajarata' => "1953-l-q3nJuFVp9nSCvB3Pm9AAtk0_MExHgX9J23DUU",
];
$spreadsheetId = "18YJN97bZAyqZJZ04gd7TbyHhNm3_klvuJDG-ApMaPwQ";
function append($values, $entity)
{
global $sheet_service;
global $spreadsheetId;
global $spreadsheetIds;
if (array_key_exists($entity, $spreadsheetIds)) {
$spreadsheetId = $spreadsheetIds[$entity];
}
$body = new Google_Service_Sheets_ValueRange([
'values' => $values
]);
$all_values = $values;
array_splice($all_values[0], 1, 0, [$entity]); // splice in at position 3
$all_body = new Google_Service_Sheets_ValueRange([
'values' => $all_values
]);
$params = [
'valueInputOption' => 'USER_ENTERED'
];
$range = 'Sign-Ups';
//Append to all sheet
$result = $sheet_service->spreadsheets_values->append(
"17CrbJe5ewkkbXA6rnkzxB7Qo4juoi29MzO6yV-r2icU",
$range,
$all_body,
$params
);
//Append to entity sheet (or other)
$result = $sheet_service->spreadsheets_values->append($spreadsheetId, $range, $body, $params);
if ($result->getUpdates()->getUpdatedCells() == 10) {
return "success";
}
return false;
}