From 894df7cc53b00369a53336556cb56f9869393de3 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Mon, 13 Dec 2021 08:44:13 +0100 Subject: [PATCH] feat: adapt to new GLPI's autoload --- inc/abstractquestionparameter.class.php | 2 +- inc/field/checkboxesfield.class.php | 15 +++++---- inc/field/floatfield.class.php | 30 +++++++++--------- inc/field/textfield.class.php | 30 +++++++++--------- inc/form_validator.class.php | 8 ++--- inc/issue.class.php | 10 +++--- inc/question.class.php | 7 ++--- inc/questiondependency.class.php | 4 +-- inc/questionparameterinterface.class.php | 9 ++++++ .../PluginFormcreatorDependentField.php | 31 +++++++++---------- tests/src/CommonTestCase.php | 2 -- 11 files changed, 74 insertions(+), 74 deletions(-) diff --git a/inc/abstractquestionparameter.class.php b/inc/abstractquestionparameter.class.php index 5761fa5c8..04da6c385 100644 --- a/inc/abstractquestionparameter.class.php +++ b/inc/abstractquestionparameter.class.php @@ -65,7 +65,7 @@ abstract class PluginFormcreatorAbstractQuestionParameter * - fieldName: name of the HTML input tag * - label : label for the parameter */ - public function __construct(PluginFormcreatorFieldInterface $field, array $options) { + public function setField(PluginFormcreatorFieldInterface $field, array $options) { $fieldType = $field->getFieldTypeName(); $fieldName = $options['fieldName']; $this->domId = $this->domId . "_{$fieldType}_{$fieldName}"; diff --git a/inc/field/checkboxesfield.class.php b/inc/field/checkboxesfield.class.php index 16b6acdfb..b6fb75323 100644 --- a/inc/field/checkboxesfield.class.php +++ b/inc/field/checkboxesfield.class.php @@ -318,15 +318,14 @@ public static function canRequire(): bool { } public function getEmptyParameters(): array { + $range = new PluginFormcreatorQuestionRange(); + $range->setField($this, [ + 'fieldName' => 'range', + 'label' => __('Range', 'formcreator'), + 'fieldType' => ['text'], + ]); return [ - 'range' => new PluginFormcreatorQuestionRange( - $this, - [ - 'fieldName' => 'range', - 'label' => __('Range', 'formcreator'), - 'fieldType' => ['text'], - ] - ), + 'range' => $range, ]; } diff --git a/inc/field/floatfield.class.php b/inc/field/floatfield.class.php index 8f16393c6..f86873534 100644 --- a/inc/field/floatfield.class.php +++ b/inc/field/floatfield.class.php @@ -252,23 +252,21 @@ public function getEmptyParameters(): array { $regexDoc .= ''; $regexDoc .= '(' . __('Regular expression', 'formcreator') . ')'; $regexDoc .= ''; + $range = new PluginFormcreatorQuestionRange(); + $range->setField($this, [ + 'fieldName' => 'range', + 'label' => __('Range', 'formcreator'), + 'fieldType' => ['text'], + ]); + $regex = new PluginFormcreatorQuestionRegex(); + $regex->setField($this, [ + 'fieldName' => 'regex', + 'label' => __('Additional validation', 'formcreator') . $regexDoc, + 'fieldType' => ['text'], + ]); return [ - 'regex' => new PluginFormcreatorQuestionRegex( - $this, - [ - 'fieldName' => 'regex', - 'label' => __('Additional validation', 'formcreator') . $regexDoc, - 'fieldType' => ['text'], - ] - ), - 'range' => new PluginFormcreatorQuestionRange( - $this, - [ - 'fieldName' => 'range', - 'label' => __('Range', 'formcreator'), - 'fieldType' => ['text'], - ] - ), + 'regex' => $regex, + 'range' => $range, ]; } diff --git a/inc/field/textfield.class.php b/inc/field/textfield.class.php index c4aeb436b..086395d08 100644 --- a/inc/field/textfield.class.php +++ b/inc/field/textfield.class.php @@ -235,23 +235,21 @@ public function getEmptyParameters(): array { $regexDoc .= ''; $regexDoc .= '(' . __('Regular expression', 'formcreator') . ')'; $regexDoc .= ''; + $range = new PluginFormcreatorQuestionRange(); + $range->setField($this, [ + 'fieldName' => 'range', + 'label' => __('Range', 'formcreator'), + 'fieldType' => ['text'], + ]); + $regex = new PluginFormcreatorQuestionRegex(); + $regex->setField($this, [ + 'fieldName' => 'regex', + 'label' => __('Additional validation', 'formcreator') . $regexDoc, + 'fieldType' => ['text'], + ]); return [ - 'regex' => new PluginFormcreatorQuestionRegex( - $this, - [ - 'fieldName' => 'regex', - 'label' => __('Additional validation', 'formcreator') . $regexDoc, - 'fieldType' => ['text'], - ] - ), - 'range' => new PluginFormcreatorQuestionRange( - $this, - [ - 'fieldName' => 'range', - 'label' => __('Range', 'formcreator'), - 'fieldType' => ['text'], - ] - ), + 'regex' => $regex, + 'range' => $range, ]; } diff --git a/inc/form_validator.class.php b/inc/form_validator.class.php index 3356b961c..7f088fd31 100644 --- a/inc/form_validator.class.php +++ b/inc/form_validator.class.php @@ -171,7 +171,7 @@ public function showForForm(PluginFormcreatorForm $item, $options = []) { ], ]; $usersCondition = [ - "$userTable.id" => new QuerySubquery($subQuery) + "$userTable.id" => new QuerySubQuery($subQuery) ]; $formValidator = new PluginFormcreatorForm_Validator(); $selectedValidatorUsers = []; @@ -253,7 +253,7 @@ public function showForForm(PluginFormcreatorForm $item, $options = []) { ], ]; $groupsCondition = [ - "$groupTable.id" => new QuerySubquery($subQuery), + "$groupTable.id" => new QuerySubQuery($subQuery), ]; $groups = $DB->request([ 'SELECT' => ['id' ,'name'], @@ -541,7 +541,7 @@ public static function dropdownValidatorUser(): string { $profileFk = Profile::getForeignKeyField(); $profileRightTable = ProfileRight::getTable(); $usersCondition = [ - "$userTable.id" => new QuerySubquery([ + "$userTable.id" => new QuerySubQuery([ 'SELECT' => "$profileUserTable.$userFk", 'FROM' => $profileUserTable, 'INNER JOIN' => [ @@ -606,7 +606,7 @@ public static function dropdownValidatorGroup(): string { $profileRightTable = ProfileRight::getTable(); $groupUserTable = Group_User::getTable(); $groupsCondition = [ - "$groupTable.id" => new QuerySubquery([ + "$groupTable.id" => new QuerySubQuery([ 'SELECT' => "$groupUserTable.$groupFk", 'FROM' => $groupUserTable, 'INNER JOIN' => [ diff --git a/inc/issue.class.php b/inc/issue.class.php index 224edea15..93091b146 100644 --- a/inc/issue.class.php +++ b/inc/issue.class.php @@ -179,9 +179,9 @@ public static function getSyncIssuesRequest() : AbstractQuery { ], ], [ - 'TABLE' => new QuerySubquery([ + 'TABLE' => new QuerySubQuery([ 'SELECT' => '*', - 'FROM' => new QuerySubquery([ + 'FROM' => new QuerySubQuery([ 'SELECT' => ['users_id', $ticketFk], 'DISTINCT' => true, 'FROM' => $ticketUserTable, @@ -222,9 +222,9 @@ public static function getSyncIssuesRequest() : AbstractQuery { // Union of the 3 previous queries $union = new QueryUnion([ - new QuerySubquery($query1), - new QuerySubquery($query2), - new QuerySubquery($query3) + new QuerySubQuery($query1), + new QuerySubQuery($query2), + new QuerySubQuery($query3) ], true); return $union; diff --git a/inc/question.class.php b/inc/question.class.php index 3eabb000b..7e62b3ad5 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -442,9 +442,8 @@ public function prepareInputForAdd($input) { // handle description field and its inline pictures if (isset($input['_description'])) { foreach ($input['_description'] as $id => $filename) { - // TODO :replace PluginFormcreatorCommon::getDuplicateOf by Document::getDuplicateOf - // when is merged https://github.com/glpi-project/glpi/pull/9335 - if ($document = PluginFormcreatorCommon::getDuplicateOf(Session::getActiveEntity(), GLPI_TMP_DIR . '/' . $filename)) { + $document = new Document(); + if ($document->getDuplicateOf(Session::getActiveEntity(), GLPI_TMP_DIR . '/' . $filename)) { $this->value = str_replace('id="' . $input['_tag_description'] . '"', $document->fields['tag'], $this->value); $input['_tag_description'][$id] = $document->fields['tag']; } @@ -720,7 +719,7 @@ public function post_purgeItem() { 'show_rule' => PluginFormcreatorCondition::SHOW_RULE_ALWAYS ], [ - 'id' => new QuerySubquery([ + 'id' => new QuerySubQuery([ 'SELECT' => self::getForeignKeyField(), 'FROM' => $condition_table, 'WHERE' => ['plugin_formcreator_questions_id' => $questionId] diff --git a/inc/questiondependency.class.php b/inc/questiondependency.class.php index a3f5c1e47..971d66594 100644 --- a/inc/questiondependency.class.php +++ b/inc/questiondependency.class.php @@ -59,8 +59,8 @@ class PluginFormcreatorQuestionDependency * - label : label for the parameter * - fieldType: array of field types the dependency should filter */ - public function __construct(PluginFormcreatorFieldInterface $field, array $options) { - parent::__construct($field, $options); + public function setField(PluginFormcreatorFieldInterface $field, array $options) { + parent::setField($field, $options); $this->fieldtype = isset($options['fieldType']) ? $options['fieldType'] : []; } diff --git a/inc/questionparameterinterface.class.php b/inc/questionparameterinterface.class.php index 09f7bb07c..3d145461b 100644 --- a/inc/questionparameterinterface.class.php +++ b/inc/questionparameterinterface.class.php @@ -33,6 +33,15 @@ } interface PluginFormcreatorQuestionParameterInterface { + /** + * set field and options related to this question parameter + * + * @param PluginFormcreatorFieldInterface $field + * @param array $options + * @return void + */ + public function setField(PluginFormcreatorFieldInterface $field, array $options); + /** * Gets the HTML form part for the parameters * @param PluginFormcreatorForm $form a form used as context when displaying parameters diff --git a/tests/fixture/PluginFormcreatorDependentField.php b/tests/fixture/PluginFormcreatorDependentField.php index 81ff05f19..9d5b21908 100644 --- a/tests/fixture/PluginFormcreatorDependentField.php +++ b/tests/fixture/PluginFormcreatorDependentField.php @@ -57,23 +57,22 @@ public static function canRequire(): bool { } public function getEmptyParameters(): array { + $firstname = new PluginFormcreatorQuestionDependency(); + $firstname->setField($this, [ + 'fieldName' => 'firstname', + 'label' => __('First name field', 'formcreator'), + 'fieldType' => ['text'], + ]); + $lastname = new PluginFormcreatorQuestionDependency(); + $lastname->setField($this, [ + 'fieldName' => 'lastname', + 'label' => __('Last name field', 'formcreator'), + 'fieldType' => ['text'], + ]); + return [ - 'firstname' => new PluginFormcreatorQuestionDependency( - $this, - [ - 'fieldName' => 'firstname', - 'label' => __('First name field', 'formcreator'), - 'fieldType' => ['text'], - ] - ), - 'lastname' => new PluginFormcreatorQuestionDependency( - $this, - [ - 'fieldName' => 'lastname', - 'label' => __('Last name field', 'formcreator'), - 'fieldType' => ['text'], - ] - ), + 'firstname' => $firstname, + 'lastname' => $lastname, ]; } diff --git a/tests/src/CommonTestCase.php b/tests/src/CommonTestCase.php index bb6b2da3e..f6eec882b 100644 --- a/tests/src/CommonTestCase.php +++ b/tests/src/CommonTestCase.php @@ -45,8 +45,6 @@ protected function setupGLPIFramework() { $DB = new DB(); - include_once (GLPI_ROOT . "/inc/timer.class.php"); - // Security of PHP_SELF $_SERVER['PHP_SELF'] = Html::cleanParametersURL($_SERVER['PHP_SELF']);