From ff037ff75bae4f8563f06af8c660806d33cc5cb6 Mon Sep 17 00:00:00 2001 From: JBthePenguin Date: Tue, 31 Aug 2021 13:36:06 +0200 Subject: [PATCH] clean and comments for category templates and php files --- src/lib/Entry.php | 12 +++++++++ src/lib/Output.php | 12 +++++++++ src/schema.sql | 12 +++++++++ src/templates/_nav.tpl | 11 +++++--- src/templates/categories/index.tpl | 15 ++++++----- .../categories/materiels_par_categorie.tpl | 23 +++++++++-------- .../categories/modifier_categorie.tpl | 14 ++++++----- .../categories/supprimer_categorie.tpl | 14 ++++++----- src/templates/common/delete_form.tpl | 2 ++ src/templates/historique.tpl | 9 +++++++ src/templates/index.tpl | 7 +++--- src/www/admin/categories/_inc.php | 9 +++++++ src/www/admin/categories/index.php | 11 +++++--- .../categories/materiels_par_categorie.php | 25 +++++++++++-------- .../admin/categories/modifier_categorie.php | 22 ++++++++++------ .../admin/categories/supprimer_categorie.php | 22 ++++++++++------ src/www/admin/historique.php | 25 +++++++++++++++++++ src/www/admin/sorties.php | 7 ------ 18 files changed, 180 insertions(+), 72 deletions(-) create mode 100644 src/templates/historique.tpl create mode 100644 src/www/admin/categories/_inc.php create mode 100644 src/www/admin/historique.php delete mode 100644 src/www/admin/sorties.php diff --git a/src/lib/Entry.php b/src/lib/Entry.php index 2613520..3881ff7 100644 --- a/src/lib/Entry.php +++ b/src/lib/Entry.php @@ -76,4 +76,16 @@ class Entry $entry->equipment_id, $entry->equipment_number, $entry->entry_date); } } + + public function AllDatesByEquipment($eqmt_id) + { + $entry_dates = DB::getInstance()->get( + 'SELECT DISTINCT entry_date FROM plugin_materiels_entry WHERE equipment_id = ? ORDER BY entry_date DESC;', $eqmt_id); + $entry_dates_array = array(); + foreach ($entry_dates as $row) + { + array_push($entry_dates_array, $row->entry_date); + } + return $entry_dates_array; + } } diff --git a/src/lib/Output.php b/src/lib/Output.php index f346e8a..a11fdb6 100644 --- a/src/lib/Output.php +++ b/src/lib/Output.php @@ -91,4 +91,16 @@ class Output } return true; } + + public function AllDatesByEquipment($eqmt_id) + { + $output_dates = DB::getInstance()->get( + 'SELECT DISTINCT output_date FROM plugin_materiels_output WHERE equipment_id = ? ORDER BY output_date DESC;', $eqmt_id); + $output_dates_array = array(); + foreach ($output_dates as $row) + { + array_push($output_dates_array, $row->output_date); + } + return $output_dates_array; + } } diff --git a/src/schema.sql b/src/schema.sql index 3280d49..c564f63 100644 --- a/src/schema.sql +++ b/src/schema.sql @@ -31,3 +31,15 @@ CREATE TABLE IF NOT EXISTS plugin_materiels_output ( additional_comment varchar(255), FOREIGN KEY ( equipment_id ) REFERENCES plugin_materiels_equipment( id ) ON DELETE RESTRICT ON UPDATE CASCADE ); + + +CREATE TABLE IF NOT EXISTS plugin_materiels_movement ( + id integer NOT NULL PRIMARY KEY autoincrement, + side boolean NOT NULL CHECK(side IN(0,1)), /*0 -> entry, 1 -> output*/ + kind varchar(20) NOT NULL, + equipment_number integer NOT NULL, + equipment_id integer NOT NULL, + mvt_date date NOT NULL, + additional_comment varchar(255), + FOREIGN KEY ( equipment_id ) REFERENCES plugin_materiels_equipment( id ) ON DELETE RESTRICT ON UPDATE CASCADE +); diff --git a/src/templates/_nav.tpl b/src/templates/_nav.tpl index 6be036a..9c08b15 100644 --- a/src/templates/_nav.tpl +++ b/src/templates/_nav.tpl @@ -1,8 +1,11 @@ +{include file="admin/_head.tpl" title="%s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id} + + diff --git a/src/templates/categories/index.tpl b/src/templates/categories/index.tpl index ab08a26..1736847 100644 --- a/src/templates/categories/index.tpl +++ b/src/templates/categories/index.tpl @@ -1,7 +1,7 @@ -{include file="admin/_head.tpl" title="%s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id} - -{include file="%s_nav.tpl"|args:$plugin_tpl current="categories"} - + +{include file="%s_nav.tpl"|args:$plugin_tpl current_nav="categories"} + +
Ajouter une catégorie @@ -15,7 +15,8 @@

