public function postPersist(LifecycleEventArgs $args) { $entity = $args->getEntity(); // only act on some "Product" entity if (!$entity instanceof Agence || !$entity instanceof BOC || !$entity instanceof CIC) { return; } $entite = new Entite(); $entite->setClasse(get_class($entity)); $entity->setEntite($entite); $entityManager = $args->getEntityManager(); $entityManager->persist($entity); $entityManager->flush(); // ... do something with the Product }
public function entitesAjoutAction($entite, $matricule = null, Request $request) { $em = $this->getDoctrine()->getManager(); $class = 'TRC\\CoreBundle\\Entity\\' . $entite; $forme = 'TRC\\CoreBundle\\Form\\' . $entite . 'Type'; $formType = new $forme(); $codeJournal = "MOD_EN_" . strtoupper(substr($entite, 0, 3)); if ($matricule === null) { $objet = new $class(); $codeJournal = "AJ_EN_" . strtoupper(substr($entite, 0, 3)); } else { $objet = $em->getRepository('TRCCoreBundle:' . $entite)->findOneByMatricule($matricule); if ($objet === null) { throw new NotFoundHttpException("Erreur de matricule '{$matricule}'"); } } $typeJournal = $em->getRepository('TRCCoreBundle:TypeJournal')->findOneByCode($codeJournal); //* $form = $this->get('form.factory')->create($formType, $objet); if ($form->handleRequest($request)->isValid()) { $sysmatricule = $this->get('trc_core.matricule'); $sysjournal = $this->get('trc_core.journal'); if ($matricule === null) { // Attribuer un matricule à l'objet $objet->setMatricule($sysmatricule->matriculeStandard($objet)); $entite = new Entite(); $entite->setClasse(get_class($objet)); $objet->setEntite($entite); $em->persist($objet); } $em->flush(); //Historiser l'action $journalisation = array('user' => $this->getUser(), 'type' => $typeJournal, 'contenu' => $objet); $sysjournal->enregistrer($journalisation); return $this->redirect($this->generateUrl('trc_admin_entites_voir_une', array('entite' => $entite, 'code' => $objet->getCode()))); } //*/ return $this->render('TRCAdminBundle:Entites:entitesAjout.html.twig', array('entite' => $entite, 'objet' => $objet, 'codeJournal' => $codeJournal, "form" => $form->createView())); }
/** * {@inheritDoc} */ public function getDateajout() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getDateajout', []); return parent::getDateajout(); }