Skip to content

Commit 8de2948

Browse files
committed
feat(questionparameter): make translatable
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent 89b6221 commit 8de2948

29 files changed

+235
-77
lines changed

inc/abstractfield.class.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,20 @@ protected function checkRegex($regex)
334334

335335
return $isValid;
336336
}
337+
338+
public function getTranslatableStrings() {
339+
$strings = [
340+
'itemlink' => [],
341+
'string' => [],
342+
'text' => [],
343+
];
344+
345+
foreach ($this->getParameters() as $fieldName => $parameter) {
346+
foreach ($parameter->getTranslatableStrings() as $type => $subStrings) {
347+
$strings[$type] = array_merge($strings[$type], $subStrings);
348+
}
349+
}
350+
351+
return $strings;
352+
}
337353
}

inc/abstractquestionparameter.class.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,27 @@ public function prepareInputforAdd($input) {
8181
return $input;
8282
}
8383

84-
public function deleteObsoleteItems(CommonDBTM $container, array $exclude) : bool {
84+
public function rawSearchOptions() {
85+
$tab = [];
86+
$tab[] = [
87+
'id' => 'common',
88+
'name' => __('Parameter', 'formcreator')
89+
];
90+
91+
$tab[] = [
92+
'id' => '3',
93+
'table' => $this::getTable(),
94+
'field' => 'fieldname',
95+
'name' => __('Field name', 'formcreator'),
96+
'datatype' => 'itemlink',
97+
'massiveaction' => false,
98+
];
99+
100+
return $tab;
101+
}
102+
103+
public function deleteObsoleteItems(CommonDBTM $container, array $exclude): bool
104+
{
85105
$keepCriteria = [
86106
static::$items_id => $container->getID(),
87107
];
@@ -90,4 +110,22 @@ public function deleteObsoleteItems(CommonDBTM $container, array $exclude) : boo
90110
}
91111
return $this->deleteByCriteria($keepCriteria);
92112
}
113+
114+
public function getTranslatableStrings() {
115+
$strings = [
116+
'itemlink' => [],
117+
'string' => [],
118+
'text' => [],
119+
];
120+
foreach ($this->getTranslatableSearchOptions() as $searchOption) {
121+
$strings[$searchOption['datatype']][] = $this->fields[$searchOption['field']];
122+
}
123+
124+
foreach (array_keys($strings) as $type) {
125+
$strings[$type] = array_unique($strings[$type]);
126+
$strings[$type] = array_filter($strings[$type]);
127+
}
128+
129+
return $strings;
130+
}
93131
}

inc/abstracttarget.class.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ abstract class PluginFormcreatorAbstractTarget extends CommonDBChild implements
4242
{
4343
use PluginFormcreatorConditionnableTrait;
4444
use PluginFormcreatorExportableTrait;
45+
use PluginFormcreatorTranslatable;
4546

4647
static public $itemtype = PluginFormcreatorForm::class;
4748
static public $items_id = 'plugin_formcreator_forms_id';
@@ -2070,4 +2071,17 @@ public function deleteObsoleteItems(CommonDBTM $container, array $exclude) : boo
20702071
}
20712072
return $this->deleteByCriteria($keepCriteria);
20722073
}
2074+
2075+
public function getTranslatableStrings() {
2076+
$strings = [
2077+
'itemlink' => [],
2078+
'string' => [],
2079+
'text' => [],
2080+
];
2081+
foreach ($this->getTranslatableSearchOptions() as $searchOption) {
2082+
$strings[$searchOption['datatype']][] = $this->fields[$searchOption['field']];
2083+
}
2084+
2085+
return $strings;
2086+
}
20732087
}

inc/field/actorfield.class.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,4 @@ public function isVisibleField(): bool {
429429
public function isEditableField(): bool {
430430
return true;
431431
}
432-
433-
public function getTranslatableStrings()
434-
{
435-
return [];
436-
}
437432
}