- + + @@ -34,5 +35,7 @@ {/foreach}
Nom
- + + {include file="admin/_foot.tpl"} + diff --git a/src/templates/categories/materiels_par_categorie.tpl b/src/templates/categories/materiels_par_categorie.tpl index f1dd46a..2051f97 100644 --- a/src/templates/categories/materiels_par_categorie.tpl +++ b/src/templates/categories/materiels_par_categorie.tpl @@ -1,11 +1,11 @@ -{include file="admin/_head.tpl" title="%s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id} - -{include file="%s_nav.tpl"|args:$plugin_tpl current="categories"} - + +{include file="%s_nav.tpl"|args:$plugin_tpl current_nav="categories"} + +

{$cat_name}

- +
- + {if $eqmts_owned} @@ -31,7 +31,8 @@
{/if} - + + {if $eqmts_no_owned} @@ -53,7 +54,8 @@
{/if} - + + {if $eqmts_just_listed} @@ -74,7 +76,8 @@
{/if} - + {linkbutton label="Retour" shape="export" href=$return_link} - + {include file="admin/_foot.tpl"} + diff --git a/src/templates/categories/modifier_categorie.tpl b/src/templates/categories/modifier_categorie.tpl index 869dd9e..e887078 100644 --- a/src/templates/categories/modifier_categorie.tpl +++ b/src/templates/categories/modifier_categorie.tpl @@ -1,13 +1,13 @@ -{include file="admin/_head.tpl" title="%s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id} - -{include file="%s_nav.tpl"|args:$plugin_tpl current="categories"} - + +{include file="%s_nav.tpl"|args:$plugin_tpl current_nav="categories"} + +
{form_errors}
Modifier cette catégorie
- {input type="text" name="name" label="Nom" required=true source=$c maxlength="100"} + {input type="text" name="name" label="Nom" required=true source=$cat_requested maxlength="100"}

@@ -16,5 +16,7 @@ {linkbutton label="Annuler" shape="export" href=$cancel_link}

- + + {include file="admin/_foot.tpl"} + diff --git a/src/templates/categories/supprimer_categorie.tpl b/src/templates/categories/supprimer_categorie.tpl index dd8a462..b454908 100644 --- a/src/templates/categories/supprimer_categorie.tpl +++ b/src/templates/categories/supprimer_categorie.tpl @@ -1,11 +1,13 @@ -{include file="admin/_head.tpl" title="%s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id} - -{include file="%s_nav.tpl"|args:$plugin_tpl current="categories"} - + +{include file="%s_nav.tpl"|args:$plugin_tpl current_nav="categories"} + + {include file="%scommon/delete_form.tpl"|args:$plugin_tpl legend="Supprimer cette catégorie de matériels ?" - warning="Êtes-vous sûr de vouloir supprimer la catégorie « %s » ?"|args:$c.name + warning="Êtes-vous sûr de vouloir supprimer la catégorie « %s » ?"|args:$cat_requested.name alert="Attention, la catégorie ne doit plus contenir de matériels pour pouvoir être supprimée." } - + + {include file="admin/_foot.tpl"} + diff --git a/src/templates/common/delete_form.tpl b/src/templates/common/delete_form.tpl index c9c01d7..5af2890 100644 --- a/src/templates/common/delete_form.tpl +++ b/src/templates/common/delete_form.tpl @@ -1,3 +1,4 @@ +
{form_errors}
@@ -13,3 +14,4 @@ {linkbutton label="Annuler" shape="export" href=$cancel_link}

+ diff --git a/src/templates/historique.tpl b/src/templates/historique.tpl new file mode 100644 index 0000000..907327a --- /dev/null +++ b/src/templates/historique.tpl @@ -0,0 +1,9 @@ +{include file="admin/_head.tpl" title="%s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id} + +{include file="%s_nav.tpl"|args:$plugin_tpl current="index"} + +{foreach from=$all_dates item='date'} +

{$date}

+{/foreach} + +{include file="admin/_foot.tpl"} diff --git a/src/templates/index.tpl b/src/templates/index.tpl index c4ed269..b2234da 100644 --- a/src/templates/index.tpl +++ b/src/templates/index.tpl @@ -1,6 +1,4 @@ -{include file="admin/_head.tpl" title="%s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id} - -{include file="%s_nav.tpl"|args:$plugin_tpl current="index"} +{include file="%s_nav.tpl"|args:$plugin_tpl current_nav="index"}

Matériel dont l'association est propriétaire

@@ -29,6 +27,7 @@ {$eqmt.out_of_stock} {$eqmt.stock - $eqmt.out_of_stock} + {linkbutton shape="edit" label="Historique des entrées / sorties" href="historique.php?id=%d"|args:$eqmt.id} {linkbutton shape="edit" label="Modifier" href="modifier_materiel.php?id=%d"|args:$eqmt.id} @@ -67,6 +66,7 @@ {$eqmt.designation} {$eqmt.no_owned} + {linkbutton shape="edit" label="Historique des entrées / sorties" href="historique.php?id=%d"|args:$eqmt.id} {linkbutton shape="edit" label="Modifier" href="modifier_materiel.php?id=%d"|args:$eqmt.id} @@ -103,6 +103,7 @@ {$eqmt.designation} + {linkbutton shape="edit" label="Historique des entrées / sorties" href="historique.php?id=%d"|args:$eqmt.id} {linkbutton shape="edit" label="Modifier" href="modifier_materiel.php?id=%d"|args:$eqmt.id} diff --git a/src/www/admin/categories/_inc.php b/src/www/admin/categories/_inc.php new file mode 100644 index 0000000..c3651f2 --- /dev/null +++ b/src/www/admin/categories/_inc.php @@ -0,0 +1,9 @@ +check($csrf_key) && !$form->hasErrors()) { + // try to add new category and if error catched add it in form try { $cat->add([ @@ -32,6 +33,8 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors()) } } +// get the list of all categories and send it to template + $list = $cat->listAll(); $tpl->assign(compact('csrf_key', 'list')); diff --git a/src/www/admin/categories/materiels_par_categorie.php b/src/www/admin/categories/materiels_par_categorie.php index 3aa5185..0ad0f7a 100644 --- a/src/www/admin/categories/materiels_par_categorie.php +++ b/src/www/admin/categories/materiels_par_categorie.php @@ -2,30 +2,35 @@ namespace Garradin; -use Garradin\Plugin\Materiels\Category; -use Garradin\Plugin\Materiels\Equipment; -use Garradin\Utils; - require_once __DIR__ . '/../_inc.php'; +require_once __DIR__ . '/_inc.php'; -$cat = new Category; +use Garradin\Plugin\Materiels\Equipment; -$c = $cat->get((int) qg('id')); +// get the category requested and his name -if (!$c) { +$cat_requested = $cat->get((int) qg('id')); + +if (!$cat_requested) { throw new UserException("Cette catégorie n'existe pas."); } -$eqmts = $cat->listAllEquipments($c->id); +$cat_name = $cat_requested->name; + +// get the list of all equipments for the requested category + +$eqmts = $cat->listAllEquipments($cat_requested->id); + +// get all lists of equipments founded $eqmt = new Equipment; list($eqmts_owned, $eqmts_no_owned, $eqmts_just_listed) = $eqmt->AllListsAll($eqmts); -$cat_name = $c->name; - $return_link = PLUGIN_URL . 'categories/index.php'; +// send to template the category's name and all lists of its equipment + $tpl->assign(compact( 'cat_name', 'eqmts_owned', 'eqmts_no_owned', 'eqmts_just_listed', 'return_link')); diff --git a/src/www/admin/categories/modifier_categorie.php b/src/www/admin/categories/modifier_categorie.php index 1c80327..c93d9c1 100644 --- a/src/www/admin/categories/modifier_categorie.php +++ b/src/www/admin/categories/modifier_categorie.php @@ -1,26 +1,30 @@ get((int) qg('id')); +// get the category requested -if (!$c) { +$cat_requested = $cat->get((int) qg('id')); + +if (!$cat_requested) { throw new UserException("Cette catégorie n'existe pas."); } -$csrf_key = 'edit_category_' . $c->id; +// check if edit form is submitted + +$csrf_key = 'edit_category_' . $cat_requested->id; if (f('save') && $form->check($csrf_key) && !$form->hasErrors()) { + // try to edit category selected and if error catched add it in form try { - $cat->edit($c->id, [ + $cat->edit($cat_requested->id, [ 'name' => ucfirst(f('name')) ]); Utils::redirect(PLUGIN_URL . 'categories/index.php'); @@ -39,6 +43,8 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors()) $cancel_link = PLUGIN_URL . 'categories/index.php'; -$tpl->assign(compact('c', 'csrf_key', 'cancel_link')); +// send to template the category requested + +$tpl->assign(compact('cat_requested', 'csrf_key', 'cancel_link')); $tpl->display(PLUGIN_ROOT . '/templates/categories/modifier_categorie.tpl'); diff --git a/src/www/admin/categories/supprimer_categorie.php b/src/www/admin/categories/supprimer_categorie.php index 00cedf4..598ed47 100644 --- a/src/www/admin/categories/supprimer_categorie.php +++ b/src/www/admin/categories/supprimer_categorie.php @@ -1,26 +1,30 @@ get((int) qg('id')); +// get the category selected -if (!$c) { +$cat_requested = $cat->get((int) qg('id')); + +if (!$cat_requested) { throw new UserException("Cette catégorie n'existe pas."); } -$csrf_key = 'delete_category_' . $c->id; +// check if delete form is submitted + +$csrf_key = 'delete_category_' . $cat_requested->id; if (f('delete') && $form->check($csrf_key) && !$form->hasErrors()) { try { - $cat->delete($c->id); + // try to delete category selected and if error catched add it in form + $cat->delete($cat_requested->id); Utils::redirect(PLUGIN_URL . 'categories/index.php'); } catch (\RuntimeException $e) @@ -37,6 +41,8 @@ if (f('delete') && $form->check($csrf_key) && !$form->hasErrors()) $cancel_link = PLUGIN_URL . 'categories/index.php'; -$tpl->assign(compact('c', 'csrf_key', 'cancel_link')); +// send to template the category requested + +$tpl->assign(compact('cat_requested', 'csrf_key', 'cancel_link')); $tpl->display(PLUGIN_ROOT . '/templates/categories/supprimer_categorie.tpl'); diff --git a/src/www/admin/historique.php b/src/www/admin/historique.php new file mode 100644 index 0000000..2f80c2c --- /dev/null +++ b/src/www/admin/historique.php @@ -0,0 +1,25 @@ +get((int) qg('id')); + +$entry_dates = $entry->AllDatesByEquipment($eq->id); +$output_dates = $output->AllDatesByEquipment($eq->id); +$all_dates = array_unique(array_merge( + $entry_dates, $output_dates), SORT_REGULAR); + +sort($all_dates); + +$tpl->assign(compact('all_dates')); + +$tpl->display(PLUGIN_ROOT . '/templates/historique.tpl'); diff --git a/src/www/admin/sorties.php b/src/www/admin/sorties.php deleted file mode 100644 index 166bb15..0000000 --- a/src/www/admin/sorties.php +++ /dev/null @@ -1,7 +0,0 @@ -display(PLUGIN_ROOT . '/templates/sorties.tpl');