Add categories template and ok to add one category in db, next modify and delete.
This commit is contained in:
parent
4448a9bde1
commit
2f9b57a842
BIN
materiels.tar.gz
BIN
materiels.tar.gz
Binary file not shown.
24
src/lib/Category.php
Normal file
24
src/lib/Category.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Garradin\Plugin\Materiels;
|
||||||
|
|
||||||
|
use Garradin\Entity;
|
||||||
|
use Garradin\DB;
|
||||||
|
|
||||||
|
class Category extends Entity
|
||||||
|
{
|
||||||
|
const TABLE = 'plugin_materiels_category';
|
||||||
|
|
||||||
|
protected $id;
|
||||||
|
protected $name;
|
||||||
|
|
||||||
|
protected $_types = [
|
||||||
|
'id' => 'int',
|
||||||
|
'name' => 'string',
|
||||||
|
];
|
||||||
|
|
||||||
|
static public function listAll(): array
|
||||||
|
{
|
||||||
|
return DB::getInstance()->get('SELECT id, name FROM plugin_materiels_category ORDER BY name COLLATE NOCASE;');
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
<nav class="tabs">
|
<nav class="tabs">
|
||||||
<ul>
|
<ul>
|
||||||
<li class="{if $current == 'index'}current{/if}"><a href="{plugin_url}">Matériels en stock</a></li>
|
<li class="{if $current == 'index'}current{/if}"><a href="{plugin_url}">Matériels en stock</a></li>
|
||||||
|
<li class="{if $current == 'categories'}current{/if}"><a href="{plugin_url file="categories.php"}">Catégories</a></li>
|
||||||
<li class="{if $current == 'entrees_definitives'}current{/if}"><a href="{plugin_url file="entrees_definitives.php"}"><b>Entrées définitives</b></a></li>
|
<li class="{if $current == 'entrees_definitives'}current{/if}"><a href="{plugin_url file="entrees_definitives.php"}"><b>Entrées définitives</b></a></li>
|
||||||
<li class="{if $current == 'entrees_provisoires'}current{/if}"><a href="{plugin_url file="entrees_provisoires.php"}">Entrées provisoires</a></li>
|
<li class="{if $current == 'entrees_provisoires'}current{/if}"><a href="{plugin_url file="entrees_provisoires.php"}">Entrées provisoires</a></li>
|
||||||
<li class="{if $current == 'sorties_definitives'}current{/if}"><a href="{plugin_url file="sorties_definitives.php"}">Sorties définitives</a></li>
|
<li class="{if $current == 'sorties_definitives'}current{/if}"><a href="{plugin_url file="sorties_definitives.php"}">Sorties définitives</a></li>
|
||||||
|
35
src/templates/categories.tpl
Normal file
35
src/templates/categories.tpl
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
{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"}
|
||||||
|
|
||||||
|
<form method="post" action="{$self_url}">
|
||||||
|
<fieldset>
|
||||||
|
<legend>Ajouter une catégorie</legend>
|
||||||
|
<dl>
|
||||||
|
{input type="text" name="name" label="Nom" required=true}
|
||||||
|
</dl>
|
||||||
|
<p class="submit">
|
||||||
|
{csrf_field key=$csrf_key}
|
||||||
|
{button type="submit" name="save" label="Ajouter" shape="right" class="main"}
|
||||||
|
</p>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<table class="list">
|
||||||
|
<thead>
|
||||||
|
<th>Nom</th>
|
||||||
|
<td></td>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{foreach from=$list item="cat"}
|
||||||
|
<tr>
|
||||||
|
<th>{$cat.name}</th>
|
||||||
|
<td class="actions">
|
||||||
|
{linkbutton shape="delete" label="Supprimer" href="supprimer_categorie.php?id=%d"|args:$cat.id}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/foreach}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{include file="admin/_foot.tpl"}
|
@ -2,4 +2,6 @@
|
|||||||
|
|
||||||
namespace Garradin;
|
namespace Garradin;
|
||||||
|
|
||||||
|
$session->requireAccess($session::SECTION_USERS, $session::ACCESS_WRITE);
|
||||||
|
|
||||||
$tpl->assign('plugin_tpl', PLUGIN_ROOT . '/templates/');
|
$tpl->assign('plugin_tpl', PLUGIN_ROOT . '/templates/');
|
||||||
|
28
src/www/admin/categories.php
Normal file
28
src/www/admin/categories.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Garradin;
|
||||||
|
|
||||||
|
use Garradin\Plugin\Materiels\Category;
|
||||||
|
use Garradin\Membres\Session;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/_inc.php';
|
||||||
|
|
||||||
|
$csrf_key = 'cat_create';
|
||||||
|
|
||||||
|
$form->runIf('save', function() {
|
||||||
|
$cat = new Category;
|
||||||
|
$cat->importForm([
|
||||||
|
'name' => ucfirst(f('name')),
|
||||||
|
]);
|
||||||
|
try {
|
||||||
|
$cat->save();
|
||||||
|
} catch (\RuntimeException $e) {
|
||||||
|
throw new UserException('Cette catégorie existe déjà.');
|
||||||
|
}
|
||||||
|
}, $csrf_key, Utils::getSelfURI());
|
||||||
|
|
||||||
|
$list = Category::listAll();
|
||||||
|
|
||||||
|
$tpl->assign(compact('csrf_key', 'list'));
|
||||||
|
|
||||||
|
$tpl->display(PLUGIN_ROOT . '/templates/categories.tpl');
|
7
src/www/admin/supprimer_categorie.php
Normal file
7
src/www/admin/supprimer_categorie.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Garradin;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/_inc.php';
|
||||||
|
|
||||||
|
$tpl->display(PLUGIN_ROOT . '/templates/index.tpl');
|
Loading…
Reference in New Issue
Block a user