forked from emilianozublena/sheetsu-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.php
71 lines (60 loc) · 1.95 KB
/
example.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
70
71
<?php
/**
* Example of usage for the Sheetsu PHP Library
* @Author: Emiliano Zublena - https://github.com/emilianozublena
* @Package: Sheetsu PHP Library - https://github.com/emilianozublena/sheetsu-php
*/
ini_set('display_error', 1);
error_reporting(E_ALL);
require('vendor/autoload.php');
use Sheetsu\Sheetsu;
use Sheetsu\Collection;
use Sheetsu\Model;
$sheetsu = new Sheetsu([
'sheetId' => 'INSERT_YOUR_SHEET_ID'
]);
//Creating new rows through collections
$collection = new Collection();
$collection->addMultiple([
Model::create(['name' => 'Peter']),
Model::create(['name' => 'Steve'])
]);
$response = $sheetsu->create($collection);
//through array of models
$response = $sheetsu->create([
Model::create(['name' => 'Peter']),
Model::create(['name' => 'Steve'])
]);
//through array of arrays
$response = $sheetsu->create([
['name' => 'Peter'],
['name' => 'Steve']
]);
//Get whole sheet
$response = $sheetsu->read();
$collection = $response->getCollection();
print_r($collection);
//Find rows matching given criteria
$response = $sheetsu->search(['name' => 'Peter']);
$collection = $response->getCollection();
print_r($collection);
//Delete rows matching given criteria
$response = $sheetsu->delete('name', 'Steve');
print_r($response);
//Updating rows matching given criteria with data of given Model
$model = Model::create(['name' => 'Stewiw']);
$response = $sheetsu->update('name', 'Peter', $model);
print_r($response);
//Change sheet id and whole spreadsheet with method chaining.
$response = $sheetsu->initialize('myNewSheetId')->read();
$collection = $response->getCollection();
print_r($collection);
//Make use of a specific sheet in next and all further calls
$response = $sheetsu->sheet('sheetName')->read();
$collection = $response->getCollection();
print_r($collection);
//Stop using specific sheet
$sheetsu->sheet('sheet2');
$response = $sheetsu->sheet('sheet2')->read();
$collection = $response->getCollection();
print_r($collection);