mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 22:04:23 +00:00
add scope to form "new" report
[ci skip]
This commit is contained in:
parent
a938ce5090
commit
ec70067429
@ -26,6 +26,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\ReportBundle\Entity\Report;
|
||||
use Chill\ReportBundle\Form\ReportType;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
|
||||
/**
|
||||
* Report controller.
|
||||
@ -194,15 +195,25 @@ class ReportController extends Controller
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
|
||||
$cFGroup = $em
|
||||
->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')
|
||||
->find($cf_group_id);
|
||||
|
||||
if ($person === NULL) {
|
||||
throw $this->createNotFoundException("Person not found");
|
||||
}
|
||||
|
||||
if ($cFGroup === NULL){
|
||||
throw $this->createNotFoundException("custom fields group not found");
|
||||
}
|
||||
|
||||
$entity = new Report();
|
||||
$entity->setUser($this->get('security.context')->getToken()->getUser());
|
||||
$entity->setDate(new \DateTime('now'));
|
||||
|
||||
$cFGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->find($cf_group_id);
|
||||
$entity->setCFGroup($cFGroup);
|
||||
|
||||
$form = $this->createCreateForm($entity, $person_id, $cFGroup);
|
||||
$form = $this->createCreateForm($entity, $person, $cFGroup);
|
||||
|
||||
return $this->render('ChillReportBundle:Report:new.html.twig', array(
|
||||
'entity' => $entity,
|
||||
@ -280,13 +291,14 @@ class ReportController extends Controller
|
||||
*/
|
||||
private function createCreateForm(Report $entity, Person $person, $cFGroup)
|
||||
{
|
||||
$form = $this->createForm(new ReportType(), $entity, array(
|
||||
$form = $this->createForm('chill_reportbundle_report', $entity, array(
|
||||
'action' => $this->generateUrl('report_create',
|
||||
array('person_id' => $person->getId(),
|
||||
'cf_group_id' => $cFGroup->getId())),
|
||||
'method' => 'POST',
|
||||
'em' => $this->getDoctrine()->getManager(),
|
||||
'cFGroup' => $cFGroup,
|
||||
'role' => new Role('CHILL_REPORT_CREATE'),
|
||||
'center' => $person->getCenter()
|
||||
));
|
||||
|
||||
return $form;
|
||||
|
@ -21,52 +21,49 @@
|
||||
|
||||
namespace Chill\ReportBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Chill\MainBundle\Form\Type\AbstractHasScopeType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
|
||||
class ReportType extends AbstractType
|
||||
{
|
||||
class ReportType extends AbstractHasScopeType
|
||||
{
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$entityManager = $options['em'];
|
||||
|
||||
$builder
|
||||
->add('user')
|
||||
->add('date', 'date',
|
||||
array('required' => true, 'widget' => 'single_text', 'format' => 'dd-MM-yyyy'))
|
||||
->add('scope', 'scope')
|
||||
->add('cFData', 'custom_field',
|
||||
array('attr' => array('class' => 'cf-fields'),
|
||||
'group' => $options['cFGroup']))
|
||||
;
|
||||
|
||||
$this->appendScopeChoices($builder, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsResolverInterface $resolver
|
||||
*/
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'Chill\ReportBundle\Entity\Report'
|
||||
));
|
||||
|
||||
$resolver->setRequired(array(
|
||||
'em',
|
||||
'cFGroup',
|
||||
'role',
|
||||
'center'
|
||||
));
|
||||
|
||||
$resolver->setAllowedTypes(array(
|
||||
'em' => 'Doctrine\Common\Persistence\ObjectManager',
|
||||
'cFGroup' => 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup',
|
||||
'role' => 'Symfony\Component\Security\Core\Role\Role',
|
||||
'center' => 'Chill\MainBundle\Entity\Center'
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -25,4 +25,13 @@ services:
|
||||
arguments:
|
||||
- "@chill.main.security.authorization.helper"
|
||||
tags:
|
||||
- { name: security.voter }
|
||||
- { name: security.voter }
|
||||
|
||||
chill.report.form.report_type:
|
||||
class: Chill\ReportBundle\Form\ReportType
|
||||
arguments:
|
||||
- "@chill.main.security.authorization.helper"
|
||||
- "@security.token_storage"
|
||||
- "@chill.main.helper.translatable_string"
|
||||
tags:
|
||||
- { name: form.type, alias: chill_reportbundle_report }
|
Loading…
x
Reference in New Issue
Block a user