mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +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();
|
||||
|
||||
foreach ($cFGroups as $g) {
|
||||
$cFGroupsChoice[$g->getId()] = $g->getName($request->getLocale());
|
||||
foreach ($cFGroups as $cFGroup) {
|
||||
$cFGroupsChoice[$cFGroup->getId()] = $cFGroup->getName($request->getLocale());
|
||||
}
|
||||
|
||||
$form = $this->get('form.factory')
|
||||
@ -40,7 +40,7 @@ class ReportController extends Controller
|
||||
'action' => $this->generateUrl('report_new'),
|
||||
'csrf_protection' => false
|
||||
))
|
||||
->add('type', 'choice', array(
|
||||
->add('cFGroup', 'choice', array(
|
||||
'choices' => $cFGroupsChoice
|
||||
))
|
||||
->getForm();
|
||||
@ -57,7 +57,20 @@ class ReportController extends Controller
|
||||
*/
|
||||
public function createAction(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$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->handleRequest($request);
|
||||
|
||||
@ -87,6 +100,7 @@ class ReportController extends Controller
|
||||
$form = $this->createForm(new ReportType(), $entity, array(
|
||||
'action' => $this->generateUrl('report_create'),
|
||||
'method' => 'POST',
|
||||
'em' => $this->getDoctrine()->getManager(),
|
||||
));
|
||||
|
||||
$form->add('submit', 'submit', array('label' => 'Create'));
|
||||
@ -98,10 +112,21 @@ class ReportController extends Controller
|
||||
* Displays a form to create a new Report entity.
|
||||
*
|
||||
*/
|
||||
public function newAction()
|
||||
public function newAction(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$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(
|
||||
'entity' => $entity,
|
||||
@ -167,6 +192,7 @@ class ReportController extends Controller
|
||||
$form = $this->createForm(new ReportType(), $entity, array(
|
||||
'action' => $this->generateUrl('report_update', array('id' => $entity->getId())),
|
||||
'method' => 'PUT',
|
||||
'em' => $this->getDoctrine()->getManager(),
|
||||
));
|
||||
|
||||
$form->add('submit', 'submit', array('label' => 'Update'));
|
||||
|
@ -6,6 +6,8 @@ use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||
|
||||
use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldsGroupToIdTransformer;
|
||||
|
||||
class ReportType extends AbstractType
|
||||
{
|
||||
/**
|
||||
@ -14,13 +16,19 @@ class ReportType extends AbstractType
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$entityManager = $options['em'];
|
||||
$transformer = new CustomFieldsGroupToIdTransformer($entityManager);
|
||||
|
||||
$builder
|
||||
->add('user')
|
||||
->add('person')
|
||||
->add('date')
|
||||
->add('scope')
|
||||
->add('cFData')
|
||||
->add('cFGroup')
|
||||
->add(
|
||||
$builder->create('cFGroup', 'text')
|
||||
->addModelTransformer($transformer)
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
@ -32,6 +40,14 @@ class ReportType extends AbstractType
|
||||
$resolver->setDefaults(array(
|
||||
'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