Commit 296f00e3 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Commit initial.

parent cd31a8e7
Loading
Loading
Loading
Loading

Module.php

0 → 100755
+60 −0
Original line number Diff line number Diff line
<?php

namespace UnicaenFaq;

use UnicaenApp\Exception\RuntimeException;
use UnicaenFaq\Service\FaqService;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;

class Module
{
    public function onBootstrap(MvcEvent $e)
    {
        $application = $e->getApplication();
        $application->getServiceManager()->get('translator');
        $eventManager = $application->getEventManager();
        $moduleRouteListener = new ModuleRouteListener();
        $moduleRouteListener->attach($eventManager);

        $this->checkModuleRequirements($e);
    }

    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
    }

    public function getAutoloaderConfig()
    {
        return [
            'Zend\Loader\StandardAutoloader' => [
                'namespaces' => [
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ],
            ],
        ];
    }

    public function checkModuleRequirements(MvcEvent $event)
    {
        $sl = $event->getApplication()->getServiceManager();

        /** @var FaqService $service */
        $service = $sl->get('UnicaenFaq\Service\FaqService');

        try {
            $service->checkSchema();
        }
        catch (\Exception $e) {
            $config = $sl->get('config');
            $pathsArray = glob($config['unicaen-faq']['db_schema_glob_paths']);
            throw new RuntimeException(sprintf(
                "Vous avez activé le module UnicaenFaq mais le schéma de base de données est incorrect: %s. " .
                "Reportez-vous aux scripts suivants : %s.",
                $e->getMessage(),
                implode(', ', array_map('realpath', $pathsArray))
            ));
        }
    }
}
+158 −0
Original line number Diff line number Diff line
<?php

use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
use UnicaenFaq\Controller\Factory\FaqControllerFactory;
use UnicaenFaq\Form\Factory\FaqFormFactory;
use UnicaenFaq\Provider\Privilege\FaqPrivileges;
use UnicaenFaq\Service\FaqServiceFactory;

