Skip to content

Commit

Permalink
Fix getTabNameForItem
Browse files Browse the repository at this point in the history
Add certificate links
  • Loading branch information
tsmr committed Nov 15, 2024
1 parent 4bb9ba1 commit 696d9bc
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 43 deletions.
7 changes: 2 additions & 5 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@

traiter l'environnement
utiliser $used

lier des processus à des entités ?

si ajout serveur - detecter si des instances de bdd existent et les ajouter automatiquement : ok
et les ajouter directement dans l'infra logique : ok


Si besoin de définir l'environnementen GLPI 10 :
https://github.com/glpi-project/glpi/pull/18288
https://github.com/glpi-project/glpi/pull/18288
133 changes: 133 additions & 0 deletions inc/certificate.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php
/*
* @version $Id: HEADER 15930 2011-10-30 15:47:55Z tsmr $
-------------------------------------------------------------------------
webapplications plugin for GLPI
Copyright (C) 2009-2023 by the webapplications Development Team.
https://github.com/InfotelGLPI/webapplications
-------------------------------------------------------------------------
LICENSE
This file is part of webapplications.
webapplications 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.
webapplications 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 webapplications. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/

if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}

use Glpi\Application\View\TemplateRenderer;

/**
* Class PluginWebapplicationsCertificate
*/
class PluginWebapplicationsCertificate extends CommonDBTM
{
public static $rightname = "plugin_webapplications_appliances";

public static function getTypeName($nb = 0)
{
return _n("Certificate", 'Certificates', $nb);
}

public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{
if ($_SESSION['glpishow_count_on_tabs']) {
$ApplianceId = $_SESSION['plugin_webapplications_loaded_appliances_id'];
$self = new Certificate();
$nb = count(PluginWebapplicationsDashboard::getObjects($self, $ApplianceId));
return self::createTabEntry(self::getTypeName($nb), $nb);
}
return self::getTypeName();
}

public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
{
$obj = new Certificate();
PluginWebapplicationsDashboard::showList($obj);
return true;
}


public function showForm($ID, $options = [])
{
$instance = new Certificate();
$instance->showForm($ID, $options);

return true;
}

public static function showListObjects($list)
{
$object = new Certificate();

echo "<div style='display: flex;flex-wrap: wrap;'>";

foreach ($list as $field) {
$name = $field['name'];
$id = $field['id'];
$object->getFromDB($id);

echo "<div class='card w-33' style='margin-right: 10px;margin-top: 10px;'>";
echo "<div class='card-body'>";
echo "<div style='display: inline-block;margin: 40px;'>";
echo "<i class='fa-5x fas fa-certificate'></i>";
echo "</div>";
echo "<div style='display: inline-block;';>";
echo "<h5 class='card-title' style='font-size: 14px;'>" . $object->getLink() . "</h5>";


echo "<p class='card-text'>";
echo Html::convDateTime($object->fields['date_expiration']);
echo "</p>";

$link = $object::getFormURLWithID($id);
$link .= "&forcetab=main";
$rand = mt_rand();
echo "<span style='float: right'>";
if ($object->canUpdate()) {
echo Html::submit(
_sx('button', 'Edit'),
[
'name' => 'edit',
'class' => 'btn btn-secondary right',
'icon' => 'fas fa-edit',
'form' => '',
'data-bs-toggle' => 'modal',
'data-bs-target' => '#edit' . $id . $rand
]
);

echo Ajax::createIframeModalWindow(
'edit' . $id . $rand,
$link,
[
'display' => false,
'reloadonclose' => true
]
);
}

echo "</div>";
echo "</div>";
echo "</div>";
echo "</span>";
}
echo "</div>";
}
}
74 changes: 54 additions & 20 deletions inc/dashboard.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,21 @@ public function defineTabs($options = [])
$ong = [];
//add main tab for current object
$this->addDefaultFormTab($ong);
$this->addStandardTab('PluginWebapplicationsEntity', $ong, $options);// Vue Ecosystème
$this->addStandardTab('PluginWebapplicationsProcess', $ong, $options);//Vue Metier
$this->addStandardTab('PluginWebapplicationsEntity', $ong, $options);
$this->addStandardTab('PluginWebapplicationsProcess', $ong, $options);
$this->addStandardTab(
'PluginWebapplicationsPhysicalInfrastructure',
$ong,
$options
);//Vue Infra physiques
);
$this->addStandardTab(
'PluginWebapplicationsLogicalInfrastructure',
$ong,
$options
);//Vue Infra physiques
$this->addStandardTab('PluginWebapplicationsDatabaseInstance', $ong, $options);//Vue Base de données
$this->addStandardTab('PluginWebapplicationsStream', $ong, $options);//Vue Flux
);
$this->addStandardTab('PluginWebapplicationsDatabaseInstance', $ong, $options);
$this->addStandardTab('PluginWebapplicationsCertificate', $ong, $options);
$this->addStandardTab('PluginWebapplicationsStream', $ong, $options);
$this->addStandardTab('PluginWebapplicationsKnowbase', $ong, $options);

