Skip to content

Commit

Permalink
Mise à jour pour la version 1.0.0 du CMS.
Browse files Browse the repository at this point in the history
  • Loading branch information
noelma committed Mar 21, 2021
1 parent 23d9fcb commit 9e9555b
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 253 deletions.
32 changes: 0 additions & 32 deletions Config/service.json

This file was deleted.

34 changes: 34 additions & 0 deletions Config/services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

return [
'starterkit' => [
'class' => "SoosyzeExtension\Starterkit\Services\Starterkit",
'arguments' => ['@query']
],
'starterkit.extend' => [
'class' => "SoosyzeExtension\Starterkit\Extend",
'hooks' => [
'install.user' => 'hookInstallUser',
'install.menu' => 'hookInstallMenu'
]
],
'starterkit.hook.config' => [
'class' => "SoosyzeExtension\Starterkit\Hook\Config",
'hooks' => [
'config.edit.menu' => 'menu'
]
],
'starterkit.hook.user' => [
'class' => "SoosyzeExtension\Starterkit\Hook\User",
'hooks' => [
'user.permission.module' => 'hookUserPermissionModule',
'route.starterkit.index' => 'hookStarterkitShow',
'route.starterkit.show' => 'hookStarterkitShow',
'route.starterkit.create' => 'hookStarterkitCreated',
'route.starterkit.store' => 'hookStarterkitCreated',
'route.starterkit.edit' => 'hookStarterkitEdited',
'route.starterkit.update' => 'hookStarterkitEdited',
'route.starterkit.delete' => 'hookStarterkitDelete'
]
]
];
86 changes: 43 additions & 43 deletions Controller/Starterkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,11 @@ class Starterkit extends \Soosyze\Controller
{
public function __construct()
{
$this->pathServices = dirname(__DIR__) . '/Config/service.json';
$this->pathServices = dirname(__DIR__) . '/Config/services.php';
$this->pathRoutes = dirname(__DIR__) . '/Config/routes.php';
$this->pathViews = dirname(__DIR__) . '/Views/';
}

public function index(ServerRequestInterface $req)
{
$linkShow = self::router()->getRoute('starterkit.show', [ ':id' => 1 ]);

return self::template()
->view('page', [
'title_main' => t('Starterkit home page')
])
->make('page.content', 'starterkit/content-starterkit-index.php', $this->pathViews, [
'link_show' => $linkShow
]);
}

public function admin(ServerRequestInterface $req)
{
$messages = [];
Expand All @@ -52,17 +39,6 @@ public function admin(ServerRequestInterface $req)
]);
}

public function show($id, ServerRequestInterface $req)
{
return self::template()
->view('page', [
'title_main' => t('Starterkit :id', [ ':id' => $id ]),
])
->make('page.content', 'starterkit/content-starterkit-show.php', $this->pathViews, [
'id' => $id
]);
}

public function create(ServerRequestInterface $req)
{
$values = [];
Expand Down Expand Up @@ -96,20 +72,9 @@ public function create(ServerRequestInterface $req)
]);
}

public function store(ServerRequestInterface $req)
public function delete($id, ServerRequestInterface $req)
{
$validator = $this->setValidator($req);

if ($validator->isValid()) {
$_SESSION[ 'messages' ][ 'success' ] = [ t('Your starterkit has been saved.') ];

return new Redirect(self::router()->getRoute('starterkit.admin'));
}

$_SESSION[ 'inputs' ] = $validator->getInputs();
$_SESSION[ 'messages' ][ 'errors' ] = $validator->getKeyErrors();

return new Redirect(self::router()->getRoute('starterkit.create'));
return new Redirect(self::router()->getRoute('starterkit.admin'));
}

public function edit($id, ServerRequestInterface $req)
Expand Down Expand Up @@ -145,7 +110,31 @@ public function edit($id, ServerRequestInterface $req)
]);
}

public function update($id, ServerRequestInterface $req)
public function index(ServerRequestInterface $req)
{
$linkShow = self::router()->getRoute('starterkit.show', [ ':id' => 1 ]);

return self::template()
->view('page', [
'title_main' => t('Starterkit home page')
])
->make('page.content', 'starterkit/content-starterkit-index.php', $this->pathViews, [
'link_show' => $linkShow
]);
}

public function show($id, ServerRequestInterface $req)
{
return self::template()
->view('page', [
'title_main' => t('Starterkit :id', [ ':id' => $id ]),
])
->make('page.content', 'starterkit/content-starterkit-show.php', $this->pathViews, [
'id' => $id
]);
}

