Skip to content

Commit 894df7c

Browse files
committed
feat: adapt to new GLPI's autoload
1 parent c6aefe1 commit 894df7c

11 files changed

+74
-74
lines changed

inc/abstractquestionparameter.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ abstract class PluginFormcreatorAbstractQuestionParameter
6565
* - fieldName: name of the HTML input tag
6666
* - label : label for the parameter
6767
*/
68-
public function __construct(PluginFormcreatorFieldInterface $field, array $options) {
68+
public function setField(PluginFormcreatorFieldInterface $field, array $options) {
6969
$fieldType = $field->getFieldTypeName();
7070
$fieldName = $options['fieldName'];
7171
$this->domId = $this->domId . "_{$fieldType}_{$fieldName}";

inc/field/checkboxesfield.class.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,14 @@ public static function canRequire(): bool {
318318
}
319319

320320
public function getEmptyParameters(): array {
321+
$range = new PluginFormcreatorQuestionRange();
322+
$range->setField($this, [
323+
'fieldName' => 'range',
324+
'label' => __('Range', 'formcreator'),
325+
'fieldType' => ['text'],
326+
]);
321327
return [
322-
'range' => new PluginFormcreatorQuestionRange(
323-
$this,
324-
[
325-
'fieldName' => 'range',
326-
'label' => __('Range', 'formcreator'),
327-
'fieldType' => ['text'],
328-
]
329-
),
328+
'range' => $range,
330329
];
331330
}
332331

inc/field/floatfield.class.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -252,23 +252,21 @@ public function getEmptyParameters(): array {
252252
$regexDoc .= '<a href="http://php.net/manual/reference.pcre.pattern.syntax.php" target="_blank">';
253253
$regexDoc .= '(' . __('Regular expression', 'formcreator') . ')';
254254
$regexDoc .= '</small>';
255+
$range = new PluginFormcreatorQuestionRange();
256+
$range->setField($this, [
257+
'fieldName' => 'range',
258+
'label' => __('Range', 'formcreator'),
259+
'fieldType' => ['text'],
260+
]);
261+
$regex = new PluginFormcreatorQuestionRegex();
262+
$regex->setField($this, [
263+
'fieldName' => 'regex',
264+
'label' => __('Additional validation', 'formcreator') . $regexDoc,
265+
'fieldType' => ['text'],
266+
]);
255267
return [
256-
'regex' => new PluginFormcreatorQuestionRegex(
257-
$this,
258-
[
259-
'fieldName' => 'regex',
260-
'label' => __('Additional validation', 'formcreator') . $regexDoc,
261-
'fieldType' => ['text'],
262-
]
263-
),
264-
'range' => new PluginFormcreatorQuestionRange(
265-
$this,
266-
[
267-
'fieldName' => 'range',
268-
'label' => __('Range', 'formcreator'),
269-
'fieldType' => ['text'],
270-
]
271-
),
268+
'regex' => $regex,
269+
'range' => $range,
272270
];
273271
}
274272

inc/field/textfield.class.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -235,23 +235,21 @@ public function getEmptyParameters(): array {
235235
$regexDoc .= '<a href="http://php.net/manual/reference.pcre.pattern.syntax.php" target="_blank">';
236236
$regexDoc .= '(' . __('Regular expression', 'formcreator') . ')';
237237
$regexDoc .= '</small>';
238+
$range = new PluginFormcreatorQuestionRange();
239+
$range->setField($this, [
240+
'fieldName' => 'range',
241+
'label' => __('Range', 'formcreator'),
242+
'fieldType' => ['text'],
243+
]);
244+
$regex = new PluginFormcreatorQuestionRegex();
245+
$regex->setField($this, [
246+
'fieldName' => 'regex',
247+
'label' => __('Additional validation', 'formcreator') . $regexDoc,
248+
'fieldType' => ['text'],
249+
]);
238250
return [
239-
'regex' => new PluginFormcreatorQuestionRegex(
240-
$this,
241-
[
242-
'fieldName' => 'regex',
243-
'label' => __('Additional validation', 'formcreator') . $regexDoc,
244-
'fieldType' => ['text'],
245-
]
246-
),
247-
'range' => new PluginFormcreatorQuestionRange(
248-
$this,
249-
[
250-
'fieldName' => 'range',
251-
'label' => __('Range', 'formcreator'),
252-
'fieldType' => ['text'],
253-
]
254-
),
251+
'regex' => $regex,
252+
'range' => $range,
255253
];
256254
}
257255

inc/form_validator.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function showForForm(PluginFormcreatorForm $item, $options = []) {
171171
],
172172
];
173173
$usersCondition = [
174-
"$userTable.id" => new QuerySubquery($subQuery)
174+
"$userTable.id" => new QuerySubQuery($subQuery)
175175
];
176176
$formValidator = new PluginFormcreatorForm_Validator();
177177
$selectedValidatorUsers = [];
@@ -253,7 +253,7 @@ public function showForForm(PluginFormcreatorForm $item, $options = []) {
253253
],
254254
];
255255
$groupsCondition = [
256-
"$groupTable.id" => new QuerySubquery($subQuery),
256+
"$groupTable.id" => new QuerySubQuery($subQuery),
257257
];
258258
$groups = $DB->request([
259259
'SELECT' => ['id' ,'name'],
@@ -541,7 +541,7 @@ public static function dropdownValidatorUser(): string {
541541
$profileFk = Profile::getForeignKeyField();
542542
$profileRightTable = ProfileRight::getTable();
543543
$usersCondition = [
544-
"$userTable.id" => new QuerySubquery([
544+
"$userTable.id" => new QuerySubQuery([
545545
'SELECT' => "$profileUserTable.$userFk",
546546
'FROM' => $profileUserTable,
547547
'INNER JOIN' => [
@@ -606,7 +606,7 @@ public static function dropdownValidatorGroup(): string {
606606
$profileRightTable = ProfileRight::getTable();
607607
$groupUserTable = Group_User::getTable();
608608
$groupsCondition = [
609-
"$groupTable.id" => new QuerySubquery([
609+
"$groupTable.id" => new QuerySubQuery([
610610
'SELECT' => "$groupUserTable.$groupFk",
611611
'FROM' => $groupUserTable,
612612
'INNER JOIN' => [

inc/issue.class.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ public static function getSyncIssuesRequest() : AbstractQuery {
179179
],
180180
],
181181
[
182-
'TABLE' => new QuerySubquery([
182+
'TABLE' => new QuerySubQuery([
183183
'SELECT' => '*',
184-
'FROM' => new QuerySubquery([
184+
'FROM' => new QuerySubQuery([
185185
'SELECT' => ['users_id', $ticketFk],
186186
'DISTINCT' => true,
187187
'FROM' => $ticketUserTable,
@@ -222,9 +222,9 @@ public static function getSyncIssuesRequest() : AbstractQuery {
222222

223223
// Union of the 3 previous queries
224224
$union = new QueryUnion([
225-
new QuerySubquery($query1),
226-
new QuerySubquery($query2),
227-
new QuerySubquery($query3)
225+
new QuerySubQuery($query1),
226+
new QuerySubQuery($query2),
227+
new QuerySubQuery($query3)
228228
], true);
229229

230230
return $union;

inc/question.class.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,8 @@ public function prepareInputForAdd($input) {
442442
// handle description field and its inline pictures
443443
if (isset($input['_description'])) {
444444
foreach ($input['_description'] as $id => $filename) {
445-
// TODO :replace PluginFormcreatorCommon::getDuplicateOf by Document::getDuplicateOf
446-
// when is merged https://github.com/glpi-project/glpi/pull/9335
447-
if ($document = PluginFormcreatorCommon::getDuplicateOf(Session::getActiveEntity(), GLPI_TMP_DIR . '/' . $filename)) {
445+
$document = new Document();
446+
if ($document->getDuplicateOf(Session::getActiveEntity(), GLPI_TMP_DIR . '/' . $filename)) {
448447
$this->value = str_replace('id="' . $input['_tag_description'] . '"', $document->fields['tag'], $this->value);
449448
$input['_tag_description'][$id] = $document->fields['tag'];
450449
}
@@ -720,7 +719,7 @@ public function post_purgeItem() {
720719
'show_rule' => PluginFormcreatorCondition::SHOW_RULE_ALWAYS
721720
],
722721
[
723-
'id' => new QuerySubquery([
722+
'id' => new QuerySubQuery([
724723
'SELECT' => self::getForeignKeyField(),
725724
'FROM' => $condition_table,
726725
'WHERE' => ['plugin_formcreator_questions_id' => $questionId]

inc/questiondependency.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class PluginFormcreatorQuestionDependency
5959
* - label : label for the parameter
6060
* - fieldType: array of field types the dependency should filter
6161
*/
62-
public function __construct(PluginFormcreatorFieldInterface $field, array $options) {
63-
parent::__construct($field, $options);
62+
public function setField(PluginFormcreatorFieldInterface $field, array $options) {
63+
parent::setField($field, $options);
6464
$this->fieldtype = isset($options['fieldType']) ? $options['fieldType'] : [];
6565
}
6666

inc/questionparameterinterface.class.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@
3333
}
3434

3535
interface PluginFormcreatorQuestionParameterInterface {
36+
/**
37+
* set field and options related to this question parameter
38+
*
39+
* @param PluginFormcreatorFieldInterface $field
40+
* @param array $options
41+
* @return void
42+
*/
43+
public function setField(PluginFormcreatorFieldInterface $field, array $options);
44+
3645
/**
3746
* Gets the HTML form part for the parameters
3847
* @param PluginFormcreatorForm $form a form used as context when displaying parameters

tests/fixture/PluginFormcreatorDependentField.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,22 @@ public static function canRequire(): bool {
5757
}
5858

5959
public function getEmptyParameters(): array {
60+
$firstname = new PluginFormcreatorQuestionDependency();
61+
$firstname->setField($this, [
62+
'fieldName' => 'firstname',
63+
'label' => __('First name field', 'formcreator'),
64+
'fieldType' => ['text'],
65+
]);
66+
$lastname = new PluginFormcreatorQuestionDependency();
67+
$lastname->setField($this, [
68+
'fieldName' => 'lastname',
69+
'label' => __('Last name field', 'formcreator'),
70+
'fieldType' => ['text'],
71+
]);
72+
6073
return [
61-
'firstname' => new PluginFormcreatorQuestionDependency(
62-
$this,
63-
[
64-
'fieldName' => 'firstname',
65-
'label' => __('First name field', 'formcreator'),
66-
'fieldType' => ['text'],
67-
]
68-
),
69-
'lastname' => new PluginFormcreatorQuestionDependency(
70-
$this,
71-
[
72-
'fieldName' => 'lastname',
73-
'label' => __('Last name field', 'formcreator'),
74-
'fieldType' => ['text'],
75-
]
76-
),
74+
'firstname' => $firstname,
75+
'lastname' => $lastname,
7776
];
7877
}
7978

0 commit comments

Comments
 (0)