return $ong;
Expand Down Expand Up @@ -326,10 +327,6 @@ public static function showFromDashboard($appliance, $item)

$ApplianceId = $appliance->getField('id');

$title = $item->getTypeName(1);

self::showTitleforDashboard($title, $ApplianceId, $item);

$app_item = new Appliance_Item();

if ($item->getType() == "PluginWebapplicationsPhysicalInfrastructure") {
Expand All @@ -338,6 +335,10 @@ public static function showFromDashboard($appliance, $item)
$apps = $app_item->find(['appliances_id' => $ApplianceId, 'itemtype' => $item->getType()]);
}

$title = $item->getTypeName(count($apps));

self::showTitleforDashboard($title, $ApplianceId, $item);

$obj = new $item();

echo "<div class='row flex-row'>";
Expand Down Expand Up @@ -425,16 +426,31 @@ public static function showFromDashboard($appliance, $item)

public static function getObjects($item, $ApplianceId)
{
$app_item = new Appliance_Item();

$apps = $app_item->find([
'appliances_id' => $ApplianceId,
'itemtype' => $item->getType()
]);
if ($item->getType() == "Certificate") {
$app_item = new Certificate_Item();
$apps = $app_item->find([
'items_id' => $ApplianceId,
'itemtype' => "Appliance"
]);
} else {
$app_item = new Appliance_Item();
$apps = $app_item->find([
'appliances_id' => $ApplianceId,
'itemtype' => $item->getType()
]);
}

$listId = [];
foreach ($apps as $app) {
array_push($listId, $app['items_id']);
if ($item->getType() == "Certificate") {
foreach ($apps as $app) {
array_push($listId, $app['certificates_id']);
}
} else {

foreach ($apps as $app) {
array_push($listId, $app['items_id']);
}
}

$list = [];
Expand Down Expand Up @@ -489,6 +505,9 @@ classname = 'accordion';
if ($object->getType() == "PluginWebapplicationsPhysicalInfrastructure") {
echo "<form name='form' method='post' action='" .
PLUGIN_WEBAPPLICATIONS_WEBDIR."/front/dashboard.php"."'>";
} else if ($object->getType() == "Certificate") {
echo "<form name='form' method='post' action='" .
Toolbox::getItemTypeFormURL('Certificate_Item') . "'>";
} else {
echo "<form name='form' method='post' action='" .
Toolbox::getItemTypeFormURL('Appliance_Item') . "'>";
Expand All @@ -510,12 +529,23 @@ classname = 'accordion';
);
} else {
$class = $object->getType();
$class::dropdown(['name' => 'items_id']);
echo Html::hidden('itemtype', ['value' => $object->getType()]);
if ($object->getType() == "Certificate") {
$class::dropdown(['name' => 'certificates_id']);
echo Html::hidden('itemtype', ['value' => 'Appliance']);
} else {
$class::dropdown(['name' => 'items_id']);
echo Html::hidden('itemtype', ['value' => $object->getType()]);
}

}
echo "</td>";
echo "<td class='tab_bg_2 center' colspan='6'>";
echo Html::hidden('appliances_id', ['value' => $ApplianceId]);
if ($object->getType() == "Certificate") {
echo Html::hidden('items_id', ['value' => $ApplianceId]);
} else {
echo Html::hidden('appliances_id', ['value' => $ApplianceId]);
}

if ($object->canCreate()) {
echo Html::submit(_sx('button', 'Associate'), ['name' => 'add', 'class' => 'btn btn-primary']);
}
Expand All @@ -537,6 +567,8 @@ classname = 'accordion';
echo _n("Item list", "Items list", $nb, 'webapplications');
} elseif ($item->getType() == "DatabaseInstance") {
echo _n("Database list", "Databases list", $nb, 'webapplications');
} elseif ($item->getType() == "Certificate") {
echo _n("Certificate list", "Certificates list", $nb, 'webapplications');
} elseif ($item->getType() == "PluginWebapplicationsStream") {
echo _n("Stream list", "Streams list", $nb, 'webapplications');
}
Expand All @@ -556,6 +588,8 @@ classname = 'accordion';
} else {
if ($item->getType() == "DatabaseInstance") {
PluginWebapplicationsDatabaseInstance::showListObjects($list);
} else if ($item->getType() == "Certificate") {
PluginWebapplicationsCertificate::showListObjects($list);
} else {
$item::showListObjects($list);
}
Expand Down
4 changes: 2 additions & 2 deletions inc/databaseinstance.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PluginWebapplicationsDatabaseInstance extends CommonDBTM

public static function getTypeName($nb = 0)
{
return _n("Database", 'Databases', $nb);
return _n('Database', 'Databases', $nb);
}

public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
Expand All @@ -51,7 +51,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
$ApplianceId = $_SESSION['plugin_webapplications_loaded_appliances_id'];
$self = new DatabaseInstance();
$nb = count(PluginWebapplicationsDashboard::getObjects($self, $ApplianceId));
return self::createTabEntry(self::getTypeName(), $nb);
return self::createTabEntry(self::getTypeName($nb), $nb);
}
return self::getTypeName();
}
Expand Down
2 changes: 1 addition & 1 deletion inc/entity.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
$ApplianceId = $_SESSION['plugin_webapplications_loaded_appliances_id'];
$self = new self();
$nb = count(PluginWebapplicationsDashboard::getObjects($self, $ApplianceId));
return self::createTabEntry(self::getTypeName(), $nb);
return self::createTabEntry(self::getTypeName($nb), $nb);
}
return self::getTypeName();
}
Expand Down
2 changes: 1 addition & 1 deletion inc/knowbase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
'itemtype' => 'Appliance']);

