1 | <?php |
||
11 | class Api |
||
12 | { |
||
13 | /** @var Collection */ |
||
14 | protected $requests; |
||
15 | |||
16 | /** @var Client */ |
||
17 | protected $client; |
||
18 | |||
19 | /** @var string */ |
||
20 | protected $spreadsheetId; |
||
21 | |||
22 | /** |
||
23 | * SheetService constructor. |
||
24 | * |
||
25 | * @param Client $client |
||
26 | */ |
||
27 | 19 | public function __construct(Client $client) |
|
32 | |||
33 | /** |
||
34 | * Set the service speadsheet ID. |
||
35 | * |
||
36 | * @param string $spreadsheetId |
||
37 | * @return $this |
||
38 | */ |
||
39 | 2 | public function setSpreadsheetId($spreadsheetId) |
|
45 | |||
46 | 1 | public function addBatchRequests($requests) |
|
55 | |||
56 | 1 | public function sendBatchRequests() |
|
71 | |||
72 | 1 | public function frozenRowRequest($sheetId, $frozonRowCount = 1) |
|
86 | |||
87 | 1 | public function frozenColumnRequest($sheetId, $frozonColumnCount = 1) |
|
101 | |||
102 | 1 | public function styleArea($range, $styles) |
|
124 | |||
125 | 1 | public function fixedColumnWidthRequest($sheetId, $startIndex, $endIndex, $width) |
|
142 | |||
143 | 1 | public function setSheetPropertiesRequest($sheetId, $title, $tabColor) |
|
156 | |||
157 | 1 | public function addSheetRequest($title, $rowCount, $columnCount, $tabColor = null) |
|
173 | |||
174 | 1 | public function addBlankSheet($title = null) |
|
179 | |||
180 | public function clearSheetRequest($sheetId) |
||
191 | |||
192 | 1 | public function protectRangeRequest($range, $description) |
|
193 | { |
||
194 | 1 | return new Google_Service_Sheets_Request([ |
|
195 | 1 | 'addProtectedRange' => [ |
|
196 | 'protectedRange' => [ |
||
197 | 1 | 'range' => $range, |
|
198 | 1 | 'description' => $description, |
|
199 | 'warningOnly' => false, |
||
200 | 'editors' => [ |
||
201 | 1 | 'users' => [config('translation_sheet.serviceAccountEmail')], |
|
202 | ], |
||
203 | ], |
||
204 | ], |
||
205 | |||
206 | ]); |
||
207 | } |
||
208 | |||
209 | 1 | public function writeCells($shortRange, $values) |
|
223 | |||
224 | public function readCells($sheetId, $range) |
||
225 | { |
||
226 | $range .= $this->getSheetRowCount($sheetId); |
||
227 | |||
228 | $sheets = new \Google_Service_Sheets($this->client); |
||
229 | |||
230 | return $sheets->spreadsheets_values->get($this->spreadsheetId, $range)->values; |
||
231 | } |
||
232 | |||
233 | public function getSheetRowCount($sheetId) |
||
234 | { |
||
235 | $sheet = $this->getSheet($sheetId); |
||
236 | |||
237 | return $sheet['properties']['gridProperties']['rowCount']; |
||
238 | } |
||
239 | |||
240 | 1 | public function getSheet($sheetId) |
|
250 | |||
251 | 2 | public function getSheets() |
|
257 | |||
258 | 2 | public function firstSheetId() |
|
262 | |||
263 | 1 | public function getSheetProtectedRanges($sheetId, $description = null) |
|
280 | |||
281 | public function deleteColumnsFrom($sheetId, $fromColumnIndex) |
||
282 | { |
||
283 | return new Google_Service_Sheets_Request([ |
||
284 | 'deleteDimension' => [ |
||
285 | 'range' => [ |
||
286 | 'sheetId' => $sheetId, |
||
287 | 'dimension' => 'COLUMNS', |
||
288 | 'startIndex' => $fromColumnIndex, |
||
289 | ], |
||
290 | ], |
||
291 | ]); |
||
292 | } |
||
293 | |||
294 | public function deleteRowsFrom($sheetId, $fromRowIndex) |
||
295 | { |
||
296 | return new Google_Service_Sheets_Request([ |
||
297 | 'deleteDimension' => [ |
||
298 | 'range' => [ |
||
299 | 'sheetId' => $sheetId, |
||
300 | 'dimension' => 'ROWS', |
||
301 | 'startIndex' => $fromRowIndex, |
||
302 | ], |
||
303 | ], |
||
304 | ]); |
||
305 | } |
||
306 | |||
307 | public function deleteProtectedRange($protectedRangeId) |
||
315 | |||
316 | 1 | public function deleteSheetRequest($sheetId) |
|
324 | |||
325 | /** |
||
326 | * Return Fractal RGB color array with r,g,b between 0 and 1. |
||
327 | * |
||
328 | * @param mixed $color array of RGB color ([255, 255, 255]) or hex string (#FFFFFF) |
||
329 | * |
||
330 | * @return array |
||
331 | */ |
||
332 | 1 | protected function fractalColors($color) |
|
346 | |||
347 | |||
348 | } |
||
349 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.