Skip to content

Commit

Permalink
Mise à jour pour la version alpha5 du CMS.
Browse files Browse the repository at this point in the history
  • Loading branch information
noelma committed Apr 9, 2019
1 parent 2bdf8e4 commit 68bce05
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 58 deletions.
23 changes: 18 additions & 5 deletions Config/service.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,28 @@
"@query"
]
},
"starterkit.hook": {
"class": "Starterkit\\Services\\StarterkitHook",
"starterkit.hook.config": {
"class": "Starterkit\\Services\\HookConfig",
"arguments": [
"@query",
"@schema"
"@config"
],
"hooks": {
"config.edit.menu": "menu",
"config.edit.starterkit.form.generate": "form",
"config.update.starterkit.validator": "validator",
"config.update.starterkit.before": "before"
}
},
},
"starterkit.hook.user": {
"class": "Starterkit\\Services\\HookUser",
"hooks": {
"user.permission.module": "hookPermission",
"route.starterkit.created": "hookStarterkitCreated",
"route.starterkit.store": "hookStarterkitCreate",
"route.starterkit.edit": "hookStarterkitEdited",
"route.starterkit.update": "hookStarterkitEdited"
}
},
"starterkit.install": {
"class": "Starterkit\\Install",
"hooks": {
Expand Down
8 changes: 3 additions & 5 deletions Controller/Starterkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public function index($req)
$linkShow = self::router()->getRoute('starterkit.show', [ ':id' => 1 ]);

return self::template()
->setTheme(false)
->view('page', [
'title_main' => 'Starterkit index'
])
Expand All @@ -44,7 +43,7 @@ public function admin($req)
$linkEdit = self::router()->getRoute('starterkit.edit', [ ':id' => 1 ]);

return self::template()
->setTheme()
->getTheme('theme_admin')
->view('page', [
'title_main' => 'Starterkit admin',
])
Expand All @@ -60,7 +59,6 @@ public function admin($req)
public function show($id, $req)
{
return self::template()
->setTheme(false)
->view('page', [
'title_main' => 'Starterkit content ' . $id,
])
Expand Down Expand Up @@ -91,7 +89,7 @@ public function create($req)
->submit('submit', 'Enregistrer', [ 'class' => 'btn btn-success' ]);

return self::template()
->setTheme()
->getTheme('theme_admin')
->view('page', [
'title_main' => 'Starterkit create'
])
Expand Down Expand Up @@ -133,7 +131,7 @@ public function edit($id, $req)
->submit('submit', 'Enregistrer', [ 'class' => 'btn btn-success' ]);

return self::template()
->setTheme()
->getTheme('theme_admin')
->view('page', [
'title_main' => 'Starterkit edit ' . $id
])
Expand Down
44 changes: 13 additions & 31 deletions Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public function install($container)
->values([ 'value_1', null ])
->execute();
// */
$container->config()->set('settings.start_check', '');
$container->config()->set('settings.start_text', '');
}

public function hookInstall($container)
Expand All @@ -34,57 +36,43 @@ public function hookInstall($container)
public function hookInstallUser($container)
{
if ($container->schema()->hasTable('user')) {
$container->query()->insertInto('permission', [
'permission_id',
'permission_label'
])
->values([ 'starterkit.index', 'Voir starterkit' ])
->values([ 'starterkit.admin', 'Voir l\'administration' ])
->values([ 'starterkit.show', 'Voir le contenu' ])
->values([ 'starterkit.create', 'Voir le formulaire d\'ajout' ])
->values([ 'starterkit.store', 'Ajouter' ])
->values([ 'starterkit.edit', 'Voir le formulaire d\'édition' ])
->values([ 'starterkit.update', 'Éditer' ])
->values([ 'starterkit.delete', 'Supprimer' ])
->execute();

$container->query()->insertInto('role_permission', [
'role_id',
'permission_id'
])
->values([ 1, 'starterkit.index' ])
->values([ 2, 'starterkit.index' ])
->values([ 3, 'starterkit.index' ])
->values([ 3, 'starterkit.admin' ])
->values([ 1, 'starterkit.show' ])
->values([ 2, 'starterkit.show' ])
->values([ 3, 'starterkit.show' ])
->values([ 3, 'starterkit.create' ])
->values([ 3, 'starterkit.store' ])
->values([ 3, 'starterkit.edit' ])
->values([ 3, 'starterkit.update' ])
->values([ 3, 'starterkit.created' ])
->values([ 3, 'starterkit.edited' ])
->values([ 3, 'starterkit.delete' ])
->values([ 2, 'starterkit.index' ])
->values([ 2, 'starterkit.show' ])
->values([ 1, 'starterkit.index' ])
->values([ 1, 'starterkit.show' ])
->execute();
}
}

public function hookInstallMenu($container)
{
if ($container->schema()->hasTable('menu')) {
$container->query()->insertInto('menu_link', [ 'title_link', 'link',
$container->query()->insertInto('menu_link', [ 'key', 'title_link', 'link',
'menu', 'weight', 'parent' ])
->values([
'<span class="glyphicon glyphicon-send" aria-hidden="true"></span> Starterkit',
'starterkit.admin',
'<i class="fa fa-send"></i> Starterkit',
'admin/starterkit',
'admin-menu',
50,
-1
])
->execute();

$container->query()->insertInto('menu_link', [ 'title_link', 'link',
$container->query()->insertInto('menu_link', [ 'key', 'title_link', 'link',
'menu', 'weight', 'parent' ])
->values([
'starterkit.index',
'Starterkit',
'starterkit/index',
'main-menu',
Expand All @@ -98,12 +86,6 @@ public function hookInstallMenu($container)
public function uninstall($container)
{
if ($container->schema()->hasTable('user')) {
$container->query()
->from('permission')
->delete()
->where('permission_id', 'like', 'starterkit%')
->execute();

$container->query()
->from('role_permission')
->delete()
Expand Down
64 changes: 64 additions & 0 deletions Services/HookConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Starterkit\Services;

class HookConfig
{
/**
* @var \Soosyze\Config
*/
protected $config;

public function __construct($config)
{
$this->config = $config;
}

public function menu(&$menu)
{
$menu[] = [
'key' => 'starterkit',
'title_link' => 'Starterkit'
];
}

public function form(&$form, $data)
{
return $form->group('start-config-fieldset', 'fieldset', function ($form) use ($data) {
$form->legend('start-config-legend', 'Starterkit config')
->group('start-start_check-group', 'div', function ($form) use ($data) {
$form->checkbox('start_check', 'start_check', [ 'checked' => $data[ 'start_check' ] ])
->label('start-start_check-label', '<span class="ui"></span> Start check.', [
'for' => 'start_check'
]);
}, [ 'class' => 'form-group' ])
->group('system-start_text-group', 'div', function ($form) use ($data) {
$form->label('system-start_text-label', 'Start text')
->text('start_text', 'start_text', [
'class' => 'form-control',
'required' => 1,
'placeholder' => 'Text exemple',
'value' => $data[ 'start_text' ]
]);
}, [ 'class' => 'form-group' ]);
})
->token()
->submit('submit', 'Enregistrer', [ 'class' => 'btn btn-success' ]);
}

public function validator(&$validator)
{
$validator->setRules([
'start_check' => '!required|bool',
'start_text' => 'required|string|max:255'
]);
}

public function before(&$validator, &$data)
{
$data = [
'start_check' => $validator->getInput('start_check'),
'start_text' => $validator->getInput('start_text')
];
}
}
28 changes: 28 additions & 0 deletions Services/HookUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Starterkit\Services;

class HookUser
{
public function hookPermission(&$permission)
{
$permission[ 'Starterkit' ] = [
'starterkit.index' => 'Voir starterkit',
'starterkit.admin' => 'Voir l\'administration',
'starterkit.show' => 'Voir le contenu',
'starterkit.created' => 'Ajouter du contenu',
'starterkit.edited' => 'Éditer du contenu',
'starterkit.delete' => 'Supprimer du contenu',
];
}

public function hookStarterkitCreated($req)
{
return 'starterkit.created';
}

public function hookStarterkitEdited($id, $req)
{
return 'starterkit.edited';
}
}
16 changes: 0 additions & 16 deletions Services/StarterkitHook.php

This file was deleted.

2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"Starterkit": "Starterkit\\Controller\\Starterkit"
},
"version": "1.0",
"description": "Pour démarrer votre module soosyze avec une base de code. ",
"description": "Pour démarrer votre module Soosyze avec une base de code :<br>CRUD, liens dans les menus, droits utilisateurs, page de configuration. ",
"package": "Development",
"locked": false,
"required": []
Expand Down

0 comments on commit 68bce05

Please sign in to comment.