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 472a5fa commit 6fb3cf4
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 140 deletions.
2 changes: 1 addition & 1 deletion Assets/style.css → Assets/css/gallery.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
padding: 1em;
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
text-overflow: ellipsis;
}
.card_gallery .overlay {
cursor: zoom-in;
Expand Down
File renamed without changes.
21 changes: 0 additions & 21 deletions Config/service.json

This file was deleted.

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

return [
'gallery.extend' => [
'class' => 'SoosyzeExtension\Gallery\Extend',
'hooks' => [
'install.user' => 'hookInstallUser'
]
],
'gallery.hook.app' => [
'class' => 'SoosyzeExtension\Gallery\Hook\App',
'arguments' => [ '@core' ],
'hooks' => [
'app.response.after' => 'hookResponseAfter'
]
],
'gallery.hook.node' => [
'class' => 'SoosyzeExtension\Gallery\Hook\Node',
'hooks' => [
'node.entity.picture_gallery.show' => 'hookNodeEntityPictureShow'
]
]
];
2 changes: 1 addition & 1 deletion Controller/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class Gallery extends \Soosyze\Controller
{
public function __construct()
{
$this->pathServices = dirname(__DIR__) . '/Config/service.json';
$this->pathServices = dirname(__DIR__) . '/Config/services.php';
}
}
126 changes: 48 additions & 78 deletions Installer.php → Extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Psr\Container\ContainerInterface;
use Queryflatfile\TableBuilder;

class Installer extends \SoosyzeCore\System\Migration
class Extend extends \SoosyzeCore\System\ExtendModule
{
protected $pathContent;

Expand All @@ -14,24 +14,56 @@ public function __construct()
$this->pathContent = __DIR__ . '/Views/Content/';
}

public function boot()
{
$this->loadTranslation('fr', __DIR__ . '/Lang/fr/main.json');
}

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

public function boot()
public function hookInstall(ContainerInterface $ci)
{
$this->loadTranslation('fr', __DIR__ . '/Lang/fr/main.json');
if ($ci->module()->has('User')) {
$this->hookInstallUser($ci);
}
}

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

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

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

public function install(ContainerInterface $ci)
{
$ci->schema()
->createTableIfNotExists('entity_page_gallery', function (TableBuilder $table) {
->createTableIfNotExists('entity_page_gallery', static function (TableBuilder $table) {
$table->increments('page_gallery_id')
->text('body');
})
->createTableIfNotExists('entity_picture_gallery', function (TableBuilder $table) {
->createTableIfNotExists('entity_picture_gallery', static function (TableBuilder $table) {
$table->increments('picture_gallery_id')
->integer('page_gallery_id')
->string('title')
Expand All @@ -46,41 +78,28 @@ public function install(ContainerInterface $ci)
->execute();

/* Champs de la node. */
$idTitle = $ci->query()
->from('field')
->where('field_name', 'title')
->fetch()[ 'field_id' ];
$idImage = $ci->query()
->from('field')
->where('field_name', 'image')
->fetch()[ 'field_id' ];
$idWeight = $ci->query()
->from('field')
->where('field_name', 'weight')
->fetch()[ 'field_id' ];
$idTitle = $ci->query()->from('field')->where('field_name', 'title')->fetch()[ 'field_id' ];
$idImage = $ci->query()->from('field')->where('field_name', 'image')->fetch()[ 'field_id' ];
$idWeight = $ci->query()->from('field')->where('field_name', 'weight')->fetch()[ 'field_id' ];

/* Champs de l'entity. */
$idBody = $ci->query()
->from('field')
->where('field_name', 'body')
->fetch()[ 'field_id' ];
$idRelation = $ci->query()
->from('field')
->where('field_name', 'picture_gallery')
->fetch()[ 'field_id' ];
$idBody = $ci->query()->from('field')->where('field_name', 'body')->fetch()[ 'field_id' ];
$idRelation = $ci->query()->from('field')->where('field_name', 'picture_gallery')->fetch()[ 'field_id' ];

$ci->query()
->insertInto('node_type', [
'node_type',
'node_type_name',
'node_type_description',
'node_type_icon'
'node_type_icon',
'node_type_color'
])
->values([
'node_type' => 'page_gallery',
'node_type_name' => 'Gallery',
'node_type_description' => 'Create an image gallery.',
'node_type_icon' => 'fa fa-images'
'node_type_icon' => 'fa fa-images',
'node_type_color' => '#f6ffa8'
])
->execute();

Expand Down Expand Up @@ -127,58 +146,9 @@ public function seeders(ContainerInterface $ci)
{
}

public function hookInstall(ContainerInterface $ci)
{
$this->hookInstallUser($ci);
}

public function hookInstallUser(ContainerInterface $ci)
{
if ($ci->module()->has('User')) {
$ci->query()
->insertInto('role_permission', [ 'role_id', 'permission_id' ])
->values([ 2, 'node.show.published.page_gallery' ])
->values([ 1, 'node.show.published.page_gallery' ])
->execute();
}
}

public function uninstall(ContainerInterface $ci)
{
$ci->query()->from('node')
->delete()
->where('type', 'page_gallery')
->execute();
$ci->query()->from('node_type_field')
->delete()
->where('node_type', 'page_gallery')
->orWhere('node_type', 'picture_gallery')
->execute();
$ci->query()->from('node_type')
->delete()
->where('node_type', 'page_gallery')
->execute();
$ci->query()->from('field')
->delete()
->where('field_name', 'picture_gallery')
->execute();
$ci->schema()->dropTable('entity_page_gallery');
$ci->schema()->dropTable('entity_picture_gallery');
}

public function hookUninstall(ContainerInterface $ci)
{
$this->hookUninstallUser($ci);
}

public function hookUninstallUser(ContainerInterface $ci)
{
if ($ci->module()->has('User')) {
$ci->query()
->from('role_permission')
->delete()
->where('permission_id', 'like', '%page_gallery%')
->execute();
}
$ci->node()->deleteAliasByType('page_gallery');
$ci->node()->deleteByType('page_gallery');
}
}
32 changes: 32 additions & 0 deletions Hook/App.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace SoosyzeExtension\Gallery\Hook;

use SoosyzeCore\Template\Services\Templating;

class App
{
/**
* @var \Soosyze\App
*/
private $core;

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

public function hookResponseAfter($request, &$response)
{
if (!($response instanceof Templating)) {
return;
}
$vendor = $this->core->getPath('modules_contributed', 'app/modules', false) . '/Gallery/vendor/simplelightbox';
$assets = $this->core->getPath('modules_contributed', 'app/modules', false) . '/Gallery/Assets';

$response->addScript('simple.lightbox', "$vendor/dist/simple-lightbox.min.js")
->addScript('gallery', "$assets/js/gallery.js")
->addStyle('simple.lightbox', "$vendor/dist/simple-lightbox.min.css")
->addStyle('gallery', "$assets/css/gallery.css");
}
}
4 changes: 2 additions & 2 deletions Service/HookNode.php → Hook/Node.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace SoosyzeExtension\Gallery\Service;
namespace SoosyzeExtension\Gallery\Hook;

class HookNode
class Node
{
public function hookNodeEntityPictureShow(&$entity)
{
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Gallery

Create an image gallery.
34 changes: 0 additions & 34 deletions Service/HookApp.php

This file was deleted.

14 changes: 11 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "soosyze-extension/gallery",
"name": "soosyze/gallery",
"type": "soosyze-module",
"description": "Create an image gallery.",
"version": "1.0",
"version": "1.0.0",
"autoload": {
"psr-4": {
"SoosyzeExtension\\Gallery\\": "/"
Expand All @@ -14,12 +14,20 @@
"package": "Content",
"controller": "SoosyzeExtension\\Gallery\\Controller\\Gallery",
"require": {
"Node": "1.0"
"Node": "1.0.*"
},
"icon": {
"name": "fa fa-images",
"background-color": "#f6ffa8",
"color": "#4e5700"
},
"assets": {
"scripts": [
"Assets/js/gallery.js"
],
"styles": [
"Assets/css/gallery.css"
]
}
}
}
Expand Down

0 comments on commit 6fb3cf4

Please sign in to comment.