From 5f226732ad5e84709e8f725a7c02cbcdff8f502f Mon Sep 17 00:00:00 2001 From: JBthePenguin Date: Thu, 3 Jun 2021 19:30:07 +0200 Subject: [PATCH] Modify categories --- src/lib/Category.php | 24 ++++++++--- src/templates/_nav.tpl | 2 +- .../{categories.tpl => categories/index.tpl} | 1 + .../categories/supprimer_categorie.tpl | 11 +++++ src/templates/common/delete_form.tpl | 13 ++++++ src/www/admin/categories.php | 28 ------------- src/www/admin/categories/index.php | 42 +++++++++++++++++++ .../admin/categories/supprimer_categorie.php | 24 +++++++++++ src/www/admin/supprimer_categorie.php | 7 ---- 9 files changed, 110 insertions(+), 42 deletions(-) rename src/templates/{categories.tpl => categories/index.tpl} (97%) create mode 100644 src/templates/categories/supprimer_categorie.tpl create mode 100644 src/templates/common/delete_form.tpl delete mode 100644 src/www/admin/categories.php create mode 100644 src/www/admin/categories/index.php create mode 100644 src/www/admin/categories/supprimer_categorie.php delete mode 100644 src/www/admin/supprimer_categorie.php diff --git a/src/lib/Category.php b/src/lib/Category.php index 1694006..b1da912 100644 --- a/src/lib/Category.php +++ b/src/lib/Category.php @@ -2,13 +2,10 @@ namespace Garradin\Plugin\Materiels; -use Garradin\Entity; use Garradin\DB; -class Category extends Entity +class Category { - const TABLE = 'plugin_materiels_category'; - protected $id; protected $name; @@ -17,8 +14,23 @@ class Category extends Entity 'name' => 'string', ]; - static public function listAll(): array + public function add($data = []) { - return DB::getInstance()->get('SELECT id, name FROM plugin_materiels_category ORDER BY name COLLATE NOCASE;'); + DB::getInstance()->insert('plugin_materiels_category', $data); + } + + public function delete($id) + { + DB::getInstance()->delete('plugin_facturation_clients', 'id = ' . $id); + } + + public function get($id) + { + return DB::getInstance()->first('SELECT * FROM plugin_materiels_category WHERE id = ?;', $id); + } + + public function listAll() + { + return DB::getInstance()->get('SELECT id, name FROM plugin_materiels_category ORDER BY name;'); } } diff --git a/src/templates/_nav.tpl b/src/templates/_nav.tpl index 68a2f6b..323a59a 100644 --- a/src/templates/_nav.tpl +++ b/src/templates/_nav.tpl @@ -1,7 +1,7 @@