mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-14 14:24:24 +00:00
105 lines
3.1 KiB
PHP
105 lines
3.1 KiB
PHP
<?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\Common\Persistence\ObjectManager;
|
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
|
|
|
|
|
class PersonDocumentType extends AbstractType
|
|
{
|
|
use AppendScopeChoiceTypeTrait;
|
|
|
|
/**
|
|
* the user running this form
|
|
*
|
|
* @var User
|
|
*/
|
|
protected $user;
|
|
|
|
/**
|
|
*
|
|
* @var AuthorizationHelper
|
|
*/
|
|
protected $authorizationHelper;
|
|
|
|
/**
|
|
*
|
|
* @var ObjectManager
|
|
*/
|
|
protected $om;
|
|
|
|
/**
|
|
*
|
|
* @var TranslatableStringHelper
|
|
*/
|
|
protected $translatableStringHelper;
|
|
|
|
public function __construct(
|
|
TokenStorageInterface $tokenStorage,
|
|
AuthorizationHelper $authorizationHelper,
|
|
ObjectManager $om,
|
|
TranslatableStringHelper $translatableStringHelper
|
|
)
|
|
{
|
|
if (!$tokenStorage->getToken()->getUser() instanceof User) {
|
|
throw new \RuntimeException("you should have a valid user");
|
|
}
|
|
$this->user = $tokenStorage->getToken()->getUser();
|
|
$this->authorizationHelper = $authorizationHelper;
|
|
$this->om = $om;
|
|
$this->translatableStringHelper = $translatableStringHelper;
|
|
}
|
|
|
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
{
|
|
$builder
|
|
->add('title')
|
|
->add('description')
|
|
->add('content')
|
|
//->add('center')
|
|
->add('scope')
|
|
->add('date', 'date', array('required' => false, 'widget' => 'single_text', 'format' => 'dd-MM-yyyy'))
|
|
->add('category', EntityType::class, array(
|
|
'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()) : '';
|
|
},
|
|
))
|
|
;
|
|
|
|
$this->appendScopeChoices($builder, $options['role'],
|
|
$options['center'], $this->user, $this->authorizationHelper,
|
|
$this->translatableStringHelper, $this->om);
|
|
|
|
}
|
|
|
|
public function configureOptions(OptionsResolver $resolver)
|
|
{
|
|
$resolver->setDefaults([
|
|
'data_class' => Document::class,
|
|
]);
|
|
|
|
$this->appendScopeChoicesOptions($resolver);
|
|
}
|
|
}
|