Ejemplo n.º 1
0
 /**
  * @param State $state
  * @return IdCardInterface
  */
 public function instantiateIdCard(State $state = null)
 {
     $event = new InstantiateIdCardEvent($state);
     $this->dispatcher->dispatch(ValidationEvents::VALIDATION_ID_CARD_INSTANTIATE, $event);
     $idCard = $event->getIdCard();
     if (!$idCard instanceof IdCardInterface) {
         $idCard = new IdCard();
         if ($state instanceof State) {
             $idCard->setState($state);
         }
     }
     return $idCard;
 }
Ejemplo n.º 2
0
 /**
  * @Route("/profile/doc/rg/edit", name="lc_profile_doc_rg_edit")
  * @Template()
  */
 public function docRgEditAction(Request $request)
 {
     $form = $this->createForm(new DocRgFormType());
     $rg = null;
     if (($id = $request->get('id')) || ($data = $request->get($form->getName())) && ($id = $data['id'])) {
         $rg = $this->getDoctrine()->getManager()->getRepository('PROCERGSLoginCidadaoCoreBundle:IdCard')->findOneBy(array('person' => $this->getUser(), 'id' => $id));
     }
     if (!$rg) {
         $rg = new IdCard();
         $rg->setPerson($this->getUser());
     }
     $form = $this->createForm(new DocRgFormType(), $rg);
     $form->handleRequest($this->getRequest());
     if ($form->isValid()) {
         $rgNum = str_split($form->get('value')->getData());
         if ($form->get('state')->getData()->getId() == 43 && ($this->checkRGDce($rgNum) != $rgNum[0] || $this->checkRGDcd($rgNum) != $rgNum[9])) {
             $form->get('value')->addError(new FormError($this->get('translator')->trans('This RG is invalid')));
             return array('form' => $form->createView());
         }
         $manager = $this->getDoctrine()->getManager();
         $dql = $manager->getRepository('PROCERGSLoginCidadaoCoreBundle:IdCard')->createQueryBuilder('u')->where('u.person = :person and u.state = :state')->setParameter('person', $this->getUser())->setParameter('state', $form->get('state')->getData())->orderBy('u.id', 'ASC');
         if ($rg->getId()) {
             $dql->andWhere('u != :rg')->setParameter('rg', $rg);
         }
         $has = $dql->getQuery()->getResult();
         if ($has) {
             $form->get('state')->addError(new FormError($this->get('translator')->trans('You already have an ID registered for this State')));
             return array('form' => $form->createView());
         }
         $manager->persist($rg);
         $manager->flush();
         $resp = new Response('<script>rgGrid.getGrid();</script>');
         return $resp;
     }
     return array('form' => $form->createView());
 }