Skip to content

Commit

Permalink
Mise à jour pour la version beta1 du CMS.
Browse files Browse the repository at this point in the history
  • Loading branch information
noelma committed Apr 26, 2020
1 parent 134affc commit cfdc9f5
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 88 deletions.
76 changes: 29 additions & 47 deletions Controller/Starterkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ]);

Expand All @@ -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 ]);
Expand All @@ -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', [
Expand All @@ -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' ]);

Expand All @@ -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',
Expand All @@ -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');

Expand Down
61 changes: 32 additions & 29 deletions Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')
Expand All @@ -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)
Expand All @@ -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.
Expand All @@ -105,7 +108,7 @@ public function hookUninstallMenu(ContainerInterface $ci)
->execute();
}
}

public function hookUninstallUser(ContainerInterface $ci)
{
if ($ci->module()->has('User')) {
Expand Down
23 changes: 13 additions & 10 deletions Services/HookConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace SoosyzeExtension\Starterkit\Services;

use Soosyze\Components\Form\FormBuilder;
use Soosyze\Components\Validator\Validator;

class HookConfig
{
/**
Expand All @@ -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', '<span class="ui"></span> ' . t('Start check.'), [
->label('start_check-label', '<span class="ui"></span> ' . 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,
Expand All @@ -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',
Expand All @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion Views/form-starterkit-create.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

<?php echo $form->renderForm(); ?>
<?php echo $form; ?>
2 changes: 1 addition & 1 deletion Views/form-starterkit-edit.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

<?php echo $form->renderForm(); ?>
<?php echo $form; ?>

0 comments on commit cfdc9f5

Please sign in to comment.