|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * ------------------------------------------------------------------------- |
| 5 | + * Example plugin for GLPI |
| 6 | + * ------------------------------------------------------------------------- |
| 7 | + * |
| 8 | + * LICENSE |
| 9 | + * |
| 10 | + * This file is part of Example. |
| 11 | + * |
| 12 | + * Example is free software; you can redistribute it and/or modify |
| 13 | + * it under the terms of the GNU General Public License as published by |
| 14 | + * the Free Software Foundation; either version 2 of the License, or |
| 15 | + * (at your option) any later version. |
| 16 | + * |
| 17 | + * Example is distributed in the hope that it will be useful, |
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | + * GNU General Public License for more details. |
| 21 | + * |
| 22 | + * You should have received a copy of the GNU General Public License |
| 23 | + * along with Example. If not, see <http://www.gnu.org/licenses/>. |
| 24 | + * ------------------------------------------------------------------------- |
| 25 | + * @copyright Copyright (C) 2006-2022 by Example plugin team. |
| 26 | + * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html |
| 27 | + * @link https://github.com/pluginsGLPI/example |
| 28 | + * ------------------------------------------------------------------------- |
| 29 | + */ |
| 30 | + |
| 31 | +namespace GlpiPlugin\Example\Filters; |
| 32 | + |
| 33 | +use ComputerModel; |
| 34 | +use DBmysql; |
| 35 | +use Glpi\Dashboard\Filters\AbstractFilter; |
| 36 | + |
| 37 | +class ComputerModelFilter extends AbstractFilter |
| 38 | +{ |
| 39 | + public static function getName(): string |
| 40 | + { |
| 41 | + return __("Computer model"); |
| 42 | + } |
| 43 | + |
| 44 | + public static function getId(): string |
| 45 | + { |
| 46 | + return "plugin_example_computer_model"; |
| 47 | + } |
| 48 | + |
| 49 | + public static function canBeApplied(string $table): bool |
| 50 | + { |
| 51 | + global $DB; |
| 52 | + |
| 53 | + return $DB->fieldExists($table, ComputerModel::getForeignKeyField()); |
| 54 | + } |
| 55 | + |
| 56 | + public static function getHtml($value): string |
| 57 | + { |
| 58 | + return self::displayList( |
| 59 | + self::getName(), |
| 60 | + is_string($value) ? $value : "", |
| 61 | + self::getId(), |
| 62 | + ComputerModel::class |
| 63 | + ); |
| 64 | + } |
| 65 | + |
| 66 | + public static function getCriteria(string $table, $value): array |
| 67 | + { |
| 68 | + if ((int) $value > 0) { |
| 69 | + $field = ComputerModel::getForeignKeyField(); |
| 70 | + return [ |
| 71 | + "WHERE" => [ |
| 72 | + "$table.$field" => (int) $value |
| 73 | + ] |
| 74 | + ]; |
| 75 | + } |
| 76 | + |
| 77 | + return []; |
| 78 | + } |
| 79 | + |
| 80 | + public static function getSearchCriteria(string $table, $value): array |
| 81 | + { |
| 82 | + if ((int) $value > 0) { |
| 83 | + return [ |
| 84 | + [ |
| 85 | + 'link' => 'AND', |
| 86 | + 'searchtype' => 'equals', |
| 87 | + 'value' => (int) $value, |
| 88 | + 'field' => self::getSearchOptionID( |
| 89 | + $table, |
| 90 | + ComputerModel::getForeignKeyField(), |
| 91 | + ComputerModel::getTable() |
| 92 | + ), |
| 93 | + ] |
| 94 | + ]; |
| 95 | + } |
| 96 | + |
| 97 | + return []; |
| 98 | + } |
| 99 | +} |
0 commit comments