public function store(ServerRequestInterface $req)
{
$validator = $this->setValidator($req);

Expand All @@ -158,12 +147,23 @@ public function update($id, ServerRequestInterface $req)
$_SESSION[ 'inputs' ] = $validator->getInputs();
$_SESSION[ 'messages' ][ 'errors' ] = $validator->getKeyErrors();

return new Redirect(self::router()->getRoute('starterkit.edit', [ ':id' => $id ]));
return new Redirect(self::router()->getRoute('starterkit.create'));
}

public function delete($id, ServerRequestInterface $req)
public function update($id, ServerRequestInterface $req)
{
return new Redirect(self::router()->getRoute('starterkit.admin'));
$validator = $this->setValidator($req);

if ($validator->isValid()) {
$_SESSION[ 'messages' ][ 'success' ] = [ t('Your starterkit has been saved.') ];

return new Redirect(self::router()->getRoute('starterkit.admin'));
}

$_SESSION[ 'inputs' ] = $validator->getInputs();
$_SESSION[ 'messages' ][ 'errors' ] = $validator->getKeyErrors();

return new Redirect(self::router()->getRoute('starterkit.edit', [ ':id' => $id ]));
}

private function setValidator(ServerRequestInterface $req)
Expand All @@ -173,7 +173,7 @@ private function setValidator(ServerRequestInterface $req)
'title' => 'required|string|max:255',
'token_starterkit' => 'token'
])
->setLabel([
->setLabels([
'title' => t('Title')
])
->setInputs($req->getParsedBody());
Expand Down
121 changes: 121 additions & 0 deletions Extend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

namespace SoosyzeExtension\Starterkit;

use Psr\Container\ContainerInterface;
use Queryflatfile\TableBuilder;

class Extend extends \SoosyzeCore\System\ExtendModule
{
public function boot()
{
$this->loadTranslation('fr', __DIR__ . '/Lang/fr/main.json');
}

public function getDir()
{
return __DIR__ . '/composer.json';
}

public function hookInstall(ContainerInterface $ci)
{
if ($ci->module()->has('Menu')) {
$this->hookInstallMenu($ci);
}
if ($ci->module()->has('User')) {
$this->hookInstallUser($ci);
}
}

public function hookInstallMenu(ContainerInterface $ci)
{
$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-main',
50, -1
])
->execute();
}

public function hookInstallUser(ContainerInterface $ci)
{
$ci->query()
->insertInto('role_permission', [ 'role_id', 'permission_id' ])
->values([ 3, 'starterkit.admin' ])
->values([ 3, 'starterkit.show' ])
->values([ 2, 'starterkit.show' ])
->values([ 1, 'starterkit.show' ])
->execute();
}

public function hookUninstall(ContainerInterface $ci)
{
if ($ci->module()->has('Menu')) {
$this->hookUninstallMenu($ci);
}
if ($ci->module()->has('User')) {
$this->hookUninstallUser($ci);
}
}

public function hookUninstallMenu(ContainerInterface $ci)
{
$ci->menu()->deleteLinks(static function () use ($ci) {
return $ci->query()
->from('menu_link')
->where('key', 'like', 'starterkit%')
->fetchAll();
});
}

public function hookUninstallUser(ContainerInterface $ci)
{
$ci->query()
->from('role_permission')
->delete()
->where('permission_id', 'like', 'starterkit%')
->execute();
}

public function install(ContainerInterface $ci)
{
/* Ajoute une table et insert des données.
$ci->schema()
->createTableIfNotExists('starterkit', static function (TableBuilder $table) {
$table->increments('id')
->string('field_1')
->integer('field_2')->nullable()
->boolean('field_3')->valueDefault(false);
});
// */
$ci->config()
->set('settings.start_check', '')
->set('settings.start_text', '');
}

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 uninstall(ContainerInterface $ci)
{
/* Supprime une table et ses données.
$container->schema()->dropTable('starterkit');
// */
}
}
14 changes: 7 additions & 7 deletions Form/FormStarterkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ class FormStarterkit extends FormBuilder
{
protected $values = [ 'title' => '' ];

public function setValues(array $values)
{
$this->values = array_merge($this->values, $values);

return $this;
}

public function makeFields()
{
return $this->group('starterkit-fieldset', 'fieldset', function ($form) {
Expand All @@ -33,4 +26,11 @@ public function makeFields()
->token('token_starterkit')
->submit('submit', t('Save'), [ 'class' => 'btn btn-success' ]);
}

public function setValues(array $values)
{
$this->values = array_merge($this->values, $values);

return $this;
}
}
Loading

0 comments on commit 9e9555b

Please sign in to comment.