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

Modification des templates (privileges, form, ...)

parent f069c6be
Pipeline #11023 passed with stage
in 21 seconds
...@@ -77,7 +77,7 @@ class TemplateForm extends Form { ...@@ -77,7 +77,7 @@ class TemplateForm extends Form {
'name' => 'complement', 'name' => 'complement',
'type' => 'textarea', 'type' => 'textarea',
'options' => [ 'options' => [
'label' => 'Complément (nom du fichier, étiquette, ... ) * : ', 'label' => 'Sujet (sujet du courrier électronique, nom du fichier, étiquette, ... ) * : ',
'label_attributes' => [ 'label_attributes' => [
'class' => 'control-label', 'class' => 'control-label',
], ],
...@@ -92,7 +92,7 @@ class TemplateForm extends Form { ...@@ -92,7 +92,7 @@ class TemplateForm extends Form {
'name' => 'template', 'name' => 'template',
'type' => 'textarea', 'type' => 'textarea',
'options' => [ 'options' => [
'label' => 'Template * : ', 'label' => 'Corps * : ',
'label_attributes' => [ 'label_attributes' => [
'class' => 'control-label', 'class' => 'control-label',
], ],
......
...@@ -2,15 +2,14 @@ ...@@ -2,15 +2,14 @@
namespace UnicaenRenderer\Provider\Privilege; namespace UnicaenRenderer\Provider\Privilege;
use UnicaenPrivilege\Entity\Db\Privilege;
use UnicaenPrivilege\Provider\Privilege\Privileges; use UnicaenPrivilege\Provider\Privilege\Privileges;
class DocumenttemplatePrivileges extends Privileges class DocumenttemplatePrivileges extends Privileges
{ {
const DOCUMENTTEMPLATE_INDEX = 'documentcontent-documenttemplate_index'; const DOCUMENTTEMPLATE_INDEX = 'documenttemplate-documenttemplate_index';
const DOCUMENTTEMPLATE_AJOUTER = 'documentcontent-documenttemplate_ajouter'; const DOCUMENTTEMPLATE_AJOUTER = 'documenttemplate-documenttemplate_ajouter';
const DOCUMENTTEMPLATE_AFFICHER = 'documentcontent-documenttemplate_afficher'; const DOCUMENTTEMPLATE_AFFICHER = 'documenttemplate-documenttemplate_afficher';
const DOCUMENTTEMPLATE_MODIFIER = 'documentcontent-documenttemplate_modifier'; const DOCUMENTTEMPLATE_MODIFIER = 'documenttemplate-documenttemplate_modifier';
const DOCUMENTTEMPLATE_HISTORISER = 'documentcontent-documenttemplate_historiser'; const DOCUMENTTEMPLATE_HISTORISER = 'documenttemplate-documenttemplate_historiser';
const DOCUMENTTEMPLATE_SUPPRIMER = 'documentcontent-documenttemplate_supprimer'; const DOCUMENTTEMPLATE_SUPPRIMER = 'documenttemplate-documenttemplate_supprimer';
} }
\ No newline at end of file
...@@ -2,15 +2,20 @@ ...@@ -2,15 +2,20 @@
namespace UnicaenRenderer\Service\Contenu; namespace UnicaenRenderer\Service\Contenu;
use DateTime;
use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\ORMException; use Doctrine\ORM\ORMException;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Service\EntityManagerAwareTrait; use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenRenderer\Entity\Db\Contenu; use UnicaenRenderer\Entity\Db\Contenu;
use UnicaenRenderer\Entity\Db\Template;
use UnicaenRenderer\Service\Template\TemplateServiceAwareTrait;
use Zend\Mvc\Controller\AbstractActionController; use Zend\Mvc\Controller\AbstractActionController;
class ContenuService { class ContenuService {
use EntityManagerAwareTrait; use EntityManagerAwareTrait;
use TemplateServiceAwareTrait;
/** Gestion des entités *******************************************************************************************/ /** Gestion des entités *******************************************************************************************/
...@@ -112,4 +117,31 @@ class ContenuService { ...@@ -112,4 +117,31 @@ class ContenuService {
$result = $this->getContenu($id); $result = $this->getContenu($id);
return $result; return $result;
} }
/** facade ********************************************************************************************************/
/**
* @param Template|string $template
* @param array $variables
* @return Contenu
*/
public function generateContenu($template, array $variables) : Contenu
{
if (is_string($template)) {
$template = $this->getTemplateService()->getTemplateByCode($template);
if ($template === null) throw new RuntimeException("Aucun template trouvé avec le code [".$template."]");
}
$contenu = new Contenu();
$contenu->setTemplate($template);
$contenu->setDate(new DateTime());
$sujet = $this->getTemplateService()->generateTitre($template, $variables);
$contenu->setSujet($sujet);
$corps = $this->getTemplateService()->generateContenu($template, $variables);
$contenu->setCorps($corps);
$this->create($contenu);
return $contenu;
}
} }
...@@ -129,7 +129,7 @@ class TemplateService { ...@@ -129,7 +129,7 @@ class TemplateService {
public function getTemplate(?int $id) : ?Template public function getTemplate(?int $id) : ?Template
{ {
$qb = $this->createQueryBuilder() $qb = $this->createQueryBuilder()
->andWhere('tempalte.id = :id') ->andWhere('template.id = :id')
->setParameter('id', $id) ->setParameter('id', $id)
; ;
...@@ -157,9 +157,6 @@ class TemplateService { ...@@ -157,9 +157,6 @@ class TemplateService {
} catch (NonUniqueResultException $e) { } catch (NonUniqueResultException $e) {
throw new RuntimeException("Plusieurs Template partagent le même code [".$code."]"); throw new RuntimeException("Plusieurs Template partagent le même code [".$code."]");
} }
if ($result === null) {
throw new RuntimeException("Aucun Template pour le code [".$code."]");
}
return $result; return $result;
} }
......
...@@ -2,31 +2,31 @@ ...@@ -2,31 +2,31 @@
/** /**
* @see \UnicaenRenderer\Controller\ContenuController::indexAction() * @see \UnicaenRenderer\Controller\ContenuController::indexAction()
* @var Content[] $contenus * @var Template[] $templates
*/ */
use UnicaenRenderer\Entity\Db\Content; use UnicaenRenderer\Entity\Db\Template;
use UnicaenRenderer\Provider\Privilege\DocumentcontentPrivileges; use UnicaenRenderer\Provider\Privilege\DocumenttemplatePrivileges;
$canAjouter = $this->isAllowed(DocumentcontentPrivileges::getResourceId(DocumentcontentPrivileges::DOCUMENTCONTENU_AJOUTER)); $canAjouter = $this->isAllowed(DocumenttemplatePrivileges::getResourceId(DocumenttemplatePrivileges::DOCUMENTTEMPLATE_AJOUTER));
$canAfficher = $this->isAllowed(DocumentcontentPrivileges::getResourceId(DocumentcontentPrivileges::DOCUMENTCONTENU_INDEX)); $canAfficher = $this->isAllowed(DocumenttemplatePrivileges::getResourceId(DocumenttemplatePrivileges::DOCUMENTTEMPLATE_AFFICHER));
$canModifier = $this->isAllowed(DocumentcontentPrivileges::getResourceId(DocumentcontentPrivileges::DOCUMENTCONTENU_MODIFIER)); $canModifier = $this->isAllowed(DocumenttemplatePrivileges::getResourceId(DocumenttemplatePrivileges::DOCUMENTTEMPLATE_MODIFIER));
$canHistoriser = $this->isAllowed(DocumentcontentPrivileges::getResourceId(DocumentcontentPrivileges::DOCUMENTCONTENU_HISTORISER)); $canHistoriser = $this->isAllowed(DocumenttemplatePrivileges::getResourceId(DocumenttemplatePrivileges::DOCUMENTTEMPLATE_HISTORISER));
$canDetruire = $this->isAllowed(DocumentcontentPrivileges::getResourceId(DocumentcontentPrivileges::DOCUMENTCONTENU_SUPPRIMER)); $canDetruire = $this->isAllowed(DocumenttemplatePrivileges::getResourceId(DocumenttemplatePrivileges::DOCUMENTTEMPLATE_SUPPRIMER));
$this->isAllowed(null, DocumentcontentPrivileges::DOCUMENTCONTENU_AJOUTER);
$this->headTitle("Index des contenus"); $this->headTitle("Index des templates");
?> ?>
<h1 class="page-header"> <h1 class="page-header">
Index des contenus Index des templates
</h1> </h1>
<?php if ($canAjouter) : ?> <?php if ($canAjouter) : ?>
<a href="<?php echo $this->url('contenu/contenu/ajouter', [], [], true); ?>" <?php /** @see \UnicaenRenderer\Controller\TemplateController::ajouterAction() */?>
<a href="<?php echo $this->url('contenu/template/ajouter', [], [], true); ?>"
class="btn btn-primary action ajax-modal" data-event="modification"> class="btn btn-primary action ajax-modal" data-event="modification">
<span class="icon ajouter"></span> <span class="icon ajouter"></span>
Ajouter un contenu Ajouter un template
</a> </a>
<?php endif; ?> <?php endif; ?>
...@@ -39,43 +39,48 @@ $this->headTitle("Index des contenus"); ...@@ -39,43 +39,48 @@ $this->headTitle("Index des contenus");
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach ($contenus as $contenu) : ?> <?php foreach ($templates as $template) : ?>
<tr class="<?php if ($contenu->estHistorise()) echo 'historise '; ?>"> <tr class="<?php if ($template->estHistorise()) echo 'historise '; ?>">
<td> <td>
<?php echo $contenu->getCode(); ?> <?php echo $template->getCode(); ?>
<?php if ($contenu->getDescription() !== null) : ?> <?php if ($template->getDescription() !== null) : ?>
<span class="icon information" title="<?php echo $contenu->getDescription(); ?>" data-toggle="tooltip" data-html="true"></span> <span class="icon information" title="<?php echo $template->getDescription(); ?>" data-toggle="tooltip" data-html="true"></span>
<?php endif; ?> <?php endif; ?>
</td> </td>
<td> <td>
<span class="icon <?php echo $contenu->getType(); ?>"></span> <span class="icon <?php echo $template->getType(); ?>"></span>
</td> </td>
<td> <td>
<?php if ($canAfficher) : ?> <?php if ($canAfficher) : ?>
<a href="<?php echo $this->url('contenu/contenu/afficher', ['contenu' => $contenu->getId()], [], true); ?>" <?php /** @see \UnicaenRenderer\Controller\TemplateController::afficherAction() */?>
<a href="<?php echo $this->url('contenu/template/afficher', ['template' => $template->getId()], [], true); ?>"
class="ajax-modal" class="ajax-modal"
> >
<span class="icon voir"></span></a> <span class="icon voir"></span></a>
<?php endif; ?> <?php endif; ?>
<?php if ($canModifier) : ?> <?php if ($canModifier) : ?>
<a href="<?php echo $this->url('contenu/contenu/modifier', ['contenu' => $contenu->getId()], [], true); ?>" <?php /** @see \UnicaenRenderer\Controller\TemplateController::modifierAction() */?>
<a href="<?php echo $this->url('contenu/template/modifier', ['template' => $template->getId()], [], true); ?>"
class="ajax-modal" data-event="modification" class="ajax-modal" data-event="modification"
> >
<span class="icon editer"></span></a> <span class="icon editer"></span></a>
<?php endif; ?> <?php endif; ?>
<?php if ($canHistoriser) : ?> <?php if ($canHistoriser) : ?>
<?php if ($contenu->estNonHistorise()) : ?> <?php if ($template->estNonHistorise()) : ?>
<a href="<?php echo $this->url('contenu/contenu/historiser', ['contenu' => $contenu->getId()], [], true); ?>" <?php /** @see \UnicaenRenderer\Controller\TemplateController::historiserAction() */?>
<a href="<?php echo $this->url('contenu/template/historiser', ['template' => $template->getId()], [], true); ?>"
> >
<span class="icon historiser"></span></a> <span class="icon historiser"></span></a>
<?php else : ?> <?php else : ?>
<a href="<?php echo $this->url('contenu/contenu/restaurer', ['contenu' => $contenu->getId()], [], true); ?>" <?php /** @see \UnicaenRenderer\Controller\TemplateController::restaurerAction() */?>
<a href="<?php echo $this->url('contenu/template/restaurer', ['template' => $template->getId()], [], true); ?>"
> >
<span class="icon restaurer"></span></a> <span class="icon restaurer"></span></a>
<?php endif; ?> <?php endif; ?>
<?php endif; ?> <?php endif; ?>
<?php if ($canDetruire) : ?> <?php if ($canDetruire) : ?>
<a href="<?php echo $this->url('contenu/contenu/detruire', ['contenu' => $contenu->getId()], [], true); ?>" <?php /** @see \UnicaenRenderer\Controller\TemplateController::detruireAction() */?>
<a href="<?php echo $this->url('contenu/template/detruire', ['template' => $template->getId()], [], true); ?>"
class="ajax-modal" data-event="modification" class="ajax-modal" data-event="modification"
> >
<span class="icon detruire"></span></a> <span class="icon detruire"></span></a>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment