1 | <?php |
||
5 | class TranslationsSheet extends AbstractSheet |
||
6 | { |
||
7 | 11 | public function getId() |
|
16 | |||
17 | 9 | public function getTitle() |
|
21 | |||
22 | 7 | public function coordinates() |
|
26 | |||
27 | 3 | public function emptyCoordinates() |
|
31 | |||
32 | 2 | public function setup() |
|
41 | |||
42 | 2 | public function writeTranslations($translations) |
|
49 | |||
50 | 2 | public function readTranslations() |
|
54 | |||
55 | 2 | public function styleDocument() |
|
56 | { |
||
57 | 2 | $fullkeyRange = $this->coordinates()->fullKeyColumnRange(); |
|
58 | 2 | $translationsRange = $this->coordinates()->translationsRange(); |
|
59 | 2 | $metaRange = $this->coordinates()->metaColumnsRange(); |
|
60 | |||
61 | $requests = [ |
||
62 | // Header row |
||
63 | 2 | $this->spreadsheet->api()->frozenRowRequest($this->getId()), |
|
64 | 2 | $this->spreadsheet->api()->styleArea($this->emptyCoordinates()->headerRange(), $this->styles()->translationsHeader()), |
|
65 | 2 | $this->spreadsheet->api()->protectRangeRequest($this->emptyCoordinates()->headerRange(), 'HEADER.'), |
|
66 | |||
67 | // Full key column |
||
68 | 2 | $this->spreadsheet->api()->frozenColumnRequest($this->getId()), |
|
69 | 2 | $this->spreadsheet->api()->protectRangeRequest($fullkeyRange, 'FULL_KEY'), |
|
70 | 2 | $this->spreadsheet->api()->fixedColumnWidthRequest($this->getId(), 0, 1, 450), |
|
71 | 2 | $this->spreadsheet->api()->styleArea($fullkeyRange, $this->styles()->fullKeyColumn()), |
|
72 | |||
73 | // Translations columns |
||
74 | 2 | $this->spreadsheet->api()->styleArea($translationsRange, $this->styles()->translationsColumns()), |
|
75 | |||
76 | // Meta columns |
||
77 | 2 | $this->spreadsheet->api()->protectRangeRequest($metaRange, 'META'), |
|
78 | 2 | $this->spreadsheet->api()->styleArea($metaRange, $this->styles()->metaColumns()), |
|
79 | 2 | $this->spreadsheet->api()->fixedColumnWidthRequest($this->getId(), $this->coordinates()->namespaceColumnIndex(), $this->coordinates()->namespaceColumnIndex() + 1, 145), |
|
80 | 2 | $this->spreadsheet->api()->fixedColumnWidthRequest($this->getId(), $this->coordinates()->groupColumnIndex(), $this->coordinates()->groupColumnIndex() + 1, 80), |
|
81 | 2 | $this->spreadsheet->api()->fixedColumnWidthRequest($this->getId(), $this->coordinates()->keyColumnIndex(), $this->coordinates()->keyColumnIndex() + 1, 240), |
|
82 | 2 | $this->spreadsheet->api()->fixedColumnWidthRequest($this->getId(), $this->coordinates()->sourceFileColumnIndex(), $this->coordinates()->sourceFileColumnIndex() + 1, 360), |
|
83 | ]; |
||
84 | |||
85 | // Fixed locales translations column width |
||
86 | 2 | $beginAt = 1; |
|
87 | 2 | foreach ($this->spreadsheet->getLocales() as $locale) { |
|
88 | 2 | $requests[] = $this->spreadsheet->api()->fixedColumnWidthRequest($this->getId(), $beginAt, $beginAt + 1, 350); |
|
89 | 2 | $beginAt++; |
|
90 | } |
||
91 | |||
92 | // Send requests |
||
93 | 2 | $this->spreadsheet->api()->addBatchRequests($requests)->sendBatchRequests(); |
|
94 | |||
95 | // Delete extra columns and rows if any |
||
96 | try { |
||
97 | 2 | $this->spreadsheet->api()->addBatchRequests([ |
|
98 | 2 | $this->spreadsheet->api()->deleteRowsFrom($this->getId(), $this->coordinates()->getRowsCount()), |
|
99 | 2 | $this->spreadsheet->api()->deleteColumnsFrom($this->getId(), $this->coordinates()->getColumnsCount()), |
|
100 | 2 | ])->sendBatchRequests(); |
|
101 | 1 | } catch (\Google_Service_Exception $e) { |
|
102 | // If there is no extra columns or rows Google api will raise an exception : |
||
103 | // ... Invalid requests[xxx].deleteDimension: Cannot delete a column that doesn't exist ... |
||
104 | } |
||
105 | 2 | } |
|
106 | |||
107 | 2 | public function prepareForWrite() |
|
113 | |||
114 | 1 | public function lockTranslations() |
|
125 | |||
126 | 1 | public function unlockTranslations() |
|
140 | |||
141 | 1 | public function isTranslationsLocked() |
|
147 | |||
148 | 2 | public function removeAllProtectedRanges() |
|
161 | |||
162 | 1 | public function updateHeaderRow() |
|
169 | } |
||
170 |