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 afd2cc8 commit d989846
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 146 deletions.
7 changes: 0 additions & 7 deletions Assets/script.js

This file was deleted.

21 changes: 0 additions & 21 deletions Config/service.json

This file was deleted.

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

return [
'faqsimple.extend' => [
'class' => 'SoosyzeExtension\FaqSimple\Extend',
'hooks' => [
'install.user' => 'hookInstallUser'
]
],
'faqsimple.node.hook' => [
'class' => 'SoosyzeExtension\FaqSimple\Hook\Node',
'hooks' => [
'node.entity.faq.show' => 'hookNodeEntityFaqShow'
]
]
];
2 changes: 1 addition & 1 deletion Controller/FaqSimple.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class FaqSimple extends \Soosyze\Controller
{
public function __construct()
{
$this->pathServices = dirname(__DIR__) . '/Config/service.json';
$this->pathServices = dirname(__DIR__) . '/Config/services.php';
}
}
129 changes: 48 additions & 81 deletions Installer.php → Extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Queryflatfile\TableBuilder;
use Soosyze\Components\Template\Template;

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

Expand All @@ -15,24 +15,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_faq' ])
->values([ 1, 'node.show.published.page_faq' ])
->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_faq%')
->execute();
}

public function install(ContainerInterface $ci)
{
$ci->schema()
->createTableIfNotExists('entity_page_faq', function (TableBuilder $table) {
->createTableIfNotExists('entity_page_faq', static function (TableBuilder $table) {
$table->increments('page_faq_id')
->text('body');
})
->createTableIfNotExists('entity_faq', function (TableBuilder $table) {
->createTableIfNotExists('entity_faq', static function (TableBuilder $table) {
$table->increments('faq_id')
->integer('page_faq_id')
->integer('weight')->valueDefault(1)
Expand All @@ -44,43 +76,29 @@ public function install(ContainerInterface $ci)
->insertInto('field', [ 'field_name', 'field_type' ])
->values([ 'field_name' => 'question', 'field_type' => 'text' ])
->values([ 'field_name' => 'response', 'field_type' => 'textarea' ])
->values([ 'field_name' => 'weight', 'field_type' => 'number' ])
->values([ 'field_name' => 'faq', 'field_type' => 'one_to_many' ])
->execute();

$idBody = $ci->query()
->from('field')
->where('field_name', 'body')
->fetch()[ 'field_id' ];
$idRelation = $ci->query()
->from('field')
->where('field_name', 'faq')
->fetch()[ 'field_id' ];
$idQuestion = $ci->query()
->from('field')
->where('field_name', 'question')
->fetch()[ 'field_id' ];
$idResponse = $ci->query()
->from('field')
->where('field_name', 'response')
->fetch()[ 'field_id' ];
$idWeight = $ci->query()
->from('field')
->where('field_name', 'weight')
->fetch()[ 'field_id' ];
$idBody = $ci->query()->from('field')->where('field_name', 'body')->fetch()[ 'field_id' ];
$idRelation = $ci->query()->from('field')->where('field_name', 'faq')->fetch()[ 'field_id' ];
$idQuestion = $ci->query()->from('field')->where('field_name', 'question')->fetch()[ 'field_id' ];
$idResponse = $ci->query()->from('field')->where('field_name', 'response')->fetch()[ 'field_id' ];
$idWeight = $ci->query()->from('field')->where('field_name', 'weight')->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_faq',
'node_type_name' => 'FAQ',
'node_type_description' => 'Create your question and answer page.',
'node_type_icon' => 'fa fa-question'
'node_type_icon' => 'fa fa-question',
'node_type_color' => '#7ff6ff'
])
->execute();

Expand Down Expand Up @@ -148,60 +166,9 @@ public function seeders(ContainerInterface $ci)
->execute();
}

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_faq' ])
->values([ 1, 'node.show.published.page_faq' ])
->execute();
}
}

public function uninstall(ContainerInterface $ci)
{
$ci->query()->from('node')
->delete()
->where('type', 'page_faq')
->execute();
$ci->query()->from('node_type_field')
->delete()
->where('node_type', 'page_faq')
->orWhere('node_type', 'faq')
->execute();
$ci->query()->from('node_type')
->delete()
->where('node_type', 'page_faq')
->execute();
$ci->query()->from('field')
->delete()
->where('field_name', 'question')
->orWhere('field_name', 'response')
->orWhere('field_name', 'faq')
->execute();
$ci->schema()->dropTable('entity_page_faq');
$ci->schema()->dropTable('entity_faq');
}

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_faq%')
->execute();
}
$ci->node()->deleteAliasByType('page_faq');
$ci->node()->deleteByType('page_faq');
}
}
4 changes: 2 additions & 2 deletions Services/HookNode.php → Hook/Node.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace SoosyzeExtension\FaqSimple\Services;
namespace SoosyzeExtension\FaqSimple\Hook;

class HookNode
class Node
{
public function hookNodeEntityFaqShow(&$entity)
{
Expand Down
28 changes: 0 additions & 28 deletions Services/HookApp.php

This file was deleted.

6 changes: 3 additions & 3 deletions Views/node/content-entity_faq-show.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<div class="faq">
<?php foreach ($entity as $keyField => $field): ?>
<?php if ($field[ 'field_show_label' ]): ?>
<h2><?php echo $field[ 'field_label' ]; ?></h2>
<h2><?php echo t($field[ 'field_label' ]); ?></h2>
<?php endif; ?>
<?php if ($keyField == 'question'): ?>
<div class="faq_head" onclick="toogle_faq('<?php echo "response-$keyEntity"; ?>')">
<div class="faq_head" data-dismiss="toogle" data-target="#resp-<?php echo $keyEntity; ?>">
<h3> <i class="fa fa-plus"></i> <?php echo $field[ 'field_value' ]; ?></h3>
</div>
<?php endif; ?>
<?php if ($keyField == 'response'): ?>
<div id="<?php echo "response-$keyEntity"; ?>" class="faq_content" style="display:none">
<div id="resp-<?php echo $keyEntity; ?>" class="hidden">
<?php echo $field[ 'field_display' ]; ?>
</div>
<?php endif; ?>
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "soosyze-extension/faqsimple",
"name": "soosyze/faqsimple",
"type": "soosyze-module",
"description": "Create your question and answer page.",
"version": "1.0",
"version": "1.0.0",
"autoload": {
"psr-4": {
"SoosyzeExtension\\FaqSimple\\": "/"
Expand All @@ -14,7 +14,7 @@
"package": "Content",
"controller": "SoosyzeExtension\\FaqSimple\\Controller\\FaqSimple",
"require": {
"Node": "1.0"
"Node": "1.0.*"
},
"icon": {
"name": "fa fa-question",
Expand Down

0 comments on commit d989846

Please sign in to comment.