Advertisement
Guest User

Untitled

a guest
Dec 13th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppBundle\Controller;
  4.  
  5. use AppBundle\Entity\Plachta;
  6. use AppBundle\Entity\Pracownik;
  7. use AppBundle\Entity\Przedmiot;
  8. use AppBundle\Entity\Przydzial;
  9. use AppBundle\Entity\Semestr;
  10. use AppBundle\Entity\StudiaTyp;
  11. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  14.  
  15. /**
  16. * Plachtum controller.
  17. *
  18. */
  19. class PlachtaController extends Controller
  20. {
  21. /**
  22. * @Route("/all", name="pracownik_index")
  23. */
  24. public function indexAction()
  25. {
  26. $em = $this->getDoctrine()->getManager();
  27.  
  28. $plachtas = $em->getRepository('AppBundle:Plachta')->findAll();
  29.  
  30. return $this->render('plachta/index.html.twig', array(
  31. 'plachtas' => $plachtas,
  32. ));
  33. }
  34.  
  35. /**
  36. * @Route("/new", name="pracownik_new")
  37. */
  38. public function newAction(Request $request)
  39. {
  40. $plachtum = new Plachta();
  41. $form = $this->createForm('AppBundle\Form\PlachtaType', $plachtum);
  42. $form->handleRequest($request);
  43.  
  44. if ($form->isSubmitted() && $form->isValid()) {
  45. $em = $this->getDoctrine()->getManager();
  46. $em->persist($plachtum);
  47. $em->flush($plachtum);
  48.  
  49. return $this->redirectToRoute('plachta_show', array('idPlachta' => $plachtum->getIdPlachta()));
  50. }
  51.  
  52. return $this->render('plachta/new.html.twig', array(
  53. 'plachtum' => $plachtum,
  54. 'form' => $form->createView(),
  55. ));
  56. }
  57.  
  58. /**
  59. * Finds and displays a plachtum entity.
  60. *
  61. */
  62. public function showAction(Plachta $plachtum)
  63. {
  64. $em = $this->getDoctrine()->getManager();
  65.  
  66. $pracowniks = $em->getRepository('AppBundle:Pracownik')->findByIdPlachta($plachtum);
  67. $przedmiots = $em->getRepository('AppBundle:Przedmiot')->findByIdPlachta($plachtum);
  68. $przydzials = $em->getRepository('AppBundle:Przydzial')->findByIdPlachta($plachtum);
  69. $semestrs = $em->getRepository('AppBundle:Semestr')->findByIdPlachta($plachtum);
  70. $studiaTyps = $em->getRepository('AppBundle:StudiaTyp')->findByIdPlachta($plachtum);
  71.  
  72. $deleteForm = $this->createDeleteForm($plachtum);
  73.  
  74. return $this->render('plachta/show.html.twig', array(
  75. 'plachtum' => $plachtum,
  76. 'pracowniks'=>$pracowniks,
  77. 'przedmiots'=>$przedmiots,
  78. 'przydzials'=>$przydzials,
  79. 'semestrs'=>$semestrs,
  80. 'studiaTyps'=>$studiaTyps,
  81. 'delete_form' => $deleteForm->createView(),
  82. ));
  83. }
  84.  
  85. /**
  86. * Displays a form to edit an existing plachtum entity.
  87. *
  88. */
  89. public function editAction(Request $request, Plachta $plachtum)
  90. {
  91. $deleteForm = $this->createDeleteForm($plachtum);
  92. $editForm = $this->createForm('AppBundle\Form\PlachtaType', $plachtum);
  93. $editForm->handleRequest($request);
  94.  
  95.  
  96. if ($editForm->isSubmitted() && $editForm->isValid()) {
  97. $this->getDoctrine()->getManager()->flush();
  98.  
  99. return $this->redirectToRoute('plachta_edit', array('idPlachta' => $plachtum->getIdPlachta()));
  100. }
  101.  
  102.  
  103. return $this->render('plachta/edit.html.twig', array(
  104. 'plachtum' => $plachtum,
  105. 'edit_form' => $editForm->createView(),
  106. 'delete_form' => $deleteForm->createView(),
  107. ));
  108. }
  109.  
  110. /**
  111. * Deletes a plachtum entity.
  112. *
  113. */
  114. public function deleteAction(Request $request, Plachta $plachtum)
  115. {
  116. $form = $this->createDeleteForm($plachtum);
  117. $form->handleRequest($request);
  118.  
  119. if ($form->isSubmitted() && $form->isValid()) {
  120. $em = $this->getDoctrine()->getManager();
  121. $em->remove($plachtum);
  122. $em->flush($plachtum);
  123.  
  124.  
  125. }
  126.  
  127.  
  128. return $this->redirectToRoute('plachta_index');
  129. }
  130.  
  131. /**
  132. * Creates a form to delete a plachtum entity.
  133. *
  134. * @param Plachta $plachtum The plachtum entity
  135. *
  136. * @return \Symfony\Component\Form\Form The form
  137. */
  138. private function createDeleteForm(Plachta $plachtum)
  139. {
  140. return $this->createFormBuilder()
  141. ->setAction($this->generateUrl('plachta_delete', array('idPlachta' => $plachtum->getIdPlachta())))
  142. ->setMethod('DELETE')
  143. ->getForm()
  144. ;
  145. }
  146.  
  147.  
  148.  
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement