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 {
'name' => 'complement',
'type' => 'textarea',
'options' => [
'label' => 'Complément (nom du fichier, étiquette, ... ) * : ',
'label' => 'Sujet (sujet du courrier électronique, nom du fichier, étiquette, ... ) * : ',
'label_attributes' => [
'class' => 'control-label',
],
......@@ -92,7 +92,7 @@ class TemplateForm extends Form {
'name' => 'template',
'type' => 'textarea',
'options' => [
'label' => 'Template * : ',
'label' => 'Corps * : ',
'label_attributes' => [
'class' => 'control-label',
],
......
......@@ -2,15 +2,14 @@
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';
const DOCUMENTTEMPLATE_INDEX = 'documenttemplate-documenttemplate_index';
const DOCUMENTTEMPLATE_AJOUTER = 'documenttemplate-documenttemplate_ajouter';
const DOCUMENTTEMPLATE_AFFICHER = 'documenttemplate-documenttemplate_afficher';
const DOCUMENTTEMPLATE_MODIFIER = 'documenttemplate-documenttemplate_modifier';
const DOCUMENTTEMPLATE_HISTORISER = 'documenttemplate-documenttemplate_historiser';
const DOCUMENTTEMPLATE_SUPPRIMER = 'documenttemplate-documenttemplate_supprimer';
}
\ No newline at end of file
......@@ -2,15 +2,20 @@
namespace UnicaenRenderer\Service\Contenu;
use DateTime;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\QueryBuilder;
use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenRenderer\Entity\Db\Contenu;
use UnicaenRenderer\Entity\Db\Template;
use UnicaenRenderer\Service\Template\TemplateServiceAwareTrait;
use Zend\Mvc\Controller\AbstractActionController;
class ContenuService {
use EntityManagerAwareTrait;
use TemplateServiceAwareTrait;
/** Gestion des entités *******************************************************************************************/
......@@ -112,4 +117,31 @@ class ContenuService {
$result = $this->getContenu($id);
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 {
public function getTemplate(?int $id) : ?Template
{
$qb = $this->createQueryBuilder()
->andWhere('tempalte.id = :id')
->andWhere('template.id = :id')
->setParameter('id', $id)
;
......@@ -157,9 +157,6 @@ class TemplateService {
} catch (NonUniqueResultException $e) {
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;
}
......
......@@ -2,31 +2,31 @@
/**
* @see \UnicaenRenderer\Controller\ContenuController::indexAction()
* @var Content[] $contenus
* @var Template[] $templates
*/
use UnicaenRenderer\Entity\Db\Content;
use UnicaenRenderer\Provider\Privilege\DocumentcontentPrivileges;
use UnicaenRenderer\Entity\Db\Template;
use UnicaenRenderer\Provider\Privilege\DocumenttemplatePrivileges;
$canAjouter = $this->isAllowed(DocumentcontentPrivileges::getResourceId(DocumentcontentPrivileges::DOCUMENTCONTENU_AJOUTER));
$canAfficher = $this->isAllowed(DocumentcontentPrivileges::getResourceId(DocumentcontentPrivileges::DOCUMENTCONTENU_INDEX));
$canModifier = $this->isAllowed(DocumentcontentPrivileges::getResourceId(DocumentcontentPrivileges::DOCUMENTCONTENU_MODIFIER));
$canHistoriser = $this->isAllowed(DocumentcontentPrivileges::getResourceId(DocumentcontentPrivileges::DOCUMENTCONTENU_HISTORISER));
$canDetruire = $this->isAllowed(DocumentcontentPrivileges::getResourceId(DocumentcontentPrivileges::DOCUMENTCONTENU_SUPPRIMER));
$this->isAllowed(null, DocumentcontentPrivileges::DOCUMENTCONTENU_AJOUTER);
$canAjouter = $this->isAllowed(DocumenttemplatePrivileges::getResourceId(DocumenttemplatePrivileges::DOCUMENTTEMPLATE_AJOUTER));
$canAfficher = $this->isAllowed(DocumenttemplatePrivileges::getResourceId(DocumenttemplatePrivileges::DOCUMENTTEMPLATE_AFFICHER));
$canModifier = $this->isAllowed(DocumenttemplatePrivileges::getResourceId(DocumenttemplatePrivileges::DOCUMENTTEMPLATE_MODIFIER));
$canHistoriser = $this->isAllowed(DocumenttemplatePrivileges::getResourceId(DocumenttemplatePrivileges::DOCUMENTTEMPLATE_HISTORISER));
$canDetruire = $this->isAllowed(DocumenttemplatePrivileges::getResourceId(DocumenttemplatePrivileges::DOCUMENTTEMPLATE_SUPPRIMER));
$this->headTitle("Index des contenus");
$this->headTitle("Index des templates");
?>
<h1 class="page-header">
Index des contenus
Index des templates
</h1>
<?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">
<span class="icon ajouter"></span>
Ajouter un contenu
Ajouter un template
</a>
<?php endif; ?>
......@@ -39,43 +39,48 @@ $this->headTitle("Index des contenus");
</tr>
</thead>
<tbody>
<?php foreach ($contenus as $contenu) : ?>
<tr class="<?php if ($contenu->estHistorise()) echo 'historise '; ?>">
<?php foreach ($templates as $template) : ?>
<tr class="<?php if ($template->estHistorise()) echo 'historise '; ?>">
<td>
<?php echo $contenu->getCode(); ?>
<?php if ($contenu->getDescription() !== null) : ?>
<span class="icon information" title="<?php echo $contenu->getDescription(); ?>" data-toggle="tooltip" data-html="true"></span>
<?php echo $template->getCode(); ?>
<?php if ($template->getDescription() !== null) : ?>
<span class="icon information" title="<?php echo $template->getDescription(); ?>" data-toggle="tooltip" data-html="true"></span>
<?php endif; ?>
</td>
<td>
<span class="icon <?php echo $contenu->getType(); ?>"></span>
<span class="icon <?php echo $template->getType(); ?>"></span>
</td>
<td>
<?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"
>
<span class="icon voir"></span></a>
<?php endif; ?>
<?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"
>
<span class="icon editer"></span></a>
<?php endif; ?>
<?php if ($canHistoriser) : ?>
<?php if ($contenu->estNonHistorise()) : ?>
<a href="<?php echo $this->url('contenu/contenu/historiser', ['contenu' => $contenu->getId()], [], true); ?>"
<?php if ($template->estNonHistorise()) : ?>
<?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>
<?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>
<?php endif; ?>
<?php endif; ?>
<?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"
>
<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