mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-17 18:52:49 +00:00
fix folder name
This commit is contained in:
50
src/Bundle/ChillDocStoreBundle/Form/DocumentCategoryType.php
Normal file
50
src/Bundle/ChillDocStoreBundle/Form/DocumentCategoryType.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\DocStoreBundle\Form;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\DocumentCategory;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
|
||||
class DocumentCategoryType extends AbstractType
|
||||
{
|
||||
private $chillBundlesFlipped;
|
||||
|
||||
public function __construct($kernelBundles)
|
||||
{
|
||||
// TODO faire un service dans CHillMain
|
||||
foreach ($kernelBundles as $key => $value) {
|
||||
if(substr($key, 0, 5) === 'Chill') {
|
||||
$this->chillBundlesFlipped[$value] = $key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('bundleId', ChoiceType::class, array(
|
||||
'choices' => $this->chillBundlesFlipped,
|
||||
'disabled' => true,
|
||||
))
|
||||
->add('idInsideBundle', null, array(
|
||||
'disabled' => true,
|
||||
))
|
||||
->add('documentClass', null, array(
|
||||
'disabled' => true,
|
||||
)) // cahcerh par default PersonDocument
|
||||
->add('name', TranslatableStringFormType::class)
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => DocumentCategory::class,
|
||||
]);
|
||||
}
|
||||
}
|
103
src/Bundle/ChillDocStoreBundle/Form/PersonDocumentType.php
Normal file
103
src/Bundle/ChillDocStoreBundle/Form/PersonDocumentType.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\DocStoreBundle\Form;
|
||||
|
||||
|
||||
use Chill\DocStoreBundle\Entity\Document;
|
||||
use Chill\DocStoreBundle\Entity\DocumentCategory;
|
||||
use Chill\DocStoreBundle\Entity\PersonDocument;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Chill\MainBundle\Form\Type\AppendScopeChoiceTypeTrait;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Form\Type\ScopePickerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
|
||||
|
||||
class PersonDocumentType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* the user running this form
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $authorizationHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var ObjectManager
|
||||
*/
|
||||
protected $om;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
public function __construct(
|
||||
TranslatableStringHelper $translatableStringHelper
|
||||
)
|
||||
{
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('title', TextType::class)
|
||||
->add('description', TextareaType::class, [
|
||||
'required' => false
|
||||
])
|
||||
->add('object', StoredObjectType::class, [
|
||||
'error_bubbling' => true
|
||||
])
|
||||
->add('scope', ScopePickerType::class, [
|
||||
'center' => $options['center'],
|
||||
'role' => $options['role']
|
||||
])
|
||||
->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')
|
||||
->where('c.documentClass = :docClass')
|
||||
->setParameter('docClass', PersonDocument::class);
|
||||
},
|
||||
'choice_label' => function ($entity = null) {
|
||||
return $entity ? $this->translatableStringHelper->localize($entity->getName()) : '';
|
||||
},
|
||||
))
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Document::class,
|
||||
]);
|
||||
|
||||
$resolver->setRequired(['role', 'center'])
|
||||
->setAllowedTypes('role', [ \Symfony\Component\Security\Core\Role\Role::class ])
|
||||
->setAllowedTypes('center', [ \Chill\MainBundle\Entity\Center::class ])
|
||||
;
|
||||
}
|
||||
}
|
108
src/Bundle/ChillDocStoreBundle/Form/StoredObjectType.php
Normal file
108
src/Bundle/ChillDocStoreBundle/Form/StoredObjectType.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/*
|
||||
*/
|
||||
namespace Chill\DocStoreBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use ChampsLibres\AsyncUploaderBundle\Form\Type\AsyncUploaderType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* Form type which allow to join a document
|
||||
*
|
||||
*/
|
||||
class StoredObjectType extends AbstractType
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
protected $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('filename', AsyncUploaderType::class)
|
||||
->add('type', HiddenType::class)
|
||||
->add('keyInfos', HiddenType::class)
|
||||
->add('iv', HiddenType::class)
|
||||
;
|
||||
|
||||
$builder
|
||||
->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()
|
||||
{
|
||||
return 'stored_object';
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setDefault('data_class', StoredObject::class)
|
||||
;
|
||||
}
|
||||
|
||||
public function reverseTransform($value)
|
||||
{
|
||||
if ($value === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return \json_decode($value, true);
|
||||
}
|
||||
|
||||
public function transform($object)
|
||||
{
|
||||
if ($object === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return \json_encode($object);
|
||||
}
|
||||
|
||||
public function transformObject($object = null)
|
||||
{
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function reverseTransformObject($object)
|
||||
{
|
||||
if (NULL === $object) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (NULL === $object->getFilename()) {
|
||||
// remove the original object
|
||||
$this->em->remove($object);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user