diff --git a/Controller/Starterkit.php b/Controller/Starterkit.php index a42cccd..639bfb3 100644 --- a/Controller/Starterkit.php +++ b/Controller/Starterkit.php @@ -4,6 +4,7 @@ use Soosyze\Components\Form\FormBuilder; use Soosyze\Components\Http\Redirect; +use Soosyze\Components\Http\ServerRequest; use Soosyze\Components\Validator\Validator; class Starterkit extends \Soosyze\Controller @@ -15,10 +16,7 @@ public function __construct() $this->pathViews = dirname(__DIR__) . '/Views/'; } - /** - * Page d'accueil du module. - */ - public function index($req) + public function index(ServerRequest $req) { $linkShow = self::router()->getRoute('starterkit.show', [ ':id' => 1 ]); @@ -31,10 +29,7 @@ public function index($req) ]); } - /** - * Page d'administration du module. - */ - public function admin($req) + public function admin(ServerRequest $req) { $linkCreate = self::router()->getRoute('starterkit.create'); $linkEdit = self::router()->getRoute('starterkit.edit', [ ':id' => 1 ]); @@ -50,10 +45,7 @@ public function admin($req) ]); } - /** - * Page pour voir un contenu du module. - */ - public function show($id, $req) + public function show($id, ServerRequest $req) { return self::template() ->view('page', [ @@ -64,24 +56,25 @@ public function show($id, $req) ]); } - /** - * Formulaire de création du module. - */ - public function create($req) + public function create(ServerRequest $req) { $action = self::router()->getRoute('starterkit.store'); $form = (new FormBuilder([ 'method' => 'post', 'action' => $action ])) - ->group('menu-link-title-group', 'div', function ($form) { - $form->label('menu-link-title-label', 'Texte', [ - 'for' => 'text' ]) - ->text('text', [ - 'class' => 'form-control', - 'maxlength' => 255, - 'placeholder' => 'Field example', - 'required' => 1 - ]); - }, [ 'class' => 'form-group' ]) + ->group('start-config-fieldset', 'fieldset', function ($form) { + $form->legend('start-config-legend', t('Starterkit config')) + ->group('title-group', 'div', function ($form) { + $form->label('title-label', 'Title', [ + 'for' => 'title' + ]) + ->text('title', [ + 'class' => 'form-control', + 'maxlength' => 255, + 'placeholder' => 'Field example', + 'required' => 1 + ]); + }, [ 'class' => 'form-group' ]); + }) ->token('starterkit_create') ->submit('submit', t('Save'), [ 'class' => 'btn btn-success' ]); @@ -95,28 +88,23 @@ public function create($req) ]); } - /** - * Fonction de validation et d'ajout du module. - */ - public function store($req) + public function store(ServerRequest $req) { $route = self::router()->getRoute('starterkit.admin'); return new Redirect($route); } - /** - * Formulaire d'édition du module. - */ - public function edit($id, $req) + public function edit($id, ServerRequest $req) { $action = self::router()->getRoute('starterkit.edit', [ ':id' => $id ]); $form = (new FormBuilder([ 'method' => 'post', 'action' => $action ])) - ->group('menu-link-title-group', 'div', function ($form) use ($id) { - $form->label('menu-link-title-label', 'Texte', [ - 'for' => 'text' ]) - ->text('text', [ + ->group('title-group', 'div', function ($form) use ($id) { + $form->label('title-label', 'Title', [ + 'for' => 'title' + ]) + ->text('title', [ 'class' => 'form-control', 'maxlength' => 255, 'placeholder' => 'Field example', @@ -130,27 +118,21 @@ public function edit($id, $req) return self::template() ->getTheme('theme_admin') ->view('page', [ - 'title_main' => t('Starterkit edit :id', [':id' => $id]) + 'title_main' => t('Starterkit edit :id', [ ':id' => $id ]) ]) ->make('page.content', 'form-starterkit-edit.php', $this->pathViews, [ 'form' => $form ]); } - /** - * Fonction de validation et modification du module. - */ - public function update($id, $req) + public function update($id, ServerRequest $req) { $route = self::router()->getRoute('starterkit.admin'); return new Redirect($route); } - /** - * Fonction de validation et suppression du module. - */ - public function delete($id, $req) + public function delete($id, ServerRequest $req) { $route = self::router()->getRoute('starterkit.admin'); diff --git a/Installer.php b/Installer.php index bbea906..d37742f 100644 --- a/Installer.php +++ b/Installer.php @@ -11,24 +11,17 @@ public function getDir() { return __DIR__ . '/composer.json'; } - + public function install(ContainerInterface $ci) { /* Ajoute une table et insert des données. $ci->schema() - ->createTableIfNotExists('starterkit', function (TableBuilder $table) { + ->createTableIfNotExists('starterkit', function (TableBuilder $table) { $table->increments('id') ->string('field_1') ->integer('field_2')->nullable() ->boolean('field_3')->valueDefault(false); - }); - - $ci->query() - ->insertInto('starterkit', [ 'field_1', 'field_2' ]) - ->values([ 'value_1', 1 ]) - ->values([ 'value_1', 2 ]) - ->values([ 'value_1', null ]) - ->execute(); + }); // */ $ci->config() ->set('settings.start_check', '') @@ -37,12 +30,39 @@ public function install(ContainerInterface $ci) public function seeders(ContainerInterface $ci) { + /* Ajout des données + $ci->query() + ->insertInto('starterkit', [ 'field_1', 'field_2' ]) + ->values([ 'value_1', 1 ]) + ->values([ 'value_1', 2 ]) + ->values([ 'value_1', null ]) + ->execute(); + // */ } public function hookInstall(ContainerInterface $ci) { - $this->hookInstallUser($ci); $this->hookInstallMenu($ci); + $this->hookInstallUser($ci); + } + + public function hookInstallMenu(ContainerInterface $ci) + { + if ($ci->module()->has('Menu')) { + $ci->query() + ->insertInto('menu_link', [ + 'key', 'icon', 'title_link', 'link', 'menu', 'weight', 'parent' + ]) + ->values([ + 'starterkit.admin', 'fa fa-puzzle-piece', 'Starterkit', 'admin/starterkit', + 'menu-admin', 50, -1 + ]) + ->values([ + 'starterkit.index', null, 'Starterkit', 'starterkit/index', 'menu-admin', + 50, 1 + ]) + ->execute(); + } } public function hookInstallUser(ContainerInterface $ci) @@ -64,23 +84,6 @@ public function hookInstallUser(ContainerInterface $ci) } } - public function hookInstallMenu(ContainerInterface $ci) - { - if ($ci->module()->has('Menu')) { - $ci->query() - ->insertInto('menu_link', [ - 'key', 'icon', 'title_link', 'link', 'menu', 'weight', 'parent' - ]) - ->values([ - 'starterkit.admin', 'fa fa-puzzle-piece', 'Starterkit', 'admin/starterkit', 'menu-admin', 50, -1 - ]) - ->values([ - 'starterkit.index', null, 'Starterkit', 'starterkit/index', 'menu-admin', 50, 1 - ]) - ->execute(); - } - } - public function uninstall(ContainerInterface $ci) { /* Supprime une table et ses données. @@ -105,7 +108,7 @@ public function hookUninstallMenu(ContainerInterface $ci) ->execute(); } } - + public function hookUninstallUser(ContainerInterface $ci) { if ($ci->module()->has('User')) { diff --git a/Services/HookConfig.php b/Services/HookConfig.php index 86da771..077f392 100644 --- a/Services/HookConfig.php +++ b/Services/HookConfig.php @@ -2,6 +2,9 @@ namespace SoosyzeExtension\Starterkit\Services; +use Soosyze\Components\Form\FormBuilder; +use Soosyze\Components\Validator\Validator; + class HookConfig { /** @@ -14,25 +17,25 @@ public function __construct($config) $this->config = $config; } - public function menu(&$menu) + public function menu(array &$menu) { $menu['starterkit'] = [ 'title_link' => 'Starterkit' ]; } - public function form(&$form, $data) + public function form(FormBuilder &$form, array $data) { - return $form->group('start-config-fieldset', 'fieldset', function ($form) use ($data) { - $form->legend('start-config-legend', t('Starterkit config')) - ->group('start-start_check-group', 'div', function ($form) use ($data) { + return $form->group('start-fieldset', 'fieldset', function ($form) use ($data) { + $form->legend('start-legend', t('Starterkit config')) + ->group('start_check-group', 'div', function ($form) use ($data) { $form->checkbox('start_check', [ 'checked' => $data[ 'start_check' ] ]) - ->label('start-start_check-label', ' ' . t('Start check.'), [ + ->label('start_check-label', ' ' . t('Start check.'), [ 'for' => 'start_check' ]); }, [ 'class' => 'form-group' ]) - ->group('system-start_text-group', 'div', function ($form) use ($data) { - $form->label('system-start_text-label', t('Start text')) + ->group('start_text-group', 'div', function ($form) use ($data) { + $form->label('start_text-label', t('Start text')) ->text('start_text', [ 'class' => 'form-control', 'required' => 1, @@ -44,7 +47,7 @@ public function form(&$form, $data) ->submit('submit', t('Save'), [ 'class' => 'btn btn-success' ]); } - public function validator(&$validator) + public function validator(Validator &$validator) { $validator->setRules([ 'start_check' => '!required|bool', @@ -53,7 +56,7 @@ public function validator(&$validator) ]); } - public function before(&$validator, &$data) + public function before(Validator &$validator, array &$data) { $data = [ 'start_check' => $validator->getInput('start_check'), diff --git a/Views/form-starterkit-create.php b/Views/form-starterkit-create.php index 8cfe79a..52d529e 100644 --- a/Views/form-starterkit-create.php +++ b/Views/form-starterkit-create.php @@ -1,2 +1,2 @@ -renderForm(); ?> \ No newline at end of file + \ No newline at end of file diff --git a/Views/form-starterkit-edit.php b/Views/form-starterkit-edit.php index 8cfe79a..52d529e 100644 --- a/Views/form-starterkit-edit.php +++ b/Views/form-starterkit-edit.php @@ -1,2 +1,2 @@ -renderForm(); ?> \ No newline at end of file + \ No newline at end of file