inc/field/checkboxesfield.class.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ public function isEditableField(): bool {
381381

382382
public function getTranslatableStrings()
383383
{
384-
return ['text' => array_values($this->getAvailableValues())];
384+
$strings = parent::getTranslatableStrings();
385+
$strings['text'] = array_merge($strings['text'], array_values($this->getAvailableValues()));
386+
return $strings;
385387
}
386388
}

inc/field/datefield.class.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,4 @@ public function isVisibleField(): bool {
233233
public function isEditableField(): bool {
234234
return true;
235235
}
236-
237-
public function getTranslatableStrings() {
238-
return [];
239-
}
240236
}

inc/field/datetimefield.class.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,4 @@ public function isVisibleField(): bool {
234234
public function isEditableField(): bool {
235235
return true;
236236
}
237-
238-
public function getTranslatableStrings() {
239-
return [];
240-
}
241237
}

inc/field/descriptionfield.class.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,4 @@ public function isVisibleField(): bool {
163163
public function isEditableField(): bool {
164164
return false;
165165
}
166-
167-
public function getTranslatableStrings()
168-
{
169-
return [];
170-
}
171166
}

inc/field/emailfield.class.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,4 @@ public function isVisibleField(): bool {
189189
public function isEditableField(): bool {
190190
return true;
191191
}
192-
193-
public function getTranslatableStrings()
194-
{
195-
return [];
196-
}
197192
}

inc/field/filefield.class.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,4 @@ public function isVisibleField(): bool {
307307
public function isEditableField(): bool {
308308
return true;
309309
}
310-
311-
public function getTranslatableStrings()
312-
{
313-
return [];
314-
}
315310
}

inc/field/floatfield.class.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,4 @@ public function isVisibleField(): bool {
308308
public function isEditableField(): bool {
309309
return true;
310310
}
311-
312-
public function getTranslatableStrings()
313-
{
314-
return [];
315-
}
316311
}

inc/field/hostnamefield.class.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,4 @@ public function isVisibleField(): bool {
164164
public function isEditableField(): bool {
165165
return false;
166166
}
167-
168-
public function getTranslatableStrings()
169-
{
170-
return [];
171-
}
172167
}

inc/field/ipfield.class.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,4 @@ public function isVisibleField(): bool {
172172
public function isEditableField(): bool {
173173
return false;
174174
}
175-
176-
public function getTranslatableStrings()
177-
{
178-
return [];
179-
}
180175
}

inc/field/ldapselectfield.class.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,4 @@ public function isVisibleField(): bool {
311311
public function isEditableField(): bool {
312312
return true;
313313
}
314-
315-
public function getTranslatableStrings() {
316-
return [];
317-
}
318314
}

inc/field/radiosfield.class.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ public function isEditableField(): bool {
301301

302302
public function getTranslatableStrings()
303303
{
304-
return ['text' => array_values($this->getAvailableValues())];
304+
$strings = parent::getTranslatableStrings();
305+
$strings['text'] = array_merge($strings['text'], array_values($this->getAvailableValues()));
306+
return $strings;
305307
}
306308
}

inc/field/tagfield.class.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,4 @@ public function isVisibleField(): bool {
257257
public function isEditableField(): bool {
258258
return true;
259259
}
260-
261-
public function getTranslatableStrings()
262-
{
263-
return [];
264-
}
265260
}

inc/field/textareafield.class.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ public function getHtmlIcon(): string {
255255

256256
public function getTranslatableStrings()
257257
{
258-
return ['string' => [$this->question->fields['default_values']]];
258+
$strings = parent::getTranslatableStrings();
259+
$strings['string'] = array_merge($strings['string'], array_values($this->getAvailableValues()));
260+
return $strings;
259261
}
260262
}

inc/field/textfield.class.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ public function isEditableField(): bool {
293293

294294
public function getTranslatableStrings()
295295
{
296-
return ['text' => [$this->question->fields['default_values']]];
296+
$strings = parent::getTranslatableStrings();
297+
$strings['text'][] = $this->question->fields['default_values'];
298+
return $strings;
297299
}
298300
}

