mirror of
https://github.com/pluginsGLPI/example.git
synced 2025-05-04 18:08:42 +02:00
Example for the new dashboard filters hooks
This commit is contained in:
parent
99ccf29a7e
commit
4899ba4968
@ -34,6 +34,7 @@ use GlpiPlugin\Example\Config;
|
||||
use GlpiPlugin\Example\Dropdown;
|
||||
use GlpiPlugin\Example\DeviceCamera;
|
||||
use GlpiPlugin\Example\Example;
|
||||
use GlpiPlugin\Example\Filters\ComputerModelFilter;
|
||||
use GlpiPlugin\Example\ItemForm;
|
||||
use GlpiPlugin\Example\RuleTestCollection;
|
||||
use GlpiPlugin\Example\Showtabitem;
|
||||
@ -232,6 +233,11 @@ function plugin_init_example() {
|
||||
// add new cards to dashboard grid
|
||||
$PLUGIN_HOOKS['dashboard_types']['example'] = [Example::class, 'dashboardTypes'];
|
||||
$PLUGIN_HOOKS['dashboard_cards']['example'] = [Example::class, 'dashboardCards'];
|
||||
|
||||
// Dashboard filter
|
||||
$PLUGIN_HOOKS[Hooks::DASHBOARD_FILTERS]['example'] = [
|
||||
ComputerModelFilter::class
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
99
src/Filters/ComputerModelFilter.php
Normal file
99
src/Filters/ComputerModelFilter.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------------
|
||||
* Example plugin for GLPI
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This file is part of Example.
|
||||
*
|
||||
* Example is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Example is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Example. If not, see <http://www.gnu.org/licenses/>.
|
||||
* -------------------------------------------------------------------------
|
||||
* @copyright Copyright (C) 2006-2022 by Example plugin team.
|
||||
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
* @link https://github.com/pluginsGLPI/example
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
namespace GlpiPlugin\Example\Filters;
|
||||
|
||||
use ComputerModel;
|
||||
use DBmysql;
|
||||
use Glpi\Dashboard\Filters\AbstractFilter;
|
||||
|
||||
class ComputerModelFilter extends AbstractFilter
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return __("Computer model");
|
||||
}
|
||||
|
||||
public static function getId(): string
|
||||
{
|
||||
return "plugin_example_computer_model";
|
||||
}
|
||||
|
||||
public static function canBeApplied(string $table): bool
|
||||
{
|
||||
global $DB;
|
||||
|
||||
return $DB->fieldExists($table, ComputerModel::getForeignKeyField());
|
||||
}
|
||||
|
||||
public static function getHtml($value): string
|
||||
{
|
||||
return self::displayList(
|
||||
self::getName(),
|
||||
is_string($value) ? $value : "",
|
||||
self::getId(),
|
||||
ComputerModel::class
|
||||
);
|
||||
}
|
||||
|
||||
public static function getCriteria(string $table, $value): array
|
||||
{
|
||||
if ((int) $value > 0) {
|
||||
$field = ComputerModel::getForeignKeyField();
|
||||
return [
|
||||
"WHERE" => [
|
||||
"$table.$field" => (int) $value
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public static function getSearchCriteria(string $table, $value): array
|
||||
{
|
||||
if ((int) $value > 0) {
|
||||
return [
|
||||
[
|
||||
'link' => 'AND',
|
||||
'searchtype' => 'equals',
|
||||
'value' => (int) $value,
|
||||
'field' => self::getSearchOptionID(
|
||||
$table,
|
||||
ComputerModel::getForeignKeyField(),
|
||||
ComputerModel::getTable()
|
||||
),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user