|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * ------------------------------------------------------------------------- |
| 5 | + * Carbon plugin for GLPI |
| 6 | + * |
| 7 | + * @copyright Copyright (C) 2024-2025 Teclib' and contributors. |
| 8 | + * @license https://www.gnu.org/licenses/gpl-3.0.txt GPLv3+ |
| 9 | + * @link https://github.com/pluginsGLPI/carbon |
| 10 | + * |
| 11 | + * ------------------------------------------------------------------------- |
| 12 | + * |
| 13 | + * LICENSE |
| 14 | + * |
| 15 | + * This file is part of Carbon plugin for GLPI. |
| 16 | + * |
| 17 | + * This program is free software: you can redistribute it and/or modify |
| 18 | + * it under the terms of the GNU General Public License as published by |
| 19 | + * the Free Software Foundation, either version 3 of the License, or |
| 20 | + * (at your option) any later version. |
| 21 | + * |
| 22 | + * This program is distributed in the hope that it will be useful, |
| 23 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 | + * GNU General Public License for more details. |
| 26 | + * |
| 27 | + * You should have received a copy of the GNU General Public License |
| 28 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 29 | + * |
| 30 | + * ------------------------------------------------------------------------- |
| 31 | + */ |
| 32 | + |
| 33 | +namespace GlpiPlugin\Carbon; |
| 34 | + |
| 35 | +use CommonDBChild; |
| 36 | +use CommonGLPI; |
| 37 | +use Datacenter as GlpiDatacenter; |
| 38 | +use Glpi\Application\View\TemplateRenderer; |
| 39 | +use Override; |
| 40 | + |
| 41 | +class Datacenter extends CommonDBChild |
| 42 | +{ |
| 43 | + // From CommonDBRelation |
| 44 | + public static $itemtype = GlpiDatacenter::class; |
| 45 | + public static $items_id = 'datacenters_id'; |
| 46 | + |
| 47 | + #[Override] |
| 48 | + public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) |
| 49 | + { |
| 50 | + if ($item instanceof GlpiDatacenter) { |
| 51 | + return self::createTabEntry(__('Environmental impact', 'carbon'), 0); |
| 52 | + } |
| 53 | + return ''; |
| 54 | + } |
| 55 | + |
| 56 | + #[Override] |
| 57 | + public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) |
| 58 | + { |
| 59 | + if ($item instanceof GlpiDatacenter) { |
| 60 | + /** @var GlpiDatacenter $item */ |
| 61 | + $location = new self(); |
| 62 | + $location->showForDatacenter($item); |
| 63 | + } |
| 64 | + return true; |
| 65 | + } |
| 66 | + |
| 67 | + public function showForDatacenter(GlpiDatacenter $item, array $options = []) |
| 68 | + { |
| 69 | + $this->getFromDBByCrit(['datacenters_id' => $item->getID()]); |
| 70 | + if ($this->isNewItem()) { |
| 71 | + $this->add(['datacenters_id' => $item->getID()]); |
| 72 | + } |
| 73 | + |
| 74 | + TemplateRenderer::getInstance()->display('@carbon/datacenter.html.twig', [ |
| 75 | + 'item' => $this, |
| 76 | + 'params' => [ |
| 77 | + 'candel' => false, |
| 78 | + ], |
| 79 | + ]); |
| 80 | + |
| 81 | + return true; |
| 82 | + } |
| 83 | +} |
0 commit comments