diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 00000000..5fd203df --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,20 @@ +in(__DIR__) + ->name('*.php'); + +$config = new Config(); + +$rules = [ + '@PER-CS2.0' => true, + 'trailing_comma_in_multiline' => ['elements' => ['arguments', 'array_destructuring', 'arrays']], // For PHP 7.4 compatibility +]; + +return $config + ->setRules($rules) + ->setFinder($finder) + ->setUsingCache(false); diff --git a/ajax/container.php b/ajax/container.php index 6d7a8c80..46b7588f 100644 --- a/ajax/container.php +++ b/ajax/container.php @@ -28,14 +28,14 @@ * ------------------------------------------------------------------------- */ -include("../../../inc/includes.php"); +include('../../../inc/includes.php'); use Glpi\Http\Response; if (isset($_GET['action']) && $_GET['action'] === 'get_fields_html') { $containers_id = $_GET['id']; $itemtype = $_GET['itemtype']; - $items_id = (int)$_GET['items_id']; + $items_id = (int) $_GET['items_id']; $type = $_GET['type']; $subtype = $_GET['subtype']; $input = $_GET['input']; @@ -52,10 +52,10 @@ $containers_id, $item, $type, - $subtype + $subtype, ); } else { - echo ""; + echo ''; } } else { Response::sendError(404, 'Not Found'); diff --git a/ajax/container_display_condition.php b/ajax/container_display_condition.php index bfa2a311..5d68a34b 100644 --- a/ajax/container_display_condition.php +++ b/ajax/container_display_condition.php @@ -28,29 +28,29 @@ * ------------------------------------------------------------------------- */ -include("../../../inc/includes.php"); +include('../../../inc/includes.php'); if (isset($_GET['action'])) { if ($_GET['action'] === 'get_add_form') { $status_override = new PluginFieldsContainerDisplayCondition(); $status_override->showForm(0, $_GET); - } else if ($_GET['action'] === 'get_edit_form') { + } elseif ($_GET['action'] === 'get_edit_form') { $status_override = new PluginFieldsContainerDisplayCondition(); $status_override->getFromDB($_GET['id']); $status_override->showForm($_GET['id'], $_GET); } -} else if (isset($_POST['action'])) { +} elseif (isset($_POST['action'])) { if ($_POST['action'] === 'get_itemtype_so') { if (isset($_POST['itemtype']) && class_exists($_POST['itemtype'])) { echo PluginFieldsContainerDisplayCondition::showItemtypeFieldForm($_POST['itemtype']) ; } else { - echo ""; + echo ''; } - } else if ($_POST['action'] === 'get_condition_switch_so') { + } elseif ($_POST['action'] === 'get_condition_switch_so') { if (isset($_POST['search_option_id']) && (isset($_POST['itemtype']) && class_exists($_POST['itemtype']))) { echo PluginFieldsContainerDisplayCondition::showSearchOptionCondition($_POST['search_option_id'], $_POST['itemtype']); } else { - echo ""; + echo ''; } } } else { diff --git a/ajax/container_itemtypes_dropdown.php b/ajax/container_itemtypes_dropdown.php index 03e0a81e..dcebe711 100644 --- a/ajax/container_itemtypes_dropdown.php +++ b/ajax/container_itemtypes_dropdown.php @@ -28,6 +28,6 @@ * ------------------------------------------------------------------------- */ -include("../../../inc/includes.php"); +include('../../../inc/includes.php'); PluginFieldsContainer::showFormItemtype($_REQUEST); diff --git a/ajax/container_subtype_dropdown.php b/ajax/container_subtype_dropdown.php index 39c189d3..904a83d5 100644 --- a/ajax/container_subtype_dropdown.php +++ b/ajax/container_subtype_dropdown.php @@ -28,6 +28,6 @@ * ------------------------------------------------------------------------- */ -include("../../../inc/includes.php"); +include('../../../inc/includes.php'); PluginFieldsContainer::showFormSubtype($_REQUEST, true); diff --git a/ajax/field_specific_fields.php b/ajax/field_specific_fields.php index cdb37b93..fd889102 100644 --- a/ajax/field_specific_fields.php +++ b/ajax/field_specific_fields.php @@ -32,7 +32,7 @@ */ include('../../../inc/includes.php'); -header("Content-Type: text/html; charset=UTF-8"); +header('Content-Type: text/html; charset=UTF-8'); Html::header_nocache(); Session::checkLoginUser(); @@ -57,7 +57,7 @@ if ($field->isNewItem()) { Dropdown::showFromArray('allowed_values', PluginFieldsToolbox::getGlpiItemtypes(), [ 'display_emptychoice' => true, - 'multiple' => true + 'multiple' => true, ]); } else { $allowed_itemtypes = !empty($field->fields['allowed_values']) @@ -71,14 +71,14 @@ function ($itemtype) { ? $itemtype::getTypeName(Session::getPluralNumber()) : $itemtype; }, - $allowed_itemtypes - ) + $allowed_itemtypes, + ), ); } echo ''; } else { $dropdown_matches = []; - $is_dropdown = $type == 'dropdown' || preg_match('/^dropdown-(?.+)$/', $type, $dropdown_matches) === 1; + $is_dropdown = $type == 'dropdown' || preg_match('/^dropdown-(?.+)$/', $type, $dropdown_matches) === 1; // Display "default value(s)" field echo ''; @@ -94,7 +94,7 @@ function ($itemtype) { echo ''; if ($is_dropdown) { - $multiple = (bool)($_POST['multiple'] ?? $field->fields['multiple']); + $multiple = (bool) ($_POST['multiple'] ?? $field->fields['multiple']); if ($field->isNewItem()) { Dropdown::showYesNo( @@ -103,7 +103,7 @@ function ($itemtype) { -1, [ 'rand' => $rand, - ] + ], ); } else { echo Dropdown::getYesNo($multiple); @@ -128,27 +128,27 @@ function ($itemtype) { 'entity_restrict' => -1, 'multiple' => $multiple, 'rand' => $rand, - ] + ], ); } echo ''; Ajax::updateItemOnSelectEvent( "dropdown_multiple$rand", "plugin_fields_specific_fields_$rand", - "../ajax/field_specific_fields.php", + '../ajax/field_specific_fields.php', [ 'id' => $id, 'type' => $type, 'multiple' => '__VALUE__', 'rand' => $rand, - ] + ], ); } else { echo Html::input( 'default_value', [ 'value' => $field->fields['default_value'], - ] + ], ); } echo ''; diff --git a/ajax/reorder.php b/ajax/reorder.php index 8356c9da..bdfc71f4 100644 --- a/ajax/reorder.php +++ b/ajax/reorder.php @@ -28,7 +28,7 @@ * ------------------------------------------------------------------------- */ -include("../../../inc/includes.php"); +include('../../../inc/includes.php'); if ( !array_key_exists('container_id', $_POST) @@ -40,9 +40,9 @@ } $table = PluginFieldsField::getTable(); -$container_id = (int)$_POST['container_id']; -$old_order = (int)$_POST['old_order']; -$new_order = (int)$_POST['new_order']; +$container_id = (int) $_POST['container_id']; +$old_order = (int) $_POST['old_order']; +$new_order = (int) $_POST['new_order']; /** @var DBmysql $DB */ global $DB; @@ -56,7 +56,7 @@ 'plugin_fields_containers_id' => $container_id, 'ranking' => $old_order, ], - ] + ], ); if (0 === $field_iterator->count()) { @@ -75,9 +75,9 @@ ], [ 'plugin_fields_containers_id' => $container_id, - ['ranking' => ['>', $old_order]], - ['ranking' => ['<=', $new_order]], - ] + ['ranking' => ['>', $old_order]], + ['ranking' => ['<=', $new_order]], + ], ); } else { $DB->update( @@ -87,9 +87,9 @@ ], [ 'plugin_fields_containers_id' => $container_id, - ['ranking' => ['<', $old_order]], - ['ranking' => ['>=', $new_order]], - ] + ['ranking' => ['<', $old_order]], + ['ranking' => ['>=', $new_order]], + ], ); } @@ -101,5 +101,5 @@ ], [ 'id' => $field_id, - ] + ], ); diff --git a/ajax/status_override.php b/ajax/status_override.php index 55e344b4..6ce7f353 100644 --- a/ajax/status_override.php +++ b/ajax/status_override.php @@ -28,15 +28,15 @@ * ------------------------------------------------------------------------- */ -include("../../../inc/includes.php"); +include('../../../inc/includes.php'); if (isset($_GET['action'])) { if ($_GET['action'] === 'get_status_dropdown') { echo PluginFieldsStatusOverride::getStatusDropdownForItemtype($_GET['itemtype']); - } else if ($_GET['action'] === 'get_add_form') { + } elseif ($_GET['action'] === 'get_add_form') { $status_override = new PluginFieldsStatusOverride(); $status_override->showForm(0, $_GET); - } else if ($_GET['action'] === 'get_edit_form') { + } elseif ($_GET['action'] === 'get_edit_form') { $status_override = new PluginFieldsStatusOverride(); $status_override->getFromDB($_GET['id']); $status_override->showForm($_GET['id'], $_GET); diff --git a/ajax/viewtranslations.php b/ajax/viewtranslations.php index 11ae54f8..df0dbc0e 100644 --- a/ajax/viewtranslations.php +++ b/ajax/viewtranslations.php @@ -33,7 +33,7 @@ */ include('../../../inc/includes.php'); -header("Content-Type: text/html; charset=UTF-8"); +header('Content-Type: text/html; charset=UTF-8'); Html::header_nocache(); Session::checkLoginUser(); diff --git a/composer.json b/composer.json index 808aef0c..5e0fc5e9 100644 --- a/composer.json +++ b/composer.json @@ -4,10 +4,10 @@ "symfony/yaml": "^5.4" }, "require-dev": { + "friendsofphp/php-cs-fixer": "^3.64", "glpi-project/tools": "^0.7.4", "php-parallel-lint/php-parallel-lint": "^1.4", - "phpstan/phpstan": "^1.12", - "squizlabs/php_codesniffer": "^3.10" + "phpstan/phpstan": "^1.12" }, "config": { "optimize-autoloader": true, diff --git a/composer.lock b/composer.lock index 3ea5f304..6d58921e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c1ed9cd9b167382f937146d7497f736f", + "content-hash": "0407e93095050fecc89dd7ab8f377a31", "packages": [ { "name": "symfony/deprecation-contracts", @@ -230,202 +230,1719 @@ ], "packages-dev": [ { - "name": "glpi-project/tools", - "version": "0.7.4", + "name": "clue/ndjson-react", + "version": "v1.3.0", "source": { "type": "git", - "url": "https://github.com/glpi-project/tools.git", - "reference": "65a09a93350da6fa67d423dd94e4cb4023a17e20" + "url": "https://github.com/clue/reactphp-ndjson.git", + "reference": "392dc165fce93b5bb5c637b67e59619223c931b0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/glpi-project/tools/zipball/65a09a93350da6fa67d423dd94e4cb4023a17e20", - "reference": "65a09a93350da6fa67d423dd94e4cb4023a17e20", + "url": "https://api.github.com/repos/clue/reactphp-ndjson/zipball/392dc165fce93b5bb5c637b67e59619223c931b0", + "reference": "392dc165fce93b5bb5c637b67e59619223c931b0", "shasum": "" }, "require": { - "symfony/console": "^5.4 || ^6.0", - "twig/twig": "^3.3" + "php": ">=5.3", + "react/stream": "^1.2" }, "require-dev": { - "nikic/php-parser": "^4.13", - "phpstan/phpstan-src": "^1.10" + "phpunit/phpunit": "^9.5 || ^5.7 || ^4.8.35", + "react/event-loop": "^1.2" }, - "bin": [ - "bin/extract-locales", - "bin/licence-headers-check", - "tools/plugin-release" - ], "type": "library", "autoload": { "psr-4": { - "GlpiProject\\Tools\\": "src/" + "Clue\\React\\NDJson\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "GPL-3.0-or-later" + "MIT" ], "authors": [ { - "name": "Teclib'", - "email": "glpi@teclib.com", - "homepage": "http://teclib-group.com" + "name": "Christian Lück", + "email": "christian@clue.engineering" } ], - "description": "Various tools for GLPI and its plugins", + "description": "Streaming newline-delimited JSON (NDJSON) parser and encoder for ReactPHP.", + "homepage": "https://github.com/clue/reactphp-ndjson", "keywords": [ - "glpi", - "plugins", - "tools" + "NDJSON", + "json", + "jsonlines", + "newline", + "reactphp", + "streaming" ], "support": { - "issues": "https://github.com/glpi-project/tools/issues", - "source": "https://github.com/glpi-project/tools" + "issues": "https://github.com/clue/reactphp-ndjson/issues", + "source": "https://github.com/clue/reactphp-ndjson/tree/v1.3.0" }, - "time": "2024-09-18T06:58:02+00:00" + "funding": [ + { + "url": "https://clue.engineering/support", + "type": "custom" + }, + { + "url": "https://github.com/clue", + "type": "github" + } + ], + "time": "2022-12-23T10:58:28+00:00" }, { - "name": "php-parallel-lint/php-parallel-lint", - "version": "v1.4.0", + "name": "composer/pcre", + "version": "3.3.1", "source": { "type": "git", - "url": "https://github.com/php-parallel-lint/PHP-Parallel-Lint.git", - "reference": "6db563514f27e19595a19f45a4bf757b6401194e" + "url": "https://github.com/composer/pcre.git", + "reference": "63aaeac21d7e775ff9bc9d45021e1745c97521c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-parallel-lint/PHP-Parallel-Lint/zipball/6db563514f27e19595a19f45a4bf757b6401194e", - "reference": "6db563514f27e19595a19f45a4bf757b6401194e", + "url": "https://api.github.com/repos/composer/pcre/zipball/63aaeac21d7e775ff9bc9d45021e1745c97521c4", + "reference": "63aaeac21d7e775ff9bc9d45021e1745c97521c4", "shasum": "" }, "require": { - "ext-json": "*", - "php": ">=5.3.0" + "php": "^7.4 || ^8.0" }, - "replace": { - "grogy/php-parallel-lint": "*", - "jakub-onderka/php-parallel-lint": "*" + "conflict": { + "phpstan/phpstan": "<1.11.10" }, "require-dev": { - "nette/tester": "^1.3 || ^2.0", - "php-parallel-lint/php-console-highlighter": "0.* || ^1.0", - "squizlabs/php_codesniffer": "^3.6" + "phpstan/phpstan": "^1.11.10", + "phpstan/phpstan-strict-rules": "^1.1", + "phpunit/phpunit": "^8 || ^9" }, - "suggest": { - "php-parallel-lint/php-console-highlighter": "Highlight syntax in code snippet" + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + }, + "phpstan": { + "includes": [ + "extension.neon" + ] + } }, - "bin": [ - "parallel-lint" + "autoload": { + "psr-4": { + "Composer\\Pcre\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "PCRE wrapping library that offers type-safe preg_* replacements.", + "keywords": [ + "PCRE", + "preg", + "regex", + "regular expression" + ], + "support": { + "issues": "https://github.com/composer/pcre/issues", + "source": "https://github.com/composer/pcre/tree/3.3.1" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } ], + "time": "2024-08-27T18:44:43+00:00" + }, + { + "name": "composer/semver", + "version": "3.4.3", + "source": { + "type": "git", + "url": "https://github.com/composer/semver.git", + "reference": "4313d26ada5e0c4edfbd1dc481a92ff7bff91f12" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/semver/zipball/4313d26ada5e0c4edfbd1dc481a92ff7bff91f12", + "reference": "4313d26ada5e0c4edfbd1dc481a92ff7bff91f12", + "shasum": "" + }, + "require": { + "php": "^5.3.2 || ^7.0 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.11", + "symfony/phpunit-bridge": "^3 || ^7" + }, "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + } + }, "autoload": { - "classmap": [ - "./src/" - ] + "psr-4": { + "Composer\\Semver\\": "src" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-2-Clause" + "MIT" ], "authors": [ { - "name": "Jakub Onderka", - "email": "ahoj@jakubonderka.cz" + "name": "Nils Adermann", + "email": "naderman@naderman.de", + "homepage": "http://www.naderman.de" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + }, + { + "name": "Rob Bast", + "email": "rob.bast@gmail.com", + "homepage": "http://robbast.nl" } ], - "description": "This tool checks the syntax of PHP files about 20x faster than serial check.", - "homepage": "https://github.com/php-parallel-lint/PHP-Parallel-Lint", + "description": "Semver library that offers utilities, version constraint parsing and validation.", "keywords": [ - "lint", - "static analysis" + "semantic", + "semver", + "validation", + "versioning" ], "support": { - "issues": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/issues", - "source": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/tree/v1.4.0" + "irc": "ircs://irc.libera.chat:6697/composer", + "issues": "https://github.com/composer/semver/issues", + "source": "https://github.com/composer/semver/tree/3.4.3" }, - "time": "2024-03-27T12:14:49+00:00" + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2024-09-19T14:15:21+00:00" }, { - "name": "phpstan/phpstan", - "version": "1.12.5", + "name": "composer/xdebug-handler", + "version": "3.0.5", "source": { "type": "git", - "url": "https://github.com/phpstan/phpstan.git", - "reference": "7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17" + "url": "https://github.com/composer/xdebug-handler.git", + "reference": "6c1925561632e83d60a44492e0b344cf48ab85ef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17", - "reference": "7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/6c1925561632e83d60a44492e0b344cf48ab85ef", + "reference": "6c1925561632e83d60a44492e0b344cf48ab85ef", "shasum": "" }, "require": { - "php": "^7.2|^8.0" + "composer/pcre": "^1 || ^2 || ^3", + "php": "^7.2.5 || ^8.0", + "psr/log": "^1 || ^2 || ^3" }, - "conflict": { - "phpstan/phpstan-shim": "*" + "require-dev": { + "phpstan/phpstan": "^1.0", + "phpstan/phpstan-strict-rules": "^1.1", + "phpunit/phpunit": "^8.5 || ^9.6 || ^10.5" }, - "bin": [ - "phpstan", - "phpstan.phar" + "type": "library", + "autoload": { + "psr-4": { + "Composer\\XdebugHandler\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "John Stevenson", + "email": "john-stevenson@blueyonder.co.uk" + } + ], + "description": "Restarts a process without Xdebug.", + "keywords": [ + "Xdebug", + "performance" + ], + "support": { + "irc": "ircs://irc.libera.chat:6697/composer", + "issues": "https://github.com/composer/xdebug-handler/issues", + "source": "https://github.com/composer/xdebug-handler/tree/3.0.5" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } ], + "time": "2024-05-06T16:37:16+00:00" + }, + { + "name": "evenement/evenement", + "version": "v3.0.2", + "source": { + "type": "git", + "url": "https://github.com/igorw/evenement.git", + "reference": "0a16b0d71ab13284339abb99d9d2bd813640efbc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/igorw/evenement/zipball/0a16b0d71ab13284339abb99d9d2bd813640efbc", + "reference": "0a16b0d71ab13284339abb99d9d2bd813640efbc", + "shasum": "" + }, + "require": { + "php": ">=7.0" + }, + "require-dev": { + "phpunit/phpunit": "^9 || ^6" + }, "type": "library", "autoload": { - "files": [ - "bootstrap.php" - ] + "psr-4": { + "Evenement\\": "src/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], - "description": "PHPStan - PHP Static Analysis Tool", + "authors": [ + { + "name": "Igor Wiedler", + "email": "igor@wiedler.ch" + } + ], + "description": "Événement is a very simple event dispatching library for PHP", "keywords": [ - "dev", - "static analysis" + "event-dispatcher", + "event-emitter" ], "support": { - "docs": "https://phpstan.org/user-guide/getting-started", - "forum": "https://github.com/phpstan/phpstan/discussions", - "issues": "https://github.com/phpstan/phpstan/issues", - "security": "https://github.com/phpstan/phpstan/security/policy", - "source": "https://github.com/phpstan/phpstan-src" + "issues": "https://github.com/igorw/evenement/issues", + "source": "https://github.com/igorw/evenement/tree/v3.0.2" + }, + "time": "2023-08-08T05:53:35+00:00" + }, + { + "name": "fidry/cpu-core-counter", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/theofidry/cpu-core-counter.git", + "reference": "8520451a140d3f46ac33042715115e290cf5785f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/8520451a140d3f46ac33042715115e290cf5785f", + "reference": "8520451a140d3f46ac33042715115e290cf5785f", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "fidry/makefile": "^0.2.0", + "fidry/php-cs-fixer-config": "^1.1.2", + "phpstan/extension-installer": "^1.2.0", + "phpstan/phpstan": "^1.9.2", + "phpstan/phpstan-deprecation-rules": "^1.0.0", + "phpstan/phpstan-phpunit": "^1.2.2", + "phpstan/phpstan-strict-rules": "^1.4.4", + "phpunit/phpunit": "^8.5.31 || ^9.5.26", + "webmozarts/strict-phpunit": "^7.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Fidry\\CpuCoreCounter\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Théo FIDRY", + "email": "theo.fidry@gmail.com" + } + ], + "description": "Tiny utility to get the number of CPU cores.", + "keywords": [ + "CPU", + "core" + ], + "support": { + "issues": "https://github.com/theofidry/cpu-core-counter/issues", + "source": "https://github.com/theofidry/cpu-core-counter/tree/1.2.0" + }, + "funding": [ + { + "url": "https://github.com/theofidry", + "type": "github" + } + ], + "time": "2024-08-06T10:04:20+00:00" + }, + { + "name": "friendsofphp/php-cs-fixer", + "version": "v3.64.0", + "source": { + "type": "git", + "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", + "reference": "58dd9c931c785a79739310aef5178928305ffa67" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/58dd9c931c785a79739310aef5178928305ffa67", + "reference": "58dd9c931c785a79739310aef5178928305ffa67", + "shasum": "" + }, + "require": { + "clue/ndjson-react": "^1.0", + "composer/semver": "^3.4", + "composer/xdebug-handler": "^3.0.3", + "ext-filter": "*", + "ext-json": "*", + "ext-tokenizer": "*", + "fidry/cpu-core-counter": "^1.0", + "php": "^7.4 || ^8.0", + "react/child-process": "^0.6.5", + "react/event-loop": "^1.0", + "react/promise": "^2.0 || ^3.0", + "react/socket": "^1.0", + "react/stream": "^1.0", + "sebastian/diff": "^4.0 || ^5.0 || ^6.0", + "symfony/console": "^5.4 || ^6.0 || ^7.0", + "symfony/event-dispatcher": "^5.4 || ^6.0 || ^7.0", + "symfony/filesystem": "^5.4 || ^6.0 || ^7.0", + "symfony/finder": "^5.4 || ^6.0 || ^7.0", + "symfony/options-resolver": "^5.4 || ^6.0 || ^7.0", + "symfony/polyfill-mbstring": "^1.28", + "symfony/polyfill-php80": "^1.28", + "symfony/polyfill-php81": "^1.28", + "symfony/process": "^5.4 || ^6.0 || ^7.0", + "symfony/stopwatch": "^5.4 || ^6.0 || ^7.0" + }, + "require-dev": { + "facile-it/paraunit": "^1.3 || ^2.3", + "infection/infection": "^0.29.5", + "justinrainbow/json-schema": "^5.2", + "keradus/cli-executor": "^2.1", + "mikey179/vfsstream": "^1.6.11", + "php-coveralls/php-coveralls": "^2.7", + "php-cs-fixer/accessible-object": "^1.1", + "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.5", + "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.5", + "phpunit/phpunit": "^9.6.19 || ^10.5.21 || ^11.2", + "symfony/var-dumper": "^5.4 || ^6.0 || ^7.0", + "symfony/yaml": "^5.4 || ^6.0 || ^7.0" + }, + "suggest": { + "ext-dom": "For handling output formats in XML", + "ext-mbstring": "For handling non-UTF8 characters." + }, + "bin": [ + "php-cs-fixer" + ], + "type": "application", + "autoload": { + "psr-4": { + "PhpCsFixer\\": "src/" + }, + "exclude-from-classmap": [ + "src/Fixer/Internal/*" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Dariusz Rumiński", + "email": "dariusz.ruminski@gmail.com" + } + ], + "description": "A tool to automatically fix PHP code style", + "keywords": [ + "Static code analysis", + "fixer", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.64.0" + }, + "funding": [ + { + "url": "https://github.com/keradus", + "type": "github" + } + ], + "time": "2024-08-30T23:09:38+00:00" + }, + { + "name": "glpi-project/tools", + "version": "0.7.4", + "source": { + "type": "git", + "url": "https://github.com/glpi-project/tools.git", + "reference": "65a09a93350da6fa67d423dd94e4cb4023a17e20" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/glpi-project/tools/zipball/65a09a93350da6fa67d423dd94e4cb4023a17e20", + "reference": "65a09a93350da6fa67d423dd94e4cb4023a17e20", + "shasum": "" + }, + "require": { + "symfony/console": "^5.4 || ^6.0", + "twig/twig": "^3.3" + }, + "require-dev": { + "nikic/php-parser": "^4.13", + "phpstan/phpstan-src": "^1.10" + }, + "bin": [ + "bin/extract-locales", + "bin/licence-headers-check", + "tools/plugin-release" + ], + "type": "library", + "autoload": { + "psr-4": { + "GlpiProject\\Tools\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-3.0-or-later" + ], + "authors": [ + { + "name": "Teclib'", + "email": "glpi@teclib.com", + "homepage": "http://teclib-group.com" + } + ], + "description": "Various tools for GLPI and its plugins", + "keywords": [ + "glpi", + "plugins", + "tools" + ], + "support": { + "issues": "https://github.com/glpi-project/tools/issues", + "source": "https://github.com/glpi-project/tools" + }, + "time": "2024-09-18T06:58:02+00:00" + }, + { + "name": "php-parallel-lint/php-parallel-lint", + "version": "v1.4.0", + "source": { + "type": "git", + "url": "https://github.com/php-parallel-lint/PHP-Parallel-Lint.git", + "reference": "6db563514f27e19595a19f45a4bf757b6401194e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-parallel-lint/PHP-Parallel-Lint/zipball/6db563514f27e19595a19f45a4bf757b6401194e", + "reference": "6db563514f27e19595a19f45a4bf757b6401194e", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": ">=5.3.0" + }, + "replace": { + "grogy/php-parallel-lint": "*", + "jakub-onderka/php-parallel-lint": "*" + }, + "require-dev": { + "nette/tester": "^1.3 || ^2.0", + "php-parallel-lint/php-console-highlighter": "0.* || ^1.0", + "squizlabs/php_codesniffer": "^3.6" + }, + "suggest": { + "php-parallel-lint/php-console-highlighter": "Highlight syntax in code snippet" + }, + "bin": [ + "parallel-lint" + ], + "type": "library", + "autoload": { + "classmap": [ + "./src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Jakub Onderka", + "email": "ahoj@jakubonderka.cz" + } + ], + "description": "This tool checks the syntax of PHP files about 20x faster than serial check.", + "homepage": "https://github.com/php-parallel-lint/PHP-Parallel-Lint", + "keywords": [ + "lint", + "static analysis" + ], + "support": { + "issues": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/issues", + "source": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/tree/v1.4.0" + }, + "time": "2024-03-27T12:14:49+00:00" + }, + { + "name": "phpstan/phpstan", + "version": "1.12.5", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17", + "reference": "7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2024-09-26T12:45:22+00:00" + }, + { + "name": "psr/container", + "version": "1.1.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "513e0666f7216c7459170d56df27dfcefe1689ea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea", + "reference": "513e0666f7216c7459170d56df27dfcefe1689ea", + "shasum": "" + }, + "require": { + "php": ">=7.4.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "support": { + "issues": "https://github.com/php-fig/container/issues", + "source": "https://github.com/php-fig/container/tree/1.1.2" + }, + "time": "2021-11-05T16:50:12+00:00" + }, + { + "name": "psr/event-dispatcher", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/event-dispatcher.git", + "reference": "dbefd12671e8a14ec7f180cab83036ed26714bb0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/event-dispatcher/zipball/dbefd12671e8a14ec7f180cab83036ed26714bb0", + "reference": "dbefd12671e8a14ec7f180cab83036ed26714bb0", + "shasum": "" + }, + "require": { + "php": ">=7.2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\EventDispatcher\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Standard interfaces for event handling.", + "keywords": [ + "events", + "psr", + "psr-14" + ], + "support": { + "issues": "https://github.com/php-fig/event-dispatcher/issues", + "source": "https://github.com/php-fig/event-dispatcher/tree/1.0.0" + }, + "time": "2019-01-08T18:20:26+00:00" + }, + { + "name": "psr/log", + "version": "1.1.4", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "support": { + "source": "https://github.com/php-fig/log/tree/1.1.4" + }, + "time": "2021-05-03T11:20:27+00:00" + }, + { + "name": "react/cache", + "version": "v1.2.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/cache.git", + "reference": "d47c472b64aa5608225f47965a484b75c7817d5b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/cache/zipball/d47c472b64aa5608225f47965a484b75c7817d5b", + "reference": "d47c472b64aa5608225f47965a484b75c7817d5b", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "react/promise": "^3.0 || ^2.0 || ^1.1" + }, + "require-dev": { + "phpunit/phpunit": "^9.5 || ^5.7 || ^4.8.35" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\Cache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christian Lück", + "email": "christian@clue.engineering", + "homepage": "https://clue.engineering/" + }, + { + "name": "Cees-Jan Kiewiet", + "email": "reactphp@ceesjankiewiet.nl", + "homepage": "https://wyrihaximus.net/" + }, + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com", + "homepage": "https://sorgalla.com/" + }, + { + "name": "Chris Boden", + "email": "cboden@gmail.com", + "homepage": "https://cboden.dev/" + } + ], + "description": "Async, Promise-based cache interface for ReactPHP", + "keywords": [ + "cache", + "caching", + "promise", + "reactphp" + ], + "support": { + "issues": "https://github.com/reactphp/cache/issues", + "source": "https://github.com/reactphp/cache/tree/v1.2.0" + }, + "funding": [ + { + "url": "https://opencollective.com/reactphp", + "type": "open_collective" + } + ], + "time": "2022-11-30T15:59:55+00:00" + }, + { + "name": "react/child-process", + "version": "v0.6.5", + "source": { + "type": "git", + "url": "https://github.com/reactphp/child-process.git", + "reference": "e71eb1aa55f057c7a4a0d08d06b0b0a484bead43" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/child-process/zipball/e71eb1aa55f057c7a4a0d08d06b0b0a484bead43", + "reference": "e71eb1aa55f057c7a4a0d08d06b0b0a484bead43", + "shasum": "" + }, + "require": { + "evenement/evenement": "^3.0 || ^2.0 || ^1.0", + "php": ">=5.3.0", + "react/event-loop": "^1.2", + "react/stream": "^1.2" + }, + "require-dev": { + "phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35", + "react/socket": "^1.8", + "sebastian/environment": "^5.0 || ^3.0 || ^2.0 || ^1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\ChildProcess\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christian Lück", + "email": "christian@clue.engineering", + "homepage": "https://clue.engineering/" + }, + { + "name": "Cees-Jan Kiewiet", + "email": "reactphp@ceesjankiewiet.nl", + "homepage": "https://wyrihaximus.net/" + }, + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com", + "homepage": "https://sorgalla.com/" + }, + { + "name": "Chris Boden", + "email": "cboden@gmail.com", + "homepage": "https://cboden.dev/" + } + ], + "description": "Event-driven library for executing child processes with ReactPHP.", + "keywords": [ + "event-driven", + "process", + "reactphp" + ], + "support": { + "issues": "https://github.com/reactphp/child-process/issues", + "source": "https://github.com/reactphp/child-process/tree/v0.6.5" + }, + "funding": [ + { + "url": "https://github.com/WyriHaximus", + "type": "github" + }, + { + "url": "https://github.com/clue", + "type": "github" + } + ], + "time": "2022-09-16T13:41:56+00:00" + }, + { + "name": "react/dns", + "version": "v1.13.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/dns.git", + "reference": "eb8ae001b5a455665c89c1df97f6fb682f8fb0f5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/dns/zipball/eb8ae001b5a455665c89c1df97f6fb682f8fb0f5", + "reference": "eb8ae001b5a455665c89c1df97f6fb682f8fb0f5", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "react/cache": "^1.0 || ^0.6 || ^0.5", + "react/event-loop": "^1.2", + "react/promise": "^3.2 || ^2.7 || ^1.2.1" + }, + "require-dev": { + "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36", + "react/async": "^4.3 || ^3 || ^2", + "react/promise-timer": "^1.11" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\Dns\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christian Lück", + "email": "christian@clue.engineering", + "homepage": "https://clue.engineering/" + }, + { + "name": "Cees-Jan Kiewiet", + "email": "reactphp@ceesjankiewiet.nl", + "homepage": "https://wyrihaximus.net/" + }, + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com", + "homepage": "https://sorgalla.com/" + }, + { + "name": "Chris Boden", + "email": "cboden@gmail.com", + "homepage": "https://cboden.dev/" + } + ], + "description": "Async DNS resolver for ReactPHP", + "keywords": [ + "async", + "dns", + "dns-resolver", + "reactphp" + ], + "support": { + "issues": "https://github.com/reactphp/dns/issues", + "source": "https://github.com/reactphp/dns/tree/v1.13.0" + }, + "funding": [ + { + "url": "https://opencollective.com/reactphp", + "type": "open_collective" + } + ], + "time": "2024-06-13T14:18:03+00:00" + }, + { + "name": "react/event-loop", + "version": "v1.5.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/event-loop.git", + "reference": "bbe0bd8c51ffc05ee43f1729087ed3bdf7d53354" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/event-loop/zipball/bbe0bd8c51ffc05ee43f1729087ed3bdf7d53354", + "reference": "bbe0bd8c51ffc05ee43f1729087ed3bdf7d53354", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36" + }, + "suggest": { + "ext-pcntl": "For signal handling support when using the StreamSelectLoop" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\EventLoop\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christian Lück", + "email": "christian@clue.engineering", + "homepage": "https://clue.engineering/" + }, + { + "name": "Cees-Jan Kiewiet", + "email": "reactphp@ceesjankiewiet.nl", + "homepage": "https://wyrihaximus.net/" + }, + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com", + "homepage": "https://sorgalla.com/" + }, + { + "name": "Chris Boden", + "email": "cboden@gmail.com", + "homepage": "https://cboden.dev/" + } + ], + "description": "ReactPHP's core reactor event loop that libraries can use for evented I/O.", + "keywords": [ + "asynchronous", + "event-loop" + ], + "support": { + "issues": "https://github.com/reactphp/event-loop/issues", + "source": "https://github.com/reactphp/event-loop/tree/v1.5.0" + }, + "funding": [ + { + "url": "https://opencollective.com/reactphp", + "type": "open_collective" + } + ], + "time": "2023-11-13T13:48:05+00:00" + }, + { + "name": "react/promise", + "version": "v3.2.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/promise.git", + "reference": "8a164643313c71354582dc850b42b33fa12a4b63" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/promise/zipball/8a164643313c71354582dc850b42b33fa12a4b63", + "reference": "8a164643313c71354582dc850b42b33fa12a4b63", + "shasum": "" + }, + "require": { + "php": ">=7.1.0" + }, + "require-dev": { + "phpstan/phpstan": "1.10.39 || 1.4.10", + "phpunit/phpunit": "^9.6 || ^7.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "React\\Promise\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com", + "homepage": "https://sorgalla.com/" + }, + { + "name": "Christian Lück", + "email": "christian@clue.engineering", + "homepage": "https://clue.engineering/" + }, + { + "name": "Cees-Jan Kiewiet", + "email": "reactphp@ceesjankiewiet.nl", + "homepage": "https://wyrihaximus.net/" + }, + { + "name": "Chris Boden", + "email": "cboden@gmail.com", + "homepage": "https://cboden.dev/" + } + ], + "description": "A lightweight implementation of CommonJS Promises/A for PHP", + "keywords": [ + "promise", + "promises" + ], + "support": { + "issues": "https://github.com/reactphp/promise/issues", + "source": "https://github.com/reactphp/promise/tree/v3.2.0" + }, + "funding": [ + { + "url": "https://opencollective.com/reactphp", + "type": "open_collective" + } + ], + "time": "2024-05-24T10:39:05+00:00" + }, + { + "name": "react/socket", + "version": "v1.16.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/socket.git", + "reference": "23e4ff33ea3e160d2d1f59a0e6050e4b0fb0eac1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/socket/zipball/23e4ff33ea3e160d2d1f59a0e6050e4b0fb0eac1", + "reference": "23e4ff33ea3e160d2d1f59a0e6050e4b0fb0eac1", + "shasum": "" + }, + "require": { + "evenement/evenement": "^3.0 || ^2.0 || ^1.0", + "php": ">=5.3.0", + "react/dns": "^1.13", + "react/event-loop": "^1.2", + "react/promise": "^3.2 || ^2.6 || ^1.2.1", + "react/stream": "^1.4" + }, + "require-dev": { + "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36", + "react/async": "^4.3 || ^3.3 || ^2", + "react/promise-stream": "^1.4", + "react/promise-timer": "^1.11" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\Socket\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christian Lück", + "email": "christian@clue.engineering", + "homepage": "https://clue.engineering/" + }, + { + "name": "Cees-Jan Kiewiet", + "email": "reactphp@ceesjankiewiet.nl", + "homepage": "https://wyrihaximus.net/" + }, + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com", + "homepage": "https://sorgalla.com/" + }, + { + "name": "Chris Boden", + "email": "cboden@gmail.com", + "homepage": "https://cboden.dev/" + } + ], + "description": "Async, streaming plaintext TCP/IP and secure TLS socket server and client connections for ReactPHP", + "keywords": [ + "Connection", + "Socket", + "async", + "reactphp", + "stream" + ], + "support": { + "issues": "https://github.com/reactphp/socket/issues", + "source": "https://github.com/reactphp/socket/tree/v1.16.0" + }, + "funding": [ + { + "url": "https://opencollective.com/reactphp", + "type": "open_collective" + } + ], + "time": "2024-07-26T10:38:09+00:00" + }, + { + "name": "react/stream", + "version": "v1.4.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/stream.git", + "reference": "1e5b0acb8fe55143b5b426817155190eb6f5b18d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/stream/zipball/1e5b0acb8fe55143b5b426817155190eb6f5b18d", + "reference": "1e5b0acb8fe55143b5b426817155190eb6f5b18d", + "shasum": "" + }, + "require": { + "evenement/evenement": "^3.0 || ^2.0 || ^1.0", + "php": ">=5.3.8", + "react/event-loop": "^1.2" + }, + "require-dev": { + "clue/stream-filter": "~1.2", + "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\Stream\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christian Lück", + "email": "christian@clue.engineering", + "homepage": "https://clue.engineering/" + }, + { + "name": "Cees-Jan Kiewiet", + "email": "reactphp@ceesjankiewiet.nl", + "homepage": "https://wyrihaximus.net/" + }, + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com", + "homepage": "https://sorgalla.com/" + }, + { + "name": "Chris Boden", + "email": "cboden@gmail.com", + "homepage": "https://cboden.dev/" + } + ], + "description": "Event-driven readable and writable streams for non-blocking I/O in ReactPHP", + "keywords": [ + "event-driven", + "io", + "non-blocking", + "pipe", + "reactphp", + "readable", + "stream", + "writable" + ], + "support": { + "issues": "https://github.com/reactphp/stream/issues", + "source": "https://github.com/reactphp/stream/tree/v1.4.0" + }, + "funding": [ + { + "url": "https://opencollective.com/reactphp", + "type": "open_collective" + } + ], + "time": "2024-06-11T12:45:25+00:00" + }, + { + "name": "sebastian/diff", + "version": "4.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/ba01945089c3a293b01ba9badc29ad55b106b0bc", + "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3", + "symfony/process": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.6" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-02T06:30:58+00:00" + }, + { + "name": "symfony/console", + "version": "v5.4.44", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "5b5a0aa66e3296e303e22490f90f521551835a83" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/5b5a0aa66e3296e303e22490f90f521551835a83", + "reference": "5b5a0aa66e3296e303e22490f90f521551835a83", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1|^3", + "symfony/polyfill-mbstring": "~1.0", + "symfony/polyfill-php73": "^1.9", + "symfony/polyfill-php80": "^1.16", + "symfony/service-contracts": "^1.1|^2|^3", + "symfony/string": "^5.1|^6.0" + }, + "conflict": { + "psr/log": ">=3", + "symfony/dependency-injection": "<4.4", + "symfony/dotenv": "<5.1", + "symfony/event-dispatcher": "<4.4", + "symfony/lock": "<4.4", + "symfony/process": "<4.4" + }, + "provide": { + "psr/log-implementation": "1.0|2.0" + }, + "require-dev": { + "psr/log": "^1|^2", + "symfony/config": "^4.4|^5.0|^6.0", + "symfony/dependency-injection": "^4.4|^5.0|^6.0", + "symfony/event-dispatcher": "^4.4|^5.0|^6.0", + "symfony/lock": "^4.4|^5.0|^6.0", + "symfony/process": "^4.4|^5.0|^6.0", + "symfony/var-dumper": "^4.4|^5.0|^6.0" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/lock": "", + "symfony/process": "" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Eases the creation of beautiful and testable command line interfaces", + "homepage": "https://symfony.com", + "keywords": [ + "cli", + "command-line", + "console", + "terminal" + ], + "support": { + "source": "https://github.com/symfony/console/tree/v5.4.44" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-09-20T07:56:40+00:00" + }, + { + "name": "symfony/event-dispatcher", + "version": "v5.4.40", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "a54e2a8a114065f31020d6a89ede83e34c3b27a4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/a54e2a8a114065f31020d6a89ede83e34c3b27a4", + "reference": "a54e2a8a114065f31020d6a89ede83e34c3b27a4", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1|^3", + "symfony/event-dispatcher-contracts": "^2|^3", + "symfony/polyfill-php80": "^1.16" + }, + "conflict": { + "symfony/dependency-injection": "<4.4" + }, + "provide": { + "psr/event-dispatcher-implementation": "1.0", + "symfony/event-dispatcher-implementation": "2.0" + }, + "require-dev": { + "psr/log": "^1|^2|^3", + "symfony/config": "^4.4|^5.0|^6.0", + "symfony/dependency-injection": "^4.4|^5.0|^6.0", + "symfony/error-handler": "^4.4|^5.0|^6.0", + "symfony/expression-language": "^4.4|^5.0|^6.0", + "symfony/http-foundation": "^4.4|^5.0|^6.0", + "symfony/service-contracts": "^1.1|^2|^3", + "symfony/stopwatch": "^4.4|^5.0|^6.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/event-dispatcher/tree/v5.4.40" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-05-31T14:33:22+00:00" + }, + { + "name": "symfony/event-dispatcher-contracts", + "version": "v2.5.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher-contracts.git", + "reference": "540f4c73e87fd0c71ca44a6aa305d024ac68cb73" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/540f4c73e87fd0c71ca44a6aa305d024ac68cb73", + "reference": "540f4c73e87fd0c71ca44a6aa305d024ac68cb73", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "psr/event-dispatcher": "^1" + }, + "suggest": { + "symfony/event-dispatcher-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.5-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\EventDispatcher\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to dispatching event", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "support": { + "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v2.5.3" }, "funding": [ { - "url": "https://github.com/ondrejmirtes", - "type": "github" + "url": "https://symfony.com/sponsor", + "type": "custom" }, { - "url": "https://github.com/phpstan", + "url": "https://github.com/fabpot", "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" } ], - "time": "2024-09-26T12:45:22+00:00" + "time": "2024-01-23T13:51:25+00:00" }, { - "name": "psr/container", - "version": "1.1.2", + "name": "symfony/filesystem", + "version": "v5.4.44", "source": { "type": "git", - "url": "https://github.com/php-fig/container.git", - "reference": "513e0666f7216c7459170d56df27dfcefe1689ea" + "url": "https://github.com/symfony/filesystem.git", + "reference": "76c3818964e9d32be3862c9318ae3ba9aa280ddc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea", - "reference": "513e0666f7216c7459170d56df27dfcefe1689ea", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/76c3818964e9d32be3862c9318ae3ba9aa280ddc", + "reference": "76c3818964e9d32be3862c9318ae3ba9aa280ddc", "shasum": "" }, "require": { - "php": ">=7.4.0" + "php": ">=7.2.5", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-mbstring": "~1.8", + "symfony/polyfill-php80": "^1.16" + }, + "require-dev": { + "symfony/process": "^5.4|^6.4" }, "type": "library", "autoload": { "psr-4": { - "Psr\\Container\\": "src/" - } + "Symfony\\Component\\Filesystem\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -433,158 +1950,122 @@ ], "authors": [ { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], - "description": "Common Container Interface (PHP FIG PSR-11)", - "homepage": "https://github.com/php-fig/container", - "keywords": [ - "PSR-11", - "container", - "container-interface", - "container-interop", - "psr" - ], + "description": "Provides basic utilities for the filesystem", + "homepage": "https://symfony.com", "support": { - "issues": "https://github.com/php-fig/container/issues", - "source": "https://github.com/php-fig/container/tree/1.1.2" + "source": "https://github.com/symfony/filesystem/tree/v5.4.44" }, - "time": "2021-11-05T16:50:12+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-09-16T14:52:48+00:00" }, { - "name": "squizlabs/php_codesniffer", - "version": "3.10.3", + "name": "symfony/finder", + "version": "v5.4.43", "source": { "type": "git", - "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "62d32998e820bddc40f99f8251958aed187a5c9c" + "url": "https://github.com/symfony/finder.git", + "reference": "ae25a9145a900764158d439653d5630191155ca0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/62d32998e820bddc40f99f8251958aed187a5c9c", - "reference": "62d32998e820bddc40f99f8251958aed187a5c9c", + "url": "https://api.github.com/repos/symfony/finder/zipball/ae25a9145a900764158d439653d5630191155ca0", + "reference": "ae25a9145a900764158d439653d5630191155ca0", "shasum": "" }, "require": { - "ext-simplexml": "*", - "ext-tokenizer": "*", - "ext-xmlwriter": "*", - "php": ">=5.4.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1|^3", + "symfony/polyfill-php80": "^1.16" }, - "bin": [ - "bin/phpcbf", - "bin/phpcs" - ], "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.x-dev" - } + "autoload": { + "psr-4": { + "Symfony\\Component\\Finder\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-3-Clause" + "MIT" ], "authors": [ { - "name": "Greg Sherwood", - "role": "Former lead" - }, - { - "name": "Juliette Reinders Folmer", - "role": "Current lead" + "name": "Fabien Potencier", + "email": "fabien@symfony.com" }, { - "name": "Contributors", - "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], - "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", - "keywords": [ - "phpcs", - "standards", - "static analysis" - ], + "description": "Finds files and directories via an intuitive fluent interface", + "homepage": "https://symfony.com", "support": { - "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", - "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", - "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", - "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + "source": "https://github.com/symfony/finder/tree/v5.4.43" }, "funding": [ { - "url": "https://github.com/PHPCSStandards", - "type": "github" + "url": "https://symfony.com/sponsor", + "type": "custom" }, { - "url": "https://github.com/jrfnl", + "url": "https://github.com/fabpot", "type": "github" }, { - "url": "https://opencollective.com/php_codesniffer", - "type": "open_collective" + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" } ], - "time": "2024-09-18T10:38:58+00:00" + "time": "2024-08-13T14:03:51+00:00" }, { - "name": "symfony/console", - "version": "v5.4.44", + "name": "symfony/options-resolver", + "version": "v5.4.40", "source": { "type": "git", - "url": "https://github.com/symfony/console.git", - "reference": "5b5a0aa66e3296e303e22490f90f521551835a83" + "url": "https://github.com/symfony/options-resolver.git", + "reference": "bd1afbde6613a8d6b956115e0e14b196191fd0c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/5b5a0aa66e3296e303e22490f90f521551835a83", - "reference": "5b5a0aa66e3296e303e22490f90f521551835a83", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/bd1afbde6613a8d6b956115e0e14b196191fd0c4", + "reference": "bd1afbde6613a8d6b956115e0e14b196191fd0c4", "shasum": "" }, "require": { "php": ">=7.2.5", "symfony/deprecation-contracts": "^2.1|^3", - "symfony/polyfill-mbstring": "~1.0", - "symfony/polyfill-php73": "^1.9", - "symfony/polyfill-php80": "^1.16", - "symfony/service-contracts": "^1.1|^2|^3", - "symfony/string": "^5.1|^6.0" - }, - "conflict": { - "psr/log": ">=3", - "symfony/dependency-injection": "<4.4", - "symfony/dotenv": "<5.1", - "symfony/event-dispatcher": "<4.4", - "symfony/lock": "<4.4", - "symfony/process": "<4.4" - }, - "provide": { - "psr/log-implementation": "1.0|2.0" - }, - "require-dev": { - "psr/log": "^1|^2", - "symfony/config": "^4.4|^5.0|^6.0", - "symfony/dependency-injection": "^4.4|^5.0|^6.0", - "symfony/event-dispatcher": "^4.4|^5.0|^6.0", - "symfony/lock": "^4.4|^5.0|^6.0", - "symfony/process": "^4.4|^5.0|^6.0", - "symfony/var-dumper": "^4.4|^5.0|^6.0" - }, - "suggest": { - "psr/log": "For using the console logger", - "symfony/event-dispatcher": "", - "symfony/lock": "", - "symfony/process": "" + "symfony/polyfill-php73": "~1.0", + "symfony/polyfill-php80": "^1.16" }, "type": "library", "autoload": { "psr-4": { - "Symfony\\Component\\Console\\": "" + "Symfony\\Component\\OptionsResolver\\": "" }, "exclude-from-classmap": [ "/Tests/" @@ -604,16 +2085,15 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Eases the creation of beautiful and testable command line interfaces", + "description": "Provides an improved replacement for the array_replace PHP function", "homepage": "https://symfony.com", "keywords": [ - "cli", - "command-line", - "console", - "terminal" + "config", + "configuration", + "options" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.44" + "source": "https://github.com/symfony/options-resolver/tree/v5.4.40" }, "funding": [ { @@ -629,7 +2109,7 @@ "type": "tidelift" } ], - "time": "2024-09-20T07:56:40+00:00" + "time": "2024-05-31T14:33:22+00:00" }, { "name": "symfony/polyfill-intl-grapheme", @@ -1102,6 +2582,68 @@ ], "time": "2024-09-09T11:45:10+00:00" }, + { + "name": "symfony/process", + "version": "v5.4.44", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "1b9fa82b5c62cd49da8c9e3952dd8531ada65096" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/1b9fa82b5c62cd49da8c9e3952dd8531ada65096", + "reference": "1b9fa82b5c62cd49da8c9e3952dd8531ada65096", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/polyfill-php80": "^1.16" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Executes commands in sub-processes", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/process/tree/v5.4.44" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-09-17T12:46:43+00:00" + }, { "name": "symfony/service-contracts", "version": "v2.5.3", @@ -1185,6 +2727,68 @@ ], "time": "2023-04-21T15:04:16+00:00" }, + { + "name": "symfony/stopwatch", + "version": "v5.4.40", + "source": { + "type": "git", + "url": "https://github.com/symfony/stopwatch.git", + "reference": "0e9daf3b7c805c747638b2cc48f1649e594f9625" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/0e9daf3b7c805c747638b2cc48f1649e594f9625", + "reference": "0e9daf3b7c805c747638b2cc48f1649e594f9625", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/service-contracts": "^1|^2|^3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Stopwatch\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides a way to profile code", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/stopwatch/tree/v5.4.40" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-05-31T14:33:22+00:00" + }, { "name": "symfony/string", "version": "v5.4.44", diff --git a/front/commondropdown.form.php b/front/commondropdown.form.php index cc20a260..b93b7b94 100644 --- a/front/commondropdown.form.php +++ b/front/commondropdown.form.php @@ -28,7 +28,7 @@ * ------------------------------------------------------------------------- */ -include "../../../inc/includes.php"; +include '../../../inc/includes.php'; if (preg_match('/[a-z]/i', $_REQUEST['ddtype']) !== 1) { throw new \RuntimeException(sprintf('Invalid itemtype "%1$s"', $_REQUEST['ddtype'])); } diff --git a/front/commondropdown.php b/front/commondropdown.php index ebd334be..16433472 100644 --- a/front/commondropdown.php +++ b/front/commondropdown.php @@ -28,7 +28,7 @@ * ------------------------------------------------------------------------- */ -include "../../../inc/includes.php"; +include '../../../inc/includes.php'; if (preg_match('/[a-z]/i', $_REQUEST['ddtype']) !== 1) { throw new \RuntimeException(sprintf('Invalid itemtype "%1$s"', $_REQUEST['ddtype'])); } diff --git a/front/container.form.php b/front/container.form.php index 03d1f63b..fb263c21 100644 --- a/front/container.form.php +++ b/front/container.form.php @@ -28,31 +28,31 @@ * ------------------------------------------------------------------------- */ -include("../../../inc/includes.php"); +include('../../../inc/includes.php'); -if (empty($_GET["id"])) { - $_GET["id"] = ""; +if (empty($_GET['id'])) { + $_GET['id'] = ''; } $container = new PluginFieldsContainer(); -if (isset($_POST["add"])) { +if (isset($_POST['add'])) { $container->check(-1, CREATE, $_POST); $newID = $container->add($_POST); Html::redirect(PLUGINFIELDS_WEB_DIR . "/front/container.form.php?id=$newID"); -} else if (isset($_POST["delete"])) { +} elseif (isset($_POST['delete'])) { $container->check($_POST['id'], DELETE); $ok = $container->delete($_POST); - Html::redirect(PLUGINFIELDS_WEB_DIR . "/front/container.php"); -} else if (isset($_REQUEST["purge"])) { + Html::redirect(PLUGINFIELDS_WEB_DIR . '/front/container.php'); +} elseif (isset($_REQUEST['purge'])) { $container->check($_REQUEST['id'], PURGE); $container->delete($_REQUEST, 1); - Html::redirect(PLUGINFIELDS_WEB_DIR . "/front/container.php"); -} else if (isset($_POST["update"])) { + Html::redirect(PLUGINFIELDS_WEB_DIR . '/front/container.php'); +} elseif (isset($_POST['update'])) { $container->check($_POST['id'], UPDATE); $container->update($_POST); Html::back(); -} else if (isset($_POST["update_fields_values"])) { +} elseif (isset($_POST['update_fields_values'])) { $right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $_POST['plugin_fields_containers_id']); if ($right > READ) { $container->updateFieldsValues($_REQUEST, $_REQUEST['itemtype'], false); @@ -60,12 +60,12 @@ Html::back(); } else { Html::header( - __("Additional fields", "fields"), + __('Additional fields', 'fields'), $_SERVER['PHP_SELF'], - "config", - "pluginfieldsmenu", - "fieldscontainer" + 'config', + 'pluginfieldsmenu', + 'fieldscontainer', ); - $container->display(['id' => $_GET["id"]]); + $container->display(['id' => $_GET['id']]); Html::footer(); } diff --git a/front/container.php b/front/container.php index b003c6e0..c22df9b1 100644 --- a/front/container.php +++ b/front/container.php @@ -28,19 +28,19 @@ * ------------------------------------------------------------------------- */ -include("../../../inc/includes.php"); +include('../../../inc/includes.php'); Html::header( - __("Additional fields", "fields"), + __('Additional fields', 'fields'), $_SERVER['PHP_SELF'], - "config", - "pluginfieldsmenu", - "fieldscontainer" + 'config', + 'pluginfieldsmenu', + 'fieldscontainer', ); Session::checkRight('entity', READ); PluginFieldsContainer::titleList(); -Search::show("PluginFieldsContainer"); +Search::show('PluginFieldsContainer'); Html::footer(); diff --git a/front/containerdisplaycondition.form.php b/front/containerdisplaycondition.form.php index 8daa118a..c61cfcdc 100644 --- a/front/containerdisplaycondition.form.php +++ b/front/containerdisplaycondition.form.php @@ -28,21 +28,21 @@ * ------------------------------------------------------------------------- */ -include("../../../inc/includes.php"); +include('../../../inc/includes.php'); $status_override = new PluginFieldsContainerDisplayCondition(); -if (isset($_POST["add"])) { +if (isset($_POST['add'])) { $status_override->check(-1, CREATE, $_POST); $status_override->add($_POST); Html::back(); -} else if (isset($_POST["update"])) { +} elseif (isset($_POST['update'])) { $status_override->check($_POST['id'], UPDATE); $status_override->update($_POST); Html::back(); -} else if (isset($_POST["delete"])) { +} elseif (isset($_POST['delete'])) { $status_override->check($_POST['id'], PURGE); $status_override->delete([ - 'id' => $_POST['id'] + 'id' => $_POST['id'], ]); Html::back(); } diff --git a/front/export_to_yaml.php b/front/export_to_yaml.php index b3808b5c..2e7016c5 100644 --- a/front/export_to_yaml.php +++ b/front/export_to_yaml.php @@ -28,8 +28,8 @@ * ------------------------------------------------------------------------- */ -include("../../../inc/includes.php"); -include("../hook.php"); +include('../../../inc/includes.php'); +include('../hook.php'); Session::checkRight('entity', READ); @@ -39,10 +39,10 @@ } if (plugin_fields_exportBlockAsYaml($ID)) { - $filename = "fields_conf.yaml"; - $path = GLPI_TMP_DIR . "/fields_conf.yaml"; + $filename = 'fields_conf.yaml'; + $path = GLPI_TMP_DIR . '/fields_conf.yaml'; Toolbox::sendFile($path, $filename, 'text/yaml'); } else { - Session::addMessageAfterRedirect("No data to export", false, INFO); + Session::addMessageAfterRedirect('No data to export', false, INFO); Html::back(); } diff --git a/front/field.form.php b/front/field.form.php index 3d85b42a..0d2f339a 100644 --- a/front/field.form.php +++ b/front/field.form.php @@ -28,40 +28,40 @@ * ------------------------------------------------------------------------- */ -include("../../../inc/includes.php"); +include('../../../inc/includes.php'); -if (empty($_GET["id"])) { - $_GET["id"] = ""; +if (empty($_GET['id'])) { + $_GET['id'] = ''; } Session::checkRight('entity', READ); $field = new PluginFieldsField(); -if (isset($_POST["add"])) { +if (isset($_POST['add'])) { $field->check(-1, CREATE, $_POST); $field->add($_POST); Html::back(); -} else if (isset($_POST["delete"])) { +} elseif (isset($_POST['delete'])) { $field->check($_POST['id'], DELETE); $field->delete($_POST); Html::back(); -} else if (isset($_REQUEST["purge"])) { +} elseif (isset($_REQUEST['purge'])) { $field->check($_REQUEST['id'], PURGE); $field->delete($_REQUEST, 1); $field->redirectToList(); -} else if (isset($_POST["update"])) { +} elseif (isset($_POST['update'])) { $field->check($_POST['id'], UPDATE); $field->update($_POST); Html::back(); -} else if (isset($_GET["id"])) { +} elseif (isset($_GET['id'])) { $field->check($_GET['id'], READ); Html::header(PluginFieldsField::getTypeName(1), $_SERVER['PHP_SELF']); $field->getFromDB($_GET['id']); - $field->display(['id' => $_GET['id'], - 'parent_id' => $field->fields['plugin_fields_containers_id'] + $field->display(['id' => $_GET['id'], + 'parent_id' => $field->fields['plugin_fields_containers_id'], ]); Html::footer(); diff --git a/front/labeltranslation.form.php b/front/labeltranslation.form.php index 9ca93470..b5ab239d 100644 --- a/front/labeltranslation.form.php +++ b/front/labeltranslation.form.php @@ -33,9 +33,9 @@ $translation = new PluginFieldsLabelTranslation(); if (isset($_POST['add'])) { $translation->add($_POST); -} else if (isset($_POST['update'])) { +} elseif (isset($_POST['update'])) { $translation->update($_POST); -} else if (isset($_POST['purge'])) { +} elseif (isset($_POST['purge'])) { $translation->delete($_POST, true); } Html::back(); diff --git a/front/profile.form.php b/front/profile.form.php index a428d255..760a5d95 100644 --- a/front/profile.form.php +++ b/front/profile.form.php @@ -28,9 +28,9 @@ * ------------------------------------------------------------------------- */ -include("../../../inc/includes.php"); +include('../../../inc/includes.php'); -if (isset($_POST["update"])) { +if (isset($_POST['update'])) { PluginFieldsProfile::updateProfile($_POST); } Html::back(); diff --git a/front/regenerate_files.php b/front/regenerate_files.php index 50296a63..57fff02d 100644 --- a/front/regenerate_files.php +++ b/front/regenerate_files.php @@ -28,8 +28,8 @@ * ------------------------------------------------------------------------- */ -include("../../../inc/includes.php"); -include("../hook.php"); +include('../../../inc/includes.php'); +include('../hook.php'); Session::checkRight('entity', READ); diff --git a/front/statusoverride.form.php b/front/statusoverride.form.php index 7226c00f..120a6ab2 100644 --- a/front/statusoverride.form.php +++ b/front/statusoverride.form.php @@ -28,21 +28,21 @@ * ------------------------------------------------------------------------- */ -include("../../../inc/includes.php"); +include('../../../inc/includes.php'); $status_override = new PluginFieldsStatusOverride(); -if (isset($_POST["add"])) { +if (isset($_POST['add'])) { $status_override->check(-1, CREATE, $_POST); $status_override->add($_POST); Html::back(); -} else if (isset($_POST["update"])) { +} elseif (isset($_POST['update'])) { $status_override->check($_POST['id'], UPDATE); $status_override->update($_POST); Html::back(); -} else if (isset($_POST["delete"])) { +} elseif (isset($_POST['delete'])) { $status_override->check($_POST['id'], PURGE); $status_override->delete([ - 'id' => $_POST['id'] + 'id' => $_POST['id'], ]); Html::back(); } diff --git a/hook.php b/hook.php index cbf44bcc..076b55f8 100644 --- a/hook.php +++ b/hook.php @@ -36,7 +36,7 @@ function plugin_fields_install() { // Regenerating tables/files can consume lot of memory/time - $memory_limit = (int)Toolbox::getMemoryLimit(); + $memory_limit = (int) Toolbox::getMemoryLimit(); $max_execution_time = ini_get('max_execution_time'); if ($memory_limit > 0 && $memory_limit < (512 * 1024 * 1024)) { ini_set('memory_limit', '512M'); @@ -52,11 +52,11 @@ function plugin_fields_install() $migration = new Migration($version); if (isCommandLine()) { - echo __("MySQL tables installation", "fields") . "\n"; + echo __('MySQL tables installation', 'fields') . "\n"; } else { - echo "
"; + echo '
'; echo ""; - echo ""; + echo ''; echo ""; echo ""; - echo ""; - echo "
" . __("MySQL tables installation", "fields") . "
' . __('MySQL tables installation', 'fields') . '
"; @@ -89,10 +89,11 @@ function plugin_fields_install() $migration->executeMigration(); if (!isCommandLine()) { - echo "
"; + echo ''; + echo ''; + echo '
'; } + return true; } @@ -103,22 +104,22 @@ function plugin_fields_install() */ function plugin_fields_uninstall() { - if (!class_exists('PluginFieldsProfile')) { Session::addMessageAfterRedirect( __("The plugin can't be uninstalled when the plugin is disabled", 'fields'), true, WARNING, - true + true, ); + return false; } $_SESSION['uninstall_fields'] = true; - echo "
"; + echo '
'; echo ""; - echo ""; + echo ''; echo ""; echo ""; - echo ""; - echo "
" . __("MySQL tables uninstallation", "fields") . "
' . __('MySQL tables uninstallation', 'fields') . '
"; @@ -130,33 +131,33 @@ function plugin_fields_uninstall() 'PluginFieldsField', 'PluginFieldsProfile', 'PluginFieldsStatusOverride', - 'PluginFieldsContainerDisplayCondition' + 'PluginFieldsContainerDisplayCondition', ]; foreach ($classesToUninstall as $class) { if ($plug = isPluginItemType($class)) { - $dir = PLUGINFIELDS_DIR . "/inc/"; + $dir = PLUGINFIELDS_DIR . '/inc/'; $item = strtolower($plug['class']); if (file_exists("$dir$item.class.php")) { include_once("$dir$item.class.php"); - if (!call_user_func([$class,'uninstall'])) { + if (!call_user_func([$class, 'uninstall'])) { return false; } } } } - echo "
"; + echo ''; + echo ''; + echo '
'; unset($_SESSION['uninstall_fields']); // clean display preferences $pref = new DisplayPreference(); $pref->deleteByCriteria([ - 'itemtype' => ['LIKE' , 'PluginFields%'] + 'itemtype' => ['LIKE' , 'PluginFields%'], ]); return true; @@ -186,12 +187,13 @@ function plugin_fields_getDropdown() $field_obj = new PluginFieldsField(); $fields = $field_obj->find(['type' => 'dropdown']); foreach ($fields as $field) { - $field['itemtype'] = PluginFieldsField::getType(); - $label = PluginFieldsLabelTranslation::getLabelFor($field); - $dropdowns["PluginFields" . ucfirst($field['name']) . "Dropdown"] = $label; + $field['itemtype'] = PluginFieldsField::getType(); + $label = PluginFieldsLabelTranslation::getLabelFor($field); + $dropdowns['PluginFields' . ucfirst($field['name']) . 'Dropdown'] = $label; } asort($dropdowns); + return $dropdowns; } @@ -205,6 +207,7 @@ function plugin_fields_MassiveActionsFieldsDisplay($options = []) if (in_array($options['itemtype'], $itemtypes)) { PluginFieldsField::showSingle($options['itemtype'], $options['options'], true); + return true; } @@ -227,8 +230,8 @@ function plugin_fields_getRuleActions($params = []) $actions = []; switch ($params['rule_itemtype']) { - case "PluginFusioninventoryTaskpostactionRule": - $options = PluginFieldsContainer::getAddSearchOptions("Computer"); + case 'PluginFusioninventoryTaskpostactionRule': + $options = PluginFieldsContainer::getAddSearchOptions('Computer'); foreach ($options as $option) { $actions[$option['linkfield']]['name'] = $option['name']; $actions[$option['linkfield']]['type'] = $option['pfields_type']; @@ -252,7 +255,7 @@ function plugin_fields_rule_matched($params = []) $container = new PluginFieldsContainer(); switch ($params['sub_type']) { - case "PluginFusioninventoryTaskpostactionRule": + case 'PluginFusioninventoryTaskpostactionRule': /** @phpstan-ignore-next-line */ $agent = new PluginFusioninventoryAgent(); @@ -260,19 +263,19 @@ function plugin_fields_rule_matched($params = []) foreach ($params['output'] as $field => $value) { // check if current field is in a tab container $iterator = $DB->request([ - 'SELECT' => 'glpi_plugin_fields_containers.id', - 'FROM' => 'glpi_plugin_fields_containers', + 'SELECT' => 'glpi_plugin_fields_containers.id', + 'FROM' => 'glpi_plugin_fields_containers', 'LEFT JOIN' => [ 'glpi_plugin_fields_fields' => [ 'FKEY' => [ 'glpi_plugin_fields_containers' => 'id', - 'glpi_plugin_fields_fields' => 'plugin_fields_containers_id' - ] - ] + 'glpi_plugin_fields_fields' => 'plugin_fields_containers_id', + ], + ], ], 'WHERE' => [ 'glpi_plugin_fields_fields.name' => $field, - ] + ], ]); if (count($iterator) > 0) { $data = $iterator->current(); @@ -286,9 +289,9 @@ function plugin_fields_rule_matched($params = []) [ 'plugin_fields_containers_id' => $data['id'], $field => $value, - 'items_id' => $agent->fields['computers_id'] + 'items_id' => $agent->fields['computers_id'], ], - Computer::getType() + Computer::getType(), ); } } @@ -300,16 +303,16 @@ function plugin_fields_rule_matched($params = []) function plugin_fields_giveItem($itemtype, $ID, $data, $num) { $searchopt = &Search::getOptions($itemtype); - $table = $searchopt[$ID]["table"]; + $table = $searchopt[$ID]['table']; //fix glpi default Search::giveItem who for empty date display "--" if ( - strpos($table, "glpi_plugin_fields") !== false - && isset($searchopt[$ID]["datatype"]) - && strpos($searchopt[$ID]["datatype"], "date") !== false + strpos($table, 'glpi_plugin_fields') !== false + && isset($searchopt[$ID]['datatype']) + && strpos($searchopt[$ID]['datatype'], 'date') !== false && empty($data['raw']["ITEM_$num"]) ) { - return " "; + return ' '; } return false; @@ -330,7 +333,7 @@ function plugin_datainjection_populate_fields() $types = json_decode($values['itemtypes']); foreach ($types as $type) { - $classname = PluginFieldsContainer::getClassname($type, $values['name'], 'Injection'); + $classname = PluginFieldsContainer::getClassname($type, $values['name'], 'Injection'); $INJECTABLE_TYPES[$classname] = 'fields'; } } @@ -342,8 +345,8 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) global $DB; $searchopt = &Search::getOptions($itemtype); - $table = $searchopt[$ID]["table"]; - $field = $searchopt[$ID]["field"]; + $table = $searchopt[$ID]['table']; + $field = $searchopt[$ID]['field']; $field_field = new PluginFieldsField(); @@ -352,26 +355,26 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) if ( $field_field->getFromDBByCrit( [ - 'name' => $field, - 'multiple' => true - ] + 'name' => $field, + 'multiple' => true, + ], ) ) { - return $link . $DB->quoteName("$table" . "_" . "$field") . "." . $DB->quoteName($field) . "LIKE " . $DB->quoteValue("%\"$val\"%") ; + return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ; } else { // if 'multiple' field with cleaned name is found -> 'dropdown' case // update WHERE clause with LIKE statement - $cleanfield = str_replace("plugin_fields_", "", $field); - $cleanfield = str_replace("dropdowns_id", "", $cleanfield); + $cleanfield = str_replace('plugin_fields_', '', $field); + $cleanfield = str_replace('dropdowns_id', '', $cleanfield); if ( $field_field->getFromDBByCrit( [ - 'name' => $cleanfield, - 'multiple' => true - ] + 'name' => $cleanfield, + 'multiple' => true, + ], ) ) { - return $link . $DB->quoteName("$table" . "_" . "$cleanfield") . "." . $DB->quoteName($field) . "LIKE " . $DB->quoteValue("%\"$val\"%") ; + return $link . $DB->quoteName("$table" . '_' . "$cleanfield") . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ; } else { return false; } diff --git a/inc/abstractcontainerinstance.class.php b/inc/abstractcontainerinstance.class.php index 0b595d12..28cc8a2e 100644 --- a/inc/abstractcontainerinstance.class.php +++ b/inc/abstractcontainerinstance.class.php @@ -32,7 +32,6 @@ abstract class PluginFieldsAbstractContainerInstance extends CommonDBTM { public static function getSpecificValueToSelect($field, $name = '', $values = '', array $options = []) { - if (!is_array($values)) { $values = [$field => $values]; } @@ -54,19 +53,21 @@ public static function getSpecificValueToSelect($field, $name = '', $values = '' if ($itemtype == User::class) { $display_with = ['realname', 'firstname']; } + return Dropdown::show($itemtype, ['displaywith' => $display_with, 'name' => $name, 'display' => false]); - } else if ( + } elseif ( $field_specs->fields['type'] === 'dropdown' && $field_specs->fields['multiple'] ) { $itemtype = PluginFieldsDropdown::getClassname($field_specs->fields['name']); + return Dropdown::show($itemtype, ['name' => $name, 'display' => false]); } } + return parent::getSpecificValueToSelect($field, $name, $values, $options); } - public static function getSpecificValueToDisplay($field, $values, array $options = []) { if (!is_array($values)) { @@ -119,7 +120,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options return implode( $options['separator'] ?? '
', - Dropdown::getDropdownArrayNames($itemtype::getTable(), $values) + Dropdown::getDropdownArrayNames($itemtype::getTable(), $values), ); } } diff --git a/inc/autoload.php b/inc/autoload.php index dd958323..4123e862 100644 --- a/inc/autoload.php +++ b/inc/autoload.php @@ -50,6 +50,7 @@ public function setOptions($options) $this->paths[] = $path; } } + return $this; } @@ -71,25 +72,26 @@ public function autoload($classname) if ($matches !== false) { $plugin_name = strtolower($matches[1]); - $class_name = strtolower($matches[2]); + $class_name = strtolower($matches[2]); - if ($plugin_name !== "fields") { + if ($plugin_name !== 'fields') { return false; } - $filename = implode(".", [ + $filename = implode('.', [ $class_name, - "class", - "php" + 'class', + 'php', ]); foreach ($this->paths as $path) { - $test = $path . DIRECTORY_SEPARATOR . $filename; + $test = $path . DIRECTORY_SEPARATOR . $filename; if (file_exists($test)) { return include_once($test); } } } + return false; } diff --git a/inc/checkdatabasecommand.class.php b/inc/checkdatabasecommand.class.php index 32fa77b6..f5380d6e 100644 --- a/inc/checkdatabasecommand.class.php +++ b/inc/checkdatabasecommand.class.php @@ -46,15 +46,15 @@ protected function configure() . sprintf( __('- some deleted fields may still be present in database (bug introduced in version %s and fixed in version %s)', 'fields'), '1.15.0', - '1.15.3' - ) + '1.15.3', + ), ); $this->addOption( 'fix', null, InputOption::VALUE_NONE, - __('Use this option to actually fix database', 'fields') + __('Use this option to actually fix database', 'fields'), ); } @@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // Read option $fix = $input->getOption('fix'); - $dead_fields = PluginFieldsMigration::checkDeadFields($fix); + $dead_fields = PluginFieldsMigration::checkDeadFields($fix); $dead_fields_count = count($dead_fields, COUNT_RECURSIVE) - count($dead_fields); // No invalid fields found @@ -71,6 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln( '' . __('Everything is in order - no action needed.', 'fields') . '', ); + return Command::SUCCESS; } @@ -94,11 +95,11 @@ protected function execute(InputInterface $input, OutputInterface $output) // Print command to do the actual deletion $next_command = sprintf( __('Run "%s" to fix database inconsistencies.', 'fields'), - sprintf("php bin/console %s --fix", $this->getName()) + sprintf('php bin/console %s --fix', $this->getName()), ); $output->writeln( '' . $next_command . '', - OutputInterface::VERBOSITY_QUIET + OutputInterface::VERBOSITY_QUIET, ); } diff --git a/inc/command/regeneratefilescommand.class.php b/inc/command/regeneratefilescommand.class.php index 10179bfc..b46cd343 100644 --- a/inc/command/regeneratefilescommand.class.php +++ b/inc/command/regeneratefilescommand.class.php @@ -40,13 +40,14 @@ protected function configure() $this->setName('plugin:fields:regenerate_files'); $this->setDescription(__('Regenerates containers files.', 'fields')); $this->setHelp( - __('This command will clean up all files generated by the plugin and regenerate them.', 'fields') + __('This command will clean up all files generated by the plugin and regenerate them.', 'fields'), ); } protected function execute($input, $output) { plugin_fields_checkFiles(); + return Command::SUCCESS; } } diff --git a/inc/container.class.php b/inc/container.class.php index e56e812f..bba4e3d6 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -49,14 +49,15 @@ public static function canPurge() public static function titleList() { echo "
"; + __('Regenerate container files', 'fields') . "   " . + __('Export to YAML', 'fields') . '
'; } public function getForbiddenStandardMassiveAction() { $forbidden = parent::getForbiddenStandardMassiveAction(); $forbidden[] = 'clone'; + return $forbidden; } @@ -73,14 +74,14 @@ public static function installBaseData(Migration $migration, $version) /** @var DBmysql $DB */ global $DB; - $default_charset = DBConnection::getDefaultCharset(); + $default_charset = DBConnection::getDefaultCharset(); $default_collation = DBConnection::getDefaultCollation(); - $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); + $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); $table = self::getTable(); if (!$DB->tableExists($table)) { - $migration->displayMessage(sprintf(__("Installing %s"), $table)); + $migration->displayMessage(sprintf(__('Installing %s'), $table)); $query = "CREATE TABLE IF NOT EXISTS `$table` ( `id` INT {$default_key_sign} NOT NULL auto_increment, @@ -99,7 +100,7 @@ public static function installBaseData(Migration $migration, $version) } // multiple itemtype for one container - if (!$DB->fieldExists($table, "itemtypes")) { + if (!$DB->fieldExists($table, 'itemtypes')) { $migration->changeField($table, 'itemtype', 'itemtypes', 'longtext'); $migration->migrationOneTable($table); @@ -111,11 +112,11 @@ public static function installBaseData(Migration $migration, $version) 'CONCAT(%s, %s, %s)', $DB->quoteValue('[\"'), $DB->quoteName('itemtype'), - $DB->quoteValue('\"]') - ) + $DB->quoteValue('\"]'), + ), ), ], - [1] + [1], ); } @@ -130,18 +131,18 @@ public static function installBaseData(Migration $migration, $version) 'itemtype' => __CLASS__, 'num' => $i, 'rank' => $i - 1, - 'users_id' => 0 + 'users_id' => 0, ], [ 'itemtype' => __CLASS__, 'num' => $i, - 'users_id' => 0 - ] + 'users_id' => 0, + ], ); } } - if (!$DB->fieldExists($table, "subtype")) { + if (!$DB->fieldExists($table, 'subtype')) { $migration->addField($table, 'subtype', 'VARCHAR(255) DEFAULT NULL', ['after' => 'type']); $migration->migrationOneTable($table); } @@ -172,13 +173,13 @@ public static function installUserData(Migration $migration, $version) : []; foreach ($itemtypes as $itemtype) { - $sysname = self::getSystemName($itemtype, $container['name']); - $class_filename = $sysname . ".class.php"; + $sysname = self::getSystemName($itemtype, $container['name']); + $class_filename = $sysname . '.class.php'; if (file_exists(PLUGINFIELDS_DIR . "/inc/$class_filename")) { unlink(PLUGINFIELDS_DIR . "/inc/$class_filename"); } - $injclass_filename = $sysname . "injection.class.php"; + $injclass_filename = $sysname . 'injection.class.php'; if (file_exists(PLUGINFIELDS_DIR . "/inc/$injclass_filename")) { unlink(PLUGINFIELDS_DIR . "/inc/$injclass_filename"); } @@ -186,7 +187,7 @@ public static function installUserData(Migration $migration, $version) } // Regenerate container classes to ensure they can be used - $migration->displayMessage(__("Regenerate containers files", "fields")); + $migration->displayMessage(__('Regenerate containers files', 'fields')); $obj = new self(); $containers = $obj->find(); foreach ($containers as $container) { @@ -196,18 +197,18 @@ public static function installUserData(Migration $migration, $version) // Fix containers names that were generated prior to Fields 1.9.2. $bad_named_containers = $DB->request( [ - 'FROM' => self::getTable(), + 'FROM' => self::getTable(), 'WHERE' => [ 'name' => [ 'REGEXP', - $DB->escape('\d+') + $DB->escape('\d+'), ], ], - ] + ], ); if ($bad_named_containers->count() > 0) { - $migration->displayMessage(__("Fix container names", "fields")); + $migration->displayMessage(__('Fix container names', 'fields')); $toolbox = new PluginFieldsToolbox(); @@ -223,17 +224,17 @@ public static function installUserData(Migration $migration, $version) } } $container['name'] = $new_name; - $container_obj = new PluginFieldsContainer(); + $container_obj = new PluginFieldsContainer(); $container_obj->update( $container, - false + false, ); // Rename container tables and itemtype if needed foreach (json_decode($container['itemtypes']) as $itemtype) { $migration->renameItemtype( self::getClassname($itemtype, $old_name), - self::getClassname($itemtype, $new_name) + self::getClassname($itemtype, $new_name), ); } } @@ -255,26 +256,26 @@ public static function installUserData(Migration $migration, $version) $fields = $fields->find(['plugin_fields_containers_id' => $ostab]); $classname = self::getClassname(Computer::getType(), $oscontainer->fields['name']); - $osdata = new $classname(); + $osdata = new $classname(); $classname = self::getClassname(Computer::getType(), $compcontainer->fields['name']); - $compdata = new $classname(); + $compdata = new $classname(); $fieldnames = []; //add fields to compcontainer foreach ($fields as $field) { - $newname = $field['name']; + $newname = $field['name']; $compfields = $fields->find(['plugin_fields_containers_id' => $comptab, 'name' => $newname]); if ($compfields) { $newname = $newname . '_os'; $DB->update( 'glpi_plugin_fields_fields', [ - 'name' => $newname + 'name' => $newname, ], [ - 'name' => $field['name'], - 'plugin_fields_containers_id' => $ostab - ] + 'name' => $field['name'], + 'plugin_fields_containers_id' => $ostab, + ], ); } $compdata::addField($newname, $field['type']); @@ -284,17 +285,17 @@ public static function installUserData(Migration $migration, $version) $DB->update( 'glpi_plugin_fields_fields', [ - 'plugin_fields_containers_id' => $comptab + 'plugin_fields_containers_id' => $comptab, ], [ - 'plugin_fields_containers_id' => $ostab - ] + 'plugin_fields_containers_id' => $ostab, + ], ); $DB->delete( 'glpi_plugin_fields_containers', [ - 'id' => $ostab - ] + 'id' => $ostab, + ], ); //migrate existing data @@ -308,17 +309,17 @@ public static function installUserData(Migration $migration, $version) } //drop old table - $DB->query("DROP TABLE " . $osdata::getTable()); + $DB->query('DROP TABLE ' . $osdata::getTable()); } else { $DB->update( 'glpi_plugin_fields_containers', [ - 'type' => 'dom', - 'subtype' => null + 'type' => 'dom', + 'subtype' => null, ], [ - 'id' => $ostab - ] + 'id' => $ostab, + ], ); } } @@ -341,14 +342,14 @@ public static function installUserData(Migration $migration, $version) ['subtype' => ['LIKE', 'Change$%']], ], ], - ] + ], ); // Ensure data is update before regenerating files. $migration->executeMigration(); // Regenerate files and install missing tables - $migration->displayMessage(__("Updating generated containers files", "fields")); + $migration->displayMessage(__('Updating generated containers files', 'fields')); $obj = new self(); $containers = $obj->find(); foreach ($containers as $container) { @@ -364,19 +365,19 @@ public static function uninstall() global $DB; //uninstall container table and class - $obj = new self(); + $obj = new self(); $containers = $obj->find(); foreach ($containers as $container) { $obj->delete(['id' => $container['id']]); } //drop global container table - $DB->query("DROP TABLE IF EXISTS `" . self::getTable() . "`"); + $DB->query('DROP TABLE IF EXISTS `' . self::getTable() . '`'); //delete display preferences for this item $pref = new DisplayPreference(); $pref->deleteByCriteria([ - 'itemtype' => __CLASS__ + 'itemtype' => __CLASS__, ]); return true; @@ -397,7 +398,7 @@ public function rawSearchOptions() 'id' => 1, 'table' => self::getTable(), 'field' => 'name', - 'name' => __("Name"), + 'name' => __('Name'), 'datatype' => 'itemlink', 'itemlink_type' => self::getType(), 'massiveaction' => false, @@ -407,7 +408,7 @@ public function rawSearchOptions() 'id' => 2, 'table' => self::getTable(), 'field' => 'label', - 'name' => __("Label"), + 'name' => __('Label'), 'massiveaction' => false, 'autocomplete' => true, ]; @@ -416,7 +417,7 @@ public function rawSearchOptions() 'id' => 3, 'table' => self::getTable(), 'field' => 'itemtypes', - 'name' => __("Associated item type"), + 'name' => __('Associated item type'), 'datatype' => 'specific', 'massiveaction' => false, 'nosearch' => true, @@ -426,25 +427,25 @@ public function rawSearchOptions() 'id' => 4, 'table' => self::getTable(), 'field' => 'type', - 'name' => __("Type"), + 'name' => __('Type'), 'searchtype' => ['equals', 'notequals'], 'massiveaction' => false, ]; $tab[] = [ - 'id' => 5, - 'table' => self::getTable(), - 'field' => 'is_active', - 'name' => __("Active"), - 'datatype' => 'bool', - 'searchtype' => ['equals', 'notequals'], + 'id' => 5, + 'table' => self::getTable(), + 'field' => 'is_active', + 'name' => __('Active'), + 'datatype' => 'bool', + 'searchtype' => ['equals', 'notequals'], ]; $tab[] = [ 'id' => 6, 'table' => 'glpi_entities', 'field' => 'completename', - 'name' => __("Entity"), + 'name' => __('Entity'), 'massiveaction' => false, 'datatype' => 'dropdown', ]; @@ -453,7 +454,7 @@ public function rawSearchOptions() 'id' => 7, 'table' => self::getTable(), 'field' => 'is_recursive', - 'name' => __("Child entities"), + 'name' => __('Child entities'), 'massiveaction' => false, 'datatype' => 'bool', ]; @@ -462,7 +463,7 @@ public function rawSearchOptions() 'id' => 8, 'table' => self::getTable(), 'field' => 'id', - 'name' => __("ID"), + 'name' => __('ID'), 'datatype' => 'number', 'massiveaction' => false, ]; @@ -478,6 +479,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options switch ($field) { case 'type': $types = self::getTypes(); + return $types[$values[$field]]; case 'itemtypes': $types = json_decode($values[$field]); @@ -492,27 +494,28 @@ public static function getSpecificValueToDisplay($field, $values, array $options $name_type = getItemForItemtype($type); $obj .= $name_type->getTypeName(2); if ($count > $i) { - $obj .= ", "; + $obj .= ', '; } $i++; } + return $obj; } return ''; } - public function getValueToSelect($field_id_or_search_options, $name = '', $values = '', $options = []) { - switch ($field_id_or_search_options['table'] . '.' . $field_id_or_search_options['field']) { // For searchoption "Type" case $this->getTable() . '.type': $options['display'] = false; + return Dropdown::showFromArray($name, self::getTypes(), $options); case $this->getTable() . '.itemtypes': $options['display'] = false; + return Dropdown::showFromArray($name, self::getItemtypes(false), $options); } @@ -537,12 +540,13 @@ public function prepareInputForAdd($input) if (!isset($input['itemtypes'])) { Session::AddMessageAfterRedirect( __( - "You cannot add block without associated element type", - "fields" + 'You cannot add block without associated element type', + 'fields', ), false, - ERROR + ERROR, ); + return false; } @@ -550,14 +554,15 @@ public function prepareInputForAdd($input) $input['itemtypes'] = [$input['itemtypes']]; } - if ($input['type'] === "dom") { + if ($input['type'] === 'dom') { //check for already exist dom container with this itemtype $found = $this->find(['type' => 'dom']); if (count($found) > 0) { foreach (array_column($found, 'itemtypes') as $founditemtypes) { foreach (json_decode($founditemtypes) as $founditemtype) { if (in_array($founditemtype, $input['itemtypes'])) { - Session::AddMessageAfterRedirect(__("You cannot add several blocks with type 'Insertion in the form' on same object", "fields"), false, ERROR); + Session::AddMessageAfterRedirect(__("You cannot add several blocks with type 'Insertion in the form' on same object", 'fields'), false, ERROR); + return false; } } @@ -565,14 +570,15 @@ public function prepareInputForAdd($input) } } - if ($input['type'] === "domtab") { + if ($input['type'] === 'domtab') { //check for already exist domtab container with this itemtype on this tab $found = $this->find(['type' => 'domtab', 'subtype' => $input['subtype']]); if (count($found) > 0) { foreach (array_column($found, 'itemtypes') as $founditemtypes) { foreach (json_decode($founditemtypes) as $founditemtype) { if (in_array($founditemtype, $input['itemtypes'])) { - Session::AddMessageAfterRedirect(__("You cannot add several blocks with type 'Insertion in the form of a specific tab' on same object tab", "fields"), false, ERROR); + Session::AddMessageAfterRedirect(__("You cannot add several blocks with type 'Insertion in the form of a specific tab' on same object tab", 'fields'), false, ERROR); + return false; } } @@ -580,7 +586,7 @@ public function prepareInputForAdd($input) } } - $toolbox = new PluginFieldsToolbox(); + $toolbox = new PluginFieldsToolbox(); $input['name'] = $toolbox->getSystemNameFromLabel($input['label']); //reject adding when container name is too long for mysql table name @@ -588,10 +594,11 @@ public function prepareInputForAdd($input) $tmp = getTableForItemType(self::getClassname($itemtype, $input['name'])); if (strlen($tmp) > 64) { Session::AddMessageAfterRedirect( - __("Container name is too long for database (digits in name are replaced by characters, try to remove them)", 'fields'), + __('Container name is too long for database (digits in name are replaced by characters, try to remove them)', 'fields'), false, - ERROR + ERROR, ); + return false; } } @@ -602,7 +609,8 @@ public function prepareInputForAdd($input) foreach (array_column($found, 'itemtypes') as $founditemtypes) { foreach (json_decode($founditemtypes) as $founditemtype) { if (in_array($founditemtype, $input['itemtypes'])) { - Session::AddMessageAfterRedirect(__("You cannot add several blocs with identical name on same object", "fields"), false, ERROR); + Session::AddMessageAfterRedirect(__('You cannot add several blocs with identical name on same object', 'fields'), false, ERROR); + return false; } } @@ -619,7 +627,6 @@ public function prepareInputForAdd($input) // phpcs:ignore PSR1.Methods.CamelCapsMethodName public function post_addItem() { - if (!isset($this->input['clone']) || !$this->input['clone']) { //create profiles associated to this container PluginFieldsProfile::createForContainer($this); @@ -658,29 +665,32 @@ public static function generateTemplate($fields) $sysname = self::getSystemName($itemtype, $fields['name']); $classname = self::getClassname($itemtype, $fields['name']); - $template_class = file_get_contents(PLUGINFIELDS_DIR . "/templates/container.class.tpl"); - $template_class = str_replace("%%CLASSNAME%%", $classname, $template_class); - $template_class = str_replace("%%ITEMTYPE%%", $itemtype, $template_class); - $template_class = str_replace("%%CONTAINER%%", $fields['id'], $template_class); - $template_class = str_replace("%%ITEMTYPE_RIGHT%%", $itemtype::$rightname, $template_class); - $class_filename = $sysname . ".class.php"; + $template_class = file_get_contents(PLUGINFIELDS_DIR . '/templates/container.class.tpl'); + $template_class = str_replace('%%CLASSNAME%%', $classname, $template_class); + $template_class = str_replace('%%ITEMTYPE%%', $itemtype, $template_class); + $template_class = str_replace('%%CONTAINER%%', $fields['id'], $template_class); + $template_class = str_replace('%%ITEMTYPE_RIGHT%%', $itemtype::$rightname, $template_class); + $class_filename = $sysname . '.class.php'; if (file_put_contents(PLUGINFIELDS_CLASS_PATH . "/$class_filename", $template_class) === false) { Toolbox::logDebug("Error : class file creation - $class_filename"); + return false; } // Generate Datainjection files - $template_class = file_get_contents(PLUGINFIELDS_DIR . "/templates/injection.class.tpl"); - $template_class = str_replace("%%CLASSNAME%%", $classname, $template_class); - $template_class = str_replace("%%ITEMTYPE%%", $itemtype, $template_class); - $template_class = str_replace("%%CONTAINER_ID%%", $fields['id'], $template_class); - $template_class = str_replace("%%CONTAINER_NAME%%", $fields['label'], $template_class); - $class_filename = $sysname . "injection.class.php"; + $template_class = file_get_contents(PLUGINFIELDS_DIR . '/templates/injection.class.tpl'); + $template_class = str_replace('%%CLASSNAME%%', $classname, $template_class); + $template_class = str_replace('%%ITEMTYPE%%', $itemtype, $template_class); + $template_class = str_replace('%%CONTAINER_ID%%', $fields['id'], $template_class); + $template_class = str_replace('%%CONTAINER_NAME%%', $fields['label'], $template_class); + $class_filename = $sysname . 'injection.class.php'; if (file_put_contents(PLUGINFIELDS_CLASS_PATH . "/$class_filename", $template_class) === false) { Toolbox::logDebug("Error : datainjection class file creation - $class_filename"); + return false; } } + return true; } @@ -694,33 +704,33 @@ public function pre_deleteItem() foreach (json_decode($this->fields['itemtypes']) as $itemtype) { $classname = self::getClassname($itemtype, $this->fields['name']); - $sysname = self::getSystemName($itemtype, $this->fields['name']); - $class_filename = $sysname . ".class.php"; - $injection_filename = $sysname . "injection.class.php"; + $sysname = self::getSystemName($itemtype, $this->fields['name']); + $class_filename = $sysname . '.class.php'; + $injection_filename = $sysname . 'injection.class.php'; //delete fields $field_obj = new PluginFieldsField(); $field_obj->deleteByCriteria([ - 'plugin_fields_containers_id' => $this->fields['id'] + 'plugin_fields_containers_id' => $this->fields['id'], ]); //delete display condition $field_obj = new PluginFieldsContainerDisplayCondition(); $field_obj->deleteByCriteria([ - 'plugin_fields_containers_id' => $this->fields['id'] + 'plugin_fields_containers_id' => $this->fields['id'], ]); //delete profiles $profile_obj = new PluginFieldsProfile(); $profile_obj->deleteByCriteria([ - 'plugin_fields_containers_id' => $this->fields['id'] + 'plugin_fields_containers_id' => $this->fields['id'], ]); //delete label translations $translation_obj = new PluginFieldsLabelTranslation(); $translation_obj->deleteByCriteria([ 'itemtype' => self::getType(), - 'items_id' => $this->fields['id'] + 'items_id' => $this->fields['id'], ]); //delete table @@ -750,33 +760,33 @@ public function pre_deleteItem() public static function preItemPurge($item) { - $itemtype = get_class($item); - $containers = new self(); + $itemtype = get_class($item); + $containers = new self(); $founded_containers = $containers->find(); foreach ($founded_containers as $container) { $itemtypes = json_decode($container['itemtypes']); if (in_array($itemtype, $itemtypes)) { $classname = 'PluginFields' . $itemtype . getSingular($container['name']); - $fields = new $classname(); + $fields = new $classname(); $fields->deleteByCriteria(['items_id' => $item->fields['id']], true); } } + return true; } public static function getTypeName($nb = 0) { - return __("Block", "fields"); + return __('Block', 'fields'); } public function showForm($ID, $options = []) { - $this->initForm($ID, $options); if (!$this->isNewID($ID)) { - $btn_url = Plugin::getWebDir('fields') . '/front/export_to_yaml.php?id=' . $ID; - $btn_label = __("Export to YAML", "fields"); + $btn_url = Plugin::getWebDir('fields') . '/front/export_to_yaml.php?id=' . $ID; + $btn_label = __('Export to YAML', 'fields'); $export_btn = <<showFormHeader($options); $rand = mt_rand(); - echo ""; - echo "" . __("Label") . " : "; + echo ''; + echo "" . __('Label') . ' : '; echo ""; echo Html::input( 'label', [ 'value' => $this->fields['label'], - ] + ], ); - echo ""; + echo ''; echo " "; echo " "; - echo ""; + echo ''; - echo ""; - echo "" . __("Type") . " : "; - echo ""; + echo ''; + echo '' . __('Type') . ' : '; + echo ''; if ($ID > 0) { $types = self::getTypes(); - echo $types[$this->fields["type"]]; + echo $types[$this->fields['type']]; } else { Dropdown::showFromArray( 'type', self::getTypes(), [ - 'value' => $this->fields["type"], - 'rand' => $rand - ] + 'value' => $this->fields['type'], + 'rand' => $rand, + ], ); Ajax::updateItemOnSelectEvent( "dropdown_type$rand", "itemtypes_$rand", - "../ajax/container_itemtypes_dropdown.php", + '../ajax/container_itemtypes_dropdown.php', [ 'type' => '__VALUE__', - 'itemtype' => $this->fields["itemtypes"], + 'itemtype' => $this->fields['itemtypes'], 'subtype' => $this->fields['subtype'], - 'rand' => $rand - ] + 'rand' => $rand, + ], ); } - echo ""; - echo "" . __("Associated item type") . " : "; - echo ""; + echo ''; + echo '' . __('Associated item type') . ' : '; + echo ''; if ($ID > 0) { $types = json_decode($this->fields['itemtypes']); - $obj = ''; + $obj = ''; $count = count($types); - $i = 1; + $i = 1; foreach ($types as $type) { // prevent usage of plugin class if not loaded if (!class_exists($type)) { @@ -848,7 +858,7 @@ public function showForm($ID, $options = []) $name_type = getItemForItemtype($type); $obj .= $name_type->getTypeName(2); if ($count > $i) { - $obj .= ", "; + $obj .= ', '; } $i++; } @@ -857,39 +867,39 @@ public function showForm($ID, $options = []) echo " "; self::showFormItemtype([ 'rand' => $rand, - 'subtype' => $this->fields['subtype'] + 'subtype' => $this->fields['subtype'], ]); - echo ""; + echo ''; } - echo ""; - echo ""; + echo ''; + echo ''; $display = "style='display:none'"; - if (!empty($this->fields["subtype"])) { - $display = ""; + if (!empty($this->fields['subtype'])) { + $display = ''; } echo ""; echo ""; - echo "" . __("Tab", "fields") . " : "; - echo ""; + echo '' . __('Tab', 'fields') . ' : '; + echo ''; echo " "; - if ($ID > 0 && !empty($this->fields["subtype"])) { - $itemtypes = json_decode($this->fields["itemtypes"], true); - $itemtype = array_shift($itemtypes); - $item = new $itemtype(); + if ($ID > 0 && !empty($this->fields['subtype'])) { + $itemtypes = json_decode($this->fields['itemtypes'], true); + $itemtype = array_shift($itemtypes); + $item = new $itemtype(); $item->getEmpty(); $tabs = self::getSubtypes($item); - echo $tabs[$this->fields["subtype"]]; + echo $tabs[$this->fields['subtype']]; } - echo ""; - echo ""; + echo ''; + echo ''; - echo ""; - echo "" . __("Active") . " : "; - echo ""; - Dropdown::showYesNo("is_active", $this->fields["is_active"]); - echo ""; - echo ""; + echo ''; + echo '' . __('Active') . ' : '; + echo ''; + Dropdown::showYesNo('is_active', $this->fields['is_active']); + echo ''; + echo ''; $this->showFormButtons($options); @@ -899,7 +909,7 @@ public function showForm($ID, $options = []) public static function showFormItemtype($params = []) { $is_domtab = isset($params['type']) && $params['type'] == 'domtab'; - $values = self::getItemtypes($is_domtab); + $values = self::getItemtypes($is_domtab); //remove ITISolution from values if type is tab if (!isset($params['type']) || (isset($params['type']) && $params['type'] == 'tab')) { @@ -908,27 +918,27 @@ public static function showFormItemtype($params = []) $rand = $params['rand']; Dropdown::showFromArray( - "itemtypes", + 'itemtypes', $values, [ 'rand' => $rand, 'multiple' => !$is_domtab, 'width' => 200, - 'display_emptychoice' => $is_domtab - ] + 'display_emptychoice' => $is_domtab, + ], ); if ($is_domtab) { Ajax::updateItemOnSelectEvent( ["dropdown_type$rand", "dropdown_itemtypes$rand"], "subtype_$rand", - "../ajax/container_subtype_dropdown.php", + '../ajax/container_subtype_dropdown.php', [ 'type' => '__VALUE0__', 'itemtype' => '__VALUE1__', - 'subtype' => $params["subtype"], - 'rand' => $rand - ] + 'subtype' => $params['subtype'], + 'rand' => $rand, + ], ); } } @@ -944,7 +954,7 @@ public static function showFormItemtype($params = []) public static function showFormSubtype($params, $display = false) { $out = ""; - if (isset($params['type']) && $params['type'] == "domtab") { + if (isset($params['type']) && $params['type'] == 'domtab') { if (class_exists($params['itemtype'])) { $item = new $params['itemtype'](); $item->getEmpty(); @@ -964,7 +974,7 @@ public static function showFormSubtype($params, $display = false) foreach ($tabs as &$value) { $results = []; if (preg_match_all('#(.+)#', $value, $results)) { - $value = str_replace($results[0][0], "", $value); + $value = str_replace($results[0][0], '', $value); } } @@ -975,10 +985,10 @@ public static function showFormSubtype($params, $display = false) $out .= Dropdown::showFromArray( 'subtype', $tabs, - ['value' => $params['subtype'], + ['value' => $params['subtype'], 'width' => '100%', - 'display' => false - ] + 'display' => false, + ], ); $out .= ""; } @@ -1010,7 +1020,7 @@ public static function getItemtypes($is_domtab) function ($itemtype) { return count(self::getSubtypes($itemtype)) > 0; }, - ARRAY_FILTER_USE_KEY + ARRAY_FILTER_USE_KEY, ); } @@ -1024,9 +1034,9 @@ function ($itemtype) { public static function getTypes() { return [ - 'tab' => __("Add tab", "fields"), - 'dom' => __("Insertion in the form (before save button)", "fields"), - 'domtab' => __("Insertion in the form of a specific tab (before save button)", "fields") + 'tab' => __('Add tab', 'fields'), + 'dom' => __('Insertion in the form (before save button)', 'fields'), + 'domtab' => __('Insertion in the form of a specific tab (before save button)', 'fields'), ]; } @@ -1038,7 +1048,7 @@ public static function getEntries($type = 'tab', $full = false): array $condition = [ 'is_active' => 1, ]; - if ($type !== "all") { + if ($type !== 'all') { $condition[] = ['type' => $type]; } @@ -1053,7 +1063,7 @@ public static function getEntries($type = 'tab', $full = false): array //entities restriction if (!in_array($item['entities_id'], $_SESSION['glpiactiveentities'])) { if ($item['is_recursive'] == 1) { - $entities = getSonsOf("glpi_entities", $item['entities_id']); + $entities = getSonsOf('glpi_entities', $item['entities_id']); if (count(array_intersect($entities, $_SESSION['glpiactiveentities'])) == 0) { continue; } @@ -1081,14 +1091,15 @@ public static function getEntries($type = 'tab', $full = false): array foreach ($jsonitemtypes as $v) { if ($full) { //check for translation - $item['itemtype'] = self::getType(); - $label = PluginFieldsLabelTranslation::getLabelFor($item); + $item['itemtype'] = self::getType(); + $label = PluginFieldsLabelTranslation::getLabelFor($item); $itemtypes[$v][$item['name']] = $label; } else { $itemtypes[] = $v; } } } + return $itemtypes; } @@ -1097,7 +1108,7 @@ public static function getUsedItemtypes($type = 'all', $must_be_active = false) /** @var DBmysql $DB */ global $DB; $itemtypes = []; - $where = []; + $where = []; if ($type !== 'all') { $where['type'] = $type; @@ -1108,10 +1119,10 @@ public static function getUsedItemtypes($type = 'all', $must_be_active = false) } $iterator = $DB->request([ - 'SELECT' => 'itemtypes', + 'SELECT' => 'itemtypes', 'DISTINCT' => true, - 'FROM' => self::getTable(), - 'WHERE' => $where, + 'FROM' => self::getTable(), + 'WHERE' => $where, ]); foreach ($iterator as $data) { @@ -1147,13 +1158,13 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) } } } + return $tabs_entries; } return ''; } - public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { if ($withtemplate) { @@ -1199,7 +1210,7 @@ public function updateFieldsValues($data, $itemtype, $massiveaction = false) 'is_active' => 1, 'multiple' => 1, 'plugin_fields_containers_id' => $data['plugin_fields_containers_id'], - ] + ], ]); foreach ($multiple_fields_iterator as $field_data) { $field_name = $field_data['name']; @@ -1238,7 +1249,7 @@ public function updateFieldsValues($data, $itemtype, $massiveaction = false) $items_id, $itemtype, $obj->input, - $obj + $obj, ); return true; @@ -1253,9 +1264,9 @@ private function addRichTextFiles(CommonDBTM $object): void 'FROM' => PluginFieldsField::getTable(), 'WHERE' => [ 'is_active' => 1, - 'type' => "richtext", - 'plugin_fields_containers_id' => $object->input['plugin_fields_containers_id'] - ] + 'type' => 'richtext', + 'plugin_fields_containers_id' => $object->input['plugin_fields_containers_id'], + ], ]); foreach ($richtext_fields_iterator as $field_data) { $field_name = $field_data['name']; @@ -1265,8 +1276,8 @@ private function addRichTextFiles(CommonDBTM $object): void [ 'force_update' => true, 'name' => $field_name, - 'content_field' => $field_name - ] + 'content_field' => $field_name, + ], ); // remove uploaded file input to ensure they will not be added to history @@ -1307,7 +1318,7 @@ public static function constructHistory( 'items_id' => 0, 'itemtype' => $itemtype, 'update_fields_values' => 0, - '_glpi_csrf_token' => 0 + '_glpi_csrf_token' => 0, ]; //remove non-data keys @@ -1322,7 +1333,7 @@ public static function constructHistory( //do not log if value is empty or if dom name is part of file upload if (!empty($value) && strpos($key, '_uploader_') === false) { //prepare log - $changes = [0, "N/A", $value]; + $changes = [0, 'N/A', $value]; //find searchoption foreach ($searchoptions as $id_search_option => $searchoption) { @@ -1332,25 +1343,25 @@ public static function constructHistory( if ($searchoption['datatype'] === 'dropdown') { //manage dropdown values $changes = [$id_search_option, - "", - Dropdown::getDropdownName($searchoption['table'], $value) + '', + Dropdown::getDropdownName($searchoption['table'], $value), ]; } elseif ($searchoption['datatype'] === 'bool') { //manage bool values - $changes = [$id_search_option, "", Dropdown::getYesNo($value)]; + $changes = [$id_search_option, '', Dropdown::getYesNo($value)]; } elseif ($searchoption['datatype'] === 'specific') { //manage specific values $changes = [ $id_search_option, - "", + '', PluginFieldsAbstractContainerInstance::getSpecificValueToDisplay( $key, $value, [ 'searchopt' => $searchoption, 'separator' => ', ', - ] - ) + ], + ), ]; } } @@ -1393,7 +1404,7 @@ public static function constructHistory( [ 'searchopt' => $searchoption, 'separator' => ', ', - ] + ], ); $changes[2] = PluginFieldsAbstractContainerInstance::getSpecificValueToDisplay( $key, @@ -1401,7 +1412,7 @@ public static function constructHistory( [ 'searchopt' => $searchoption, 'separator' => ', ', - ] + ], ); } } @@ -1436,16 +1447,16 @@ public static function validateValues($data, $itemtype, $massiveaction) $container->getFromDB($data['plugin_fields_containers_id']); $field_obj = new PluginFieldsField(); - $fields = $field_obj->find([ - 'plugin_fields_containers_id' => $data['plugin_fields_containers_id'] + $fields = $field_obj->find([ + 'plugin_fields_containers_id' => $data['plugin_fields_containers_id'], ]); - $status_value = null; + $status_value = null; $status_field_name = PluginFieldsStatusOverride::getStatusFieldName($itemtype); if ($container->fields['type'] === 'dom') { $status_value = $data[$status_field_name] ?? null; } else { - $relatedItem = new $itemtype(); + $relatedItem = new $itemtype(); $status_value = $relatedItem->fields[$status_field_name] ?? null; } // Apply status overrides @@ -1456,7 +1467,7 @@ public static function validateValues($data, $itemtype, $massiveaction) foreach ($status_overrides as $status_override) { if (isset($fields[$status_override['plugin_fields_fields_id']])) { $fields[$status_override['plugin_fields_fields_id']]['is_readonly'] = $status_override['is_readonly']; - $fields[$status_override['plugin_fields_fields_id']]['mandatory'] = $status_override['mandatory']; + $fields[$status_override['plugin_fields_fields_id']]['mandatory'] = $status_override['mandatory']; } } @@ -1465,14 +1476,14 @@ public static function validateValues($data, $itemtype, $massiveaction) continue; } - if ($field['type'] == "yesno" || $field['type'] == "header") { + if ($field['type'] == 'yesno' || $field['type'] == 'header') { continue; } $name = $field['name']; $value = null; - if ($field['type'] == "glpi_item") { + if ($field['type'] == 'glpi_item') { $itemtype_key = sprintf('itemtype_%s', $name); $items_id_key = sprintf('items_id_%s', $name); @@ -1482,7 +1493,7 @@ public static function validateValues($data, $itemtype, $massiveaction) && $data[$items_id_key] > 0 ) { $glpi_item = new $data[$itemtype_key](); - $value = $glpi_item->getFromDB($data[$items_id_key]) ? $data[$items_id_key] : null; + $value = $glpi_item->getFromDB($data[$items_id_key]) ? $data[$items_id_key] : null; } } elseif (isset($data[$name])) { $value = $data[$name]; @@ -1496,13 +1507,13 @@ public static function validateValues($data, $itemtype, $massiveaction) //translate label $field['itemtype'] = PluginFieldsField::getType(); - $field['label'] = PluginFieldsLabelTranslation::getLabelFor($field); + $field['label'] = PluginFieldsLabelTranslation::getLabelFor($field); // Check mandatory fields if ( $field['mandatory'] == 1 && ( - $value === null + $value === null || $value === '' || (($field['type'] === 'dropdown' || preg_match('/^dropdown-.+/i', $field['type'])) && $value == 0) || ($field['type'] === 'glpi_item' && $value === null) @@ -1510,63 +1521,61 @@ public static function validateValues($data, $itemtype, $massiveaction) ) ) { $empty_errors[] = $field['label']; - $valid = false; + $valid = false; } elseif ($field['type'] == 'number' && !empty($value) && !is_numeric($value)) { // Check number fields $number_errors[] = $field['label']; - $valid = false; + $valid = false; } elseif ($field['type'] == 'url' && !empty($value)) { if (filter_var($value, FILTER_VALIDATE_URL) === false) { $url_errors[] = $field['label']; - $valid = false; + $valid = false; } } } if (!empty($empty_errors)) { - Session::AddMessageAfterRedirect(__("Some mandatory fields are empty", "fields") . - " : " . implode(', ', $empty_errors), false, ERROR); + Session::AddMessageAfterRedirect(__('Some mandatory fields are empty', 'fields') . + ' : ' . implode(', ', $empty_errors), false, ERROR); } if (!empty($number_errors)) { - Session::AddMessageAfterRedirect(__("Some numeric fields contains non numeric values", "fields") . - " : " . implode(', ', $number_errors), false, ERROR); + Session::AddMessageAfterRedirect(__('Some numeric fields contains non numeric values', 'fields') . + ' : ' . implode(', ', $number_errors), false, ERROR); } if (!empty($url_errors)) { - Session::AddMessageAfterRedirect(__("Some URL fields contains invalid links", "fields") . - " : " . implode(', ', $url_errors), false, ERROR); + Session::AddMessageAfterRedirect(__('Some URL fields contains invalid links', 'fields') . + ' : ' . implode(', ', $url_errors), false, ERROR); } return $valid; } - public static function findContainer($itemtype, $type = 'tab', $subtype = '') { - $condition = [ 'is_active' => 1, - ['type' => $type], + ['type' => $type], ]; $entity = isset($_SESSION['glpiactiveentities']) ? $_SESSION['glpiactiveentities'] : 0; - $condition += getEntitiesRestrictCriteria("", "", $entity, true, true); + $condition += getEntitiesRestrictCriteria('', '', $entity, true, true); if ($subtype != '') { if ($subtype == $itemtype . '$main') { $condition[] = ['type' => 'dom']; } else { - $condition[] = ['type' => ['!=', 'dom']]; + $condition[] = ['type' => ['!=', 'dom']]; $condition['subtype'] = $subtype; } } $container = new PluginFieldsContainer(); $itemtypes = $container->find($condition); - $id = false; // default value when no container matches criterion + $id = false; // default value when no container matches criterion if (count($itemtypes) < 1) { return false; } @@ -1600,13 +1609,14 @@ public static function findContainer($itemtype, $type = 'tab', $subtype = '') public static function postItemAdd(CommonDBTM $item) { if (array_key_exists('_plugin_fields_data', $item->input)) { - $data = $item->input['_plugin_fields_data']; + $data = $item->input['_plugin_fields_data']; $data['items_id'] = $item->getID(); //update data $container = new self(); if ($container->updateFieldsValues($data, $item->getType(), isset($_REQUEST['massiveaction']))) { return true; } + return $item->input = []; } @@ -1632,16 +1642,17 @@ public static function preItemUpdate(CommonDBTM $item) count($data) == 0 || $container->updateFieldsValues($data, $item->getType(), isset($_REQUEST['massiveaction'])) ) { - $item->input['date_mod'] = $_SESSION["glpi_currenttime"]; + $item->input['date_mod'] = $_SESSION['glpi_currenttime']; + return true; } + return $item->input = []; } return true; } - /** * Pre item hook for add and update * Validates and store plugin data in item object @@ -1706,9 +1717,11 @@ public static function preItem(CommonDBTM $item) if (false !== ($data = self::populateData($c_id, $item))) { if (self::validateValues($data, $item::getType(), isset($_REQUEST['massiveaction'])) === false) { $item->input = []; + return []; } $item->input['_plugin_fields_data'] = $data; + return $data; } @@ -1727,12 +1740,12 @@ private static function populateData($c_id, CommonDBTM $item) { //find fields associated to found container $field_obj = new PluginFieldsField(); - $fields = $field_obj->find( + $fields = $field_obj->find( [ 'plugin_fields_containers_id' => $c_id, - 'type' => ['!=', 'header'] + 'type' => ['!=', 'header'], ], - "ranking" + 'ranking', ); //prepare data to update @@ -1743,12 +1756,12 @@ private static function populateData($c_id, CommonDBTM $item) } // Add status so it can be used with status overrides - $status_field_name = PluginFieldsStatusOverride::getStatusFieldName($item->getType()); + $status_field_name = PluginFieldsStatusOverride::getStatusFieldName($item->getType()); $data[$status_field_name] = null; if (array_key_exists($status_field_name, $item->input) && $item->input[$status_field_name] !== '') { - $data[$status_field_name] = (int)$item->input[$status_field_name]; + $data[$status_field_name] = (int) $item->input[$status_field_name]; } elseif (array_key_exists($status_field_name, $item->fields) && $item->fields[$status_field_name] !== '') { - $data[$status_field_name] = (int)$item->fields[$status_field_name]; + $data[$status_field_name] = (int) $item->fields[$status_field_name]; } $has_fields = false; @@ -1761,7 +1774,7 @@ private static function populateData($c_id, CommonDBTM $item) continue; // not a valid input } - $has_fields = true; + $has_fields = true; $data[$itemtype_key] = $item->input[$itemtype_key]; $data[$items_id_key] = $item->input[$items_id_key]; @@ -1773,13 +1786,13 @@ private static function populateData($c_id, CommonDBTM $item) $input = $field['name']; } else { //dropdown field - $input = "plugin_fields_" . $field['name'] . "dropdowns_id"; + $input = 'plugin_fields_' . $field['name'] . 'dropdowns_id'; } if (isset($item->input[$input])) { $has_fields = true; // Before is_number check, help user to have a number correct, during a massive action of a number field if ($field['type'] == 'number') { - $item->input[$input] = str_replace(",", ".", $item->input[$input]); + $item->input[$input] = str_replace(',', '.', $item->input[$input]); } $data[$input] = $item->input[$input]; @@ -1789,8 +1802,8 @@ private static function populateData($c_id, CommonDBTM $item) $tag_input = sprintf('_tag_%s', $input); $data[$filename_input] = $item->input[$filename_input] ?? []; - $data[$prefix_input] = $item->input[$prefix_input] ?? []; - $data[$tag_input] = $item->input[$tag_input] ?? []; + $data[$prefix_input] = $item->input[$prefix_input] ?? []; + $data[$tag_input] = $item->input[$tag_input] ?? []; } } else { //the absence of the field in the input may be due to the fact that the input allows multiple selection @@ -1799,18 +1812,18 @@ private static function populateData($c_id, CommonDBTM $item) if ($field['multiple']) { //handle multi dropdown field if ($field['type'] == 'dropdown') { - $multiple_key = sprintf('plugin_fields_%sdropdowns_id', $field['name']); + $multiple_key = sprintf('plugin_fields_%sdropdowns_id', $field['name']); $multiple_key_defined = '_' . $multiple_key . '_defined'; //values are defined by user if (isset($item->input[$multiple_key])) { $data[$multiple_key] = $item->input[$multiple_key]; - $has_fields = true; + $has_fields = true; } elseif ( isset($item->input[$multiple_key_defined]) && $item->input[$multiple_key_defined] ) { //multi dropdown is empty or has been emptied $data[$multiple_key] = []; - $has_fields = true; + $has_fields = true; } } @@ -1819,7 +1832,7 @@ private static function populateData($c_id, CommonDBTM $item) //values are defined by user if (isset($item->input[$field['name']])) { $data[$field['name']] = $item->input[$field['name']]; - $has_fields = true; + $has_fields = true; } else { //multi dropdown is empty or has been emptied $data[$field['name']] = []; } @@ -1866,32 +1879,32 @@ public static function getAddSearchOptions($itemtype, $containers_id = false) Session::isCron() ? new QueryExpression(sprintf('%s AS %s', READ + CREATE, $DB->quoteName('right'))) : 'glpi_plugin_fields_profiles.right' - ) + ), ], - 'DISTINCT' => true, - 'FROM' => 'glpi_plugin_fields_fields', + 'DISTINCT' => true, + 'FROM' => 'glpi_plugin_fields_fields', 'INNER JOIN' => [ 'glpi_plugin_fields_containers' => [ 'FKEY' => [ 'glpi_plugin_fields_containers' => 'id', 'glpi_plugin_fields_fields' => 'plugin_fields_containers_id', - ] + ], ], 'glpi_plugin_fields_profiles' => [ 'FKEY' => [ 'glpi_plugin_fields_containers' => 'id', 'glpi_plugin_fields_profiles' => 'plugin_fields_containers_id', - ] + ], ], ], 'WHERE' => [ - 'glpi_plugin_fields_containers.is_active' => 1, - 'glpi_plugin_fields_containers.itemtypes' => ['LIKE', '%' . $DB->escape($search_string) . '%'], - 'glpi_plugin_fields_profiles.right' => ['>', 0], - 'glpi_plugin_fields_fields.is_active' => 1, - ['NOT' => ['glpi_plugin_fields_fields.type' => 'header']], + 'glpi_plugin_fields_containers.is_active' => 1, + 'glpi_plugin_fields_containers.itemtypes' => ['LIKE', '%' . $DB->escape($search_string) . '%'], + 'glpi_plugin_fields_profiles.right' => ['>', 0], + 'glpi_plugin_fields_fields.is_active' => 1, + ['NOT' => ['glpi_plugin_fields_fields.type' => 'header']], ], - 'ORDERBY' => [ + 'ORDERBY' => [ 'glpi_plugin_fields_fields.id', ], ]; @@ -1899,7 +1912,7 @@ public static function getAddSearchOptions($itemtype, $containers_id = false) $request['WHERE'][] = ['glpi_plugin_fields_containers.id' => $containers_id]; } if (!Session::isCron()) { - $request['WHERE'][] = ['glpi_plugin_fields_profiles.profiles_id' => (int)$_SESSION['glpiactiveprofile']['id']]; + $request['WHERE'][] = ['glpi_plugin_fields_profiles.profiles_id' => (int) $_SESSION['glpiactiveprofile']['id']]; } $iterator = $DB->request($request); @@ -1912,23 +1925,23 @@ public static function getAddSearchOptions($itemtype, $containers_id = false) $container = [ 'itemtype' => PluginFieldsContainer::getType(), 'id' => $data['container_id'], - 'label' => $data['container_label'] + 'label' => $data['container_label'], ]; $data['container_label'] = PluginFieldsLabelTranslation::getLabelFor($container); $field = [ 'itemtype' => PluginFieldsField::getType(), 'id' => $data['field_id'], - 'label' => $data['field_label'] + 'label' => $data['field_label'], ]; $data['field_label'] = PluginFieldsLabelTranslation::getLabelFor($field); // Default SO params - $opt[$i]['table'] = $tablename; - $opt[$i]['field'] = $data['field_name']; - $opt[$i]['name'] = $data['container_label'] . " - " . $data['field_label']; - $opt[$i]['linkfield'] = $data['field_name']; - $opt[$i]['joinparams']['jointype'] = "itemtype_item"; + $opt[$i]['table'] = $tablename; + $opt[$i]['field'] = $data['field_name']; + $opt[$i]['name'] = $data['container_label'] . ' - ' . $data['field_label']; + $opt[$i]['linkfield'] = $data['field_name']; + $opt[$i]['joinparams']['jointype'] = 'itemtype_item'; $opt[$i]['pfields_type'] = $data['type']; $opt[$i]['pfields_fields_id'] = $data['field_id']; @@ -1938,10 +1951,10 @@ public static function getAddSearchOptions($itemtype, $containers_id = false) } switch ($data['type']) { case 'yesno': - $opt[$i]['datatype'] = "bool"; + $opt[$i]['datatype'] = 'bool'; break; case 'textarea': - $opt[$i]['datatype'] = "text"; + $opt[$i]['datatype'] = 'text'; break; case 'number': case 'date': @@ -1952,29 +1965,29 @@ public static function getAddSearchOptions($itemtype, $containers_id = false) $opt[$i]['datatype'] = 'weblink'; break; default: - $opt[$i]['datatype'] = "string"; + $opt[$i]['datatype'] = 'string'; } - $dropdown_matches = []; - if ($data['type'] === "dropdown") { - $field_name = "plugin_fields_" . $data['field_name'] . "dropdowns_id"; + $dropdown_matches = []; + if ($data['type'] === 'dropdown') { + $field_name = 'plugin_fields_' . $data['field_name'] . 'dropdowns_id'; if ($data['multiple']) { $opt[$i]['table'] = $tablename; $opt[$i]['field'] = $field_name; - $opt[$i]['searchtype'] = ['equals', 'notequals']; + $opt[$i]['searchtype'] = ['equals', 'notequals']; $opt[$i]['datatype'] = 'specific'; } else { - $opt[$i]['table'] = 'glpi_plugin_fields_' . $data['field_name'] . 'dropdowns'; - $opt[$i]['field'] = 'completename'; - $opt[$i]['linkfield'] = $field_name; - $opt[$i]['datatype'] = "dropdown"; + $opt[$i]['table'] = 'glpi_plugin_fields_' . $data['field_name'] . 'dropdowns'; + $opt[$i]['field'] = 'completename'; + $opt[$i]['linkfield'] = $field_name; + $opt[$i]['datatype'] = 'dropdown'; $opt[$i]['forcegroupby'] = true; - $opt[$i]['joinparams']['jointype'] = ""; - $opt[$i]['joinparams']['beforejoin']['table'] = $tablename; - $opt[$i]['joinparams']['beforejoin']['joinparams']['jointype'] = "itemtype_item"; + $opt[$i]['joinparams']['jointype'] = ''; + $opt[$i]['joinparams']['beforejoin']['table'] = $tablename; + $opt[$i]['joinparams']['beforejoin']['joinparams']['jointype'] = 'itemtype_item'; } } elseif ( preg_match('/^dropdown-(?.+)$/i', $data['type'], $dropdown_matches) @@ -1982,43 +1995,43 @@ public static function getAddSearchOptions($itemtype, $containers_id = false) ) { if ($data['multiple']) { $opt[$i]['datatype'] = 'specific'; - $opt[$i]['searchtype'] = ['equals', 'notequals']; + $opt[$i]['searchtype'] = ['equals', 'notequals']; } else { - $opt[$i]['table'] = CommonDBTM::getTable($dropdown_matches['class']); - $opt[$i]['field'] = 'name'; - $opt[$i]['right'] = 'all'; - $opt[$i]['datatype'] = "dropdown"; + $opt[$i]['table'] = CommonDBTM::getTable($dropdown_matches['class']); + $opt[$i]['field'] = 'name'; + $opt[$i]['right'] = 'all'; + $opt[$i]['datatype'] = 'dropdown'; $opt[$i]['forcegroupby'] = true; - $opt[$i]['joinparams']['jointype'] = ""; - $opt[$i]['joinparams']['beforejoin']['table'] = $tablename; - $opt[$i]['joinparams']['beforejoin']['joinparams']['jointype'] = "itemtype_item"; + $opt[$i]['joinparams']['jointype'] = ''; + $opt[$i]['joinparams']['beforejoin']['table'] = $tablename; + $opt[$i]['joinparams']['beforejoin']['joinparams']['jointype'] = 'itemtype_item'; } - } elseif ($data['type'] === "glpi_item") { + } elseif ($data['type'] === 'glpi_item') { $itemtype_field = sprintf('itemtype_%s', $data['field_name']); $items_id_field = sprintf('items_id_%s', $data['field_name']); - $opt[$i]['table'] = $tablename; - $opt[$i]['field'] = $itemtype_field; - $opt[$i]['linkfield'] = $itemtype_field; - $opt[$i]['name'] = $data['container_label'] . " - " . $data['field_label'] . ' - ' . _n('Associated item type', 'Associated item types', Session::getPluralNumber()); - $opt[$i]['datatype'] = 'itemtypename'; - $opt[$i]['types'] = !empty($data['allowed_values']) ? json_decode($data['allowed_values']) : []; - $opt[$i]['additionalfields'] = ['itemtype']; + $opt[$i]['table'] = $tablename; + $opt[$i]['field'] = $itemtype_field; + $opt[$i]['linkfield'] = $itemtype_field; + $opt[$i]['name'] = $data['container_label'] . ' - ' . $data['field_label'] . ' - ' . _n('Associated item type', 'Associated item types', Session::getPluralNumber()); + $opt[$i]['datatype'] = 'itemtypename'; + $opt[$i]['types'] = !empty($data['allowed_values']) ? json_decode($data['allowed_values']) : []; + $opt[$i]['additionalfields'] = ['itemtype']; $opt[$i]['joinparams']['jointype'] = 'itemtype_item'; - $opt[$i]['forcegroupby'] = true; - $opt[$i]['massiveaction'] = false; + $opt[$i]['forcegroupby'] = true; + $opt[$i]['massiveaction'] = false; $i++; - $opt[$i]['table'] = $tablename; - $opt[$i]['field'] = $items_id_field; - $opt[$i]['linkfield'] = $items_id_field; - $opt[$i]['name'] = $data['container_label'] . " - " . $data['field_label'] . ' - ' . __('Associated item ID'); - $opt[$i]['massiveaction'] = false; + $opt[$i]['table'] = $tablename; + $opt[$i]['field'] = $items_id_field; + $opt[$i]['linkfield'] = $items_id_field; + $opt[$i]['name'] = $data['container_label'] . ' - ' . $data['field_label'] . ' - ' . __('Associated item ID'); + $opt[$i]['massiveaction'] = false; $opt[$i]['joinparams']['jointype'] = 'itemtype_item'; - $opt[$i]['datatype'] = 'text'; - $opt[$i]['additionalfields'] = ['itemtype']; + $opt[$i]['datatype'] = 'text'; + $opt[$i]['additionalfields'] = ['itemtype']; } } @@ -2044,7 +2057,7 @@ private static function getSubtypes($item) 'Entity$3' => __('Advanced information'), 'Entity$4' => __('Notifications'), 'Entity$5' => __('Assistance'), - 'Entity$6' => __('Assets') + 'Entity$6' => __('Assets'), ]; break; default: @@ -2074,7 +2087,7 @@ public static function getClassname(string $itemtype, string $container_name, st return sprintf( 'PluginFields%s%s', ucfirst(self::getSystemName($itemtype, $container_name)), - $suffix + $suffix, ); } @@ -2091,10 +2104,9 @@ protected static function getSystemName(string $itemtype, string $container_name return strtolower(str_replace('\\', '', $itemtype) . preg_replace('/s$/', '', $container_name)); } - public static function getIcon() { - return "fas fa-tasks"; + return 'fas fa-tasks'; } public static function getNameField() diff --git a/inc/containerdisplaycondition.class.php b/inc/containerdisplaycondition.class.php index 9dd72eef..5d20bb71 100644 --- a/inc/containerdisplaycondition.class.php +++ b/inc/containerdisplaycondition.class.php @@ -38,13 +38,13 @@ class PluginFieldsContainerDisplayCondition extends CommonDBChild public static $itemtype = PluginFieldsContainer::class; public static $items_id = 'plugin_fields_containers_id'; - const SHOW_CONDITION_EQ = 1; - const SHOW_CONDITION_NE = 2; - const SHOW_CONDITION_LT = 3; - const SHOW_CONDITION_GT = 4; - const SHOW_CONDITION_REGEX = 5; - const SHOW_CONDITION_UNDER = 6; - const SHOW_CONDITION_NOT_UNDER = 7; + public const SHOW_CONDITION_EQ = 1; + public const SHOW_CONDITION_NE = 2; + public const SHOW_CONDITION_LT = 3; + public const SHOW_CONDITION_GT = 4; + public const SHOW_CONDITION_REGEX = 5; + public const SHOW_CONDITION_UNDER = 6; + public const SHOW_CONDITION_NOT_UNDER = 7; /** * Install or update plugin base data. @@ -58,13 +58,13 @@ public static function installBaseData(Migration $migration, $version) { /** @var DBmysql $DB */ global $DB; - $default_charset = DBConnection::getDefaultCharset(); + $default_charset = DBConnection::getDefaultCharset(); $default_collation = DBConnection::getDefaultCollation(); - $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); - $table = self::getTable(); + $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); + $table = self::getTable(); if (!$DB->tableExists($table)) { - $migration->displayMessage(sprintf(__("Installing %s"), $table)); + $migration->displayMessage(sprintf(__('Installing %s'), $table)); $query = "CREATE TABLE IF NOT EXISTS `$table` ( `id` INT {$default_key_sign} NOT NULL auto_increment, `plugin_fields_containers_id` INT {$default_key_sign} NOT NULL DEFAULT '0', @@ -100,13 +100,13 @@ private static function getComparisonOperators( ]; if ($with_treedropdown_conditions) { - $conditions[self::SHOW_CONDITION_UNDER] = __('under', 'fields'); + $conditions[self::SHOW_CONDITION_UNDER] = __('under', 'fields'); $conditions[self::SHOW_CONDITION_NOT_UNDER] = __('not under', 'fields'); } if (!$only_simple_conditions) { - $conditions[self::SHOW_CONDITION_LT] = '<'; - $conditions[self::SHOW_CONDITION_GT] = '>'; + $conditions[self::SHOW_CONDITION_LT] = '<'; + $conditions[self::SHOW_CONDITION_GT] = '>'; $conditions[self::SHOW_CONDITION_REGEX] = __('regular expression matches', 'fields'); } @@ -140,41 +140,39 @@ public static function getConditionName($condition) } } - public static function uninstall() { /** @var DBmysql $DB */ global $DB; - $DB->query("DROP TABLE IF EXISTS `" . self::getTable() . "`"); + $DB->query('DROP TABLE IF EXISTS `' . self::getTable() . '`'); + return true; } - public static function getTypeName($nb = 0) { return _n('Condition to hide block', 'Conditions to hide block', $nb, 'fields'); } - public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { return self::createTabEntry( self::getTypeName(Session::getPluralNumber()), - countElementsInTable(self::getTable(), ['plugin_fields_containers_id' => $item->getID()]) + countElementsInTable(self::getTable(), ['plugin_fields_containers_id' => $item->getID()]), ); } - public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { if ($item instanceof PluginFieldsContainer) { self::showForTabContainer($item); + return true; } + return false; } - public static function getDisplayConditionForContainer(int $container_id): array { /** @var DBmysql $DB */ @@ -183,20 +181,20 @@ public static function getDisplayConditionForContainer(int $container_id): array 'SELECT' => [ self::getTable() . '.*', ], - 'FROM' => self::getTable(), - 'WHERE' => [ + 'FROM' => self::getTable(), + 'WHERE' => [ 'plugin_fields_containers_id' => $container_id, - ] + ], ]); $conditions = []; foreach ($iterator as $data) { $conditions[] = $data; } + return $conditions; } - private static function getItemtypesForContainer(int $container_id): array { /** @var DBmysql $DB */ @@ -209,7 +207,7 @@ private static function getItemtypesForContainer(int $container_id): array 'FROM' => PluginFieldsContainer::getTable(), 'WHERE' => [ 'id' => $container_id, - ] + ], ]); if (count($iterator)) { @@ -223,35 +221,31 @@ private static function getItemtypesForContainer(int $container_id): array return $results; } - public static function getFieldName($so_id, $itemtype) { echo Search::getOptions($itemtype)[$so_id]['name']; } - public static function showItemtypeFieldForm($itemtype) { - $rand = mt_rand(); - $out = ""; - $out .= Dropdown::showFromArray("search_option", self::removeBlackListedOption(Search::getOptions($itemtype), $itemtype), ["display_emptychoice" => true, "display" => false, 'rand' => $rand]); + $out = ''; + $out .= Dropdown::showFromArray('search_option', self::removeBlackListedOption(Search::getOptions($itemtype), $itemtype), ['display_emptychoice' => true, 'display' => false, 'rand' => $rand]); $out .= Ajax::updateItemOnSelectEvent( - "dropdown_search_option" . $rand, - "results_condition", + 'dropdown_search_option' . $rand, + 'results_condition', Plugin::getWebDir('fields') . '/ajax/container_display_condition.php', [ - 'search_option_id' => '__VALUE__', - 'itemtype' => $itemtype, - 'action' => 'get_condition_switch_so' - ] + 'search_option_id' => '__VALUE__', + 'itemtype' => $itemtype, + 'action' => 'get_condition_switch_so', + ], ); echo $out; } - public static function showSearchOptionCondition($searchoption_id, $itemtype, ?string $condition = null, ?string $value = null) { $so = Search::getOptions($itemtype)[$searchoption_id]; @@ -268,11 +262,11 @@ public static function showSearchOptionCondition($searchoption_id, $itemtype, ?s ]; if ($so['datatype'] == 'dropdown' || ($so['datatype'] == 'itemlink' && $so['table'] !== $itemtypetable)) { - $twig_params['is_dropdown'] = true; + $twig_params['is_dropdown'] = true; $twig_params['dropdown_itemtype'] = getItemTypeForTable($so['table']); $twig_params['list_conditions'] = self::getComparisonOperators( true, - is_a($twig_params['dropdown_itemtype'], CommonTreeDropdown::class, true) + is_a($twig_params['dropdown_itemtype'], CommonTreeDropdown::class, true), ); $twig_params['dropdown_option'] = []; @@ -280,50 +274,48 @@ public static function showSearchOptionCondition($searchoption_id, $itemtype, ?s $twig_params['dropdown_option'] = ['right' => 'all']; } } elseif ($so['datatype'] == 'specific' && get_parent_class($itemtype) == CommonITILObject::getType()) { - $twig_params['list_conditions'] = self::getComparisonOperators(true); - $twig_params['is_specific'] = true; + $twig_params['list_conditions'] = self::getComparisonOperators(true); + $twig_params['is_specific'] = true; switch ($so['field']) { case 'status': $twig_params['is_list_values'] = true; - $twig_params['list_values'] = $itemtype::getAllStatusArray(false); + $twig_params['list_values'] = $itemtype::getAllStatusArray(false); break; case 'type': - $twig_params['is_list_values'] = true; - $twig_params['list_values'] = $itemtype::getTypes(); + $twig_params['is_list_values'] = true; + $twig_params['list_values'] = $itemtype::getTypes(); break; case 'impact': case 'urgency': case 'priority': - $twig_params['item'] = new $itemtype(); + $twig_params['item'] = new $itemtype(); $twig_params['itemtype_field'] = $so['field']; break; case 'global_validation': $twig_params['is_list_values'] = true; - $twig_params['list_values'] = CommonITILValidation::getAllStatusArray(false, true); + $twig_params['list_values'] = CommonITILValidation::getAllStatusArray(false, true); break; } } else { - $twig_params['list_conditions'] = self::getComparisonOperators(); + $twig_params['list_conditions'] = self::getComparisonOperators(); } TemplateRenderer::getInstance()->display('@fields/forms/container_display_condition_so_condition.html.twig', $twig_params); } - public static function getRawValue($searchoption_id, $itemtype, $value) { - - $so = Search::getOptions($itemtype)[$searchoption_id]; + $so = Search::getOptions($itemtype)[$searchoption_id]; $itemtypetable = $itemtype::getTable(); $raw_value = ''; if ($so['datatype'] == 'dropdown' || ($so['datatype'] == 'itemlink' && $so['table'] !== $itemtypetable)) { $dropdown_itemtype = getItemTypeForTable($so['table']); - $dropdown = new $dropdown_itemtype(); + $dropdown = new $dropdown_itemtype(); $dropdown->getFromDB($value); $raw_value = $dropdown->fields['name']; - } else if ($so['datatype'] == 'specific' && get_parent_class($itemtype) == CommonITILObject::getType()) { + } elseif ($so['datatype'] == 'specific' && get_parent_class($itemtype) == CommonITILObject::getType()) { switch ($so['field']) { case 'status': $raw_value = $itemtype::getStatus($value); @@ -351,12 +343,10 @@ public static function getRawValue($searchoption_id, $itemtype, $value) echo $raw_value; } - public static function removeBlackListedOption($array, $itemtype_class) { - $itemtype_object = new $itemtype_class(); - $allowed_so = []; + $allowed_so = []; //remove "Common" unset($array['common']); @@ -386,29 +376,28 @@ public static function removeBlackListedOption($array, $itemtype_class) } //allow specific datatype - $allowed_datatype = ["email", "weblink", "specific", "itemlink", "string", "text","number", "dropdown", "decimal", "integer", "bool"]; + $allowed_datatype = ['email', 'weblink', 'specific', 'itemlink', 'string', 'text', 'number', 'dropdown', 'decimal', 'integer', 'bool']; foreach ($array as $subKey => $subArray) { if ( - isset($subArray["table"]) && in_array($subArray["table"], $allowed_table) - && (isset($subArray["datatype"]) && in_array($subArray["datatype"], $allowed_datatype)) - && !isset($subArray["nosearch"]) //Exclude SO with no search - && !isset($subArray["usehaving"]) //Exclude count SO ex: Ticket -> Number of sons tickets - && !isset($subArray["forcegroupby"]) //Exclude 1-n relation ex: Ticket_User - && !isset($subArray["computation"]) //Exclude SO with computation Ex : Ticket -> Time to own exceeded + isset($subArray['table']) && in_array($subArray['table'], $allowed_table) + && (isset($subArray['datatype']) && in_array($subArray['datatype'], $allowed_datatype)) + && !isset($subArray['nosearch']) //Exclude SO with no search + && !isset($subArray['usehaving']) //Exclude count SO ex: Ticket -> Number of sons tickets + && !isset($subArray['forcegroupby']) //Exclude 1-n relation ex: Ticket_User + && !isset($subArray['computation']) //Exclude SO with computation Ex : Ticket -> Time to own exceeded ) { - $allowed_so[$subKey] = $subArray["name"]; + $allowed_so[$subKey] = $subArray['name']; } } return $allowed_so; } - public function computeDisplayContainer($item, $container_id) { //load all condition for itemtype and container $displayCondition = new self(); - $found_dc = $displayCondition->find(['itemtype' => get_class($item), 'plugin_fields_containers_id' => $container_id]); + $found_dc = $displayCondition->find(['itemtype' => get_class($item), 'plugin_fields_containers_id' => $container_id]); if (count($found_dc)) { $display = true; @@ -427,11 +416,10 @@ public function computeDisplayContainer($item, $container_id) } } - public function checkCondition($item) { - $value = $this->fields['value']; - $condition = $this->fields['condition']; + $value = $this->fields['value']; + $condition = $this->fields['condition']; $searchOption = Search::getOptions(get_class($item))[$this->fields['search_option']]; $fields = array_merge($item->fields, $item->input); @@ -465,7 +453,7 @@ public function checkCondition($item) //'regex'; if (self::checkRegex($value)) { $value = Sanitizer::unsanitize($value); - if (preg_match_all($value . "i", $fields[$searchOption['linkfield']]) > 0) { + if (preg_match_all($value . 'i', $fields[$searchOption['linkfield']]) > 0) { return false; } } @@ -487,14 +475,13 @@ public function checkCondition($item) return true; } - public static function checkRegex($regex) { // Avoid php notice when validating the regular expression - set_error_handler(function ($errno, $errstr, $errfile, $errline) { - }); + set_error_handler(function ($errno, $errstr, $errfile, $errline) {}); $isValid = !(preg_match($regex, null) === false); restore_error_handler(); + return $isValid; } @@ -505,8 +492,9 @@ public function prepareInputForAdd($input) Session::addMessageAfterRedirect( __('You must specify an item type, search option and condition.', 'fields'), true, - ERROR + ERROR, ); + return false; } @@ -520,18 +508,19 @@ public function prepareInputForUpdate($input) Session::addMessageAfterRedirect( __('You must specify an item type, search option and condition.', 'fields'), true, - ERROR + ERROR, ); + return false; } + return parent::prepareInputForUpdate($input); } public static function showForTabContainer(CommonGLPI $item, $options = []) { - $displayCondition_id = $options['displaycondition_id'] ?? 0; - $display_condition = null; + $display_condition = null; if ($displayCondition_id) { $display_condition = new self(); @@ -539,13 +528,13 @@ public static function showForTabContainer(CommonGLPI $item, $options = []) } $container_id = $item->getID(); - $has_fields = countElementsInTable(PluginFieldsField::getTable(), [ - 'plugin_fields_containers_id' => $container_id + $has_fields = countElementsInTable(PluginFieldsField::getTable(), [ + 'plugin_fields_containers_id' => $container_id, ]) > 0; $twig_params = [ - 'container_id' => $container_id, - 'container_display_conditions' => self::getDisplayConditionForContainer($container_id), - 'has_fields' => $has_fields, + 'container_id' => $container_id, + 'container_display_conditions' => self::getDisplayConditionForContainer($container_id), + 'has_fields' => $has_fields, ]; TemplateRenderer::getInstance()->display('@fields/container_display_conditions.html.twig', $twig_params); diff --git a/inc/dropdown.class.php b/inc/dropdown.class.php index 7b1f36f8..c3810aa7 100644 --- a/inc/dropdown.class.php +++ b/inc/dropdown.class.php @@ -30,7 +30,7 @@ class PluginFieldsDropdown { - public static $rightname = 'dropdown'; + public static $rightname = 'dropdown'; public $can_be_translated = true; /** @@ -48,21 +48,21 @@ public static function installUserData(Migration $migration, $version) // NEW path: PLUGINFIELDS_CLASS_PATH . "/$class_filename" // OLD path: GLPI_ROOT."/plugins/fields/front/$class_filename" // NEW path: PLUGINFIELDS_FRONT_PATH . "/$class_filename" - $obj = new PluginFieldsField(); + $obj = new PluginFieldsField(); $fields = $obj->find(['type' => 'dropdown']); foreach ($fields as $field) { //First, drop old fields from plugin directories - $class_filename = $field['name'] . "dropdown.class.php"; + $class_filename = $field['name'] . 'dropdown.class.php'; if (file_exists(PLUGINFIELDS_DIR . "/inc/$class_filename")) { unlink(PLUGINFIELDS_DIR . "/inc/$class_filename"); } - $front_filename = $field['name'] . "dropdown.php"; + $front_filename = $field['name'] . 'dropdown.php'; if (file_exists(PLUGINFIELDS_DIR . "/front/$front_filename")) { unlink(PLUGINFIELDS_DIR . "/front/$front_filename"); } - $form_filename = $field['name'] . "dropdown.form.php"; + $form_filename = $field['name'] . 'dropdown.form.php'; if (file_exists(PLUGINFIELDS_DIR . "/front/$form_filename")) { unlink(PLUGINFIELDS_DIR . "/front/$form_filename"); } @@ -75,8 +75,8 @@ public static function installUserData(Migration $migration, $version) $migration->executeMigration(); // Regenerate files and install missing tables - $migration->displayMessage(__("Updating generated dropdown files", "fields")); - $obj = new PluginFieldsField(); + $migration->displayMessage(__('Updating generated dropdown files', 'fields')); + $obj = new PluginFieldsField(); $fields = $obj->find(['type' => 'dropdown']); foreach ($fields as $field) { self::create($field); @@ -91,21 +91,22 @@ public static function uninstall() global $DB; //remove dropdown tables and files - if ($DB->tableExists("glpi_plugin_fields_fields")) { - require_once "field.class.php"; - $field = new PluginFieldsField(); + if ($DB->tableExists('glpi_plugin_fields_fields')) { + require_once 'field.class.php'; + $field = new PluginFieldsField(); $dropdowns = $field->find(['type' => 'dropdown']); foreach ($dropdowns as $dropdown) { self::destroy($dropdown['name']); } } + return true; } public static function create($input) { //get class template - $template_class = file_get_contents(PLUGINFIELDS_DIR . "/templates/dropdown.class.tpl"); + $template_class = file_get_contents(PLUGINFIELDS_DIR . '/templates/dropdown.class.tpl'); if ($template_class === false) { return false; } @@ -114,72 +115,76 @@ public static function create($input) //create dropdown class file $template_class = str_replace( - "%%CLASSNAME%%", + '%%CLASSNAME%%', $classname, - $template_class + $template_class, ); $template_class = str_replace( - "%%FIELDNAME%%", + '%%FIELDNAME%%', $input['name'], - $template_class + $template_class, ); $template_class = str_replace( - "%%FIELDID%%", + '%%FIELDID%%', $input['id'], - $template_class + $template_class, ); $template_class = str_replace( - "%%LABEL%%", + '%%LABEL%%', $input['label'], - $template_class + $template_class, ); - $class_filename = $input['name'] . "dropdown.class.php"; + $class_filename = $input['name'] . 'dropdown.class.php'; if ( file_put_contents( PLUGINFIELDS_CLASS_PATH . "/$class_filename", - $template_class + $template_class, ) === false ) { Toolbox::logDebug("Error : dropdown class file creation - $class_filename"); + return false; } //get front template - $template_front = file_get_contents(PLUGINFIELDS_DIR . "/templates/dropdown.tpl"); + $template_front = file_get_contents(PLUGINFIELDS_DIR . '/templates/dropdown.tpl'); if ($template_front === false) { - Toolbox::logDebug("Error : get dropdown front template error"); + Toolbox::logDebug('Error : get dropdown front template error'); + return false; } //create dropdown front file - $template_front = str_replace("%%CLASSNAME%%", $classname, $template_front); - $front_filename = $input['name'] . "dropdown.php"; + $template_front = str_replace('%%CLASSNAME%%', $classname, $template_front); + $front_filename = $input['name'] . 'dropdown.php'; if ( file_put_contents( PLUGINFIELDS_FRONT_PATH . "/$front_filename", - $template_front + $template_front, ) === false ) { Toolbox::logDebug("Error : dropdown front file creation - $class_filename"); + return false; } //get form template - $template_form = file_get_contents(PLUGINFIELDS_DIR . "/templates/dropdown.form.tpl"); + $template_form = file_get_contents(PLUGINFIELDS_DIR . '/templates/dropdown.form.tpl'); if ($template_form === false) { return false; } //create dropdown form file - $template_form = str_replace("%%CLASSNAME%%", $classname, $template_form); - $form_filename = $input['name'] . "dropdown.form.php"; + $template_form = str_replace('%%CLASSNAME%%', $classname, $template_form); + $form_filename = $input['name'] . 'dropdown.form.php'; if ( file_put_contents( PLUGINFIELDS_FRONT_PATH . "/$form_filename", - $template_form + $template_form, ) === false ) { - Toolbox::logDebug("Error : get dropdown form template error"); + Toolbox::logDebug('Error : get dropdown form template error'); + return false; } @@ -191,6 +196,7 @@ public static function create($input) //call install method (create table) if ($classname::install() === false) { Toolbox::logDebug("Error : calling dropdown $classname installation"); + return false; } @@ -202,37 +208,41 @@ public static function create($input) public static function destroy($dropdown_name) { - $classname = self::getClassname($dropdown_name); - $class_filename = PLUGINFIELDS_CLASS_PATH . "/" . $dropdown_name . "dropdown.class.php"; + $classname = self::getClassname($dropdown_name); + $class_filename = PLUGINFIELDS_CLASS_PATH . '/' . $dropdown_name . 'dropdown.class.php'; //call uninstall method in dropdown class if ($classname::uninstall() === false) { Toolbox::logDebug("Error : calling dropdown $classname uninstallation"); + return false; } //remove class file for this dropdown if (file_exists($class_filename)) { if (unlink($class_filename) === false) { - Toolbox::logDebug("Error : dropdown class file creation - " . $dropdown_name . "dropdown.class.php"); + Toolbox::logDebug('Error : dropdown class file creation - ' . $dropdown_name . 'dropdown.class.php'); + return false; } } //remove front file for this dropdown - $front_filename = PLUGINFIELDS_FRONT_PATH . "/" . $dropdown_name . "dropdown.php"; + $front_filename = PLUGINFIELDS_FRONT_PATH . '/' . $dropdown_name . 'dropdown.php'; if (file_exists($front_filename)) { if (unlink($front_filename) === false) { - Toolbox::logDebug("Error : dropdown front file removing - " . $dropdown_name . "dropdown.php"); + Toolbox::logDebug('Error : dropdown front file removing - ' . $dropdown_name . 'dropdown.php'); + return false; } } //remove front.form file for this dropdown - $form_filename = PLUGINFIELDS_FRONT_PATH . "/" . $dropdown_name . "dropdown.form.php"; + $form_filename = PLUGINFIELDS_FRONT_PATH . '/' . $dropdown_name . 'dropdown.form.php'; if (file_exists($form_filename)) { if (unlink($form_filename) === false) { - Toolbox::logDebug("Error : dropdown form file removing - " . $dropdown_name . "dropdown.form.php"); + Toolbox::logDebug('Error : dropdown form file removing - ' . $dropdown_name . 'dropdown.form.php'); + return false; } } @@ -242,6 +252,6 @@ public static function destroy($dropdown_name) public static function getClassname($system_name) { - return "PluginFields" . ucfirst($system_name) . "Dropdown"; + return 'PluginFields' . ucfirst($system_name) . 'Dropdown'; } } diff --git a/inc/field.class.php b/inc/field.class.php index b9aeb8fb..8e32845d 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -44,15 +44,14 @@ class PluginFieldsField extends CommonDBChild public static $itemtype = PluginFieldsContainer::class; public static $items_id = 'plugin_fields_containers_id'; - public function getForbiddenStandardMassiveAction() { $forbidden = parent::getForbiddenStandardMassiveAction(); $forbidden[] = 'clone'; + return $forbidden; } - /** * Install or update plugin base data. * @@ -66,14 +65,14 @@ public static function installBaseData(Migration $migration, $version) /** @var DBmysql $DB */ global $DB; - $default_charset = DBConnection::getDefaultCharset(); + $default_charset = DBConnection::getDefaultCharset(); $default_collation = DBConnection::getDefaultCollation(); - $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); + $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); $table = self::getTable(); if (!$DB->tableExists($table)) { - $migration->displayMessage(sprintf(__("Installing %s"), $table)); + $migration->displayMessage(sprintf(__('Installing %s'), $table)); $query = "CREATE TABLE IF NOT EXISTS `$table` ( `id` INT {$default_key_sign} NOT NULL auto_increment, @@ -131,16 +130,16 @@ public static function installBaseData(Migration $migration, $version) $DB->buildUpdate( PluginFieldsField::getTable(), ['type' => 'dropdown-User'], - ['type' => 'dropdownuser'] - ) + ['type' => 'dropdownuser'], + ), ); $migration->addPostQuery( $DB->buildUpdate( PluginFieldsField::getTable(), ['type' => 'dropdown-OperatingSystem'], - ['type' => 'dropdownoperatingsystems'] - ) + ['type' => 'dropdownoperatingsystems'], + ), ); // 1.18.3 Make search options ID stable over time ad constant across profiles @@ -188,7 +187,7 @@ private static function migrateToStableSO(Migration $migration): void $fields = $DB->request( [ - 'SELECT' => [ + 'SELECT' => [ 'glpi_plugin_fields_fields.id', ], 'FROM' => 'glpi_plugin_fields_fields', @@ -200,19 +199,19 @@ private static function migrateToStableSO(Migration $migration): void [ 'AND' => [ 'glpi_plugin_fields_containers.is_active' => 1, - ] - ] - ] + ], + ], + ], ], ], 'WHERE' => [ 'glpi_plugin_fields_containers.itemtypes' => ['LIKE', '%' . $DB->escape($search_string) . '%'], - ['NOT' => ['glpi_plugin_fields_fields.type' => 'header']], + ['NOT' => ['glpi_plugin_fields_fields.type' => 'header']], ], - 'ORDERBY' => [ + 'ORDERBY' => [ 'glpi_plugin_fields_fields.id', ], - ] + ], ); $i = PluginFieldsField::SEARCH_OPTION_STARTING_INDEX; @@ -221,7 +220,7 @@ private static function migrateToStableSO(Migration $migration): void $migration->changeSearchOption( $itemtype, $i, - PluginFieldsField::SEARCH_OPTION_STARTING_INDEX + $field_data['id'] + PluginFieldsField::SEARCH_OPTION_STARTING_INDEX + $field_data['id'], ); $i++; @@ -234,17 +233,16 @@ public static function uninstall() /** @var DBmysql $DB */ global $DB; - $DB->query("DROP TABLE IF EXISTS `" . self::getTable() . "`"); + $DB->query('DROP TABLE IF EXISTS `' . self::getTable() . '`'); return true; } public static function getTypeName($nb = 0) { - return __("Field", "fields"); + return __('Field', 'fields'); } - public function prepareInputForAdd($input) { //parse name @@ -257,46 +255,49 @@ public function prepareInputForAdd($input) //reject adding when field name is too long for mysql if (strlen($input['name']) > 64) { Session::AddMessageAfterRedirect( - __("Field name is too long for database (digits in name are replaced by characters, try to remove them)", 'fields'), + __('Field name is too long for database (digits in name are replaced by characters, try to remove them)', 'fields'), false, - ERROR + ERROR, ); + return false; } - if ($input['type'] === "dropdown") { + if ($input['type'] === 'dropdown') { //search if dropdown already exist in this container $found = $this->find( [ - 'name' => $input['name'], + 'name' => $input['name'], 'plugin_fields_containers_id' => $input['plugin_fields_containers_id'], - ] + ], ); //reject adding for same dropdown on same bloc if (!empty($found)) { Session::AddMessageAfterRedirect(__("You cannot add same field 'dropdown' on same bloc", 'fields'), false, ERROR); + return false; } //reject adding when dropdown name is too long for mysql table name if (strlen(getTableForItemType(PluginFieldsDropdown::getClassname($input['name']))) > 64) { Session::AddMessageAfterRedirect( - __("Field name is too long for database (digits in name are replaced by characters, try to remove them)", 'fields'), + __('Field name is too long for database (digits in name are replaced by characters, try to remove them)', 'fields'), false, - ERROR + ERROR, ); + return false; } } // Before adding, add the ranking of the new field - if (empty($input["ranking"])) { - $input["ranking"] = $this->getNextRanking(); + if (empty($input['ranking'])) { + $input['ranking'] = $this->getNextRanking(); } //add field to container table - if ($input['type'] !== "header") { + if ($input['type'] !== 'header') { $container_obj = new PluginFieldsContainer(); $container_obj->getFromDB($input['plugin_fields_containers_id']); foreach (json_decode($container_obj->fields['itemtypes']) as $itemtype) { @@ -305,8 +306,8 @@ public function prepareInputForAdd($input) $input['name'], $input['type'], [ - 'multiple' => (bool)($input['multiple'] ?? false) - ] + 'multiple' => (bool) ($input['multiple'] ?? false), + ], ); } } @@ -318,7 +319,6 @@ public function prepareInputForAdd($input) return $input; } - public function prepareInputForUpdate($input) { if ( @@ -331,13 +331,12 @@ public function prepareInputForUpdate($input) return $input; } - private function cleanDisplayPreferences($itemtype, $so_id) { $displayPref = new DisplayPreference(); $displayPref->deleteByCriteria([ - "itemtype" => $itemtype, - "num" => $so_id + 'itemtype' => $itemtype, + 'num' => $so_id, ]); } @@ -353,13 +352,13 @@ public function pre_deleteItem() foreach ($so as $so_id => $so_value) { if ($this->fields['type'] == 'glpi_item') { if ( - $so_value['field'] == "items_id_" . $this->fields['name'] - || $so_value['field'] == "itemtype_" . $this->fields['name'] + $so_value['field'] == 'items_id_' . $this->fields['name'] + || $so_value['field'] == 'itemtype_' . $this->fields['name'] ) { $this->cleanDisplayPreferences($itemtype, $so_id); } } elseif ($this->fields['type'] == 'dropdown') { - if ($so_value['linkfield'] == "plugin_fields_" . $this->fields['name'] . "dropdowns_id") { + if ($so_value['linkfield'] == 'plugin_fields_' . $this->fields['name'] . 'dropdowns_id') { $this->cleanDisplayPreferences($itemtype, $so_id); } } else { @@ -372,7 +371,7 @@ public function pre_deleteItem() //remove field in container table if ( - $this->fields['type'] !== "header" + $this->fields['type'] !== 'header' && !isset($_SESSION['uninstall_fields']) && !isset($_SESSION['delete_container']) ) { @@ -386,12 +385,13 @@ public function pre_deleteItem() $translation_obj = new PluginFieldsLabelTranslation(); $translation_obj->deleteByCriteria([ 'itemtype' => self::getType(), - 'items_id' => $this->fields['id'] + 'items_id' => $this->fields['id'], ]); - if ($this->fields['type'] === "dropdown") { + if ($this->fields['type'] === 'dropdown') { return PluginFieldsDropdown::destroy($this->fields['name']); } + return true; } @@ -408,18 +408,17 @@ public function post_purgeItem() $DB->update( $table, [ - 'ranking' => new QueryExpression($DB->quoteName('ranking') . ' - 1') + 'ranking' => new QueryExpression($DB->quoteName('ranking') . ' - 1'), ], [ 'plugin_fields_containers_id' => $old_container, - 'ranking' => ['>', $old_ranking] - ] + 'ranking' => ['>', $old_ranking], + ], ); return true; } - /** * parse name for avoid non alphanumeric char in it and conflict with other fields * @param array $input the field form input @@ -435,7 +434,7 @@ public function prepareName($input, bool $prevent_duplicated = true) } //for dropdown, if already exists, link to it - if (isset($input['type']) && $input['type'] === "dropdown") { + if (isset($input['type']) && $input['type'] === 'dropdown') { $found = $this->find(['name' => $input['name']]); if (!empty($found)) { return $input['name']; @@ -472,7 +471,7 @@ public function prepareName($input, bool $prevent_duplicated = true) // but there is a bug when trying to drop the column and the real max len is 53 chars // FIXME: see: https://bugs.mysql.com/bug.php?id=107165 if (strlen($field_name) > 52) { - $rand = rand(); + $rand = rand(); $field_name = substr($field_name, 0, 52 - strlen($rand)) . $rand; } @@ -491,18 +490,20 @@ public function getNextRanking() $iterator = $DB->request([ 'SELECT' => new \QueryExpression( - 'max(' . $DB->quoteName('ranking') . ') AS ' . $DB->quoteName('rank') + 'max(' . $DB->quoteName('ranking') . ') AS ' . $DB->quoteName('rank'), ), - 'FROM' => self::getTable(), - 'WHERE' => [ - 'plugin_fields_containers_id' => $this->fields['plugin_fields_containers_id'] - ] + 'FROM' => self::getTable(), + 'WHERE' => [ + 'plugin_fields_containers_id' => $this->fields['plugin_fields_containers_id'], + ], ]); if (count($iterator) > 0) { $data = $iterator->current(); - return $data["rank"] + 1; + + return $data['rank'] + 1; } + return 0; } @@ -512,16 +513,17 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) switch ($item->getType()) { case __CLASS__: $ong[1] = $this->getTypeName(1); + return $ong; } } return self::createTabEntry( - __("Fields", "fields"), + __('Fields', 'fields'), countElementsInTable( self::getTable(), - ['plugin_fields_containers_id' => $item->getID()] - ) + ['plugin_fields_containers_id' => $item->getID()], + ), ); } @@ -529,6 +531,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ { $fup = new self(); $fup->showSummary($item); + return true; } @@ -554,19 +557,19 @@ public function showSummary($container) // Display existing Fields $iterator = $DB->request([ 'SELECT' => ['id', 'label'], - 'FROM' => self::getTable(), - 'WHERE' => ['plugin_fields_containers_id' => $cID], - 'ORDER' => 'ranking ASC' + 'FROM' => self::getTable(), + 'WHERE' => ['plugin_fields_containers_id' => $cID], + 'ORDER' => 'ranking ASC', ]); - $rand = mt_rand(); + $rand = mt_rand(); echo "
"; $ajax_params = [ 'type' => __CLASS__, 'parenttype' => PluginFieldsContainer::class, 'plugin_fields_containers_id' => $cID, - 'id' => -1 + 'id' => -1, ]; echo Html::scriptBlock(' viewAddField' . $cID . $rand . ' = function() { @@ -579,26 +582,26 @@ public function showSummary($container) echo "
"; + echo __('Add a new field', 'fields') . '
'; if (count($iterator) == 0) { echo ""; - echo "
" . __("No field for this block", "fields") . "
"; + echo "" . __('No field for this block', 'fields') . ''; } else { echo '
'; - echo Html::hidden("_plugin_fields_containers_id", ['value' => $cID, - 'id' => 'plugin_fields_containers_id' + echo Html::hidden('_plugin_fields_containers_id', ['value' => $cID, + 'id' => 'plugin_fields_containers_id', ]); echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; echo ""; - echo ""; + echo ''; $fields_type = self::getTypes(); @@ -608,12 +611,12 @@ public function showSummary($container) if ($this->getFromDB($data['id'])) { echo ""; - echo ""; - echo ""; - echo "'; + echo ''; + echo '"; - echo ""; + echo ''; + echo "'; echo ""; + echo ''; - echo ""; + echo ''; echo ''; - echo ""; + echo ''; } } } @@ -681,7 +684,6 @@ public function showSummary($container) });'); } - public function showForm($ID, $options = []) { $rand = mt_rand(); @@ -689,7 +691,7 @@ public function showForm($ID, $options = []) $container = new PluginFieldsContainer(); if (isset($options['parent_id']) && !empty($options['parent_id'])) { $container->getFromDB($options['parent_id']); - } else if ( + } elseif ( isset($options['parent']) && $options['parent'] instanceof CommonDBTM ) { @@ -698,32 +700,32 @@ public function showForm($ID, $options = []) if ($ID > 0) { $attrs = ['readonly' => 'readonly']; - $edit = true; + $edit = true; } else { $attrs = []; // Create item - $edit = false; + $edit = false; $options['plugin_fields_containers_id'] = $container->getField('id'); } $this->initForm($ID, $options); $this->showFormHeader($options); - echo ""; - echo ""; + echo ''; + echo ''; echo ""; + echo ''; - echo ""; - echo ""; - echo ""; + echo ''; + echo ''; + echo ''; echo ""; - echo ""; + echo ''; + echo ''; echo ''; echo ''; echo ''; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - - echo ""; - echo ""; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + + echo ''; + echo ''; echo ""; - echo ""; + Dropdown::showYesNo('is_readonly', $this->fields['is_readonly']); + echo ''; + echo ''; $this->showFormButtons($options); @@ -799,7 +801,7 @@ public static function showForTabContainer($c_id, $item) //get fields for this container $field_obj = new self(); - $fields = $field_obj->find(['plugin_fields_containers_id' => $c_id, 'is_active' => 1], "ranking"); + $fields = $field_obj->find(['plugin_fields_containers_id' => $c_id, 'is_active' => 1], 'ranking'); echo ""; echo Html::hidden('plugin_fields_containers_id', ['value' => $c_id]); echo Html::hidden('items_id', ['value' => $item->getID()]); @@ -810,11 +812,11 @@ public static function showForTabContainer($c_id, $item) if ($canedit) { echo ""; + _sx('button', 'Save') . "\" class='submit'>"; + echo ''; } - echo "
" . __("Label") . "" . __("Type") . "" . __("Default values") . "" . __("Mandatory field") . "" . __("Active") . "" . __("Read only", "fields") . "
' . __('Label') . '' . __('Type') . '' . __('Default values') . '' . __('Mandatory field') . '' . __('Active') . '' . __('Read only', 'fields') . ' 
"; + echo ''; $label = !empty($this->fields['label']) ? $this->fields['label'] : NOT_AVAILABLE; echo "getID()}'>{$label}"; - echo "" . $fields_type[$this->fields['type']] . "" ; + echo '' . $fields_type[$this->fields['type']] . '' ; $dropdown_matches = []; if ( preg_match('/^dropdown-(?.+)$/', $this->fields['type'], $dropdown_matches) === 1 @@ -645,7 +648,7 @@ public function showSummary($container) if ($this->fields['multiple']) { echo implode( ', ', - Dropdown::getDropdownArrayNames($table, json_decode($this->fields['default_value'])) + Dropdown::getDropdownArrayNames($table, json_decode($this->fields['default_value'])), ); } else { echo Dropdown::getDropdownName($table, $this->fields['default_value']); @@ -653,24 +656,24 @@ public function showSummary($container) } else { echo $this->fields['default_value']; } - echo "" . Dropdown::getYesNo($this->fields["mandatory"]) . "" . Dropdown::getYesNo($this->fields['mandatory']) . '"; echo ($this->isActive()) ? __('Yes') : '' . __('No') . ''; - echo ""; - echo Dropdown::getYesNo($this->fields["is_readonly"]); - echo "'; + echo Dropdown::getYesNo($this->fields['is_readonly']); + echo ''; echo '
'; echo ''; echo '
'; echo '
" . __("Label") . " :
' . __('Label') . ' : "; echo Html::hidden('plugin_fields_containers_id', ['value' => $container->getField('id')]); echo Html::input( 'label', [ 'value' => $this->fields['label'], - ] + $attrs + ] + $attrs, ); - echo "
" . __("Type") . " :
' . __('Type') . ' : "; if ($edit) { echo self::getTypes(true)[$this->fields['type']]; @@ -734,54 +736,54 @@ public function showForm($ID, $options = []) [ 'value' => $this->fields['type'], 'rand' => $rand, - ] + ], ); } - echo "
'; Ajax::updateItemOnSelectEvent( "dropdown_type$rand", "plugin_fields_specific_fields_$rand", - "../ajax/field_specific_fields.php", + '../ajax/field_specific_fields.php', [ 'id' => $ID, 'type' => '__VALUE__', 'rand' => $rand, - ] + ], ); Ajax::updateItem( "plugin_fields_specific_fields_$rand", - "../ajax/field_specific_fields.php", + '../ajax/field_specific_fields.php', [ 'id' => $ID, 'type' => $this->fields['type'] ?? '', 'rand' => $rand, - ] + ], ); echo '
" . __('Active') . " :"; - Dropdown::showYesNo('is_active', $this->fields["is_active"]); - echo "" . __("Mandatory field") . " : "; - Dropdown::showYesNo("mandatory", $this->fields["mandatory"]); - echo "
" . __("Read only", "fields") . " :
' . __('Active') . ' :'; + Dropdown::showYesNo('is_active', $this->fields['is_active']); + echo '' . __('Mandatory field') . ' : '; + Dropdown::showYesNo('mandatory', $this->fields['mandatory']); + echo '
' . __('Read only', 'fields') . ' :"; - Dropdown::showYesNo("is_readonly", $this->fields["is_readonly"]); - echo "
"; echo ""; - echo "
"; + echo ''; Html::closeForm(); return true; @@ -830,18 +832,17 @@ public static function showForTabContainer($c_id, $item) * * @return void */ - public static function showDomContainer($id, $item, $type = "dom", $subtype = "", $field_options = []) + public static function showDomContainer($id, $item, $type = 'dom', $subtype = '', $field_options = []) { - if ($id !== false) { //get fields for this container $field_obj = new self(); - $fields = $field_obj->find( + $fields = $field_obj->find( [ 'plugin_fields_containers_id' => $id, - 'is_active' => 1, + 'is_active' => 1, ], - "ranking" + 'ranking', ); } else { $fields = []; @@ -864,8 +865,8 @@ public static function showForTab($params) $item = $params['item']; $functions = array_column(debug_backtrace(), 'function'); - $subtype = isset($_SESSION['glpi_tabs'][strtolower($item::getType())]) ? $_SESSION['glpi_tabs'][strtolower($item::getType())] : ""; - $type = substr($subtype, -strlen('$main')) === '$main' + $subtype = isset($_SESSION['glpi_tabs'][strtolower($item::getType())]) ? $_SESSION['glpi_tabs'][strtolower($item::getType())] : ''; + $type = substr($subtype, -strlen('$main')) === '$main' || in_array('showForm', $functions) || in_array('showPrimaryForm', $functions) || in_array('showFormHelpdesk', $functions) @@ -877,13 +878,13 @@ public static function showForTab($params) } // if we are in 'dom' or 'tab' type, no need for subtype ('domtab' specific) if ($type != 'domtab') { - $subtype = ""; + $subtype = ''; } //find container (if not exist, do nothing) if (isset($_REQUEST['c_id'])) { $c_id = $_REQUEST['c_id']; - } else if (!$c_id = PluginFieldsContainer::findContainer(get_Class($item), $type, $subtype)) { + } elseif (!$c_id = PluginFieldsContainer::findContainer(get_Class($item), $type, $subtype)) { return false; } @@ -915,10 +916,10 @@ public static function showForTab($params) } $current_url = $_SERVER['REQUEST_URI']; if ( - strpos($current_url, ".form.php") === false - && strpos($current_url, ".injector.php") === false - && strpos($current_url, ".public.php") === false - && strpos($current_url, "ajax/timeline.php") === false // ITILSolution load from timeline + strpos($current_url, '.form.php') === false + && strpos($current_url, '.injector.php') === false + && strpos($current_url, '.public.php') === false + && strpos($current_url, 'ajax/timeline.php') === false // ITILSolution load from timeline ) { return false; } @@ -932,12 +933,12 @@ public static function showForTab($params) } $html_id = 'plugin_fields_container_' . mt_rand(); - if (strpos($current_url, "helpdesk.public.php") !== false) { + if (strpos($current_url, 'helpdesk.public.php') !== false) { echo "
"; echo "
"; $field_options = [ 'label_class' => 'col-lg-3', - 'input_class' => 'col-lg-9' + 'input_class' => 'col-lg-9', ]; } else { echo "
"; @@ -949,18 +950,19 @@ public static function showForTab($params) $item, $type, $subtype, - $field_options ?? [] + $field_options ?? [], ); } - if (strpos($current_url, "helpdesk.public.php") !== false) { - echo "
"; + if (strpos($current_url, 'helpdesk.public.php') !== false) { + echo '
'; } - echo "
"; + echo '
'; //JS to trigger any change and check if container need to be display or not - $ajax_url = Plugin::getWebDir('fields') . '/ajax/container.php'; + $ajax_url = Plugin::getWebDir('fields') . '/ajax/container.php'; $items_id = !$item->isNewItem() ? $item->getID() : 0; - echo Html::scriptBlock(<<getFromDB($first_field['plugin_fields_containers_id'])) { return false; @@ -1081,7 +1081,7 @@ public static function prepareHtmlFields( foreach ($status_overrides as $status_override) { if (isset($fields[$status_override['plugin_fields_fields_id']])) { $fields[$status_override['plugin_fields_fields_id']]['is_readonly'] = $status_override['is_readonly']; - $fields[$status_override['plugin_fields_fields_id']]['mandatory'] = $status_override['mandatory']; + $fields[$status_override['plugin_fields_fields_id']]['mandatory'] = $status_override['mandatory']; } } } @@ -1089,13 +1089,13 @@ public static function prepareHtmlFields( $found_v = null; if (!$item->isNewItem()) { //find row for this object with the items_id - $classname = PluginFieldsContainer::getClassname($item->getType(), $container_obj->fields['name']); - $obj = new $classname(); + $classname = PluginFieldsContainer::getClassname($item->getType(), $container_obj->fields['name']); + $obj = new $classname(); $found_values = $obj->find( [ 'plugin_fields_containers_id' => $first_field['plugin_fields_containers_id'], - 'items_id' => $item->getID(), - ] + 'items_id' => $item->getID(), + ], ); $found_v = array_shift($found_values); } @@ -1108,11 +1108,11 @@ public static function prepareHtmlFields( //show all fields foreach ($fields as &$field) { $field['itemtype'] = self::getType(); - $field['label'] = PluginFieldsLabelTranslation::getLabelFor($field); + $field['label'] = PluginFieldsLabelTranslation::getLabelFor($field); $field['allowed_values'] = !empty($field['allowed_values']) ? json_decode($field['allowed_values']) : []; if ($field['type'] === 'glpi_item') { - // Convert allowed values to [$itemtype_class => $itemtype_name] format + // Convert allowed values to [$itemtype_class => $itemtype_name] format $allowed_itemtypes = []; foreach ($field['allowed_values'] as $allowed_itemtype) { if (is_a($allowed_itemtype, CommonDBTM::class, true)) { @@ -1130,7 +1130,7 @@ public static function prepareHtmlFields( ) { $dropdown_class = $dropdown_matches['class']; - $field['dropdown_class'] = $dropdown_class; + $field['dropdown_class'] = $dropdown_class; $field['dropdown_condition'] = []; $object = new $dropdown_class(); @@ -1145,22 +1145,22 @@ public static function prepareHtmlFields( //get value $value = null; if (is_array($found_v)) { - if ($field['type'] == "dropdown") { - $value = $found_v["plugin_fields_" . $field['name'] . "dropdowns_id"]; - } else if ($field['type'] == "glpi_item") { + if ($field['type'] == 'dropdown') { + $value = $found_v['plugin_fields_' . $field['name'] . 'dropdowns_id']; + } elseif ($field['type'] == 'glpi_item') { $itemtype_key = sprintf('itemtype_%s', $field['name']); $items_id_key = sprintf('items_id_%s', $field['name']); - $value = [ + $value = [ 'itemtype' => $found_v[$itemtype_key], 'items_id' => $found_v[$items_id_key], ]; } else { - $value = $found_v[$field['name']] ?? ""; + $value = $found_v[$field['name']] ?? ''; } } if (!$field['is_readonly']) { - if ($field['type'] == "dropdown") { + if ($field['type'] == 'dropdown') { $field_name = sprintf('plugin_fields_%sdropdowns_id', $field['name']); if (isset($_SESSION['plugin']['fields']['values_sent'][$field_name])) { $value = $_SESSION['plugin']['fields']['values_sent'][$field_name]; @@ -1169,15 +1169,15 @@ public static function prepareHtmlFields( $value = $item->input[$field_name]; } } elseif ($field['type'] === 'glpi_item') { - if (isset($_SESSION['plugin']['fields']['values_sent']["itemtype_" . $field['name']])) { - $value['itemtype'] = $_SESSION['plugin']['fields']['values_sent']["itemtype_" . $field['name']]; - } elseif (isset($item->input["itemtype_" . $field['name']])) { - $value['itemtype'] = $item->input["itemtype_" . $field['name']] ?? ''; + if (isset($_SESSION['plugin']['fields']['values_sent']['itemtype_' . $field['name']])) { + $value['itemtype'] = $_SESSION['plugin']['fields']['values_sent']['itemtype_' . $field['name']]; + } elseif (isset($item->input['itemtype_' . $field['name']])) { + $value['itemtype'] = $item->input['itemtype_' . $field['name']] ?? ''; } - if (isset($_SESSION['plugin']['fields']['values_sent']["items_id_" . $field['name']])) { - $value['items_id'] = $_SESSION['plugin']['fields']['values_sent']["items_id_" . $field['name']]; - } elseif (isset($item->input["items_id_" . $field['name']])) { - $value['items_id'] = $item->input["items_id_" . $field['name']] ?? ''; + if (isset($_SESSION['plugin']['fields']['values_sent']['items_id_' . $field['name']])) { + $value['items_id'] = $_SESSION['plugin']['fields']['values_sent']['items_id_' . $field['name']]; + } elseif (isset($item->input['items_id_' . $field['name']])) { + $value['items_id'] = $item->input['items_id_' . $field['name']] ?? ''; } } else { if (isset($_SESSION['plugin']['fields']['values_sent'][$field['name']])) { @@ -1193,7 +1193,7 @@ public static function prepareHtmlFields( if ($value === null) { if (in_array($field['type'], ['dropdown', 'yesno']) && $field['default_value'] === '') { $value = 0; - } else if ($field['default_value'] !== "") { + } elseif ($field['default_value'] !== '') { $value = $field['default_value']; // shortcut for date/datetime @@ -1201,7 +1201,7 @@ public static function prepareHtmlFields( in_array($field['type'], ['date', 'datetime']) && $value == 'now' ) { - $value = $_SESSION["glpi_currenttime"]; + $value = $_SESSION['glpi_currenttime']; } } } @@ -1221,12 +1221,12 @@ public static function prepareHtmlFields( } $html = TemplateRenderer::getInstance()->render('@fields/fields.html.twig', [ - 'item' => $item, - 'fields' => $fields, - 'canedit' => $canedit, - 'massiveaction' => $massiveaction, - 'container' => $container_obj, - 'field_options' => $field_options, + 'item' => $item, + 'fields' => $fields, + 'canedit' => $canedit, + 'massiveaction' => $massiveaction, + 'container' => $container_obj, + 'field_options' => $field_options, ]); unset($_SESSION['plugin']['fields']['values_sent']); @@ -1241,9 +1241,9 @@ public static function showSingle($itemtype, $searchOption, $massiveaction = fal //clean dropdown [pre/su]fix if exists $cleaned_linkfield = preg_replace( - "/plugin_fields_(.*)dropdowns_id/", - "$1", - $searchOption['linkfield'] + '/plugin_fields_(.*)dropdowns_id/', + '$1', + $searchOption['linkfield'], ); //find field @@ -1252,20 +1252,20 @@ public static function showSingle($itemtype, $searchOption, $massiveaction = fal 'fields.plugin_fields_containers_id', 'fields.is_readonly', 'fields.multiple', - 'fields.default_value' + 'fields.default_value', ], - 'FROM' => self::getTable() . ' AS fields', + 'FROM' => self::getTable() . ' AS fields', 'LEFT JOIN' => [ 'glpi_plugin_fields_containers AS containers' => [ 'FKEY' => [ 'containers' => 'id', - 'fields' => 'plugin_fields_containers_id', - ] - ] + 'fields' => 'plugin_fields_containers_id', + ], + ], ], 'WHERE' => [ - 'fields.name' => $cleaned_linkfield, - 'containers.itemtypes' => ['LIKE', "%$itemtype%"] + 'fields.name' => $cleaned_linkfield, + 'containers.itemtypes' => ['LIKE', "%$itemtype%"], ], ]); @@ -1286,8 +1286,8 @@ public static function showSingle($itemtype, $searchOption, $massiveaction = fal 'name' => $cleaned_linkfield, 'is_readonly' => $data['is_readonly'], 'default_value' => $data['default_value'], - 'multiple' => $data['multiple'] - ] + 'multiple' => $data['multiple'], + ], ]; //show field @@ -1309,17 +1309,17 @@ public function post_getEmpty() public static function getTypes(bool $flat_list = true) { $common_types = [ - 'header' => __("Header", "fields"), - 'text' => __("Text (single line)", "fields"), - 'textarea' => __("Text (multiples lines)", "fields"), - 'richtext' => __("Rich Text", "fields"), - 'number' => __("Number", "fields"), - 'url' => __("URL", "fields"), - 'dropdown' => __("Dropdown", "fields"), - 'yesno' => __("Yes/No", "fields"), - 'date' => __("Date", "fields"), - 'datetime' => __("Date & time", "fields"), - 'glpi_item' => __("GLPI item", "fields"), + 'header' => __('Header', 'fields'), + 'text' => __('Text (single line)', 'fields'), + 'textarea' => __('Text (multiples lines)', 'fields'), + 'richtext' => __('Rich Text', 'fields'), + 'number' => __('Number', 'fields'), + 'url' => __('URL', 'fields'), + 'dropdown' => __('Dropdown', 'fields'), + 'yesno' => __('Yes/No', 'fields'), + 'date' => __('Date', 'fields'), + 'datetime' => __('Date & time', 'fields'), + 'glpi_item' => __('GLPI item', 'fields'), ]; $all_types = [ @@ -1342,7 +1342,7 @@ public function post_addItem() $input = $this->fields; //dropdowns : create files - if ($input['type'] === "dropdown") { + if ($input['type'] === 'dropdown') { //search if dropdown already exist in other container $found = $this->find(['id' => ['!=', $input['id']], 'name' => $input['name']]); //for dropdown, if already exist, don't create files diff --git a/inc/inventory.class.php b/inc/inventory.class.php index 3eedca2f..6881601d 100644 --- a/inc/inventory.class.php +++ b/inc/inventory.class.php @@ -36,14 +36,14 @@ public static function updateInventory($params = []) !empty($params) && isset($params['inventory_data']) && !empty($params['inventory_data']) ) { - $availaibleItemType = ["Computer","Printer","NetworkEquipment"]; + $availaibleItemType = ['Computer', 'Printer', 'NetworkEquipment']; foreach (array_keys($params['inventory_data']) as $itemtype) { if (in_array($itemtype, $availaibleItemType)) { $items_id = 0; //retrieve items id switch itemtype switch ($itemtype) { case Computer::getType(): - $items_id = $params['computers_id']; + $items_id = $params['computers_id']; break; case NetworkEquipment::getType(): @@ -70,8 +70,8 @@ public static function updateInventory($params = []) //Load XML file because FI always update XML file and don't store inventory into DB $file = self::loadXMLFile($itemtype, $items_id); if ($file !== false) { - /** @phpstan-ignore-next-line */ - $arrayinventory = PluginFusioninventoryFormatconvert::XMLtoArray($file); + /** @phpstan-ignore-next-line */ + $arrayinventory = PluginFusioninventoryFormatconvert::XMLtoArray($file); if (isset($arrayinventory['CUSTOM'])) { self::updateFields($arrayinventory['CUSTOM']['CONTAINER'], $itemtype, $items_id); } @@ -91,10 +91,10 @@ public static function updateFields($containersData, $itemtype, $items_id) foreach ($containersData as $key => $containerData) { $container = new PluginFieldsContainer(); $container->getFromDB($containerData['ID']); - $data = []; - $data["items_id"] = $items_id; - $data["itemtype"] = $itemtype; - $data["plugin_fields_containers_id"] = $containerData['ID']; + $data = []; + $data['items_id'] = $items_id; + $data['itemtype'] = $itemtype; + $data['plugin_fields_containers_id'] = $containerData['ID']; foreach ($containerData['FIELDS'] as $key => $value) { $data[strtolower($key)] = $value; } @@ -104,7 +104,7 @@ public static function updateFields($containersData, $itemtype, $items_id) public static function loadXMLFile($itemtype, $items_id) { - $pxml = false; + $pxml = false; $folder = substr($items_id, 0, -1); if (empty($folder)) { $folder = '0'; @@ -112,13 +112,14 @@ public static function loadXMLFile($itemtype, $items_id) //Check if the file exists with the .xml extension (new format) /** @phpstan-ignore-next-line */ - $file = PLUGIN_FUSIONINVENTORY_XML_DIR . strtolower($itemtype) . "/" . $folder . "/" . $items_id; + $file = PLUGIN_FUSIONINVENTORY_XML_DIR . strtolower($itemtype) . '/' . $folder . '/' . $items_id; if (file_exists($file . '.xml')) { $file .= '.xml'; - } else if (!file_exists($file)) { + } elseif (!file_exists($file)) { return false; } $pxml = simplexml_load_file($file, 'SimpleXMLElement', LIBXML_NOCDATA); + return $pxml; } } diff --git a/inc/labeltranslation.class.php b/inc/labeltranslation.class.php index 464d0972..271f0a18 100644 --- a/inc/labeltranslation.class.php +++ b/inc/labeltranslation.class.php @@ -48,14 +48,14 @@ public static function installBaseData(Migration $migration, $version) /** @var DBmysql $DB */ global $DB; - $default_charset = DBConnection::getDefaultCharset(); + $default_charset = DBConnection::getDefaultCharset(); $default_collation = DBConnection::getDefaultCollation(); - $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); + $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); $table = self::getTable(); if (!$DB->tableExists($table)) { - $migration->displayMessage(sprintf(__("Installing %s"), $table)); + $migration->displayMessage(sprintf(__('Installing %s'), $table)); $query = "CREATE TABLE IF NOT EXISTS `$table` ( `id` INT {$default_key_sign} NOT NULL auto_increment, @@ -94,14 +94,14 @@ public static function uninstall() /** @var DBmysql $DB */ global $DB; - $DB->query("DROP TABLE IF EXISTS `" . self::getTable() . "`"); + $DB->query('DROP TABLE IF EXISTS `' . self::getTable() . '`'); return true; } public static function getTypeName($nb = 0) { - return _n("Translation", "Translations", $nb); + return _n('Translation', 'Translations', $nb); } public static function createForItem(CommonDBTM $item) @@ -111,8 +111,9 @@ public static function createForItem(CommonDBTM $item) 'itemtype' => $item::getType(), 'items_id' => $item->getID(), 'language' => $_SESSION['glpilanguage'], - 'label' => $item->fields['label'] + 'label' => $item->fields['label'], ]); + return true; } @@ -123,14 +124,16 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) [ 'itemtype' => $item::getType(), 'items_id' => $item->getID(), - ] + ], ); + return self::createTabEntry(self::getTypeName($nb), $nb); } public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { self::showTranslations($item); + return true; } @@ -152,7 +155,7 @@ public static function showTranslations(CommonDBTM $item) 'type' => __CLASS__, 'itemtype' => $item::getType(), 'items_id' => $item->fields['id'], - 'id' => -1 + 'id' => -1, ]; echo Html::scriptBlock(' addTranslation' . $item->getID() . $rand . ' = function() { @@ -165,7 +168,7 @@ public static function showTranslations(CommonDBTM $item) echo "
"; + __('Add a new translation') . '
'; } $obj = new self(); @@ -174,7 +177,7 @@ public static function showTranslations(CommonDBTM $item) 'itemtype' => $item::getType(), 'items_id' => $item->getID(), ], - "language ASC" + 'language ASC', ); if (count($found) > 0) { @@ -185,29 +188,29 @@ public static function showTranslations(CommonDBTM $item) } echo "
"; echo ""; - echo ""; + echo "'; if ($canedit) { echo ""; + echo ''; } - echo ""; - echo ""; + echo ''; + echo ''; foreach ($found as $data) { echo ""; + onClick=\"viewEditTranslation" . $data['id'] . "$rand();\"" : '') . '>'; if ($canedit) { - echo ""; + echo "'; } - echo ""; + echo ''; } - echo "
" . __("List of translations") . "
" . __('List of translations') . '
"; echo Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); - echo "" . __("Language", "fields") . "" . __("Label", "fields") . "' . __('Language', 'fields') . '' . __('Label', 'fields') . '
"; - Html::showMassiveActionCheckBox(__CLASS__, $data["id"]); - echo ""; + Html::showMassiveActionCheckBox(__CLASS__, $data['id']); + echo '"; + echo ''; if ($canedit) { $ajax_params = [ 'type' => __CLASS__, 'itemtype' => $item::getType(), 'items_id' => $item->getID(), - 'id' => $data['id'] + 'id' => $data['id'], ]; echo Html::scriptBlock(' viewEditTranslation' . $data['id'] . $rand . ' = function() { @@ -219,11 +222,11 @@ public static function showTranslations(CommonDBTM $item) '); } echo Dropdown::getLanguageName($data['language']); - echo ""; + echo ''; echo $data['label']; - echo "
"; + echo ''; if ($canedit) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); @@ -231,7 +234,7 @@ public static function showTranslations(CommonDBTM $item) } } else { echo ""; - echo "
" . __("No translation found") . "
"; + echo "" . __('No translation found') . ''; } return true; @@ -256,36 +259,37 @@ public function showFormForItem($itemtype, $items_id, $id = -1) } $this->showFormHeader(); echo ""; - echo "" . __('Language') . " :"; - echo ""; + echo '' . __('Language') . ' :'; + echo ''; echo ""; echo ""; if ($id > 0) { echo Dropdown::getLanguageName($this->fields['language']); } else { Dropdown::showLanguages( - "language", + 'language', ['display_none' => false, - 'value' => $_SESSION['glpilanguage'], - 'used' => self::getAlreadyTranslatedForItem( + 'value' => $_SESSION['glpilanguage'], + 'used' => self::getAlreadyTranslatedForItem( $itemtype, - $items_id - ) - ] + $items_id, + ), + ], ); } echo " "; echo ""; - echo ""; + echo "'; echo ""; echo Html::input('label', [ - 'value' => $this->fields["label"], - 'id' => 'label' + 'value' => $this->fields['label'], + 'id' => 'label', ]); - echo ""; + echo ''; $this->showFormButtons(); + return true; } @@ -308,13 +312,14 @@ public static function getAlreadyTranslatedForItem($itemtype, $items_id) 'WHERE' => [ 'itemtype' => $itemtype, 'items_id' => $items_id, - ] - ] + ], + ], ); $tab = []; foreach ($iterator as $data) { $tab[$data['language']] = $data['language']; } + return $tab; } @@ -329,8 +334,8 @@ public static function getLabelFor(array $item) { $obj = new self(); $found = $obj->find(['itemtype' => $item['itemtype'], - 'items_id' => $item['id'], - 'language' => $_SESSION['glpilanguage'] + 'items_id' => $item['id'], + 'language' => $_SESSION['glpilanguage'], ]); if (count($found) > 0) { diff --git a/inc/menu.class.php b/inc/menu.class.php index d9eab257..5b309afa 100644 --- a/inc/menu.class.php +++ b/inc/menu.class.php @@ -34,7 +34,7 @@ class PluginFieldsMenu extends CommonGLPI public static function getMenuName() { - return __("Additional fields", "fields"); + return __('Additional fields', 'fields'); } public static function getMenuContent() @@ -43,10 +43,10 @@ public static function getMenuContent() return; } - $front_fields = Plugin::getPhpDir('fields', false) . "/front"; - $menu = [ + $front_fields = Plugin::getPhpDir('fields', false) . '/front'; + $menu = [ 'title' => self::getMenuName(), - 'page' => "$front_fields/container.php", + 'page' => "$front_fields/container.php", 'icon' => PluginFieldsContainer::getIcon(), ]; @@ -57,14 +57,15 @@ public static function getMenuContent() 'title' => $itemtype::getTypeName(2), 'page' => $itemtype::getSearchURL(false), 'links' => [ - 'search' => $itemtype::getSearchURL(false) - ] + 'search' => $itemtype::getSearchURL(false), + ], ]; if ($itemtype::canCreate()) { $menu['options'][$option]['links']['add'] = $itemtype::getFormURL(false); } } + return $menu; } } diff --git a/inc/migration.class.php b/inc/migration.class.php index 8f3850fa..4cb3736d 100644 --- a/inc/migration.class.php +++ b/inc/migration.class.php @@ -59,7 +59,7 @@ public static function getSQLFields(string $field_name, string $field_type, arra $field_name = getForeignKeyFieldForItemType(PluginFieldsDropdown::getClassname($field_name)); } if ($options['multiple'] ?? false) { - $fields[$field_name] = "LONGTEXT"; + $fields[$field_name] = 'LONGTEXT'; } else { $fields[$field_name] = "INT {$default_key_sign} NOT NULL DEFAULT 0"; } @@ -119,7 +119,7 @@ public static function checkDeadFields(bool $fix): array // Read itemtypes and container name $itemtypes = importArrayFromDB($row['itemtypes']); - $name = $row['name']; + $name = $row['name']; // One table to handle per itemtype foreach ($itemtypes as $itemtype) { @@ -198,7 +198,7 @@ private static function getCustomFieldsInContainerTable( $fields = $DB->listFields($table); // Reduce to fields name only - $fields = array_column($fields, "Field"); + $fields = array_column($fields, 'Field'); // Remove basic fields $basic_fields = [ @@ -207,11 +207,12 @@ private static function getCustomFieldsInContainerTable( 'itemtype', 'plugin_fields_containers_id', ]; + return array_filter( $fields, function (string $field) use ($basic_fields) { return !in_array($field, $basic_fields); - } + }, ); } } diff --git a/inc/profile.class.php b/inc/profile.class.php index 7f518bf8..72e991e2 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -50,14 +50,14 @@ public static function installBaseData(Migration $migration, $version) /** @var DBmysql $DB */ global $DB; - $default_charset = DBConnection::getDefaultCharset(); + $default_charset = DBConnection::getDefaultCharset(); $default_collation = DBConnection::getDefaultCollation(); - $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); + $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); $table = self::getTable(); if (!$DB->tableExists($table)) { - $migration->displayMessage(sprintf(__("Installing %s"), $table)); + $migration->displayMessage(sprintf(__('Installing %s'), $table)); $query = "CREATE TABLE IF NOT EXISTS `$table` ( `id` INT {$default_key_sign} NOT NULL auto_increment, @@ -79,20 +79,19 @@ public static function uninstall() /** @var DBmysql $DB */ global $DB; - $DB->query("DROP TABLE IF EXISTS `" . self::getTable() . "`"); + $DB->query('DROP TABLE IF EXISTS `' . self::getTable() . '`'); return true; } - public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - return self::createTabEntry(_n("Profile", "Profiles", 2)); + return self::createTabEntry(_n('Profile', 'Profiles', 2)); } public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { - $profile = new Profile(); + $profile = new Profile(); $found_profiles = $profile->find(); $fields_profile = new self(); @@ -100,34 +99,35 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ echo "
"; echo ""; - echo ""; + echo "'; foreach ($found_profiles as $profile_item) { //get right for current profile $found = $fields_profile->find([ - 'profiles_id' => $profile_item['id'], - 'plugin_fields_containers_id' => $item->fields['id'] + 'profiles_id' => $profile_item['id'], + 'plugin_fields_containers_id' => $item->fields['id'], ]); $first_found = array_shift($found); //display right - echo ""; - echo ""; - echo "'; + echo ''; + echo '"; - echo ""; + echo ''; + echo ''; } - echo "
    "; + echo '
      '; echo "
"; - echo ""; - echo "
" . _n("Profile", "Profiles", 2) . "
" . _n('Profile', 'Profiles', 2) . '
" . $profile_item['name'] . ""; + echo '
' . $profile_item['name'] . ''; Profile::dropdownRight( - "rights[" . $profile_item['id'] . "]", - ['value' => $first_found['right']] + 'rights[' . $profile_item['id'] . ']', + ['value' => $first_found['right']], ); - echo "
"; echo ""; - echo ""; - echo "
"; + echo ""; + echo ''; + echo ''; + echo '
'; Html::closeForm(); + return true; } @@ -137,24 +137,24 @@ public static function updateProfile($input) foreach ($input['rights'] as $profiles_id => $right) { $found = $fields_profile->find( [ - 'profiles_id' => $profiles_id, - 'plugin_fields_containers_id' => $input['plugin_fields_containers_id'] - ] + 'profiles_id' => $profiles_id, + 'plugin_fields_containers_id' => $input['plugin_fields_containers_id'], + ], ); if (count($found) > 0) { - $first_found = array_shift($found); - - $fields_profile->update([ - 'id' => $first_found['id'], - 'profiles_id' => $profiles_id, - 'plugin_fields_containers_id' => $input['plugin_fields_containers_id'], - 'right' => $right - ]); + $first_found = array_shift($found); + + $fields_profile->update([ + 'id' => $first_found['id'], + 'profiles_id' => $profiles_id, + 'plugin_fields_containers_id' => $input['plugin_fields_containers_id'], + 'right' => $right, + ]); } else { $fields_profile->add([ 'profiles_id' => $profiles_id, 'plugin_fields_containers_id' => $input['plugin_fields_containers_id'], - 'right' => $right + 'right' => $right, ]); } } @@ -164,7 +164,7 @@ public static function updateProfile($input) public static function createForContainer(PluginFieldsContainer $container) { - $profile = new Profile(); + $profile = new Profile(); $found_profiles = $profile->find(); $fields_profile = new self(); @@ -172,24 +172,26 @@ public static function createForContainer(PluginFieldsContainer $container) $fields_profile->add([ 'profiles_id' => $profile_item['id'], 'plugin_fields_containers_id' => $container->fields['id'], - 'right' => CREATE + 'right' => CREATE, ]); } + return true; } public static function addNewProfile(Profile $profile) { - $containers = new PluginFieldsContainer(); + $containers = new PluginFieldsContainer(); $found_containers = $containers->find(); $fields_profile = new self(); foreach ($found_containers as $container) { $fields_profile->add([ 'profiles_id' => $profile->fields['id'], - 'plugin_fields_containers_id' => $container['id'] + 'plugin_fields_containers_id' => $container['id'], ]); } + return true; } @@ -197,6 +199,7 @@ public static function deleteProfile(Profile $profile) { $fields_profile = new self(); $fields_profile->deleteByCriteria(['profiles_id' => $profile->fields['id']]); + return true; } @@ -207,15 +210,15 @@ public static function getRightOnContainer(int $profile_id, int $container_id): $container_profile = $DB->request( [ - 'SELECT' => ['MAX' => 'right AS right'], - 'FROM' => self::getTable(), - 'WHERE' => [ - 'profiles_id' => $profile_id, + 'SELECT' => ['MAX' => 'right AS right'], + 'FROM' => self::getTable(), + 'WHERE' => [ + 'profiles_id' => $profile_id, 'plugin_fields_containers_id' => $container_id, ], - ] + ], ); - return (int)$container_profile->current()['right']; + return (int) $container_profile->current()['right']; } } diff --git a/inc/statusoverride.class.php b/inc/statusoverride.class.php index d46dc878..c6e7d31e 100644 --- a/inc/statusoverride.class.php +++ b/inc/statusoverride.class.php @@ -50,14 +50,14 @@ public static function installBaseData(Migration $migration, $version) /** @var DBmysql $DB */ global $DB; - $default_charset = DBConnection::getDefaultCharset(); + $default_charset = DBConnection::getDefaultCharset(); $default_collation = DBConnection::getDefaultCollation(); - $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); + $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); $table = self::getTable(); if (!$DB->tableExists($table)) { - $migration->displayMessage(sprintf(__("Installing %s"), $table)); + $migration->displayMessage(sprintf(__('Installing %s'), $table)); $query = "CREATE TABLE IF NOT EXISTS `$table` ( `id` INT {$default_key_sign} NOT NULL auto_increment, @@ -80,7 +80,7 @@ public static function uninstall() /** @var DBmysql $DB */ global $DB; - $DB->query("DROP TABLE IF EXISTS `" . self::getTable() . "`"); + $DB->query('DROP TABLE IF EXISTS `' . self::getTable() . '`'); return true; } @@ -99,8 +99,10 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ { if ($item instanceof PluginFieldsContainer) { self::showForTabContainer($item); + return true; } + return false; } @@ -109,6 +111,7 @@ public function prepareInputForAdd($input) if (isset($input['states']) && is_array($input['states'])) { $input['states'] = json_encode($input['states']); } + return parent::prepareInputForAdd($input); } @@ -117,6 +120,7 @@ public function prepareInputForUpdate($input) if (isset($input['states']) && is_array($input['states'])) { $input['states'] = json_encode($input['states']); } + return parent::prepareInputForUpdate($input); } @@ -133,6 +137,7 @@ public static function getStatusItemtypes(): array { /** @var array $CFG_GLPI */ global $CFG_GLPI; + return array_merge(['Ticket', 'Change', 'Problem', 'Project', 'ProjectTask'], $CFG_GLPI['state_types']); } @@ -141,28 +146,28 @@ public static function countOverridesForContainer(int $container_id) /** @var DBmysql $DB */ global $DB; - $fields_table = PluginFieldsField::getTable(); + $fields_table = PluginFieldsField::getTable(); $container_table = PluginFieldsContainer::getTable(); - $iterator = $DB->request([ - 'COUNT' => 'cpt', - 'FROM' => self::getTable(), + $iterator = $DB->request([ + 'COUNT' => 'cpt', + 'FROM' => self::getTable(), 'LEFT JOIN' => [ - $fields_table => [ + $fields_table => [ 'ON' => [ self::getTable() => 'plugin_fields_fields_id', - $fields_table => 'id' - ] + $fields_table => 'id', + ], ], $container_table => [ 'ON' => [ - $fields_table => 'plugin_fields_containers_id', - $container_table => 'id' - ] - ] + $fields_table => 'plugin_fields_containers_id', + $container_table => 'id', + ], + ], ], - 'WHERE' => [ + 'WHERE' => [ 'plugin_fields_containers_id' => $container_id, - ] + ], ]); return $iterator->current()['cpt'] ?? 0; @@ -173,39 +178,40 @@ public static function getOverridesForContainer(int $container_id): array /** @var DBmysql $DB */ global $DB; - $fields_table = PluginFieldsField::getTable(); + $fields_table = PluginFieldsField::getTable(); $container_table = PluginFieldsContainer::getTable(); - $iterator = $DB->request([ + $iterator = $DB->request([ 'SELECT' => [ self::getTable() . '.*', $fields_table . '.label AS field_name', ], - 'FROM' => self::getTable(), + 'FROM' => self::getTable(), 'LEFT JOIN' => [ - $fields_table => [ + $fields_table => [ 'ON' => [ self::getTable() => 'plugin_fields_fields_id', - $fields_table => 'id' - ] + $fields_table => 'id', + ], ], $container_table => [ 'ON' => [ - $fields_table => 'plugin_fields_containers_id', - $container_table => 'id' - ] + $fields_table => 'plugin_fields_containers_id', + $container_table => 'id', + ], ], ], - 'WHERE' => [ + 'WHERE' => [ 'plugin_fields_containers_id' => $container_id, - ] + ], ]); $overrides = []; foreach ($iterator as $data) { $data['states'] = !empty($data['states']) ? json_decode($data['states']) : []; - $overrides[] = $data; + $overrides[] = $data; } self::addStatusNames($overrides); + return $overrides; } @@ -216,11 +222,11 @@ public static function getOverridesForItem(int $container_id, CommonDBTM $item): } $status_field_name = self::getStatusFieldName($item->getType()); - $status = null; + $status = null; if (array_key_exists($status_field_name, $item->input) && $item->input[$status_field_name] !== '') { - $status = (int)$item->input[$status_field_name]; + $status = (int) $item->input[$status_field_name]; } elseif (array_key_exists($status_field_name, $item->fields) && $item->fields[$status_field_name] !== '') { - $status = (int)$item->fields[$status_field_name]; + $status = (int) $item->fields[$status_field_name]; } return $status !== null @@ -235,6 +241,7 @@ public static function getOverridesForItemtypeAndStatus(int $container_id, strin } $overrides = self::getOverridesForContainer($container_id); + return array_filter($overrides, static function ($override) use ($itemtype, $status) { return $override['itemtype'] === $itemtype && in_array($status, $override['states'], false); }); @@ -250,12 +257,12 @@ private static function getItemtypesForContainer(int $container_id): array 'FROM' => PluginFieldsContainer::getTable(), 'WHERE' => [ 'id' => $container_id, - ] + ], ]); if (count($iterator)) { - $itemtypes = $iterator->current()['itemtypes']; - $itemtypes = importArrayFromDB($itemtypes); + $itemtypes = $iterator->current()['itemtypes']; + $itemtypes = importArrayFromDB($itemtypes); $status_itemtypes = self::getStatusItemtypes(); // Get only itemtypes that exist and have a status field $itemtypes = array_filter($itemtypes, static function ($itemtype) use ($status_itemtypes) { @@ -265,8 +272,10 @@ private static function getItemtypesForContainer(int $container_id): array foreach ($itemtypes as $itemtype) { $results[$itemtype] = $itemtype::getTypeName(); } + return $results; } + return []; } @@ -291,17 +300,17 @@ private static function addStatusNames(array &$overrides): void global $DB; $statuses = [ - 'Ticket' => Ticket::getAllStatusArray(), - 'Change' => Change::getAllStatusArray(), - 'Problem' => Problem::getAllStatusArray(), - 'Project' => [], + 'Ticket' => Ticket::getAllStatusArray(), + 'Change' => Change::getAllStatusArray(), + 'Problem' => Problem::getAllStatusArray(), + 'Project' => [], 'ProjectTask' => [], - 'Other' => [], + 'Other' => [], ]; $iterator = $DB->request([ 'SELECT' => ['id', 'name'], - 'FROM' => ProjectState::getTable() + 'FROM' => ProjectState::getTable(), ]); foreach ($iterator as $row) { $statuses['Project'][$row['id']] = $row['name']; @@ -310,14 +319,14 @@ private static function addStatusNames(array &$overrides): void $iterator = $DB->request([ 'SELECT' => ['id', 'name'], - 'FROM' => State::getTable() + 'FROM' => State::getTable(), ]); foreach ($iterator as $row) { $statuses['Other'][$row['id']] = $row['name']; } foreach ($overrides as &$override) { - $names = $statuses[$override['itemtype']] ?? $statuses['Other']; + $names = $statuses[$override['itemtype']] ?? $statuses['Other']; $override['status_names'] = array_filter($names, static function ($name, $id) use ($override) { return in_array($id, $override['states']); }, ARRAY_FILTER_USE_BOTH); @@ -330,25 +339,26 @@ private static function getFieldsChoiceForContainer(int $container_id): array global $DB; $iterator = $DB->request([ - 'SELECT' => ['glpi_plugin_fields_fields.*'], - 'FROM' => 'glpi_plugin_fields_fields', + 'SELECT' => ['glpi_plugin_fields_fields.*'], + 'FROM' => 'glpi_plugin_fields_fields', 'LEFT JOIN' => [ 'glpi_plugin_fields_containers' => [ 'ON' => [ 'glpi_plugin_fields_fields' => 'plugin_fields_containers_id', - 'glpi_plugin_fields_containers' => 'id' - ] - ] + 'glpi_plugin_fields_containers' => 'id', + ], + ], ], - 'WHERE' => [ + 'WHERE' => [ 'plugin_fields_containers_id' => $container_id, - ] + ], ]); $fields = []; foreach ($iterator as $data) { $fields[$data['id']] = $data['label']; } + return $fields; } @@ -372,9 +382,9 @@ public static function getStatusDropdownForItemtype(string $itemtype, array $val case 'Project': case 'ProjectTask': $projectstate_table = ProjectState::getTable(); - $iterator = $DB->request([ + $iterator = $DB->request([ 'SELECT' => ['name'], - 'FROM' => $projectstate_table + 'FROM' => $projectstate_table, ]); foreach ($iterator as $data) { $statuses[] = $data['name']; @@ -399,13 +409,13 @@ public static function getStatusDropdownForItemtype(string $itemtype, array $val public static function showForTabContainer(CommonGLPI $item, $options = []) { $container_id = $item->getID(); - $has_fields = countElementsInTable(PluginFieldsField::getTable(), [ - 'plugin_fields_containers_id' => $container_id + $has_fields = countElementsInTable(PluginFieldsField::getTable(), [ + 'plugin_fields_containers_id' => $container_id, ]) > 0; $twig_params = [ - 'container_id' => $container_id, - 'overrides' => self::getOverridesForContainer($container_id), - 'has_fields' => $has_fields, + 'container_id' => $container_id, + 'overrides' => self::getOverridesForContainer($container_id), + 'has_fields' => $has_fields, ]; TemplateRenderer::getInstance()->display('@fields/status_overrides.html.twig', $twig_params); } @@ -421,6 +431,7 @@ public function showForm($ID, array $options = []) 'container_fields' => self::getFieldsChoiceForContainer($container_id), ]; TemplateRenderer::getInstance()->display('@fields/forms/status_override.html.twig', $twig_params); + return true; } } diff --git a/inc/toolbox.class.php b/inc/toolbox.class.php index 28867582..fbd7ba48 100644 --- a/inc/toolbox.class.php +++ b/inc/toolbox.class.php @@ -30,83 +30,82 @@ class PluginFieldsToolbox { - /** - * Get a clean system name from a label. - * - * @param string $label - * - * @return string - */ + /** + * Get a clean system name from a label. + * + * @param string $label + * + * @return string + */ public function getSystemNameFromLabel($label) { - $name = strtolower($label); - // 1. remove trailing "s" (plural forms) + // 1. remove trailing "s" (plural forms) $name = getSingular($name); - // 2. keep only alphanum + // 2. keep only alphanum $name = preg_replace('/[^\da-z]/i', '', $name); - // 3. if empty, uses a random number + // 3. if empty, uses a random number if (strlen($name) == 0) { $name = rand(); } - // 4. replace numbers by letters + // 4. replace numbers by letters $name = $this->replaceIntByLetters($name); return $name; } - /** - * Return system name incremented by given increment. - * - * @param string $name - * @param integer $increment - * - * @return string - */ + /** + * Return system name incremented by given increment. + * + * @param string $name + * @param integer $increment + * + * @return string + */ public function getIncrementedSystemName($name, $increment) { - return $name . $this->replaceIntByLetters((string)$increment); + return $name . $this->replaceIntByLetters((string) $increment); } - /** - * Replace integers by corresponding letters inside given string. - * - * @param string $str - * - * @return mixed - */ + /** + * Replace integers by corresponding letters inside given string. + * + * @param string $str + * + * @return mixed + */ private function replaceIntByLetters($str) { return str_replace( ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'], - $str + $str, ); } - /** - * Fix dropdown names that were generated prior to Fields 1.9.2. - * - * @param Migration $migration - * @param mixed $condition - * - * @return void - */ + /** + * Fix dropdown names that were generated prior to Fields 1.9.2. + * + * @param Migration $migration + * @param mixed $condition + * + * @return void + */ public function fixFieldsNames(Migration $migration, $condition) { /** @var DBmysql $DB */ global $DB; $bad_named_fields = []; - $fields = $DB->request( + $fields = $DB->request( [ - 'FROM' => PluginFieldsField::getTable(), + 'FROM' => PluginFieldsField::getTable(), 'WHERE' => $condition, - ] + ], ); foreach ($fields as $field) { $field_copy = $field; @@ -120,30 +119,30 @@ public function fixFieldsNames(Migration $migration, $condition) return; } - $migration->displayMessage(__("Fix fields names", "fields")); + $migration->displayMessage(__('Fix fields names', 'fields')); foreach ($bad_named_fields as $field) { $old_name = $field['name']; - // Update field name + // Update field name $field['name'] = null; - $field_obj = new PluginFieldsField(); - $new_name = $field_obj->prepareName($field); + $field_obj = new PluginFieldsField(); + $new_name = $field_obj->prepareName($field); if ($new_name > 64) { - // limit fields names to 64 chars (MySQL limit) + // limit fields names to 64 chars (MySQL limit) $new_name = substr($new_name, 0, 64); } while ( 'dropdown' === $field['type'] && strlen(getTableForItemType(PluginFieldsDropdown::getClassname($new_name))) > 64 ) { - // limit tables names to 64 chars (MySQL limit) + // limit tables names to 64 chars (MySQL limit) $new_name = substr($new_name, 0, -1); } $DB->update( PluginFieldsField::getTable(), ['name' => $new_name], - ['id' => $field['id']] + ['id' => $field['id']], ); $sql_fields_to_rename = [ @@ -151,7 +150,7 @@ public function fixFieldsNames(Migration $migration, $condition) ]; if ('dropdown' === $field['type']) { - // Rename dropdown table + // Rename dropdown table $old_table = getTableForItemType(PluginFieldsDropdown::getClassname($old_name)); $new_table = getTableForItemType(PluginFieldsDropdown::getClassname($new_name)); @@ -159,53 +158,53 @@ public function fixFieldsNames(Migration $migration, $condition) $migration->renameTable($old_table, $new_table); } - // Rename foreign keys in containers tables - $old_fk = getForeignKeyFieldForTable($old_table); - $new_fk = getForeignKeyFieldForTable($new_table); + // Rename foreign keys in containers tables + $old_fk = getForeignKeyFieldForTable($old_table); + $new_fk = getForeignKeyFieldForTable($new_table); $sql_fields_to_rename[$old_fk] = $new_fk; } - // Rename columns in plugin tables + // Rename columns in plugin tables foreach ($sql_fields_to_rename as $old_field_name => $new_field_name) { $tables_to_update = $DB->request( [ - 'SELECT' => 'TABLE_NAME', - 'DISTINCT' => true, - 'FROM' => 'INFORMATION_SCHEMA.COLUMNS', - 'WHERE' => [ - 'TABLE_SCHEMA' => $DB->dbdefault, - 'TABLE_NAME' => ['LIKE', 'glpi_plugin_fields_%'], - 'COLUMN_NAME' => $old_field_name + 'SELECT' => 'TABLE_NAME', + 'DISTINCT' => true, + 'FROM' => 'INFORMATION_SCHEMA.COLUMNS', + 'WHERE' => [ + 'TABLE_SCHEMA' => $DB->dbdefault, + 'TABLE_NAME' => ['LIKE', 'glpi_plugin_fields_%'], + 'COLUMN_NAME' => $old_field_name, ], - ] + ], ); foreach ($tables_to_update as $table_to_update) { - $sql_fields = PluginFieldsMigration::getSQLFields($new_field_name, $field['type'], $field); + $sql_fields = PluginFieldsMigration::getSQLFields($new_field_name, $field['type'], $field); if (count($sql_fields) !== 1 || !array_key_exists($new_field_name, $sql_fields)) { // when this method has been made, only fields types that were matching a unique SQL field were existing // other cases can be ignored continue; } - $migration->changeField( - $table_to_update['TABLE_NAME'], - $old_field_name, - $new_field_name, - $sql_fields[$new_field_name] - ); - $migration->migrationOneTable($table_to_update['TABLE_NAME']); + $migration->changeField( + $table_to_update['TABLE_NAME'], + $old_field_name, + $new_field_name, + $sql_fields[$new_field_name], + ); + $migration->migrationOneTable($table_to_update['TABLE_NAME']); } } } } - /** - * Return a list of GLPI itemtypes. - * These itemtypes will be available to attach fields containers on them, - * and will be usable in dropdown / glpi_item fields. - * - * @return array - */ + /** + * Return a list of GLPI itemtypes. + * These itemtypes will be available to attach fields containers on them, + * and will be usable in dropdown / glpi_item fields. + * + * @return array + */ public static function getGlpiItemtypes(): array { /** @@ -295,12 +294,12 @@ public static function getGlpiItemtypes(): array } } - $dropdowns_sections = []; + $dropdowns_sections = []; foreach (Dropdown::getStandardDropdownItemTypes() as $section => $itemtypes) { $section_name = sprintf( __('%s: %s'), _n('Dropdown', 'Dropdowns', Session::getPluralNumber()), - $section + $section, ); $dropdowns_sections[$section_name] = array_keys($itemtypes); } @@ -322,7 +321,7 @@ public static function getGlpiItemtypes(): array _n('Component', 'Components', Session::getPluralNumber()) => $components_itemtypes, __('Component items', 'fields') => $component_items_itemtypes, ] + $dropdowns_sections + [ - __('Other') => $other_itemtypes, + __('Other') => $other_itemtypes, ]; $plugin = new Plugin(); @@ -358,7 +357,7 @@ public static function getGlpiItemtypes(): array $all_itemtypes[$section] = $named_itemtypes; } - // Remove empty lists (e.g. Plugin list). + // Remove empty lists (e.g. Plugin list). $all_itemtypes = array_filter($all_itemtypes); return $all_itemtypes; diff --git a/setup.php b/setup.php index 1e7d017c..58f6605b 100644 --- a/setup.php +++ b/setup.php @@ -31,33 +31,33 @@ define('PLUGIN_FIELDS_VERSION', '1.21.13'); // Minimal GLPI version, inclusive -define("PLUGIN_FIELDS_MIN_GLPI", "10.0.0"); +define('PLUGIN_FIELDS_MIN_GLPI', '10.0.0'); // Maximum GLPI version, exclusive -define("PLUGIN_FIELDS_MAX_GLPI", "10.0.99"); +define('PLUGIN_FIELDS_MAX_GLPI', '10.0.99'); -if (!defined("PLUGINFIELDS_DIR")) { - define("PLUGINFIELDS_DIR", Plugin::getPhpDir("fields")); +if (!defined('PLUGINFIELDS_DIR')) { + define('PLUGINFIELDS_DIR', Plugin::getPhpDir('fields')); } -if (!defined("PLUGINFIELDS_WEB_DIR")) { - define("PLUGINFIELDS_WEB_DIR", Plugin::getWebDir("fields")); +if (!defined('PLUGINFIELDS_WEB_DIR')) { + define('PLUGINFIELDS_WEB_DIR', Plugin::getWebDir('fields')); } -if (!defined("PLUGINFIELDS_DOC_DIR")) { - define("PLUGINFIELDS_DOC_DIR", GLPI_PLUGIN_DOC_DIR . "/fields"); +if (!defined('PLUGINFIELDS_DOC_DIR')) { + define('PLUGINFIELDS_DOC_DIR', GLPI_PLUGIN_DOC_DIR . '/fields'); } if (!file_exists(PLUGINFIELDS_DOC_DIR)) { mkdir(PLUGINFIELDS_DOC_DIR); } -if (!defined("PLUGINFIELDS_CLASS_PATH")) { - define("PLUGINFIELDS_CLASS_PATH", PLUGINFIELDS_DOC_DIR . "/inc"); +if (!defined('PLUGINFIELDS_CLASS_PATH')) { + define('PLUGINFIELDS_CLASS_PATH', PLUGINFIELDS_DOC_DIR . '/inc'); } if (!file_exists(PLUGINFIELDS_CLASS_PATH)) { mkdir(PLUGINFIELDS_CLASS_PATH); } -if (!defined("PLUGINFIELDS_FRONT_PATH")) { - define("PLUGINFIELDS_FRONT_PATH", PLUGINFIELDS_DOC_DIR . "/front"); +if (!defined('PLUGINFIELDS_FRONT_PATH')) { + define('PLUGINFIELDS_FRONT_PATH', PLUGINFIELDS_DOC_DIR . '/front'); } if (!file_exists(PLUGINFIELDS_FRONT_PATH)) { mkdir(PLUGINFIELDS_FRONT_PATH); @@ -79,10 +79,10 @@ function plugin_init_fields() $PLUGIN_HOOKS['csrf_compliant']['fields'] = true; // manage autoload of plugin custom classes - include_once(PLUGINFIELDS_DIR . "/inc/autoload.php"); + include_once(PLUGINFIELDS_DIR . '/inc/autoload.php'); // manage autoload of vendor classes - include_once(PLUGINFIELDS_DIR . "/vendor/autoload.php"); + include_once(PLUGINFIELDS_DIR . '/vendor/autoload.php'); $pluginfields_autoloader = new PluginFieldsAutoloader([PLUGINFIELDS_CLASS_PATH]); $pluginfields_autoloader->register(); @@ -119,14 +119,14 @@ function plugin_init_fields() $PLUGIN_HOOKS['config_page']['fields'] = 'front/container.php'; // add entry to configuration menu - $PLUGIN_HOOKS["menu_toadd"]['fields'] = ['config' => 'PluginFieldsMenu']; + $PLUGIN_HOOKS['menu_toadd']['fields'] = ['config' => 'PluginFieldsMenu']; // add tabs to itemtypes $itemtypes = array_unique(PluginFieldsContainer::getEntries()); if (count($itemtypes) > 0) { Plugin::registerClass( 'PluginFieldsContainer', - ['addtabon' => $itemtypes] + ['addtabon' => $itemtypes], ); } @@ -140,15 +140,15 @@ function plugin_init_fields() } // Add/delete profiles to automaticaly to container - $PLUGIN_HOOKS['item_add']['fields']['Profile'] = ["PluginFieldsProfile", "addNewProfile"]; - $PLUGIN_HOOKS['pre_item_purge']['fields']['Profile'] = ["PluginFieldsProfile", "deleteProfile"]; + $PLUGIN_HOOKS['item_add']['fields']['Profile'] = ['PluginFieldsProfile', 'addNewProfile']; + $PLUGIN_HOOKS['pre_item_purge']['fields']['Profile'] = ['PluginFieldsProfile', 'deleteProfile']; //load drag and drop javascript library on Package Interface if ( - plugin_fields_script_endswith("container.form.php") + plugin_fields_script_endswith('container.form.php') ) { - $PLUGIN_HOOKS['add_javascript']['fields'][] = "lib/redips-drag-min.js"; + $PLUGIN_HOOKS['add_javascript']['fields'][] = 'lib/redips-drag-min.js'; if (!$debug && file_exists(__DIR__ . '/js/drag-field-row.min.js')) { $PLUGIN_HOOKS['add_javascript']['fields'][] = 'js/drag-field-row.min.js'; } else { @@ -159,7 +159,7 @@ function plugin_init_fields() // Add Fields to Datainjection if (Plugin::isPluginActive('datainjection')) { - $PLUGIN_HOOKS['plugin_datainjection_populate']['fields'] = "plugin_datainjection_populate_fields"; + $PLUGIN_HOOKS['plugin_datainjection_populate']['fields'] = 'plugin_datainjection_populate_fields'; } //Retrieve dom container @@ -167,20 +167,20 @@ function plugin_init_fields() if ($itemtypes !== false) { foreach ($itemtypes as $itemtype) { $PLUGIN_HOOKS['pre_item_update']['fields'][$itemtype] = [ - "PluginFieldsContainer", - "preItemUpdate" + 'PluginFieldsContainer', + 'preItemUpdate', ]; - $PLUGIN_HOOKS['pre_item_add']['fields'][$itemtype] = [ - "PluginFieldsContainer", - "preItem" + $PLUGIN_HOOKS['pre_item_add']['fields'][$itemtype] = [ + 'PluginFieldsContainer', + 'preItem', ]; - $PLUGIN_HOOKS['item_add']['fields'][$itemtype] = [ - "PluginFieldsContainer", - "postItemAdd" + $PLUGIN_HOOKS['item_add']['fields'][$itemtype] = [ + 'PluginFieldsContainer', + 'postItemAdd', ]; $PLUGIN_HOOKS['pre_item_purge'] ['fields'][$itemtype] = [ - "PluginFieldsContainer", - "preItemPurge" + 'PluginFieldsContainer', + 'preItemPurge', ]; } } @@ -188,7 +188,7 @@ function plugin_init_fields() // Display fields in any existing tab $PLUGIN_HOOKS['post_item_form']['fields'] = [ 'PluginFieldsField', - 'showForTab' + 'showForTab', ]; } } @@ -203,7 +203,7 @@ function plugin_init_fields() function plugin_fields_script_endswith($scriptname) { //append plugin directory to avoid dumb errors... - $scriptname = 'fields/front/' . $scriptname; + $scriptname = 'fields/front/' . $scriptname; $script_name = $_SERVER['SCRIPT_NAME']; return substr($script_name, -strlen($scriptname)) === $scriptname; @@ -220,18 +220,18 @@ function plugin_fields_script_endswith($scriptname) function plugin_version_fields() { return [ - 'name' => __("Additional fields", "fields"), - 'version' => PLUGIN_FIELDS_VERSION, - 'author' => 'Teclib\', Olivier Moron', - 'homepage' => 'https://github.com/pluginsGLPI/fields', - 'license' => 'GPLv2+', - 'requirements' => [ + 'name' => __('Additional fields', 'fields'), + 'version' => PLUGIN_FIELDS_VERSION, + 'author' => 'Teclib\', Olivier Moron', + 'homepage' => 'https://github.com/pluginsGLPI/fields', + 'license' => 'GPLv2+', + 'requirements' => [ 'glpi' => [ 'min' => PLUGIN_FIELDS_MIN_GLPI, 'max' => PLUGIN_FIELDS_MAX_GLPI, 'dev' => true, //Required to allow 9.2-dev - ] - ] + ], + ], ]; } @@ -244,7 +244,8 @@ function plugin_version_fields() function plugin_fields_check_prerequisites() { if (!is_readable(__DIR__ . '/vendor/autoload.php') || !is_file(__DIR__ . '/vendor/autoload.php')) { - echo "Run composer install --no-dev in the plugin directory
"; + echo 'Run composer install --no-dev in the plugin directory
'; + return false; } @@ -299,10 +300,10 @@ function plugin_fields_exportBlockAsYaml($container_id = null) && Plugin::isPluginActive('fields') ) { if ($DB->tableExists(PluginFieldsContainer::getTable())) { - $where = []; - $where["is_active"] = true; + $where = []; + $where['is_active'] = true; if ($container_id != null) { - $where["id"] = $container_id; + $where['id'] = $container_id; } $container_obj = new PluginFieldsContainer(); $containers = $container_obj->find($where); @@ -315,67 +316,67 @@ function plugin_fields_exportBlockAsYaml($container_id = null) foreach ($itemtypes as $itemtype) { $fields_obj = new PluginFieldsField(); // to get translation - $container["itemtype"] = PluginFieldsContainer::getType(); - $yaml_conf['container'][$container['id'] . "-" . $itemtype] = [ - "id" => (int) $container['id'], - "name" => PluginFieldsLabelTranslation::getLabelFor($container), - "itemtype" => $itemtype, - "type" => $container['type'], - "subtype" => $container['subtype'], - "fields" => [], + $container['itemtype'] = PluginFieldsContainer::getType(); + $yaml_conf['container'][$container['id'] . '-' . $itemtype] = [ + 'id' => (int) $container['id'], + 'name' => PluginFieldsLabelTranslation::getLabelFor($container), + 'itemtype' => $itemtype, + 'type' => $container['type'], + 'subtype' => $container['subtype'], + 'fields' => [], ]; - $fields = $fields_obj->find(["plugin_fields_containers_id" => $container['id'], - "is_active" => true, - "is_readonly" => false + $fields = $fields_obj->find(['plugin_fields_containers_id' => $container['id'], + 'is_active' => true, + 'is_readonly' => false, ]); if (count($fields)) { foreach ($fields as $field) { - $tmp_field = []; + $tmp_field = []; $tmp_field['id'] = (int) $field['id']; - //to get translation - $field["itemtype"] = PluginFieldsField::getType(); - $tmp_field['label'] = PluginFieldsLabelTranslation::getLabelFor($field); - $tmp_field['xml_node'] = strtoupper($field['name']); - $tmp_field['type'] = $field['type']; - $tmp_field['ranking'] = $field['ranking']; - $tmp_field['default_value'] = $field['default_value']; - $tmp_field['mandatory'] = $field['mandatory']; - $tmp_field['possible_value'] = ""; + //to get translation + $field['itemtype'] = PluginFieldsField::getType(); + $tmp_field['label'] = PluginFieldsLabelTranslation::getLabelFor($field); + $tmp_field['xml_node'] = strtoupper($field['name']); + $tmp_field['type'] = $field['type']; + $tmp_field['ranking'] = $field['ranking']; + $tmp_field['default_value'] = $field['default_value']; + $tmp_field['mandatory'] = $field['mandatory']; + $tmp_field['possible_value'] = ''; switch ($field['type']) { case 'dropdown': $obj = new $itemtype(); $obj->getEmpty(); - $dropdown_itemtype = PluginFieldsDropdown::getClassname($field['name']); + $dropdown_itemtype = PluginFieldsDropdown::getClassname($field['name']); $tmp_field['xml_node'] = strtoupper(getForeignKeyFieldForItemType($dropdown_itemtype)); - $dropdown_obj = new $dropdown_itemtype(); + $dropdown_obj = new $dropdown_itemtype(); $dropdown_datas = $dropdown_obj->find(); - $datas = []; + $datas = []; foreach ($dropdown_datas as $value) { - $items = []; - $items['id'] = (int)$value['id']; - $items['value'] = $value['name']; - $datas[] = $items; + $items = []; + $items['id'] = (int) $value['id']; + $items['value'] = $value['name']; + $datas[] = $items; } $tmp_field['possible_value'] = $datas; break; case 'yesno': - $datas = []; - $datas["0"]['id'] = 0; - $datas["0"]['value'] = __('No'); - $datas["1"]['id'] = 1; - $datas["1"]['value'] = __('Yes'); + $datas = []; + $datas['0']['id'] = 0; + $datas['0']['value'] = __('No'); + $datas['1']['id'] = 1; + $datas['1']['value'] = __('Yes'); $tmp_field['possible_value'] = $datas; break; case 'dropdownuser': - $datas = Dropdown::getDropdownUsers(['is_active' => 1,'is_deleted' => 0], false); + $datas = Dropdown::getDropdownUsers(['is_active' => 1, 'is_deleted' => 0], false); $tmp_field['possible_value'] = $datas['results']; break; } - $yaml_conf['container'][$container['id'] . "-" . $itemtype]["fields"][] = $tmp_field; + $yaml_conf['container'][$container['id'] . '-' . $itemtype]['fields'][] = $tmp_field; } } } @@ -384,9 +385,10 @@ function plugin_fields_exportBlockAsYaml($container_id = null) } if (count($yaml_conf)) { - $dump = Yaml::dump($yaml_conf, 10); - $filename = GLPI_TMP_DIR . "/fields_conf.yaml"; + $dump = Yaml::dump($yaml_conf, 10); + $filename = GLPI_TMP_DIR . '/fields_conf.yaml'; file_put_contents($filename, $dump); + return true; }