mirror of
https://github.com/pluginsGLPI/example.git
synced 2025-08-24 14:45:48 +02:00
Feature GLP11
This commit is contained in:
@@ -1,16 +1,26 @@
|
|||||||
{
|
{
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.4"
|
"php": ">=8.2"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"friendsofphp/php-cs-fixer": "^3.75",
|
"friendsofphp/php-cs-fixer": "^3.75",
|
||||||
"glpi-project/tools": "^0.7.5"
|
"friendsoftwig/twigcs": "^6.1",
|
||||||
|
"glpi-project/tools": "^0.7.5",
|
||||||
|
"php-parallel-lint/php-parallel-lint": "^1.4"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"optimize-autoloader": true,
|
"optimize-autoloader": true,
|
||||||
"platform": {
|
"platform": {
|
||||||
"php": "7.4.0"
|
"php": "8.2.99"
|
||||||
},
|
},
|
||||||
"sort-packages": true
|
"sort-packages": true,
|
||||||
|
"allow-plugins": {
|
||||||
|
"phpstan/extension-installer": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"Glpi\\Tools\\": "../../tools/src/"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
611
composer.lock
generated
611
composer.lock
generated
File diff suppressed because it is too large
Load Diff
19
hook.php
19
hook.php
@@ -33,9 +33,7 @@
|
|||||||
// Purpose of file:
|
// Purpose of file:
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
use GlpiPlugin\Example\Dropdown;
|
|
||||||
use GlpiPlugin\Example\Example;
|
use GlpiPlugin\Example\Example;
|
||||||
use Dropdown as GlpiDropdown;
|
|
||||||
|
|
||||||
function plugin_change_profile_example()
|
function plugin_change_profile_example()
|
||||||
{
|
{
|
||||||
@@ -72,7 +70,6 @@ function plugin_example_getAddSearchOptions($itemtype)
|
|||||||
$sopt[1001]['linkfield'] = 'plugin_example_dropdowns_id';
|
$sopt[1001]['linkfield'] = 'plugin_example_dropdowns_id';
|
||||||
$sopt[1001]['name'] = __('Example plugin', 'example');
|
$sopt[1001]['name'] = __('Example plugin', 'example');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $sopt;
|
return $sopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +86,6 @@ function plugin_example_getAddSearchOptionsNew($itemtype)
|
|||||||
'name' => __('Example plugin new', 'example'),
|
'name' => __('Example plugin new', 'example'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $options;
|
return $options;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +197,6 @@ function plugin_example_forceGroupBy($type)
|
|||||||
// Force add GROUP BY IN REQUEST
|
// Force add GROUP BY IN REQUEST
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,7 +245,7 @@ function plugin_example_addHaving($link, $nott, $type, $ID, $val, $num)
|
|||||||
$ADD = " OR ITEM_$num IS NULL";
|
$ADD = " OR ITEM_$num IS NULL";
|
||||||
}
|
}
|
||||||
|
|
||||||
return " $LINK ( ITEM_" . $num . $SEARCH . " $ADD ) ";
|
return " $link ( ITEM_" . $num . $SEARCH . " $ADD ) ";
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
@@ -338,7 +333,6 @@ function plugin_example_MassiveActionsFieldsDisplay($options = [])
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to return false on non display item
|
// Need to return false on non display item
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -616,7 +610,6 @@ function plugin_example_install()
|
|||||||
// To be called for each task the plugin manage
|
// To be called for each task the plugin manage
|
||||||
// task in class
|
// task in class
|
||||||
CronTask::Register(Example::class, 'Sample', DAY_TIMESTAMP, ['param' => 50]);
|
CronTask::Register(Example::class, 'Sample', DAY_TIMESTAMP, ['param' => 50]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -710,7 +703,7 @@ function plugin_example_postinit()
|
|||||||
*
|
*
|
||||||
* @param $datas array
|
* @param $datas array
|
||||||
*
|
*
|
||||||
* @return un tableau
|
* @return array
|
||||||
**/
|
**/
|
||||||
function plugin_retrieve_more_data_from_ldap_example(array $datas)
|
function plugin_retrieve_more_data_from_ldap_example(array $datas)
|
||||||
{
|
{
|
||||||
@@ -723,7 +716,7 @@ function plugin_retrieve_more_data_from_ldap_example(array $datas)
|
|||||||
*
|
*
|
||||||
* @param $fields array
|
* @param $fields array
|
||||||
*
|
*
|
||||||
* @return un tableau
|
* @return array
|
||||||
**/
|
**/
|
||||||
function plugin_retrieve_more_field_from_ldap_example($fields)
|
function plugin_retrieve_more_field_from_ldap_example($fields)
|
||||||
{
|
{
|
||||||
@@ -744,7 +737,6 @@ function plugin_example_Status($param)
|
|||||||
$param['ok'] = false;
|
$param['ok'] = false;
|
||||||
}
|
}
|
||||||
echo "\n";
|
echo "\n";
|
||||||
|
|
||||||
return $param;
|
return $param;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -790,12 +782,15 @@ function plugin_example_filter_actors(array $params = []): array
|
|||||||
|
|
||||||
function plugin_example_set_impact_icon(array $params)
|
function plugin_example_set_impact_icon(array $params)
|
||||||
{
|
{
|
||||||
|
/** @var array $CFG_GLPI */
|
||||||
|
global $CFG_GLPI;
|
||||||
|
|
||||||
$itemtype = $params['itemtype'];
|
$itemtype = $params['itemtype'];
|
||||||
$items_id = $params['items_id'];
|
$items_id = $params['items_id'];
|
||||||
|
|
||||||
$item = getItemForItemtype($itemtype);
|
$item = getItemForItemtype($itemtype);
|
||||||
if ($item instanceof Computer && $item->getFromDB($items_id)) {
|
if ($item instanceof Computer && $item->getFromDB($items_id)) {
|
||||||
return Plugin::getWebDir('example', true, false) . '/public/computer_icon.svg';
|
return $CFG_GLPI['root_doc'] . '/plugins/example/public/computer_icon.svg';
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@@ -42,9 +42,9 @@ use GlpiPlugin\Example\Showtabitem;
|
|||||||
define('PLUGIN_EXAMPLE_VERSION', '0.0.1');
|
define('PLUGIN_EXAMPLE_VERSION', '0.0.1');
|
||||||
|
|
||||||
// Minimal GLPI version, inclusive
|
// Minimal GLPI version, inclusive
|
||||||
define('PLUGIN_EXAMPLE_MIN_GLPI', '10.0.0');
|
define('PLUGIN_EXAMPLE_MIN_GLPI', '11.0.0');
|
||||||
// Maximum GLPI version, exclusive
|
// Maximum GLPI version, exclusive
|
||||||
define('PLUGIN_EXAMPLE_MAX_GLPI', '10.0.99');
|
define('PLUGIN_EXAMPLE_MAX_GLPI', '11.0.99');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init hooks of the plugin.
|
* Init hooks of the plugin.
|
||||||
@@ -340,7 +340,6 @@ function plugin_example_check_prerequisites()
|
|||||||
if (false) {
|
if (false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,6 +359,5 @@ function plugin_example_check_config($verbose = false)
|
|||||||
if ($verbose) {
|
if ($verbose) {
|
||||||
echo __('Installed / not configured', 'example');
|
echo __('Installed / not configured', 'example');
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -59,25 +59,25 @@ class Child extends CommonDBChild
|
|||||||
// - CommonDBConnexity::HAVE_SAME_RIGHT_ON_ITEM we must have at least update right
|
// - CommonDBConnexity::HAVE_SAME_RIGHT_ON_ITEM we must have at least update right
|
||||||
// on the item
|
// on the item
|
||||||
// * $mustBeAttached: some CommonDBChild can be free, without any parent.
|
// * $mustBeAttached: some CommonDBChild can be free, without any parent.
|
||||||
public static function canCreate()
|
public static function canCreate(): bool
|
||||||
{
|
{
|
||||||
return (Session::haveRight('internet', UPDATE)
|
return (Session::haveRight('internet', UPDATE)
|
||||||
&& parent::canCreate());
|
&& parent::canCreate());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function canView()
|
public static function canView(): bool
|
||||||
{
|
{
|
||||||
return (Session::haveRight('internet', READ)
|
return (Session::haveRight('internet', READ)
|
||||||
&& parent::canView());
|
&& parent::canView());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function canUpdate()
|
public static function canUpdate(): bool
|
||||||
{
|
{
|
||||||
return (Session::haveRight('internet', UPDATE)
|
return (Session::haveRight('internet', UPDATE)
|
||||||
&& parent::canUpdate());
|
&& parent::canUpdate());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function canDelete()
|
public static function canDelete(): bool
|
||||||
{
|
{
|
||||||
return (Session::haveRight('internet', DELETE)
|
return (Session::haveRight('internet', DELETE)
|
||||||
&& parent::canDelete());
|
&& parent::canDelete());
|
||||||
|
@@ -37,12 +37,6 @@ namespace GlpiPlugin\Example;
|
|||||||
|
|
||||||
use CommonDBTM;
|
use CommonDBTM;
|
||||||
|
|
||||||
// Class of the defined type
|
|
||||||
|
|
||||||
if (!defined('GLPI_ROOT')) {
|
|
||||||
die("Sorry. You can't access directly to this file");
|
|
||||||
}
|
|
||||||
|
|
||||||
class Computer extends CommonDBTM
|
class Computer extends CommonDBTM
|
||||||
{
|
{
|
||||||
public static function showInfo()
|
public static function showInfo()
|
||||||
|
@@ -37,12 +37,6 @@ namespace GlpiPlugin\Example;
|
|||||||
|
|
||||||
use CommonDevice;
|
use CommonDevice;
|
||||||
|
|
||||||
// Class of the defined type
|
|
||||||
|
|
||||||
if (!defined('GLPI_ROOT')) {
|
|
||||||
die("Sorry. You can't access directly to this file");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Class DeviceCamera
|
/// Class DeviceCamera
|
||||||
class DeviceCamera extends CommonDevice
|
class DeviceCamera extends CommonDevice
|
||||||
{
|
{
|
||||||
|
@@ -1,30 +1,31 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/**
|
||||||
-------------------------------------------------------------------------
|
* -------------------------------------------------------------------------
|
||||||
GLPI - Gestionnaire Libre de Parc Informatique
|
* Example plugin for GLPI
|
||||||
Copyright (C) 2003-2011 by the INDEPNET Development Team.
|
* -------------------------------------------------------------------------
|
||||||
|
*
|
||||||
http://indepnet.net/ http://glpi-project.org
|
* LICENSE
|
||||||
-------------------------------------------------------------------------
|
*
|
||||||
|
* This file is part of Example.
|
||||||
LICENSE
|
*
|
||||||
|
* Example is free software; you can redistribute it and/or modify
|
||||||
This file is part of GLPI.
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
GLPI is free software; you can redistribute it and/or modify
|
* (at your option) any later version.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Example is distributed in the hope that it will be useful,
|
||||||
(at your option) any later version.
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GLPI is distributed in the hope that it will be useful,
|
* GNU General Public License for more details.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
*
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* You should have received a copy of the GNU General Public License
|
||||||
GNU General Public License for more details.
|
* along with Example. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
You should have received a copy of the GNU General Public License
|
* @copyright Copyright (C) 2006-2022 by Example plugin team.
|
||||||
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
|
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
--------------------------------------------------------------------------
|
* @link https://github.com/pluginsGLPI/example
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,10 +58,9 @@ along with GLPI. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
namespace GlpiPlugin\Example;
|
namespace GlpiPlugin\Example;
|
||||||
|
|
||||||
use Document as GlpiDocument;
|
use Document as GlpiDocument;
|
||||||
|
use Exception;
|
||||||
if (!defined('GLPI_ROOT')) {
|
use Glpi\Exception\Http\NotFoundHttpException;
|
||||||
die("Sorry. You can't access this file directly");
|
use Sabre\DAV\Exception\BadRequest;
|
||||||
}
|
|
||||||
|
|
||||||
class Document extends GlpiDocument
|
class Document extends GlpiDocument
|
||||||
{
|
{
|
||||||
|
@@ -38,6 +38,7 @@ namespace GlpiPlugin\Example;
|
|||||||
use CommonDBTM;
|
use CommonDBTM;
|
||||||
use CommonGLPI;
|
use CommonGLPI;
|
||||||
use Computer;
|
use Computer;
|
||||||
|
use DBmysql;
|
||||||
use Html;
|
use Html;
|
||||||
use Log;
|
use Log;
|
||||||
use MassiveAction;
|
use MassiveAction;
|
||||||
@@ -487,7 +488,7 @@ class Example extends CommonDBTM
|
|||||||
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
|
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function generateLinkContents($link, CommonDBTM $item)
|
public static function generateLinkContents($link, CommonDBTM $item, bool $safe_url = true)
|
||||||
{
|
{
|
||||||
if (strstr($link, '[EXAMPLE_ID]')) {
|
if (strstr($link, '[EXAMPLE_ID]')) {
|
||||||
$link = str_replace('[EXAMPLE_ID]', $item->getID(), $link);
|
$link = str_replace('[EXAMPLE_ID]', $item->getID(), $link);
|
||||||
|
@@ -48,6 +48,7 @@ class ComputerModelFilter extends AbstractFilter
|
|||||||
|
|
||||||
public static function canBeApplied(string $table): bool
|
public static function canBeApplied(string $table): bool
|
||||||
{
|
{
|
||||||
|
/** @var DBmysql $DB */
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
return $DB->fieldExists($table, ComputerModel::getForeignKeyField());
|
return $DB->fieldExists($table, ComputerModel::getForeignKeyField());
|
||||||
|
@@ -40,10 +40,6 @@ namespace GlpiPlugin\Example;
|
|||||||
use GlpiPlugin\Example\DeviceCamera;
|
use GlpiPlugin\Example\DeviceCamera;
|
||||||
use Item_Devices;
|
use Item_Devices;
|
||||||
|
|
||||||
if (!defined('GLPI_ROOT')) {
|
|
||||||
die("Sorry. You can't access directly to this file");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Relation between item and devices
|
* Relation between item and devices
|
||||||
**/
|
**/
|
||||||
|
@@ -32,10 +32,6 @@ namespace GlpiPlugin\Example;
|
|||||||
|
|
||||||
use NotificationTarget;
|
use NotificationTarget;
|
||||||
|
|
||||||
if (!defined('GLPI_ROOT')) {
|
|
||||||
die("Sorry. You can't access directly to this file");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Class NotificationTarget
|
// Class NotificationTarget
|
||||||
class NotificationTargetExample extends NotificationTarget
|
class NotificationTargetExample extends NotificationTarget
|
||||||
{
|
{
|
||||||
@@ -46,8 +42,6 @@ class NotificationTargetExample extends NotificationTarget
|
|||||||
|
|
||||||
public function addDataForTemplate($event, $options = [])
|
public function addDataForTemplate($event, $options = [])
|
||||||
{
|
{
|
||||||
global $DB, $CFG_GLPI;
|
|
||||||
|
|
||||||
$this->data['##example.name##'] = __('Example', 'example');
|
$this->data['##example.name##'] = __('Example', 'example');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,17 +34,27 @@ use CommonGLPI;
|
|||||||
use Html;
|
use Html;
|
||||||
use Session;
|
use Session;
|
||||||
|
|
||||||
final class Profile extends \Profile
|
class Profile extends \Profile
|
||||||
{
|
{
|
||||||
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
|
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
|
||||||
{
|
{
|
||||||
return __('Example plugin');
|
if (
|
||||||
|
$item instanceof \Profile
|
||||||
|
&& $item->getField('id')
|
||||||
|
) {
|
||||||
|
return self::createTabEntry(__('Example plugin'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
|
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
|
||||||
{
|
{
|
||||||
$profile = new self();
|
if ($item instanceof self) {
|
||||||
$profile->showFormExample($item->getID());
|
$profile = new self();
|
||||||
|
$profile->showFormExample($item->getID());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showFormExample(int $profiles_id): void
|
public function showFormExample(int $profiles_id): void
|
||||||
|
@@ -37,11 +37,6 @@ namespace GlpiPlugin\Example;
|
|||||||
|
|
||||||
use Rule;
|
use Rule;
|
||||||
|
|
||||||
if (!defined('GLPI_ROOT')) {
|
|
||||||
die("Sorry. You can't access directly to this file");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rule class store all informations about a GLPI rule :
|
* Rule class store all informations about a GLPI rule :
|
||||||
* - description
|
* - description
|
||||||
|
@@ -37,11 +37,6 @@ namespace GlpiPlugin\Example;
|
|||||||
|
|
||||||
use RuleCollection;
|
use RuleCollection;
|
||||||
|
|
||||||
if (!defined('GLPI_ROOT')) {
|
|
||||||
die("Sorry. You can't access directly to this file");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class RuleTestCollection extends RuleCollection
|
class RuleTestCollection extends RuleCollection
|
||||||
{
|
{
|
||||||
// From RuleCollection
|
// From RuleCollection
|
||||||
|
Reference in New Issue
Block a user