Advertisement
Guest User

Untitled

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