$nbEntities = count($kbApp);
return self::createTabEntry(self::getTypeName(), $nbEntities);
return self::createTabEntry(self::getTypeName($nbEntities), $nbEntities);
}
return self::getTypeName();
}
Expand Down
2 changes: 1 addition & 1 deletion inc/logicalinfrastructure.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
]
]));
}
return self::createTabEntry(self::getTypeName(), $total);
return self::createTabEntry(self::getTypeName($total), $total);
}

public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
Expand Down
2 changes: 1 addition & 1 deletion inc/physicalinfrastructure.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{
if ($_SESSION['glpishow_count_on_tabs']) {
$nb = count(self::getItems());
return self::createTabEntry(self::getTypeName(), $nb);
return self::createTabEntry(self::getTypeName($nb), $nb);
}
return self::getTypeName();
}
Expand Down
2 changes: 1 addition & 1 deletion inc/process.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
$ApplianceId = $_SESSION['plugin_webapplications_loaded_appliances_id'];
$self = new self();
$nb = count(PluginWebapplicationsDashboard::getObjects($self, $ApplianceId));
return self::createTabEntry(self::getTypeName(), $nb);
return self::createTabEntry(self::getTypeName($nb), $nb);
}
return self::getTypeName();
}
Expand Down
22 changes: 12 additions & 10 deletions inc/process_entity.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,27 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
case 'PluginWebapplicationsEntity':
if ($_SESSION['glpishow_count_on_tabs']) {
$dbu = new DbUtils();
$nb = $dbu->countElementsInTable(
$this->getTable(),
["plugin_webapplications_entities_id" => $item->getID()]
);
return self::createTabEntry(
PluginWebapplicationsProcess::getTypeName(),
$dbu->countElementsInTable(
$this->getTable(),
["plugin_webapplications_entities_id" => $item->getID()]
)
PluginWebapplicationsProcess::getTypeName($nb),
$nb
);
}
return _n('Process', 'Processes', 2, 'webapplications');
break;
case 'PluginWebapplicationsProcess':
if ($_SESSION['glpishow_count_on_tabs']) {
$dbu = new DbUtils();
$nb = $dbu->countElementsInTable(
$this->getTable(),
["plugin_webapplications_processes_id" => $item->getID()]
);
return self::createTabEntry(
PluginWebapplicationsEntity::getTypeName(),
$dbu->countElementsInTable(
$this->getTable(),
["plugin_webapplications_processes_id" => $item->getID()]
)
PluginWebapplicationsEntity::getTypeName($nb),
$nb
);
}
return _n('Entity', 'Entities', 2);
Expand Down
Loading

0 comments on commit 696d9bc

Please sign in to comment.