diff --git a/Entity/Document.php b/Entity/Document.php index ee744fbfa..67159ad7d 100644 --- a/Entity/Document.php +++ b/Entity/Document.php @@ -49,6 +49,9 @@ class Document implements HasScopeInterface * cascade={"persist"} * ) * @Assert\Valid() + * @Assert\NotNull( + * message="Upload a document" + * ) */ private $object; @@ -113,18 +116,6 @@ class Document implements HasScopeInterface return $this; } - public function getContent(): ?string - { - return $this->content; - } - - public function setContent(string $content): self - { - $this->content = $content; - - return $this; - } - /** * Get scope * diff --git a/Entity/DocumentCategory.php b/Entity/DocumentCategory.php index 29d02efb4..a2a8167cc 100644 --- a/Entity/DocumentCategory.php +++ b/Entity/DocumentCategory.php @@ -37,15 +37,16 @@ class DocumentCategory * @ORM\Column(type="json_array") */ private $name; - - public function getBundleId() // ::class BundleClass (FQDN) - { - return $this->bundleId; - } - - public function setBundleId($bundleId) + + public function __construct($bundleId, $idInsideBundle) { $this->bundleId = $bundleId; + $this->idInsideBundle = $idInsideBundle; + } + + public function getBundleId() // ::class BundleClass (FQDN) + { + return $this->bundleId; } public function getIdInsideBundle() @@ -53,13 +54,6 @@ class DocumentCategory return $this->idInsideBundle; } - public function setIdInsideBundle($idInsideBundle): self - { - $this->idInsideBundle = $idInsideBundle; - - return $this; - } - public function getDocumentClass() { return $this->documentClass; diff --git a/Form/PersonDocumentType.php b/Form/PersonDocumentType.php index d99c7b2b8..ffb494ec8 100644 --- a/Form/PersonDocumentType.php +++ b/Form/PersonDocumentType.php @@ -74,6 +74,7 @@ class PersonDocumentType extends AbstractType ]) ->add('date', ChillDateType::class) ->add('category', EntityType::class, array( + 'placeholder' => 'Choose a document category', 'class' => 'ChillDocStoreBundle:DocumentCategory', 'query_builder' => function (EntityRepository $er) { return $er->createQueryBuilder('c') diff --git a/Form/StoredObjectType.php b/Form/StoredObjectType.php index 31dc25528..824bd62ad 100644 --- a/Form/StoredObjectType.php +++ b/Form/StoredObjectType.php @@ -31,14 +31,17 @@ class StoredObjectType extends AbstractType ->get('keyInfos') ->addModelTransformer(new CallbackTransformer( [$this, 'transform'], [$this, 'reverseTransform'] - )) - ; + )); $builder ->get('iv') ->addModelTransformer(new CallbackTransformer( [$this, 'transform'], [$this, 'reverseTransform'] - )) - ; + )); + + $builder + ->addModelTransformer(new CallbackTransformer( + [ $this, 'transformObject'], [$this, 'reverseTransformObject'] + )); } public function getBlockPrefix() @@ -70,4 +73,22 @@ class StoredObjectType extends AbstractType return \json_encode($object); } + + public function transformObject($object = null) + { + return $object; + } + + public function reverseTransformObject($object) + { + if (NULL === $object) { + return null; + } + + if (NULL === $object->getFilename()) { + return null; + } + + return $object; + } } diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index b73cef05f..5bc81ad59 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -9,5 +9,5 @@ Editing document for %name%: Modification d'un document pour %name% Edit Document: Modification d'un document Existing document: Document existant The document is successfully updated: Le document est mis à jour - - +No document to download: Aucun document à télécharger +'Choose a document category': Choisissez une catégorie de document diff --git a/Resources/translations/validators.fr.yml b/Resources/translations/validators.fr.yml index cf2283889..38f21d4ab 100644 --- a/Resources/translations/validators.fr.yml +++ b/Resources/translations/validators.fr.yml @@ -1 +1,2 @@ The file is not stored properly: Le fichier n'est pas téléchargé correctement +Upload a document: Téléversez un document \ No newline at end of file diff --git a/Resources/views/Macro/macro.html.twig b/Resources/views/Macro/macro.html.twig index a9f990dca..4579d4c1e 100644 --- a/Resources/views/Macro/macro.html.twig +++ b/Resources/views/Macro/macro.html.twig @@ -1,3 +1,7 @@ {% macro download_button(storedObject, filename = null) %} - {{ 'Download'|trans }} + {% if storedObject is null %} + + {% else %} + {{ 'Download'|trans }} + {% endif %} {% endmacro %}