From c3eb06ce0df75956d91a717f9d447e760df97bda Mon Sep 17 00:00:00 2001 From: JBthePenguin Date: Sat, 5 Jun 2021 13:52:32 +0200 Subject: [PATCH] ok to display entries and equipments in templates --- src/lib/Entry.php | 5 +++++ src/lib/Equipment.php | 5 +++++ src/templates/entrees/definitives/index.tpl | 19 +++++++++++++++++++ src/templates/index.tpl | 1 - .../admin/categories/supprimer_categorie.php | 8 +++++++- src/www/admin/entrees/definitives/index.php | 14 ++++++++++++++ 6 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/lib/Entry.php b/src/lib/Entry.php index 94e0dc2..0984aa2 100644 --- a/src/lib/Entry.php +++ b/src/lib/Entry.php @@ -27,4 +27,9 @@ class Entry // entrées définitives { DB::getInstance()->insert('plugin_materiels_entry', $data); } + + public function listAll() + { + return DB::getInstance()->get('SELECT * FROM plugin_materiels_entry ORDER BY date_of_entry DESC;'); + } } diff --git a/src/lib/Equipment.php b/src/lib/Equipment.php index f35a4ff..3e0d3de 100644 --- a/src/lib/Equipment.php +++ b/src/lib/Equipment.php @@ -20,6 +20,11 @@ class Equipment return $db->lastInsertRowId(); } + public function get($id) + { + return DB::getInstance()->first('SELECT * FROM plugin_materiels_equipment WHERE id = ?;', $id); + } + public function listAll() { return DB::getInstance()->get('SELECT * FROM plugin_materiels_equipment ORDER BY designation;'); diff --git a/src/templates/entrees/definitives/index.tpl b/src/templates/entrees/definitives/index.tpl index e09f9d8..a31691e 100644 --- a/src/templates/entrees/definitives/index.tpl +++ b/src/templates/entrees/definitives/index.tpl @@ -8,4 +8,23 @@ {linkbutton shape="plus" label="Matériel déjà répertorié" href="deja_repertorie.php"} + + + + + + + + + {foreach from=$entries item="entry"} + + + + + + + {/foreach} + +
DateTypeNombreMatériel
{$entry.date_of_entry}{$entry.kind}{$entry.number_of_equipments}{$entry.equipment.designation}
+ {include file="admin/_foot.tpl"} diff --git a/src/templates/index.tpl b/src/templates/index.tpl index 058e310..acb3416 100644 --- a/src/templates/index.tpl +++ b/src/templates/index.tpl @@ -3,7 +3,6 @@ {include file="%s_nav.tpl"|args:$plugin_tpl current="index"} - diff --git a/src/www/admin/categories/supprimer_categorie.php b/src/www/admin/categories/supprimer_categorie.php index d59b8af..00cedf4 100644 --- a/src/www/admin/categories/supprimer_categorie.php +++ b/src/www/admin/categories/supprimer_categorie.php @@ -25,7 +25,13 @@ if (f('delete') && $form->check($csrf_key) && !$form->hasErrors()) } catch (\RuntimeException $e) { - $form->addError($e->getMessage()); + if (strstr($e->getMessage(), 'FOREIGN KEY constraint failed')) + { + $form->addError('Cette catégorie contient des matériels et ne peut donc pas être supprimée.'); + } else + { + $form->addError($e->getMessage()); + } } } diff --git a/src/www/admin/entrees/definitives/index.php b/src/www/admin/entrees/definitives/index.php index 2f4b03c..db76ecb 100644 --- a/src/www/admin/entrees/definitives/index.php +++ b/src/www/admin/entrees/definitives/index.php @@ -2,6 +2,20 @@ namespace Garradin; +use Garradin\Plugin\Materiels\Equipment; +use Garradin\Plugin\Materiels\Entry; + require_once __DIR__ . '/../../_inc.php'; +$eqmt = new Equipment; +$entry = new Entry; + +$entries = $entry->listAll(); + +foreach ($entries as $key => $value) { + $entries[$key]->equipment = $eqmt->get($value->equipment_id); +} + +$tpl->assign(compact('entries')); + $tpl->display(PLUGIN_ROOT . '/templates/entrees/definitives/index.tpl');
Matériels
Nombre en stock Categorie