Commit f069c6be authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Ajout de l'entity contenu et des controller/service liés

parent 61c6e37e
Pipeline #11022 passed with stage
in 18 seconds
<?php
namespace UnicaenRenderer;
use UnicaenRenderer\Controller\ContenuController;
use UnicaenRenderer\Controller\ContenuControllerFactory;
use UnicaenRenderer\Service\Contenu\ContenuService;
use UnicaenRenderer\Service\Contenu\ContenuServiceFactory;
use UnicaenRenderer\Provider\Privilege\DocumentcontenuPrivileges;
use UnicaenPrivilege\Guard\PrivilegeController;
use UnicaenRenderer\View\Helper\ContenuViewHelper;
use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;
return [
'bjyauthorize' => [
'guards' => [
PrivilegeController::class => [
[
'controller' => ContenuController::class,
'action' => [
'index',
],
'privileges' => [
DocumentcontenuPrivileges::DOCUMENTCONTENU_INDEX,
],
],
[
'controller' => ContenuController::class,
'action' => [
'afficher',
],
'privileges' => [
DocumentcontenuPrivileges::DOCUMENTCONTENU_AFFICHER,
],
],
[
'controller' => ContenuController::class,
'action' => [
'supprimer',
],
'privileges' => [
DocumentcontenuPrivileges::DOCUMENTCONTENU_SUPPRIMER,
],
],
],
],
],
'navigation' => [
'default' => [
'home' => [
'pages' => [
'administration' => [
'pages' => [
'contenu' => [
'pages' => [
'contenu' => [
'label' => 'Contenu',
'route' => 'contenu/contenu',
'resource' => PrivilegeController::getResourceId(ContenuController::class, 'index'),
'order' => 10003,
],
],
],
],
],
],
],
],
],
'router' => [
'routes' => [
'contenu' => [
'child_routes' => [
'contenu' => [
'type' => Literal::class,
'options' => [
'route' => '/contenu',
'defaults' => [
'controller' => ContenuController::class,
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
'afficher' => [
'type' => Segment::class,
'options' => [
'route' => '/afficher/:contenu',
'defaults' => [
'controller' => ContenuController::class,
'action' => 'afficher',
],
],
],
'supprimer' => [
'type' => Segment::class,
'options' => [
'route' => '/supprimer/:contenu',
'defaults' => [
'controller' => ContenuController::class,
'action' => 'supprimer',
],
],
],
],
],
],
],
],
],
'service_manager' => [
'factories' => [
ContenuService::class => ContenuServiceFactory::class,
],
],
'form_elements' => [
'factories' => [],
],
'hydrators' => [
'factories' => [],
],
'controllers' => [
'factories' => [
ContenuController::class => ContenuControllerFactory::class,
]
],
'view_helpers' => [
'invokables' => [
'contenu' => ContenuViewHelper::class,
],
],
];
......@@ -2,8 +2,9 @@
use UnicaenRenderer\Controller\IndexController;
use UnicaenRenderer\Controller\IndexControllerFactory;
use UnicaenRenderer\Provider\Privilege\DocumentcontentPrivileges;
use UnicaenRenderer\Provider\Privilege\DocumentcontenuPrivileges;
use UnicaenRenderer\Provider\Privilege\DocumentmacroPrivileges;
use UnicaenRenderer\Provider\Privilege\DocumenttemplatePrivileges;
use UnicaenPrivilege\Guard\PrivilegeController;
use Zend\Router\Http\Literal;
......@@ -17,8 +18,9 @@ return [
'index',
],
'privileges' => [
DocumentcontentPrivileges::DOCUMENTCONTENU_INDEX,
DocumentcontenuPrivileges::DOCUMENTCONTENU_INDEX,
DocumentmacroPrivileges::DOCUMENTMACRO_INDEX,
DocumenttemplatePrivileges::DOCUMENTTEMPLATE_INDEX
],
],
],
......
......@@ -6,7 +6,7 @@ use UnicaenRenderer\Form\Template\TemplateForm;
use UnicaenRenderer\Form\Template\TemplateFormFactory;
use UnicaenRenderer\Form\Template\TemplateHydrator;
use UnicaenRenderer\Form\Template\TemplateHydratorFactory;
use UnicaenRenderer\Provider\Privilege\DocumentcontentPrivileges;
use UnicaenRenderer\Provider\Privilege\DocumenttemplatePrivileges;
use UnicaenRenderer\Service\Template\TemplateService;
use UnicaenRenderer\Service\Template\TemplateServiceFactory;
use UnicaenPrivilege\Guard\PrivilegeController;
......@@ -21,10 +21,18 @@ return [
'controller' => TemplateController::class,
'action' => [
'index',
],
'privileges' => [
DocumenttemplatePrivileges::DOCUMENTTEMPLATE_INDEX,
],
],
[
'controller' => TemplateController::class,
'action' => [
'afficher',
],
'privileges' => [
DocumentcontentPrivileges::DOCUMENTCONTENU_INDEX,
DocumenttemplatePrivileges::DOCUMENTTEMPLATE_AFFICHER,
],
],
[
......@@ -33,7 +41,7 @@ return [
'ajouter',
],
'privileges' => [
DocumentcontentPrivileges::DOCUMENTCONTENU_AJOUTER,
DocumenttemplatePrivileges::DOCUMENTTEMPLATE_AJOUTER,
],
],
[
......@@ -42,7 +50,7 @@ return [
'modifier',
],
'privileges' => [
DocumentcontentPrivileges::DOCUMENTCONTENU_MODIFIER,
DocumenttemplatePrivileges::DOCUMENTTEMPLATE_MODIFIER,
],
],
[
......@@ -52,7 +60,7 @@ return [
'restaurer',
],
'privileges' => [
DocumentcontentPrivileges::DOCUMENTCONTENU_HISTORISER,
DocumenttemplatePrivileges::DOCUMENTTEMPLATE_HISTORISER,
],
],
[
......@@ -61,7 +69,7 @@ return [
'detruire',
],
'privileges' => [
DocumentcontentPrivileges::DOCUMENTCONTENU_SUPPRIMER,
DocumenttemplatePrivileges::DOCUMENTTEMPLATE_SUPPRIMER,
],
],
],
......@@ -76,7 +84,7 @@ return [
'pages' => [
'contenu' => [
'pages' => [
'contenu' => [
'template' => [
'label' => 'Template',
'route' => 'contenu/template',
'resource' => PrivilegeController::getResourceId(TemplateController::class, 'index'),
......@@ -95,7 +103,7 @@ return [
'routes' => [
'contenu' => [
'child_routes' => [
'contenu' => [
'template' => [
'type' => Literal::class,
'options' => [
'route' => '/template',
......
<?php
namespace UnicaenRenderer\Controller;
use UnicaenRenderer\Service\Contenu\ContenuServiceAwareTrait;
use Zend\Http\Request;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class ContenuController extends AbstractActionController {
use ContenuServiceAwareTrait;
public function indexAction()
{
$contenus = $this->getContenuService()->getContenus();
return new ViewModel([
'contenus' => $contenus,
]);
}
public function afficherAction()
{
$contenu = $this->getContenuService()->getRequestedContenu($this);
return new ViewModel([
'title' => "Affichage du contenu #" . $contenu->getId(),
'contenu' => $contenu,
]);
}
public function supprimerAction()
{
$contenu = $this->getContenuService()->getRequestedContenu($this);
/** @var Request $request */
$request = $this->getRequest();
if ($request->isPost()) {
$data = $request->getPost();
if ($data["reponse"] === "oui") {
$this->getContenuService()->delete($contenu);
}
exit();
}
$vm = new ViewModel();
if ($contenu !== null) {
$vm->setTemplate('unicaen-renderer/default/confirmation');
$vm->setVariables([
'title' => "Suppression du contenu [" . $contenu->getId() . "]",
'text' => "La suppression est définitive êtes-vous sûr&middot;e de vouloir continuer ?",
'action' => $this->url()->fromRoute('contenu/contenu/supprimer', ["contenu" => $contenu->getId()], [], true),
]);
}
return $vm;
}
}
\ No newline at end of file
<?php
namespace UnicaenRenderer\Controller;
use Interop\Container\ContainerInterface;
use UnicaenRenderer\Service\Contenu\ContenuService;
class ContenuControllerFactory {
public function __invoke(ContainerInterface $container)
{
/**
* @var ContenuService $contenuService
*/
$contenuService = $container->get(ContenuService::class);
$controller = new ContenuController();
$controller->setContenuService($contenuService);
return $controller;
}
}
\ No newline at end of file
<?php
namespace UnicaenRenderer\Entity\Db;
use DateTime;
use Zend\Permissions\Acl\Resource\ResourceInterface;
class Contenu implements ResourceInterface
{
const RESOURCE_ID = 'Contenu';
/**
* @return string
*/
public function getResourceId()
{
return self::RESOURCE_ID;
}
/** @var int */
private $id;
/** @var Template */
private $template;
/** @var DateTime */
private $date;
/** @var string */
private $sujet;
/** @var string */
private $corps;
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @return Template
*/
public function getTemplate(): Template
{
return $this->template;
}
/**
* @param Template $template
* @return Contenu
*/
public function setTemplate(Template $template): Contenu
{
$this->template = $template;
return $this;
}
/**
* @return DateTime
*/
public function getDate(): DateTime
{
return $this->date;
}
/**
* @param DateTime $date
* @return Contenu
*/
public function setDate(DateTime $date): Contenu
{
$this->date = $date;
return $this;
}
/**
* @return string
*/
public function getSujet(): string
{
return $this->sujet;
}
/**
* @param string $sujet
* @return Contenu
*/
public function setSujet(string $sujet): Contenu
{
$this->sujet = $sujet;
return $this;
}
/**
* @return string
*/
public function getCorps(): string
{
return $this->corps;
}
/**
* @param string $corps
* @return Contenu
*/
public function setCorps(string $corps): Contenu
{
$this->corps = $corps;
return $this;
}
}
\ No newline at end of file
......@@ -11,9 +11,8 @@ class Macro implements HistoriqueAwareInterface , ResourceInterface
use HistoriqueAwareTrait;
const RESOURCE_ID = 'Macro';
/**
* Returns the string identifier of the Resource
*
* @return string
*/
public function getResourceId()
......
<?xml version="1.0" encoding="utf-8" ?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="UnicaenRenderer\Entity\Db\Contenu" table="unicaen_renderer_contenu">
<id name="id" column="id" type="integer">
<generator strategy="IDENTITY"/>
</id>
<many-to-one target-entity="UnicaenRenderer\Entity\Db\Template" field="template">
<join-column name="template_id" referenced-column-name="id"/>
</many-to-one>
<field name="date" column="date_generation" type="datetime" nullable="false"/>
<field name="sujet" column="sujet" type="string" length="9999" nullable="false" />
<field name="corps" column="corps" type="string" length="9999" nullable="false" />
</entity>
</doctrine-mapping>
\ No newline at end of file
......@@ -11,9 +11,8 @@ class Template implements HistoriqueAwareInterface, ResourceInterface
use HistoriqueAwareTrait;
const RESOURCE_ID = 'Template';
/**
* Returns the string identifier of the Resource
*
* @return string
*/
public function getResourceId()
......
<?php
namespace UnicaenRenderer\Provider\Privilege;
use UnicaenPrivilege\Entity\Db\Privilege;
use UnicaenPrivilege\Provider\Privilege\Privileges;
class DocumentcontentPrivileges extends Privileges
{
public static function getResourceId( $privilege )
{
if ($privilege instanceof Privilege){
$privilege = $privilege->getFullCode();
}
return 'privilege/'.$privilege;
}
const DOCUMENTCONTENU_INDEX = 'documentcontent-documentcontenu_index';
const DOCUMENTCONTENU_AJOUTER = 'documentcontent-documentcontenu_ajouter';
const DOCUMENTCONTENU_MODIFIER = 'documentcontent-documentcontenu_modifier';
const DOCUMENTCONTENU_HISTORISER = 'documentcontent-documentcontenu_historiser';
const DOCUMENTCONTENU_SUPPRIMER = 'documentcontent-documentcontenu_supprimer';
}
\ No newline at end of file
<?php
namespace UnicaenRenderer\Provider\Privilege;
use UnicaenPrivilege\Entity\Db\Privilege;
use UnicaenPrivilege\Provider\Privilege\Privileges;
class DocumentcontenuPrivileges extends Privileges
{
const DOCUMENTCONTENU_INDEX = 'documentcontenu-documentcontenu_index';
const DOCUMENTCONTENU_AFFICHER = 'documentcontenu-documentcontenu_afficher';
const DOCUMENTCONTENU_SUPPRIMER = 'documentcontenu-documentcontenu_supprimer';
}
\ No newline at end of file
<?php
namespace UnicaenRenderer\Provider\Privilege;
use UnicaenPrivilege\Entity\Db\Privilege;
use UnicaenPrivilege\Provider\Privilege\Privileges;
class DocumenttemplatePrivileges extends Privileges
{
const DOCUMENTTEMPLATE_INDEX = 'documentcontent-documenttemplate_index';
const DOCUMENTTEMPLATE_AJOUTER = 'documentcontent-documenttemplate_ajouter';
const DOCUMENTTEMPLATE_AFFICHER = 'documentcontent-documenttemplate_afficher';
const DOCUMENTTEMPLATE_MODIFIER = 'documentcontent-documenttemplate_modifier';
const DOCUMENTTEMPLATE_HISTORISER = 'documentcontent-documenttemplate_historiser';
const DOCUMENTTEMPLATE_SUPPRIMER = 'documentcontent-documenttemplate_supprimer';
}
\ No newline at end of file
<?php
namespace UnicaenRenderer\Service\Contenu;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\QueryBuilder;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenRenderer\Entity\Db\Contenu;
use Zend\Mvc\Controller\AbstractActionController;
class ContenuService {
use EntityManagerAwareTrait;
/** Gestion des entités *******************************************************************************************/
/**
* @param Contenu $contenu
* @return Contenu
*/
public function create(Contenu $contenu) : Contenu
{
try {
$this->getEntityManager()->persist($contenu);
$this->getEntityManager()->flush($contenu);
} catch (ORMException $e) {
throw new RuntimeException("Un problème est survenue lors de l'enregistrement en BD d'un Contenu.", $e);
}
return $contenu;
}
/**
* @param Contenu $contenu
* @return Contenu
*/
public function update(Contenu $contenu) : Contenu
{
try {
$this->getEntityManager()->flush($contenu);
} catch (ORMException $e) {
throw new RuntimeException("Un problème est survenue lors de l'enregistrement en BD d'un Contenu.", $e);
}
return $contenu;
}
/**
* @param Contenu $contenu
* @return Contenu
*/
public function delete(Contenu $contenu) : Contenu
{
try {
$this->getEntityManager()->remove($contenu);
$this->getEntityManager()->flush($contenu);
} catch (ORMException $e) {
throw new RuntimeException("Un problème est survenue lors de l'enregistrement en BD d'un Contenu.", $e);
}
return $contenu;
}
/** Requetages ****************************************************************************************************/
/**
* @return QueryBuilder
*/
public function createQueryBuilder() : QueryBuilder
{
$qb = $this->getEntityManager()->getRepository(Contenu::class)->createQueryBuilder('contenu')
->leftJoin('contenu.template', 'template')->addSelect('template');
return $qb;
}
/**
* @param string $champ
* @param string $or