diff --git a/.eslintrc.js b/.eslintrc.js
new file mode 100644
index 0000000..f2d44b7
--- /dev/null
+++ b/.eslintrc.js
@@ -0,0 +1,44 @@
+
+module.exports = {
+ "root": true,
+ "ignorePatterns": [
+ "/node_modules/*",
+ "/vendor/*",
+ ],
+ "env": {
+ "browser": true,
+ "es6": true,
+ "jquery": true,
+ },
+ "extends": "eslint:recommended",
+ "globals": {
+ "CFG_GLPI": true,
+ "GLPI_PLUGINS_PATH": true,
+ "__": true,
+ "_n": true,
+ "_x": true,
+ "_nx": true
+ },
+ "parserOptions": {
+ "ecmaVersion": 8,
+ },
+ "plugins": [
+ "@stylistic/js",
+ ],
+ "rules": {
+ "no-console": ["error", {"allow": ["warn", "error"]}],
+ "no-unused-vars": ["error", {"vars": "local"}],
+ "@stylistic/js/eol-last": ["error", "always"],
+ "@stylistic/js/indent": ["error", 4],
+ "@stylistic/js/linebreak-style": ["error", "unix"],
+ "@stylistic/js/semi": ["error", "always"],
+ },
+ "overrides": [
+ {
+ "files": [".eslintrc.js", ".stylelintrc.js"],
+ "env": {
+ "node": true
+ }
+ },
+ ],
+};
diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml
new file mode 100644
index 0000000..77f0f86
--- /dev/null
+++ b/.github/workflows/continuous-integration.yml
@@ -0,0 +1,31 @@
+name: "Continuous integration"
+
+on:
+ push:
+ branches:
+ - "master"
+ tags:
+ - "*"
+ pull_request:
+ schedule:
+ - cron: "0 0 * * *"
+ workflow_dispatch:
+
+jobs:
+ ci:
+ name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}"
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - {glpi-version: "10.0.x", php-version: "7.4", db-image: "mysql:5.7"}
+ - {glpi-version: "10.0.x", php-version: "8.0", db-image: "mysql:8.0"}
+ - {glpi-version: "10.0.x", php-version: "8.1", db-image: "mariadb:10.2"}
+ - {glpi-version: "10.0.x", php-version: "8.2", db-image: "mariadb:11.0"}
+ - {glpi-version: "10.0.x", php-version: "8.3-rc", db-image: "mysql:8.0"}
+ uses: "glpi-project/plugin-ci-workflows/.github/workflows/continuous-integration.yml@v1"
+ with:
+ plugin-key: "tag"
+ glpi-version: "${{ matrix.glpi-version }}"
+ php-version: "${{ matrix.php-version }}"
+ db-image: "${{ matrix.db-image }}"
diff --git a/.gitignore b/.gitignore
index f033123..f5446d0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,4 @@
-dist/
-vendor/
+/dist/
+/node_modules/
+/vendor/
.gh_token
-*.min.*
-
diff --git a/.phpcs.xml b/.phpcs.xml
new file mode 100644
index 0000000..7cc76ed
--- /dev/null
+++ b/.phpcs.xml
@@ -0,0 +1,18 @@
+
+
+ .
+ /.git/
+ ^node_modules/
+ ^vendor/
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.stylelintrc.js b/.stylelintrc.js
new file mode 100644
index 0000000..80ff93d
--- /dev/null
+++ b/.stylelintrc.js
@@ -0,0 +1,11 @@
+
+module.exports = {
+ "extends": "stylelint-config-standard",
+ "ignoreFiles": [
+ "node_modules/**/*",
+ "vendor/**/*"
+ ],
+ "rules": {
+ "selector-class-pattern": null, // DISABLE: Expected class selector to be kebab-case
+ },
+};
diff --git a/ajax/get_entity_tags.php b/ajax/get_entity_tags.php
index 48f2e0d..619a824 100644
--- a/ajax/get_entity_tags.php
+++ b/ajax/get_entity_tags.php
@@ -28,14 +28,14 @@
* -------------------------------------------------------------------------
*/
-include ("../../../inc/includes.php");
+include("../../../inc/includes.php");
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
if (!isset($_REQUEST['name'])) {
- exit;
+ exit;
}
echo PluginTagTag::getTagForEntityName($_REQUEST['name']);
diff --git a/composer.json b/composer.json
index 4d0e2db..e511074 100644
--- a/composer.json
+++ b/composer.json
@@ -3,13 +3,21 @@
"php": ">=7.4"
},
"require-dev": {
- "glpi-project/tools": "^0.6"
+ "glpi-project/tools": "^0.7.1",
+ "php-parallel-lint/php-parallel-lint": "^1.3",
+ "phpstan/extension-installer": "^1.3",
+ "phpstan/phpstan": "^1.10",
+ "phpstan/phpstan-deprecation-rules": "^1.1",
+ "squizlabs/php_codesniffer": "^3.7"
},
"config": {
"optimize-autoloader": true,
"platform": {
"php": "7.4.0"
},
- "sort-packages": true
+ "sort-packages": true,
+ "allow-plugins": {
+ "phpstan/extension-installer": true
+ }
}
}
diff --git a/composer.lock b/composer.lock
index ff4864b..4853b57 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,27 +4,31 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "49ff730c8068667841d45903c3c04259",
+ "content-hash": "53b0dda4208b78e493a979e2ed492618",
"packages": [],
"packages-dev": [
{
"name": "glpi-project/tools",
- "version": "0.6.4",
+ "version": "0.7.1",
"source": {
"type": "git",
"url": "https://github.com/glpi-project/tools.git",
- "reference": "8ef917fa2967e716eaed198bb803f418a80cd621"
+ "reference": "4bc5a725d9f4da0ee946ad3cbdd54a782d2f40fb"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/glpi-project/tools/zipball/8ef917fa2967e716eaed198bb803f418a80cd621",
- "reference": "8ef917fa2967e716eaed198bb803f418a80cd621",
+ "url": "https://api.github.com/repos/glpi-project/tools/zipball/4bc5a725d9f4da0ee946ad3cbdd54a782d2f40fb",
+ "reference": "4bc5a725d9f4da0ee946ad3cbdd54a782d2f40fb",
"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",
@@ -33,7 +37,7 @@
"type": "library",
"autoload": {
"psr-4": {
- "Glpi\\": "src/"
+ "GlpiProject\\Tools\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -57,7 +61,218 @@
"issues": "https://github.com/glpi-project/tools/issues",
"source": "https://github.com/glpi-project/tools"
},
- "time": "2023-07-27T12:32:25+00:00"
+ "time": "2023-10-16T11:40:35+00:00"
+ },
+ {
+ "name": "php-parallel-lint/php-parallel-lint",
+ "version": "v1.3.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/php-parallel-lint/PHP-Parallel-Lint.git",
+ "reference": "6483c9832e71973ed29cf71bd6b3f4fde438a9de"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/php-parallel-lint/PHP-Parallel-Lint/zipball/6483c9832e71973ed29cf71bd6b3f4fde438a9de",
+ "reference": "6483c9832e71973ed29cf71bd6b3f4fde438a9de",
+ "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 check syntax of PHP files about 20x faster than serial check.",
+ "homepage": "https://github.com/php-parallel-lint/PHP-Parallel-Lint",
+ "support": {
+ "issues": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/issues",
+ "source": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/tree/v1.3.2"
+ },
+ "time": "2022-02-21T12:50:22+00:00"
+ },
+ {
+ "name": "phpstan/extension-installer",
+ "version": "1.3.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/phpstan/extension-installer.git",
+ "reference": "f45734bfb9984c6c56c4486b71230355f066a58a"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/f45734bfb9984c6c56c4486b71230355f066a58a",
+ "reference": "f45734bfb9984c6c56c4486b71230355f066a58a",
+ "shasum": ""
+ },
+ "require": {
+ "composer-plugin-api": "^2.0",
+ "php": "^7.2 || ^8.0",
+ "phpstan/phpstan": "^1.9.0"
+ },
+ "require-dev": {
+ "composer/composer": "^2.0",
+ "php-parallel-lint/php-parallel-lint": "^1.2.0",
+ "phpstan/phpstan-strict-rules": "^0.11 || ^0.12 || ^1.0"
+ },
+ "type": "composer-plugin",
+ "extra": {
+ "class": "PHPStan\\ExtensionInstaller\\Plugin"
+ },
+ "autoload": {
+ "psr-4": {
+ "PHPStan\\ExtensionInstaller\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "description": "Composer plugin for automatic installation of PHPStan extensions",
+ "support": {
+ "issues": "https://github.com/phpstan/extension-installer/issues",
+ "source": "https://github.com/phpstan/extension-installer/tree/1.3.1"
+ },
+ "time": "2023-05-24T08:59:17+00:00"
+ },
+ {
+ "name": "phpstan/phpstan",
+ "version": "1.10.41",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/phpstan/phpstan.git",
+ "reference": "c6174523c2a69231df55bdc65b61655e72876d76"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/phpstan/phpstan/zipball/c6174523c2a69231df55bdc65b61655e72876d76",
+ "reference": "c6174523c2a69231df55bdc65b61655e72876d76",
+ "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"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2023-11-05T12:57:57+00:00"
+ },
+ {
+ "name": "phpstan/phpstan-deprecation-rules",
+ "version": "1.1.4",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/phpstan/phpstan-deprecation-rules.git",
+ "reference": "089d8a8258ed0aeefdc7b68b6c3d25572ebfdbaa"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/089d8a8258ed0aeefdc7b68b6c3d25572ebfdbaa",
+ "reference": "089d8a8258ed0aeefdc7b68b6c3d25572ebfdbaa",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^7.2 || ^8.0",
+ "phpstan/phpstan": "^1.10.3"
+ },
+ "require-dev": {
+ "php-parallel-lint/php-parallel-lint": "^1.2",
+ "phpstan/phpstan-php-parser": "^1.1",
+ "phpstan/phpstan-phpunit": "^1.0",
+ "phpunit/phpunit": "^9.5"
+ },
+ "type": "phpstan-extension",
+ "extra": {
+ "phpstan": {
+ "includes": [
+ "rules.neon"
+ ]
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "PHPStan\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.",
+ "support": {
+ "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues",
+ "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/1.1.4"
+ },
+ "time": "2023-08-05T09:02:04+00:00"
},
{
"name": "psr/container",
@@ -107,6 +322,63 @@
},
"time": "2021-11-05T16:50:12+00:00"
},
+ {
+ "name": "squizlabs/php_codesniffer",
+ "version": "3.7.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
+ "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ed8e00df0a83aa96acf703f8c2979ff33341f879",
+ "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879",
+ "shasum": ""
+ },
+ "require": {
+ "ext-simplexml": "*",
+ "ext-tokenizer": "*",
+ "ext-xmlwriter": "*",
+ "php": ">=5.4.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
+ },
+ "bin": [
+ "bin/phpcs",
+ "bin/phpcbf"
+ ],
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.x-dev"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Greg Sherwood",
+ "role": "lead"
+ }
+ ],
+ "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
+ "homepage": "https://github.com/squizlabs/PHP_CodeSniffer",
+ "keywords": [
+ "phpcs",
+ "standards",
+ "static analysis"
+ ],
+ "support": {
+ "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues",
+ "source": "https://github.com/squizlabs/PHP_CodeSniffer",
+ "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki"
+ },
+ "time": "2023-02-22T23:07:41+00:00"
+ },
{
"name": "symfony/console",
"version": "v5.4.26",
@@ -1018,5 +1290,5 @@
"platform-overrides": {
"php": "7.4.0"
},
- "plugin-api-version": "2.3.0"
+ "plugin-api-version": "2.6.0"
}
diff --git a/front/tag.form.php b/front/tag.form.php
index 3a76b74..8a32c90 100644
--- a/front/tag.form.php
+++ b/front/tag.form.php
@@ -28,30 +28,32 @@
* -------------------------------------------------------------------------
*/
-include ('../../../inc/includes.php');
+include('../../../inc/includes.php');
Session::checkRight(PluginTagTag::$rightname, UPDATE);
if (!Plugin::isPluginActive("tag")) {
- Html::displayNotFoundError();
+ Html::displayNotFoundError();
}
if (isset($_POST['add'])) {
- $item = new PluginTagTagItem();
-
- // Check unicity :
- if (isset($_REQUEST['plugin_tag_tags_id'])) {
- $found = $item->find(['plugin_tag_tags_id' => $_REQUEST['plugin_tag_tags_id'],
- 'items_id' => $_REQUEST['items_id'],
- 'itemtype' => $_REQUEST['itemtype']]);
-
- if (count($found) == 0) {
- $item->add($_REQUEST);
- }
- } else {
- $item->add($_REQUEST);
- }
+ $item = new PluginTagTagItem();
+
+ // Check unicity :
+ if (isset($_REQUEST['plugin_tag_tags_id'])) {
+ $found = $item->find([
+ 'plugin_tag_tags_id' => $_REQUEST['plugin_tag_tags_id'],
+ 'items_id' => $_REQUEST['items_id'],
+ 'itemtype' => $_REQUEST['itemtype']
+ ]);
+
+ if (count($found) == 0) {
+ $item->add($_REQUEST);
+ }
+ } else {
+ $item->add($_REQUEST);
+ }
}
$dropdown = new PluginTagTag();
-include (GLPI_ROOT . "/front/dropdown.common.form.php");
+include(GLPI_ROOT . "/front/dropdown.common.form.php");
diff --git a/front/tag.php b/front/tag.php
index c1c2305..36ce012 100644
--- a/front/tag.php
+++ b/front/tag.php
@@ -28,10 +28,9 @@
* -------------------------------------------------------------------------
*/
-include ('../../../inc/includes.php');
+include('../../../inc/includes.php');
if (Plugin::isPluginActive("tag")) {
-
- $dropdown = new PluginTagTag();
- include (GLPI_ROOT . "/front/dropdown.common.php");
+ $dropdown = new PluginTagTag();
+ include(GLPI_ROOT . "/front/dropdown.common.php");
}
diff --git a/hook.php b/hook.php
index f8eb8a9..0822246 100644
--- a/hook.php
+++ b/hook.php
@@ -29,134 +29,141 @@
*/
// Plugin hook after *Uninstall*
-function plugin_uninstall_after_tag($item) {
- $tagitem = new PluginTagTagItem();
- $tagitem->deleteByCriteria([
- 'itemtype' => $item->getType(),
- 'items_id' => $item->getID()
- ]);
+function plugin_uninstall_after_tag($item)
+{
+ $tagitem = new PluginTagTagItem();
+ $tagitem->deleteByCriteria([
+ 'itemtype' => $item->getType(),
+ 'items_id' => $item->getID()
+ ]);
}
-function plugin_datainjection_populate_tag() {
- global $INJECTABLE_TYPES;
+function plugin_datainjection_populate_tag()
+{
+ /** @var array $INJECTABLE_TYPES */
+ global $INJECTABLE_TYPES;
- $INJECTABLE_TYPES['PluginTagTagInjection'] = 'tag';
+ $INJECTABLE_TYPES['PluginTagTagInjection'] = 'tag';
}
-function plugin_tag_getAddSearchOptionsNew($itemtype) {
- if (!PluginTagTag::canView() || !PluginTagTag::canItemtype($itemtype)) {
- return [];
- }
-
- $options = [
- [
- 'id' => PluginTagTag::S_OPTION,
- 'table' => PluginTagTag::getTable(),
- 'field' => 'name',
- 'name' => PluginTagTag::getTypeName(2),
- 'datatype' => 'dropdown',
- 'searchtype' => ['equals','notequals','contains'],
- 'massiveaction' => false,
- 'forcegroupby' => true,
- 'joinparams' => [
- 'beforejoin' => [
- 'table' => 'glpi_plugin_tag_tagitems',
- 'joinparams' => [
- 'jointype' => 'itemtype_item'
- ]
- ]
- ]
- ]
- ];
-
- if ($itemtype != 'AllAssets') {
- $item = new $itemtype;
- if ($item->isEntityAssign()) {
- $options [] = [
- 'id' => (PluginTagTag::S_OPTION + 1),
+function plugin_tag_getAddSearchOptionsNew($itemtype)
+{
+ if (!PluginTagTag::canView() || !PluginTagTag::canItemtype($itemtype)) {
+ return [];
+ }
+
+ $options = [
+ [
+ 'id' => PluginTagTag::S_OPTION,
'table' => PluginTagTag::getTable(),
'field' => 'name',
- 'name' => PluginTagTag::getTypeName(2)." - ".__("Entity"),
- 'datatype' => 'string',
- 'searchtype' => 'contains',
+ 'name' => PluginTagTag::getTypeName(2),
+ 'datatype' => 'dropdown',
+ 'searchtype' => ['equals','notequals','contains'],
'massiveaction' => false,
'forcegroupby' => true,
- 'usehaving' => true,
'joinparams' => [
- 'condition' => "AND 1=1", // to force distinct complex id than the previous option
- 'beforejoin' => [
- 'table' => 'glpi_plugin_tag_tagitems',
- 'joinparams' => [
- 'jointype' => 'itemtype_item',
- 'specific_itemtype' => 'Entity',
- 'beforejoin' => [
- 'table' => 'glpi_entities',
- ]
- ]
- ]
+ 'beforejoin' => [
+ 'table' => 'glpi_plugin_tag_tagitems',
+ 'joinparams' => [
+ 'jointype' => 'itemtype_item'
+ ]
+ ]
]
- ];
- }
- }
-
- return $options;
+ ]
+ ];
+
+ if ($itemtype != 'AllAssets') {
+ $item = new $itemtype();
+ if ($item->isEntityAssign()) {
+ $options [] = [
+ 'id' => (PluginTagTag::S_OPTION + 1),
+ 'table' => PluginTagTag::getTable(),
+ 'field' => 'name',
+ 'name' => PluginTagTag::getTypeName(2) . " - " . __("Entity"),
+ 'datatype' => 'string',
+ 'searchtype' => 'contains',
+ 'massiveaction' => false,
+ 'forcegroupby' => true,
+ 'usehaving' => true,
+ 'joinparams' => [
+ 'condition' => "AND 1=1", // to force distinct complex id than the previous option
+ 'beforejoin' => [
+ 'table' => 'glpi_plugin_tag_tagitems',
+ 'joinparams' => [
+ 'jointype' => 'itemtype_item',
+ 'specific_itemtype' => 'Entity',
+ 'beforejoin' => [
+ 'table' => 'glpi_entities',
+ ]
+ ]
+ ]
+ ]
+ ];
+ }
+ }
+
+ return $options;
}
-function plugin_tag_giveItem($type, $field, $data, $num, $linkfield = "") {
- switch ($field) {
- case PluginTagTag::S_OPTION:
- case PluginTagTag::S_OPTION+1:
- $out = '
+function plugin_tag_giveItem($type, $field, $data, $num, $linkfield = "")
+{
+ switch ($field) {
+ case PluginTagTag::S_OPTION:
+ case PluginTagTag::S_OPTION + 1:
+ $out = '
';
- $separator = '';
- foreach ($data[$num] as $tag) {
- if (isset($tag['id']) && isset($tag['name'])) {
- $out .= PluginTagTag::getSingleTag($tag['id'], $separator);
- //For export (CSV, PDF) of GLPI core
- $separator = ', ';
+ $separator = '';
+ foreach ($data[$num] as $tag) {
+ if (isset($tag['id']) && isset($tag['name'])) {
+ $out .= PluginTagTag::getSingleTag($tag['id'], $separator);
+ //For export (CSV, PDF) of GLPI core
+ $separator = ', ';
+ }
}
- }
- $out .= '
';
- return $out;
- }
+ $out .= '
';
+ return $out;
+ }
- return "";
+ return "";
}
-function plugin_tag_addHaving($link, $nott, $itemtype, $id, $val, $num) {
- $searchopt = &Search::getOptions($itemtype);
- $table = $searchopt[$id]["table"];
- $field = $searchopt[$id]["field"];
-
- if ($table.".".$field == "glpi_plugin_tag_tags.type_menu") {
- $values = explode(",", $val);
- $where = "$link `ITEM_$num` LIKE '%".$values[0]."%'";
- array_shift($values);
- foreach ($values as $value) {
- $value = trim($value);
- $where .= " OR `ITEM_$num` LIKE '%$value%'";
- }
- return $where;
- }
+function plugin_tag_addHaving($link, $nott, $itemtype, $id, $val, $num)
+{
+ $searchopt = &Search::getOptions($itemtype);
+ $table = $searchopt[$id]["table"];
+ $field = $searchopt[$id]["field"];
+
+ if ($table . "." . $field == "glpi_plugin_tag_tags.type_menu") {
+ $values = explode(",", $val);
+ $where = "$link `ITEM_$num` LIKE '%" . $values[0] . "%'";
+ array_shift($values);
+ foreach ($values as $value) {
+ $value = trim($value);
+ $where .= " OR `ITEM_$num` LIKE '%$value%'";
+ }
+ return $where;
+ }
}
-function plugin_tag_addWhere($link, $nott, $itemtype, $id, $val, $searchtype) {
- $searchopt = &Search::getOptions($itemtype);
- $table = $searchopt[$id]["table"];
- $field = $searchopt[$id]["field"];
+function plugin_tag_addWhere($link, $nott, $itemtype, $id, $val, $searchtype)
+{
+ $searchopt = &Search::getOptions($itemtype);
+ $table = $searchopt[$id]["table"];
+ $field = $searchopt[$id]["field"];
- if ($table.".".$field == "glpi_plugin_tag_tags.type_menu") {
- switch ($searchtype) {
- case 'equals':
- return "`glpi_plugin_tag_tags`.`type_menu` LIKE '%\"$val\"%'";
+ if ($table . "." . $field == "glpi_plugin_tag_tags.type_menu") {
+ switch ($searchtype) {
+ case 'equals':
+ return "`glpi_plugin_tag_tags`.`type_menu` LIKE '%\"$val\"%'";
- case 'notequals':
- return "`glpi_plugin_tag_tags`.`type_menu` NOT LIKE '%\"$val\"%'";
- }
- }
+ case 'notequals':
+ return "`glpi_plugin_tag_tags`.`type_menu` NOT LIKE '%\"$val\"%'";
+ }
+ }
- return "";
+ return "";
}
@@ -165,8 +172,9 @@ function plugin_tag_addWhere($link, $nott, $itemtype, $id, $val, $searchtype) {
*
* @return array the list of dropdowns (label => class)
*/
-function plugin_tag_getDropdown() {
- return ['PluginTagTag' => PluginTagTag::getTypeName(2)];
+function plugin_tag_getDropdown()
+{
+ return ['PluginTagTag' => PluginTagTag::getTypeName(2)];
}
/**
@@ -175,17 +183,18 @@ function plugin_tag_getDropdown() {
* @param string $itemtype
* @return array the massive action list
*/
-function plugin_tag_MassiveActions($itemtype = '') {
- if (PluginTagTag::canItemtype($itemtype) && is_a($itemtype, CommonDBTM::class, true) && $itemtype::canUpdate()) {
- return [
- 'PluginTagTagItem'.MassiveAction::CLASS_ACTION_SEPARATOR.'addTag'
+function plugin_tag_MassiveActions($itemtype = '')
+{
+ if (PluginTagTag::canItemtype($itemtype) && is_a($itemtype, CommonDBTM::class, true) && $itemtype::canUpdate()) {
+ return [
+ 'PluginTagTagItem' . MassiveAction::CLASS_ACTION_SEPARATOR . 'addTag'
=> __("Add tags", 'tag'),
- 'PluginTagTagItem'.MassiveAction::CLASS_ACTION_SEPARATOR.'removeTag'
+ 'PluginTagTagItem' . MassiveAction::CLASS_ACTION_SEPARATOR . 'removeTag'
=> __("Remove tags", 'tag'),
- ];
- }
+ ];
+ }
- return [];
+ return [];
}
/**
@@ -193,29 +202,30 @@ function plugin_tag_MassiveActions($itemtype = '') {
*
* @return boolean
*/
-function plugin_tag_install() {
- $version = plugin_version_tag();
- $migration = new Migration($version['version']);
-
- // Parse inc directory
- foreach (glob(dirname(__FILE__).'/inc/*') as $filepath) {
- // Load *.class.php files and get the class name
- if (preg_match("/inc.(.+)\.class.php/", $filepath, $matches)) {
- $classname = 'PluginTag' . ucfirst($matches[1]);
-
- // Don't load Datainjection mapping lass (no install + bug if datainjection is not installed and activated)
- if ($classname == 'PluginTagTaginjection') {
- continue;
- }
-
- include_once($filepath);
- // If the install method exists, load it
- if (method_exists($classname, 'install')) {
- $classname::install($migration);
- }
- }
- }
- return true;
+function plugin_tag_install()
+{
+ $version = plugin_version_tag();
+ $migration = new Migration($version['version']);
+
+ // Parse inc directory
+ foreach (glob(dirname(__FILE__) . '/inc/*') as $filepath) {
+ // Load *.class.php files and get the class name
+ if (preg_match("/inc.(.+)\.class.php/", $filepath, $matches)) {
+ $classname = 'PluginTag' . ucfirst($matches[1]);
+
+ // Don't load Datainjection mapping lass (no install + bug if datainjection is not installed and activated)
+ if ($classname == 'PluginTagTaginjection') {
+ continue;
+ }
+
+ include_once($filepath);
+ // If the install method exists, load it
+ if (method_exists($classname, 'install')) {
+ $classname::install($migration);
+ }
+ }
+ }
+ return true;
}
/**
@@ -223,63 +233,66 @@ function plugin_tag_install() {
*
* @return boolean
*/
-function plugin_tag_uninstall() {
- // Parse inc directory
- foreach (glob(dirname(__FILE__).'/inc/*') as $filepath) {
- // Load *.class.php files and get the class name
- if (preg_match("/inc.(.+)\.class.php/", $filepath, $matches)) {
- $classname = 'PluginTag' . ucfirst($matches[1]);
-
- // Don't load Datainjection mapping lass (no uninstall + bug if datainjection is not installed and activated)
- if ($classname == 'PluginTagTaginjection') {
- continue;
- }
-
- include_once($filepath);
- // If the uninstall method exists, load it
- if (method_exists($classname, 'uninstall')) {
- $classname::uninstall();
- }
- }
- }
- return true;
+function plugin_tag_uninstall()
+{
+ // Parse inc directory
+ foreach (glob(dirname(__FILE__) . '/inc/*') as $filepath) {
+ // Load *.class.php files and get the class name
+ if (preg_match("/inc.(.+)\.class.php/", $filepath, $matches)) {
+ $classname = 'PluginTag' . ucfirst($matches[1]);
+
+ // Don't load Datainjection mapping lass (no uninstall + bug if datainjection is not installed and activated)
+ if ($classname == 'PluginTagTaginjection') {
+ continue;
+ }
+
+ include_once($filepath);
+ // If the uninstall method exists, load it
+ if (method_exists($classname, 'uninstall')) {
+ $classname::uninstall();
+ }
+ }
+ }
+ return true;
}
-function plugin_tag_post_init() {
- global $PLUGIN_HOOKS;
-
- // hook on object changes
- if ($itemtype = PluginTagTag::getCurrentItemtype()) {
- if (PluginTagTag::canItemtype($itemtype)) {
- $PLUGIN_HOOKS['item_add']['tag'][$itemtype] = ['PluginTagTagItem', 'updateItem'];
- $PLUGIN_HOOKS['pre_item_update']['tag'][$itemtype] = ['PluginTagTagItem', 'updateItem'];
- $PLUGIN_HOOKS['pre_item_purge']['tag'][$itemtype] = ['PluginTagTagItem', 'purgeItem'];
- }
- }
-
- // Always define hook for tickets
- // Needed for rules to function properly when a ticket is created from a mail
- // collector
- $PLUGIN_HOOKS['item_add']['tag'][Ticket::getType()] = ['PluginTagTagItem', 'updateItem'];
- $PLUGIN_HOOKS['pre_item_update']['tag'][Ticket::getType()] = ['PluginTagTagItem', 'updateItem'];
- $PLUGIN_HOOKS['pre_item_purge']['tag'][Ticket::getType()] = ['PluginTagTagItem', 'purgeItem'];
+function plugin_tag_post_init()
+{
+ /** @var array $PLUGIN_HOOKS */
+ global $PLUGIN_HOOKS;
+
+ // hook on object changes
+ if ($itemtype = PluginTagTag::getCurrentItemtype()) {
+ if (PluginTagTag::canItemtype($itemtype)) {
+ $PLUGIN_HOOKS['item_add']['tag'][$itemtype] = ['PluginTagTagItem', 'updateItem'];
+ $PLUGIN_HOOKS['pre_item_update']['tag'][$itemtype] = ['PluginTagTagItem', 'updateItem'];
+ $PLUGIN_HOOKS['pre_item_purge']['tag'][$itemtype] = ['PluginTagTagItem', 'purgeItem'];
+ }
+ }
+
+ // Always define hook for tickets
+ // Needed for rules to function properly when a ticket is created from a mail
+ // collector
+ $PLUGIN_HOOKS['item_add']['tag'][Ticket::getType()] = ['PluginTagTagItem', 'updateItem'];
+ $PLUGIN_HOOKS['pre_item_update']['tag'][Ticket::getType()] = ['PluginTagTagItem', 'updateItem'];
+ $PLUGIN_HOOKS['pre_item_purge']['tag'][Ticket::getType()] = ['PluginTagTagItem', 'purgeItem'];
}
function plugin_tag_getRuleActions($params = [])
{
- $actions = [];
+ $actions = [];
- switch ($params['rule_itemtype']) {
- case "RuleTicket":
- $actions['_plugin_tag_tag_values'] = [
- 'name' => __("Add tags", 'tag'),
- 'type' => 'dropdown',
- 'table' => PluginTagTag::getTable(),
- 'condition' => ['type_menu' => ['LIKE', '%\"Ticket\"%']],
- ];
+ switch ($params['rule_itemtype']) {
+ case "RuleTicket":
+ $actions['_plugin_tag_tag_values'] = [
+ 'name' => __("Add tags", 'tag'),
+ 'type' => 'dropdown',
+ 'table' => PluginTagTag::getTable(),
+ 'condition' => ['type_menu' => ['LIKE', '%\"Ticket\"%']],
+ ];
- break;
- }
+ break;
+ }
- return $actions;
+ return $actions;
}
diff --git a/inc/config.class.php b/inc/config.class.php
index 26de661..95467e9 100644
--- a/inc/config.class.php
+++ b/inc/config.class.php
@@ -28,64 +28,69 @@
* -------------------------------------------------------------------------
*/
-class PluginTagConfig extends CommonDBTM {
+class PluginTagConfig extends CommonDBTM
+{
+ protected static $notable = true;
- static protected $notable = true;
+ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
+ {
- function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
+ if (!$withtemplate && $item->getType() === 'Config') {
+ return __('Tag Management', 'tag');
+ }
+ return '';
+ }
- if (!$withtemplate && $item->getType() === 'Config') {
- return __('Tag Management', 'tag');
- }
- return '';
- }
+ public function showConfigForm()
+ {
+ if (!Session::haveRight('config', UPDATE)) {
+ return false;
+ }
+ $config = Config::getConfigurationValues('plugin:Tag');
- public function showConfigForm() {
- global $CFG_GLPI;
- if (!Session::haveRight('config', UPDATE)) {
- return false;
- }
- $config = Config::getConfigurationValues('plugin:Tag');
+ echo "