1 | <?php |
||
5 | class TranslationsSheet extends AbstractSheet |
||
6 | { |
||
7 | 10 | public function getId() |
|
11 | |||
12 | 8 | public function getTitle() |
|
16 | |||
17 | 6 | public function coordinates() |
|
21 | |||
22 | 2 | public function emptyCoordinates() |
|
26 | |||
27 | 1 | public function setup() |
|
28 | { |
||
29 | 1 | $this->spreadsheet->api() |
|
30 | 1 | ->addBatchRequests([ |
|
31 | // Set properties |
||
32 | 1 | $this->spreadsheet->api()->setSheetPropertiesRequest($this->getId(), $this->getTitle(), $this->styles()->translationSheetTabColor()), |
|
33 | ]) |
||
34 | 1 | ->sendBatchRequests(); |
|
35 | 1 | } |
|
36 | |||
37 | 1 | public function writeTranslations($translations) |
|
44 | |||
45 | 1 | public function readTranslations() |
|
49 | |||
50 | 1 | public function styleDocument() |
|
51 | { |
||
52 | 1 | $fullkeyRange = $this->coordinates()->fullKeyColumnRange(); |
|
53 | 1 | $translationsRange = $this->coordinates()->translationsRange(); |
|
54 | 1 | $metaRange = $this->coordinates()->metaColumnsRange(); |
|
55 | |||
56 | $requests = [ |
||
57 | // Header row |
||
58 | 1 | $this->spreadsheet->api()->frozenRowRequest($this->getId()), |
|
59 | 1 | $this->spreadsheet->api()->styleArea($this->emptyCoordinates()->headerRange(), $this->styles()->translationsHeader()), |
|
60 | 1 | $this->spreadsheet->api()->protectRangeRequest($this->emptyCoordinates()->headerRange(), 'HEADER.'), |
|
61 | |||
62 | // Full key column |
||
63 | 1 | $this->spreadsheet->api()->frozenColumnRequest($this->getId()), |
|
64 | 1 | $this->spreadsheet->api()->protectRangeRequest($fullkeyRange, 'FULL_KEY'), |
|
65 | 1 | $this->spreadsheet->api()->fixedColumnWidthRequest($this->getId(), 0, 1, 450), |
|
66 | 1 | $this->spreadsheet->api()->styleArea($fullkeyRange, $this->styles()->fullKeyColumn()), |
|
67 | |||
68 | // Translations columns |
||
69 | 1 | $this->spreadsheet->api()->styleArea($translationsRange, $this->styles()->translationsColumns()), |
|
70 | |||
71 | // Meta columns |
||
72 | 1 | $this->spreadsheet->api()->protectRangeRequest($metaRange, 'META'), |
|
73 | 1 | $this->spreadsheet->api()->styleArea($metaRange, $this->styles()->metaColumns()), |
|
74 | 1 | $this->spreadsheet->api()->fixedColumnWidthRequest($this->getId(), $this->coordinates()->namespaceColumnIndex(), $this->coordinates()->namespaceColumnIndex() + 1, 145), |
|
75 | 1 | $this->spreadsheet->api()->fixedColumnWidthRequest($this->getId(), $this->coordinates()->groupColumnIndex(), $this->coordinates()->groupColumnIndex() + 1, 80), |
|
76 | 1 | $this->spreadsheet->api()->fixedColumnWidthRequest($this->getId(), $this->coordinates()->keyColumnIndex(), $this->coordinates()->keyColumnIndex() + 1, 240), |
|
77 | 1 | $this->spreadsheet->api()->fixedColumnWidthRequest($this->getId(), $this->coordinates()->sourceFileColumnIndex(), $this->coordinates()->sourceFileColumnIndex() + 1, 360), |
|
78 | |||
79 | // Delete extra columns and rows |
||
80 | 1 | $this->spreadsheet->api()->deleteRowsFrom($this->getId(), $this->coordinates()->getRowsCount()), |
|
81 | 1 | $this->spreadsheet->api()->deleteColumnsFrom($this->getId(), $this->coordinates()->getColumnsCount()), |
|
82 | ]; |
||
83 | |||
84 | // Fixed locales translations column width |
||
85 | 1 | $beginAt = 1; |
|
86 | 1 | foreach ($this->spreadsheet->getLocales() as $locale) { |
|
87 | 1 | $requests[] = $this->spreadsheet->api()->fixedColumnWidthRequest($this->getId(), $beginAt, $beginAt + 1, 350); |
|
88 | 1 | $beginAt++; |
|
89 | } |
||
90 | |||
91 | // Send requests |
||
92 | 1 | $this->spreadsheet->api()->addBatchRequests($requests)->sendBatchRequests(); |
|
93 | 1 | } |
|
94 | |||
95 | 1 | public function prepareForWrite() |
|
101 | |||
102 | 1 | public function lockTranslations() |
|
103 | { |
||
104 | 1 | $range = $this->coordinates()->translationsRange(1, $this->spreadsheet->api()->getSheetRowCount($this->getId())); |
|
105 | |||
106 | 1 | $this->api() |
|
107 | 1 | ->addBatchRequests([ |
|
108 | 1 | $this->spreadsheet->api()->protectRangeRequest($range, 'TRANSLATIONS'), |
|
109 | 1 | $this->spreadsheet->api()->styleArea($range, $this->styles()->lockedTranslationsColumns()), |
|
110 | ]) |
||
111 | 1 | ->sendBatchRequests(); |
|
112 | 1 | } |
|
113 | |||
114 | 1 | public function unlockTranslations() |
|
115 | { |
||
116 | 1 | $requests = []; |
|
117 | 1 | $range = $this->coordinates()->translationsRange(1, $this->spreadsheet->api()->getSheetRowCount($this->getId())); |
|
118 | |||
119 | 1 | $protectedRanges = $this->spreadsheet->api()->getSheetProtectedRanges($this->getId(), 'TRANSLATIONS'); |
|
120 | 1 | foreach ($protectedRanges as $protectedRange) { |
|
121 | 1 | $requests[] = $this->spreadsheet->api()->deleteProtectedRange($protectedRange->protectedRangeId); |
|
122 | } |
||
123 | |||
124 | 1 | $requests[] = $this->spreadsheet->api()->styleArea($range, $this->styles()->translationsColumns()); |
|
125 | |||
126 | 1 | $this->spreadsheet->api()->addBatchRequests($requests)->sendBatchRequests(); |
|
127 | 1 | } |
|
128 | |||
129 | 1 | public function isTranslationsLocked() |
|
135 | |||
136 | 1 | public function removeAllProtectedRanges() |
|
137 | { |
||
138 | 1 | $protectedRanges = $this->spreadsheet->api()->getSheetProtectedRanges($this->getId()); |
|
139 | |||
140 | 1 | $requests = []; |
|
141 | 1 | foreach ($protectedRanges as $protectedRange) { |
|
142 | 1 | $requests[] = $this->spreadsheet->api()->deleteProtectedRange($protectedRange->protectedRangeId); |
|
143 | } |
||
144 | |||
145 | 1 | if (! empty($requests)) { |
|
146 | 1 | $this->spreadsheet->api()->addBatchRequests($requests)->sendBatchRequests(); |
|
147 | } |
||
148 | 1 | } |
|
149 | |||
150 | public function updateHeaderRow() |
||
157 | } |
||
158 |