add scope type to report [transfer]

[ci skip]
This commit is contained in:
Julien Fastré 2015-06-23 21:36:02 +02:00
parent 4d2b3f2a61
commit c75ba202b4
2 changed files with 23 additions and 13 deletions

View File

@ -23,7 +23,7 @@ namespace Chill\ReportBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Chill\PersonBundle\Entity\Person;
use Chill\ReportBundle\Entity\Report;
use Chill\ReportBundle\Form\ReportType;
@ -224,16 +224,21 @@ class ReportController extends Controller
$em = $this->getDoctrine()->getManager();
$entity = new Report();
$cFGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->find($cf_group_id);
$cFGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')
->find($cf_group_id);
$form = $this->createCreateForm($entity, $person_id, $cFGroup);
$person = $em->getRepository('ChillPersonBundle:Person')
->find($person_id);
if($person === NULL OR $cFGroup === NULL) {
throw $this->createNotFoundException();
}
$form = $this->createCreateForm($entity, $person, $cFGroup);
$form->handleRequest($request);
if ($form->isValid()) {
$cFGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->find($cf_group_id);
$entity->setCFGroup($cFGroup);
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
$entity->setPerson($person);
$em->persist($entity);
@ -250,7 +255,6 @@ class ReportController extends Controller
array('person_id' => $person_id,'report_id' => $entity->getId())));
}
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
$this->get('session')
->getFlashBag()->add('danger',
@ -274,11 +278,12 @@ class ReportController extends Controller
*
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateForm(Report $entity, $person_id, $cFGroup)
private function createCreateForm(Report $entity, Person $person, $cFGroup)
{
$form = $this->createForm(new ReportType(), $entity, array(
'action' => $this->generateUrl('report_create',
array('person_id' => $person_id, 'cf_group_id' => $cFGroup->getId())),
array('person_id' => $person->getId(),
'cf_group_id' => $cFGroup->getId())),
'method' => 'POST',
'em' => $this->getDoctrine()->getManager(),
'cFGroup' => $cFGroup,
@ -302,7 +307,7 @@ class ReportController extends Controller
$entity = $em->getRepository('ChillReportBundle:Report')->find($report_id);
if (!$entity) {
if (!$entity OR !$person) {
throw $this->createNotFoundException(
$this->get('translator')->trans('Unable to find this report.'));
}

View File

@ -39,9 +39,10 @@ class ReportType extends AbstractType
->add('user')
->add('date', 'date',
array('required' => true, 'widget' => 'single_text', 'format' => 'dd-MM-yyyy'))
//->add('scope')
->add('scope', 'scope')
->add('cFData', 'custom_field',
array('attr' => array('class' => 'cf-fields'), 'group' => $options['cFGroup']))
array('attr' => array('class' => 'cf-fields'),
'group' => $options['cFGroup']))
;
}
@ -57,11 +58,15 @@ class ReportType extends AbstractType
$resolver->setRequired(array(
'em',
'cFGroup',
'role',
'center'
));
$resolver->setAllowedTypes(array(
'em' => 'Doctrine\Common\Persistence\ObjectManager',
'cFGroup' => 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup'
'cFGroup' => 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup',
'role' => 'Symfony\Component\Security\Core\Role\Role',
'center' => 'Chill\MainBundle\Entity\Center'
));
}