improve doc storing

This commit is contained in:
Julien Fastré 2018-09-10 10:49:37 +02:00
parent 32402d8c7a
commit 0eccda06d6
7 changed files with 45 additions and 33 deletions

View File

@ -49,6 +49,9 @@ class Document implements HasScopeInterface
* cascade={"persist"} * cascade={"persist"}
* ) * )
* @Assert\Valid() * @Assert\Valid()
* @Assert\NotNull(
* message="Upload a document"
* )
*/ */
private $object; private $object;
@ -113,18 +116,6 @@ class Document implements HasScopeInterface
return $this; return $this;
} }
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
/** /**
* Get scope * Get scope
* *

View File

@ -37,15 +37,16 @@ class DocumentCategory
* @ORM\Column(type="json_array") * @ORM\Column(type="json_array")
*/ */
private $name; private $name;
public function getBundleId() // ::class BundleClass (FQDN) public function __construct($bundleId, $idInsideBundle)
{
return $this->bundleId;
}
public function setBundleId($bundleId)
{ {
$this->bundleId = $bundleId; $this->bundleId = $bundleId;
$this->idInsideBundle = $idInsideBundle;
}
public function getBundleId() // ::class BundleClass (FQDN)
{
return $this->bundleId;
} }
public function getIdInsideBundle() public function getIdInsideBundle()
@ -53,13 +54,6 @@ class DocumentCategory
return $this->idInsideBundle; return $this->idInsideBundle;
} }
public function setIdInsideBundle($idInsideBundle): self
{
$this->idInsideBundle = $idInsideBundle;
return $this;
}
public function getDocumentClass() public function getDocumentClass()
{ {
return $this->documentClass; return $this->documentClass;

View File

@ -74,6 +74,7 @@ class PersonDocumentType extends AbstractType
]) ])
->add('date', ChillDateType::class) ->add('date', ChillDateType::class)
->add('category', EntityType::class, array( ->add('category', EntityType::class, array(
'placeholder' => 'Choose a document category',
'class' => 'ChillDocStoreBundle:DocumentCategory', 'class' => 'ChillDocStoreBundle:DocumentCategory',
'query_builder' => function (EntityRepository $er) { 'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('c') return $er->createQueryBuilder('c')

View File

@ -31,14 +31,17 @@ class StoredObjectType extends AbstractType
->get('keyInfos') ->get('keyInfos')
->addModelTransformer(new CallbackTransformer( ->addModelTransformer(new CallbackTransformer(
[$this, 'transform'], [$this, 'reverseTransform'] [$this, 'transform'], [$this, 'reverseTransform']
)) ));
;
$builder $builder
->get('iv') ->get('iv')
->addModelTransformer(new CallbackTransformer( ->addModelTransformer(new CallbackTransformer(
[$this, 'transform'], [$this, 'reverseTransform'] [$this, 'transform'], [$this, 'reverseTransform']
)) ));
;
$builder
->addModelTransformer(new CallbackTransformer(
[ $this, 'transformObject'], [$this, 'reverseTransformObject']
));
} }
public function getBlockPrefix() public function getBlockPrefix()
@ -70,4 +73,22 @@ class StoredObjectType extends AbstractType
return \json_encode($object); 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;
}
} }

View File

@ -9,5 +9,5 @@ Editing document for %name%: Modification d'un document pour %name%
Edit Document: Modification d'un document Edit Document: Modification d'un document
Existing document: Document existant Existing document: Document existant
The document is successfully updated: Le document est mis à jour 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

View File

@ -1 +1,2 @@
The file is not stored properly: Le fichier n'est pas téléchargé correctement The file is not stored properly: Le fichier n'est pas téléchargé correctement
Upload a document: Téléversez un document

View File

@ -1,3 +1,7 @@
{% macro download_button(storedObject, filename = null) %} {% macro download_button(storedObject, filename = null) %}
<a class="sc-button bt-download" data-label-preparing="{{ ('Preparing'|trans ~ '...')|escape('html_attr') }}" data-label-ready="{{ 'Ready to show'|trans|escape('html_attr') }}" data-download-button data-key="{{ storedObject.keyInfos|json_encode|escape('html_attr') }}" data-iv="{{ storedObject.iv|json_encode|escape('html_attr') }}" data-temp-url-get-generator="{{ storedObject|generate_url|escape('html_attr') }}" data-mime-type="{{ storedObject.type|escape('html_attr') }}" {% if filename is not null %}data-filename="{{ filename|escape('html_attr') }}"{% endif %}>{{ 'Download'|trans }}</a> {% if storedObject is null %}
<!-- No document to download -->
{% else %}
<a class="sc-button bt-download" data-label-preparing="{{ ('Preparing'|trans ~ '...')|escape('html_attr') }}" data-label-ready="{{ 'Ready to show'|trans|escape('html_attr') }}" data-download-button data-key="{{ storedObject.keyInfos|json_encode|escape('html_attr') }}" data-iv="{{ storedObject.iv|json_encode|escape('html_attr') }}" data-temp-url-get-generator="{{ storedObject|generate_url|escape('html_attr') }}" data-mime-type="{{ storedObject.type|escape('html_attr') }}" {% if filename is not null %}data-filename="{{ filename|escape('html_attr') }}"{% endif %}>{{ 'Download'|trans }}</a>
{% endif %}
{% endmacro %} {% endmacro %}