inc/field/timefield.class.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,4 @@ public function isVisibleField(): bool {
225225
public function isEditableField(): bool {
226226
return true;
227227
}
228-
229-
public function getTranslatableStrings() {
230-
return [];
231-
}
232228
}

inc/field/urgencyfield.class.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,4 @@ public function isVisibleField(): bool {
244244
public function isEditableField(): bool {
245245
return true;
246246
}
247-
248-
public function getTranslatableStrings()
249-
{
250-
return [];
251-
}
252247
}

inc/form.class.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,6 +2509,14 @@ public function getTranslatableStrings() {
25092509
}
25102510
}
25112511

2512+
foreach (self::getTargetTypes() as $targetType) {
2513+
foreach ((new $targetType())->getTargetsForForm($this->getID()) as $target) {
2514+
foreach ($target->getTranslatableStrings() as $type => $subStrings) {
2515+
$strings[$type] = array_merge($strings[$type], $subStrings);
2516+
}
2517+
}
2518+
}
2519+
25122520
// deduplicate strings and remove empty strings
25132521
foreach (array_keys($strings) as $type) {
25142522
$strings[$type] = array_unique($strings[$type]);

inc/question.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ public function post_getFromDB() {
12821282
* @return void
12831283
*/
12841284
private function loadField($fieldType) {
1285-
if (!$this->field === null || $this->isNewItem()) {
1285+
if (!$this->field === null) {
12861286
return;
12871287
}
12881288
$this->field = PluginFormcreatorFields::getFieldInstance($fieldType, $this);

inc/questionrange.class.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,38 @@
4444
class PluginFormcreatorQuestionRange
4545
extends PluginFormcreatorAbstractQuestionParameter
4646
{
47+
use PluginFormcreatorTranslatable;
4748

4849
protected $domId = 'plugin_formcreator_questionRange';
4950

5051
public static function getTypeName($nb = 0) {
5152
return _n('Question range', 'Question ranges', $nb, 'formcreator');
5253
}
5354

55+
public function rawSearchOptions() {
56+
$tab = parent::rawSearchOptions();
57+
58+
$tab[] = [
59+
'id' => '4',
60+
'table' => $this::getTable(),
61+
'field' => 'range_min',
62+
'name' => __('Minimum range', 'formcreator'),
63+
'datatype' => 'integer',
64+
'massiveaction' => false,
65+
];
66+
67+
$tab[] = [
68+
'id' => '4',
69+
'table' => $this::getTable(),
70+
'field' => 'range_max',
71+
'name' => __('maximum range', 'formcreator'),
72+
'datatype' => 'integer',
73+
'massiveaction' => false,
74+
];
75+
76+
return $tab;
77+
}
78+
5479
public function getParameterFormSize() {
5580
return 0;
5681
}

inc/questionregex.class.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,30 @@
4444
class PluginFormcreatorQuestionRegex
4545
extends PluginFormcreatorAbstractQuestionParameter
4646
{
47+
use PluginFormcreatorTranslatable;
4748

4849
protected $domId = 'plugin_formcreator_questionRegex';
4950

5051
public static function getTypeName($nb = 0) {
5152
return _n('Question regular expression', 'Question regular expressions', $nb, 'formcreator');
5253
}
5354

55+
public function rawSearchOptions() {
56+
$tab = parent::rawSearchOptions();
57+
58+
$tab[] = [
59+
'id' => '4',
60+
'table' => $this::getTable(),
61+
'field' => 'regex',
62+
'name' => __('Regular expression', 'formcreator'),
63+
'datatype' => 'text',
64+
'massiveaction' => false,
65+
];
66+
67+
return $tab;
68+
}
69+
70+
5471
public function getParameterFormSize() {
5572
return 1;
5673
}

0 commit comments

Comments
 (0)