-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add process and environment capacities
Add test on inventory
- Loading branch information
Showing
6 changed files
with
682 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
/** | ||
* --------------------------------------------------------------------- | ||
* | ||
* GLPI - Gestionnaire Libre de Parc Informatique | ||
* | ||
* http://glpi-project.org | ||
* | ||
* @copyright 2015-2024 Teclib' and contributors. | ||
* @copyright 2003-2014 by the INDEPNET Development Team. | ||
* @licence https://www.gnu.org/licenses/gpl-3.0.html | ||
* | ||
* --------------------------------------------------------------------- | ||
* | ||
* LICENSE | ||
* | ||
* This file is part of GLPI. | ||
* | ||
* This program 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 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* --------------------------------------------------------------------- | ||
*/ | ||
|
||
namespace Glpi\Asset\Capacity; | ||
|
||
use CommonGLPI; | ||
use Item_Environment; | ||
use Session; | ||
|
||
class HasEnvironmentsCapacity extends AbstractCapacity | ||
{ | ||
public function getLabel(): string | ||
{ | ||
return Item_Environment::getTypeName(Session::getPluralNumber()); | ||
} | ||
|
||
public function getIcon(): string | ||
{ | ||
return Item_Environment::getIcon(); | ||
} | ||
|
||
public function isUsed(string $classname): bool | ||
{ | ||
return parent::isUsed($classname) | ||
&& $this->countAssetsLinkedToPeerItem($classname, Item_Environment::class) > 0; | ||
} | ||
|
||
public function getCapacityUsageDescription(string $classname): string | ||
{ | ||
return sprintf( | ||
__('%1$s environments attached to %2$s assets'), | ||
$this->countPeerItemsUsage($classname, Item_Environment::class), | ||
$this->countAssetsLinkedToPeerItem($classname, Item_Environment::class) | ||
); | ||
} | ||
|
||
public function onClassBootstrap(string $classname): void | ||
{ | ||
$this->registerToTypeConfig('environment_types', $classname); | ||
CommonGLPI::registerStandardTab($classname, Item_Environment::class, 85); | ||
} | ||
|
||
public function onCapacityDisabled(string $classname): void | ||
{ | ||
$this->unregisterFromTypeConfig('environment_types', $classname); | ||
|
||
$appliance_item = new Item_Environment(); | ||
$appliance_item->deleteByCriteria([ | ||
'itemtype' => $classname, | ||
], true, false); | ||
|
||
$this->deleteRelationLogs($classname, Item_Environment::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
/** | ||
* --------------------------------------------------------------------- | ||
* | ||
* GLPI - Gestionnaire Libre de Parc Informatique | ||
* | ||
* http://glpi-project.org | ||
* | ||
* @copyright 2015-2024 Teclib' and contributors. | ||
* @copyright 2003-2014 by the INDEPNET Development Team. | ||
* @licence https://www.gnu.org/licenses/gpl-3.0.html | ||
* | ||
* --------------------------------------------------------------------- | ||
* | ||
* LICENSE | ||
* | ||
* This file is part of GLPI. | ||
* | ||
* This program 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 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* --------------------------------------------------------------------- | ||
*/ | ||
|
||
namespace Glpi\Asset\Capacity; | ||
|
||
use Appliance; | ||
use Appliance_Item; | ||
use CommonGLPI; | ||
use Item_Process; | ||
use Session; | ||
|
||
class HasProcessCapacity extends AbstractCapacity | ||
{ | ||
public function getLabel(): string | ||
{ | ||
return Item_Process::getTypeName(Session::getPluralNumber()); | ||
} | ||
|
||
public function getIcon(): string | ||
{ | ||
return Item_Process::getIcon(); | ||
} | ||
|
||
public function isUsed(string $classname): bool | ||
{ | ||
return parent::isUsed($classname) | ||
&& $this->countAssetsLinkedToPeerItem($classname, Item_Process::class) > 0; | ||
} | ||
|
||
public function getCapacityUsageDescription(string $classname): string | ||
{ | ||
return sprintf( | ||
__('%1$s process attached to %2$s assets'), | ||
$this->countPeerItemsUsage($classname, Item_Process::class), | ||
$this->countAssetsLinkedToPeerItem($classname, Item_Process::class) | ||
); | ||
} | ||
|
||
public function onClassBootstrap(string $classname): void | ||
{ | ||
$this->registerToTypeConfig('process_types', $classname); | ||
CommonGLPI::registerStandardTab($classname, Item_Process::class, 85); | ||
} | ||
|
||
public function onCapacityDisabled(string $classname): void | ||
{ | ||
$this->unregisterFromTypeConfig('process_types', $classname); | ||
|
||
$appliance_item = new Item_Process(); | ||
$appliance_item->deleteByCriteria([ | ||
'itemtype' => $classname, | ||
], true, false); | ||
|
||
$this->deleteRelationLogs($classname, Item_Process::class); | ||
} | ||
} |
Oops, something went wrong.