/** * @Route("/{id}", name="applicant_update") * @Method("POST") * @Template("LanggasSisdikBundle:SiswaPendaftar:edit.html.twig") */ public function updateAction(Request $request, $id) { $sekolah = $this->getSekolah(); $this->setCurrentMenu(); $panitiaAktif = $this->getPanitiaAktif(); if (!is_array($panitiaAktif) || count($panitiaAktif) <= 0) { throw new AccessDeniedException($this->get('translator')->trans('exception.tidak.ada.panitia.pendaftaran')); } if (!(is_array($panitiaAktif[0]) && in_array($this->getUser()->getId(), $panitiaAktif[0]) || $panitiaAktif[1] == $this->getUser()->getId())) { throw new AccessDeniedException($this->get('translator')->trans('exception.register.as.committee')); } $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('LanggasSisdikBundle:Siswa')->find($id); $this->verifyTahun($entity->getTahun()->getTahun()); if (!$entity) { throw $this->createNotFoundException('Entity Siswa tak ditemukan.'); } if ($this->get('security.authorization_checker')->isGranted('edit', $entity) === false) { throw new AccessDeniedException($this->get('translator')->trans('akses.ditolak')); } $deleteForm = $this->createDeleteForm($id); $editForm = $this->createForm('sisdik_siswapendaftar', $entity, ['tahun_aktif' => $panitiaAktif[2], 'mode' => 'edit']); $editForm->submit($request); if ($editForm->isValid()) { try { if ($editForm['referensi']->getData() === null && $editForm['namaReferensi']->getData() != "") { $referensi = new Referensi(); $referensi->setNama($editForm['namaReferensi']->getData()); $referensi->setSekolah($sekolah); $entity->setReferensi($referensi); } if ($editForm['sekolahAsal']->getData() === null && $editForm['namaSekolahAsal']->getData() != "") { $sekolahAsal = new SekolahAsal(); $sekolahAsal->setNama($editForm['namaSekolahAsal']->getData()); $sekolahAsal->setSekolah($sekolah); $entity->setSekolahAsal($sekolahAsal); } // force unit of work detect entity 'changes' // possible problem source: too many objects handled by doctrine $entity->setWaktuUbah(new \DateTime()); $entity->setDiubahOleh($this->getUser()); $em->persist($entity); $em->flush(); $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('flash.applicant.updated', ['%name%' => $entity->getNamaLengkap()])); } catch (DBALException $e) { $message = $this->get('translator')->trans('exception.unique.applicant'); throw new DBALException($message); } return $this->redirect($this->generateUrl('applicant_edit', ['id' => $id])); } return ['entity' => $entity, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView()]; }