1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nikaia\TranslationSheet\Sheet; |
4
|
|
|
|
5
|
|
|
class TranslationsSheetCoordinates |
|
|
|
|
6
|
|
|
{ |
7
|
|
|
protected $headerRowsCount = 1; |
8
|
|
|
|
9
|
|
|
protected $dataRowsCount = 0; |
10
|
|
|
|
11
|
|
|
protected $columnsCount = 0; |
12
|
|
|
|
13
|
|
|
protected $localesCount = 1; |
14
|
|
|
|
15
|
|
|
protected $sheetId; |
16
|
|
|
|
17
|
|
|
protected $sheetTitle; |
18
|
|
|
|
19
|
3 |
|
private function __construct() |
20
|
|
|
{ |
21
|
3 |
|
} |
22
|
|
|
|
23
|
3 |
|
public function setSheetId($sheetId) |
24
|
|
|
{ |
25
|
3 |
|
$this->sheetId = $sheetId; |
26
|
|
|
|
27
|
3 |
|
return $this; |
28
|
|
|
} |
29
|
|
|
|
30
|
3 |
|
public function setSheetTitle($sheetTitle) |
31
|
|
|
{ |
32
|
3 |
|
$this->sheetTitle = $sheetTitle; |
33
|
|
|
|
34
|
3 |
|
return $this; |
35
|
|
|
} |
36
|
|
|
|
37
|
1 |
|
public static function emptySheet($columnsCount, $localesCount, $headerRowsCount) |
38
|
|
|
{ |
39
|
1 |
|
$instance = new self; |
40
|
|
|
|
41
|
1 |
|
$instance->headerRowsCount = $headerRowsCount; |
42
|
1 |
|
$instance->dataRowsCount = 10; |
43
|
1 |
|
$instance->columnsCount = $columnsCount; |
44
|
1 |
|
$instance->localesCount = $localesCount; |
45
|
|
|
|
46
|
1 |
|
return $instance; |
47
|
|
|
} |
48
|
|
|
|
49
|
2 |
|
public static function sheetWithData($dataRowsCount, $columnsCount, $localesCount, $headerRowsCount) |
50
|
|
|
{ |
51
|
2 |
|
$instance = new self; |
52
|
|
|
|
53
|
2 |
|
$instance->headerRowsCount = $headerRowsCount; |
54
|
2 |
|
$instance->dataRowsCount = $dataRowsCount; |
55
|
2 |
|
$instance->columnsCount = $columnsCount; |
56
|
2 |
|
$instance->localesCount = $localesCount; |
57
|
|
|
|
58
|
2 |
|
return $instance; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function headerShortRange() |
62
|
|
|
{ |
63
|
|
|
$alphabet = range('A', 'Z'); |
64
|
|
|
|
65
|
|
|
return $this->sheetTitle.'!A1:'.$alphabet[$this->getColumnsCount() - 1].'1'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function headerRange() |
69
|
|
|
{ |
70
|
|
|
return [ |
71
|
|
|
'sheetId' => $this->sheetId, |
72
|
|
|
'startRowIndex' => 0, |
73
|
|
|
'endRowIndex' => 1, |
74
|
|
|
'startColumnIndex' => 0, |
75
|
|
|
'endColumnIndex' => $this->getColumnsCount(), |
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function fullKeyColumnRange() |
80
|
|
|
{ |
81
|
|
|
return [ |
82
|
|
|
'sheetId' => $this->sheetId, |
83
|
|
|
'startRowIndex' => 1, |
84
|
|
|
'endRowIndex' => $this->getRowsCount(), |
85
|
|
|
'startColumnIndex' => 0, |
86
|
|
|
'endColumnIndex' => 1, |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function metaColumnsRange() |
91
|
|
|
{ |
92
|
|
|
return [ |
93
|
|
|
'sheetId' => $this->sheetId, |
94
|
|
|
'startRowIndex' => 1, |
95
|
|
|
'endRowIndex' => $this->getRowsCount(), |
96
|
|
|
'startColumnIndex' => $this->getLocalesCount() + 1, |
97
|
|
|
'endColumnIndex' => $this->getColumnsCount(), |
98
|
|
|
]; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function dataShortRange($firstRow = 2, $noLastRow = false) |
102
|
|
|
{ |
103
|
|
|
$alphabet = range('A', 'Z'); |
104
|
|
|
$firstColumn = 'A'; |
105
|
|
|
$lastColumn = $alphabet[$this->getColumnsCount() - 1]; |
106
|
|
|
$lastRow = $this->getRowsCount(); |
107
|
|
|
|
108
|
|
|
return $this->sheetTitle.'!'.$firstColumn.$firstRow.':'.$lastColumn.($noLastRow ? '' : $lastRow); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function dataRange($endRow, $firstRow = 2) |
112
|
|
|
{ |
113
|
|
|
return [ |
114
|
|
|
'sheetId' => $this->sheetId, |
115
|
|
|
'startRowIndex' => $firstRow, |
116
|
|
|
'endRowIndex' => $endRow, |
117
|
|
|
'startColumnIndex' => 0, |
118
|
|
|
'endColumnIndex' => $this->getColumnsCount(), |
119
|
|
|
]; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function translationsRange($firstColumn = 1, $rowCount = null) |
123
|
|
|
{ |
124
|
|
|
return [ |
125
|
|
|
'sheetId' => $this->sheetId, |
126
|
|
|
'startRowIndex' => 1, |
127
|
|
|
'endRowIndex' => $rowCount ?: $this->getRowsCount(), |
128
|
|
|
'startColumnIndex' => $firstColumn, |
129
|
|
|
'endColumnIndex' => $firstColumn + $this->getLocalesCount(), |
130
|
|
|
]; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function getColumnsCount() |
134
|
|
|
{ |
135
|
|
|
return $this->columnsCount; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function getRowsCount() |
139
|
|
|
{ |
140
|
|
|
return $this->dataRowsCount + $this->headerRowsCount; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function getLocalesCount() |
144
|
|
|
{ |
145
|
|
|
return $this->localesCount; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function namespaceColumnIndex() |
149
|
|
|
{ |
150
|
|
|
return $this->getLocalesCount() + 1; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function groupColumnIndex() |
154
|
|
|
{ |
155
|
|
|
return $this->getLocalesCount() + 2; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function keyColumnIndex() |
159
|
|
|
{ |
160
|
|
|
return $this->getLocalesCount() + 3; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function sourceFileColumnIndex() |
164
|
|
|
{ |
165
|
|
|
return $this->getLocalesCount() + 4; |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|