mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
cFGroup selection by Id
This commit is contained in:
parent
1ea54c39b3
commit
c0c36bc1ec
@ -30,8 +30,8 @@ class ReportController extends Controller
|
|||||||
|
|
||||||
$cFGroupsChoice = array();
|
$cFGroupsChoice = array();
|
||||||
|
|
||||||
foreach ($cFGroups as $g) {
|
foreach ($cFGroups as $cFGroup) {
|
||||||
$cFGroupsChoice[$g->getId()] = $g->getName($request->getLocale());
|
$cFGroupsChoice[$cFGroup->getId()] = $cFGroup->getName($request->getLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = $this->get('form.factory')
|
$form = $this->get('form.factory')
|
||||||
@ -40,7 +40,7 @@ class ReportController extends Controller
|
|||||||
'action' => $this->generateUrl('report_new'),
|
'action' => $this->generateUrl('report_new'),
|
||||||
'csrf_protection' => false
|
'csrf_protection' => false
|
||||||
))
|
))
|
||||||
->add('type', 'choice', array(
|
->add('cFGroup', 'choice', array(
|
||||||
'choices' => $cFGroupsChoice
|
'choices' => $cFGroupsChoice
|
||||||
))
|
))
|
||||||
->getForm();
|
->getForm();
|
||||||
@ -57,7 +57,20 @@ class ReportController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function createAction(Request $request)
|
public function createAction(Request $request)
|
||||||
{
|
{
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
$entity = new Report();
|
$entity = new Report();
|
||||||
|
|
||||||
|
$cFGroupId = $request->query->get('cFGroup',null);
|
||||||
|
echo $cFGroupId;
|
||||||
|
die();
|
||||||
|
|
||||||
|
if($cFGroupId) {
|
||||||
|
$entity.setCFGroup(
|
||||||
|
$em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->find($cFGroupID)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$form = $this->createCreateForm($entity);
|
$form = $this->createCreateForm($entity);
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
@ -87,6 +100,7 @@ class ReportController extends Controller
|
|||||||
$form = $this->createForm(new ReportType(), $entity, array(
|
$form = $this->createForm(new ReportType(), $entity, array(
|
||||||
'action' => $this->generateUrl('report_create'),
|
'action' => $this->generateUrl('report_create'),
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
|
'em' => $this->getDoctrine()->getManager(),
|
||||||
));
|
));
|
||||||
|
|
||||||
$form->add('submit', 'submit', array('label' => 'Create'));
|
$form->add('submit', 'submit', array('label' => 'Create'));
|
||||||
@ -98,10 +112,21 @@ class ReportController extends Controller
|
|||||||
* Displays a form to create a new Report entity.
|
* Displays a form to create a new Report entity.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function newAction()
|
public function newAction(Request $request)
|
||||||
{
|
{
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
$entity = new Report();
|
$entity = new Report();
|
||||||
$form = $this->createCreateForm($entity);
|
|
||||||
|
$cFGroupId = $request->query->get('cFGroup');
|
||||||
|
|
||||||
|
if($cFGroupId) {
|
||||||
|
$entity->setCFGroup(
|
||||||
|
$em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->find($cFGroupId)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$form = $this->createCreateForm($entity);
|
||||||
|
|
||||||
return $this->render('ChillReportBundle:Report:new.html.twig', array(
|
return $this->render('ChillReportBundle:Report:new.html.twig', array(
|
||||||
'entity' => $entity,
|
'entity' => $entity,
|
||||||
@ -167,6 +192,7 @@ class ReportController extends Controller
|
|||||||
$form = $this->createForm(new ReportType(), $entity, array(
|
$form = $this->createForm(new ReportType(), $entity, array(
|
||||||
'action' => $this->generateUrl('report_update', array('id' => $entity->getId())),
|
'action' => $this->generateUrl('report_update', array('id' => $entity->getId())),
|
||||||
'method' => 'PUT',
|
'method' => 'PUT',
|
||||||
|
'em' => $this->getDoctrine()->getManager(),
|
||||||
));
|
));
|
||||||
|
|
||||||
$form->add('submit', 'submit', array('label' => 'Update'));
|
$form->add('submit', 'submit', array('label' => 'Update'));
|
||||||
|
@ -6,6 +6,8 @@ use Symfony\Component\Form\AbstractType;
|
|||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||||
|
|
||||||
|
use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldsGroupToIdTransformer;
|
||||||
|
|
||||||
class ReportType extends AbstractType
|
class ReportType extends AbstractType
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -14,13 +16,19 @@ class ReportType extends AbstractType
|
|||||||
*/
|
*/
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
|
$entityManager = $options['em'];
|
||||||
|
$transformer = new CustomFieldsGroupToIdTransformer($entityManager);
|
||||||
|
|
||||||
$builder
|
$builder
|
||||||
->add('user')
|
->add('user')
|
||||||
->add('person')
|
->add('person')
|
||||||
->add('date')
|
->add('date')
|
||||||
->add('scope')
|
->add('scope')
|
||||||
->add('cFData')
|
->add('cFData')
|
||||||
->add('cFGroup')
|
->add(
|
||||||
|
$builder->create('cFGroup', 'text')
|
||||||
|
->addModelTransformer($transformer)
|
||||||
|
)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,6 +40,14 @@ class ReportType extends AbstractType
|
|||||||
$resolver->setDefaults(array(
|
$resolver->setDefaults(array(
|
||||||
'data_class' => 'Chill\ReportBundle\Entity\Report'
|
'data_class' => 'Chill\ReportBundle\Entity\Report'
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$resolver->setRequired(array(
|
||||||
|
'em',
|
||||||
|
));
|
||||||
|
|
||||||
|
$resolver->setAllowedTypes(array(
|
||||||
|
'em' => 'Doctrine\Common\Persistence\ObjectManager',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user