return array(
    'unicaen-faq' => [
        /*
         * Masque des chemins vers les scripts SQL de création du schéma de base de données sur lequel repose ce module.
         */
        'db_schema_glob_paths' => __DIR__ . '/../data/*.sql',
    ],
    'doctrine'     => [
        'driver'     => [
            'orm_default' => [
                'class' => MappingDriverChain::class,
                'drivers' => [
                    'UnicaenFaq\Entity\Db' => 'orm_default_xml_driver',
                ],
            ],
            'orm_default_xml_driver' => [
                'class' => XmlDriver::class,
                'cache' => 'array',
                'paths' => [
                    __DIR__ . '/../src/UnicaenFaq/Entity/Db/Mapping',
                ],
            ],
        ],
    ],
    'bjyauthorize'    => [
        'resource_providers' => [
            'BjyAuthorize\Provider\Resource\Config' => [
                'Faq' => [],
            ],
        ],
        'guards' => [
            '\UnicaenAuth\Guard\PrivilegeController' => [
                [
                    'controller' => 'UnicaenFaq\Controller\Index',
                    'action'     => [
                        'index',
                    ],
                    'roles' => ['guest'], // pas d'authentification requise
                ],
                [
                    'controller' => 'UnicaenFaq\Controller\Index',
                    'action'     => [
                        'ajouter',
                        'modifier',
                        'supprimer',
                    ],
                    'privileges' => [FaqPrivileges::FAQ_MODIFICATION]
                ],
            ],
        ],
    ],
    'router' => [
        'routes' => [
            'faq' => [
                'type' => 'Literal',
                'options' => [
                    'route'    => '/faq',
                    'defaults' => [
                        'controller' => 'UnicaenFaq\Controller\Index',
                        'action'     => 'index',
                    ],
                ],
                'may_terminate' => true,
                'child_routes' => [
                    'ajouter' => [
                        'type'    => 'Segment',
                        'options' => [
                            'route'    => '/ajouter',
                            'defaults' => [
                                'action' => 'ajouter',
                            ],
                        ],
                    ],
                    'modifier' => [
                        'type'    => 'Segment',
                        'options' => [
                            'route'    => '/:faq/modifier',
                            'constraints' => [
                                'faq' => '\d+',
                            ],
                            'defaults' => [
                                'action' => 'modifier',
                            ],
                        ],
                    ],
                    'supprimer' => [
                        'type'    => 'Segment',
                        'options' => [
                            'route'    => '/:faq/supprimer',
                            'constraints' => [
                                'faq' => '\d+',
                            ],
                            'defaults' => [
                                'action' => 'supprimer',
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ],
    'navigation'      => [
        'default' => [
            'home' => [
                'pages' => [
                    'faq' => [
                        'label' => 'FAQ',
                        'route' => 'faq',
                    ],
                ],
            ],
        ],
    ],
    'service_manager' => [
        'factories' => [
            'UnicaenFaq\Service\FaqService' => FaqServiceFactory::class,
        ],
    ],
    'controllers' => [
        'factories' => [
            'UnicaenFaq\Controller\Index' => FaqControllerFactory::class,
        ],
    ],
    'form_elements'   => [
        'factories' => [
            'UnicaenFaq\Form\FaqForm' => FaqFormFactory::class,
        ],
    ],
    'view_manager' => [
        'template_map' => [
            'unicaen-faq/index'    => __DIR__ . '/../view/unicaen-faq/index.phtml',
            'unicaen-faq/modifier' => __DIR__ . '/../view/unicaen-faq/modifier.phtml',
        ],
        'template_path_stack' => [
            __DIR__ . '/../view',
        ],
    ],
    'public_files' => [
        'inline_scripts' => [
            '902_' => '//gest.unicaen.fr/public/tinymce-4.4.1/js/tinymce/tinymce.min.js',
        ],
        'stylesheets'    => [
//            '112_' => 'https://gest.unicaen.fr/public/font-awesome-4.5.0/css/font-awesome.min.css',
//            '113_' => 'https://gest.unicaen.fr/public/open-sans-gh-pages/open-sans.css',
//            '120_' => 'css/callout.css',
//            '121_' => 'https://gest.unicaen.fr/public/DataTables-1.10.12/media/css/dataTables.bootstrap.min.css',
        ],
    ],
);
 No newline at end of file
+38 −0
Original line number Diff line number Diff line
<?php

use UnicaenFaq\Entity\Db\Faq;

return array(
    'unicaen-faq' => [
        /*
         * Nom du gestionnaire d'entité concerné.
         * Par défaut: 'orm_default'.
         */
        'entity_manager_name' => 'orm_default',

        /*
         * Classe de l'entité représentant un couple question-réponse.
         * Par défaut: 'UnicaenFaq\Entity\Db\Faq'.
         */
        'faq_entity_class' => Faq::class,
    ],

    /*
     * Customisation de la navigation.
     * Ex: masquer le menu, modifier sa position, changer son label, associer une ressource ACL.
     */
//    'navigation'      => [
//        'default' => [
//            'home' => [
//                'pages' => [
//                    'faq' => [
//                        'visible'  => true,
//                        'order'    => -1000,
//                        'label'    => 'FAQ',
//                        'resource' => PrivilegeController::getResourceId('UnicaenFaq\Controller\Index', 'index'),
//                    ],
//                ],
//            ],
//        ],
//    ],
);
 No newline at end of file

data/schema.oracle.sql

0 → 100644
+37 −0
Original line number Diff line number Diff line
--
-- Table FAQ.
--
CREATE TABLE FAQ (
  ID       NUMBER(38, 0),
  QUESTION VARCHAR2(2000 CHAR) NOT NULL,
  REPONSE  VARCHAR2(2000 CHAR) NOT NULL,
  ORDRE    NUMBER(38, 0),
  CONSTRAINT FAQ_PK PRIMARY KEY (ID)
);

CREATE SEQUENCE FAQ_ID_SEQ;




--
-- Jeu d'essai.
--
INSERT INTO FAQ(ID, QUESTION, REPONSE, ORDRE) VALUES
  (FAQ_ID_SEQ.nextval, 'Qu''est-ce qu''une question ?', 'C''est une phrase appelant une réponse.', 10);





--
-- Création si besoin de la catégorie de privilège 'faq'.
--
insert into CATEGORIE_PRIVILEGE(ID, CODE, LIBELLE, ORDRE) values
  (CATEGORIE_PRIVILEGE_ID_SEQ.nextval, 'faq', 'FAQ', 10);
--
-- Privilège 'modification'.
--
insert into PRIVILEGE(ID, CATEGORIE_ID, CODE, LIBELLE, ORDRE)
  select privilege_id_seq.nextval, cp.id, 'modification', 'Modification de la FAQ', 10
  from CATEGORIE_PRIVILEGE cp where cp.CODE = 'faq';
+39 −0
Original line number Diff line number Diff line
<?php

namespace UnicaenFaq\Controller\Factory;

use UnicaenFaq\Controller\FaqController;
use UnicaenFaq\Form\FaqForm;
use UnicaenFaq\Service\FaqService;
use Zend\Mvc\Controller\ControllerManager;
use Zend\ServiceManager\ServiceLocatorInterface;

class FaqControllerFactory
{
    /**
     * Create service
     *
     * @param ControllerManager $controllerManager
     * @return FaqController
     */
    public function __invoke(ControllerManager $controllerManager)
    {
        $faqService = $this->getFaqService($controllerManager->getServiceLocator());

        /** @var FaqForm $form */
        $form = $controllerManager->getServiceLocator()->get('FormElementManager')->get('UnicaenFaq\Form\FaqForm');

        $controller = new FaqController($form);
        $controller->setFaqService($faqService);

        return $controller;
    }

    private function getFaqService(ServiceLocatorInterface $serviceLocator)
    {
        /** @var FaqService $service */
        $service = $serviceLocator->get('UnicaenFaq\Service\FaqService');

        return $service;
    }
}
 No newline at end of file
Loading