Advertisement
Guest User

Untitled

a guest
Apr 16th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. namespace AppBundle\Controller;
  2. use AppBundle\Entity\Przydzial;
  3. use AppBundle\Entity\Przedmiot;
  4. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\PropertyAccess\PropertyAccess;
  7.  
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  10. use Symfony\Component\HttpFoundation\Session\Session;
  11.  
  12. /**
  13. * Creates a new przydzial entity.
  14. *
  15. */
  16. public function newAction(Request $request)
  17. {
  18. $przydzial = new Przydzial();
  19. $przedmiot = new Przedmiot();
  20.  
  21. $plachta = $request->getSession()->get('plachta');
  22.  
  23.  
  24. $form = $this->createForm('AppBundle\Form\PrzydzialType', $przydzial);
  25. $form->handleRequest($request);
  26.  
  27. $idPrzedmiot = $request->query->get($form->getName());
  28.  
  29. $idPrzedmiot = $idPrzedmiot['idPrzedmiot'];
  30.  
  31. if ($form->isSubmitted() && $form->isValid()) {
  32.  
  33. // $liczbaGodzin = $form['liczbaGodzin']->getData() * 100;
  34.  
  35.  
  36. $em = $this->getDoctrine()->getManager();
  37. $query = $em->createQuery(
  38. "SELECT prz.liczGodzLabJedn,
  39. prz.liczGodzCwJedn,
  40. prz.liczGodzWykJedn,
  41. prz.liczGrupWyk,
  42. prz.liczGrupLab,
  43. prz.liczGrupCw
  44. FROM AppBundle:Przedmiot prz
  45. WHERE prz.idPrzedmiot ='$idPrzedmiot '"
  46.  
  47. );
  48. $tab_Przedmiot = $query->getResult();
  49.  
  50.  
  51. $laboratoriumLiczbaGodz = $form['laboratoriumLiczbaGodz']->getData();
  52. $cwiczeniaLiczbaGodzin = $form['cwiczeniaLiczbaGodzin']->getData();
  53. $wykladLiczbaGodz = $form['wykladLiczbaGodz']->getData();
  54.  
  55.  
  56. $singleHourLab = $tab_Przedmiot[0]['liczGodzLabJedn'];
  57. $singleHourCw = $tab_Przedmiot[0]['liczGodzCwJedn'];
  58. $singleHourWyk = $tab_Przedmiot[0]['liczGodzWykJedn'];
  59.  
  60. $liczGrupLab = $tab_Przedmiot[0]['liczGrupLab'];
  61. $liczGrupCw = $tab_Przedmiot[0]['liczGrupCw'];
  62. $liczGrupWyk = $tab_Przedmiot[0]['liczGrupWyk'];
  63.  
  64. $sub_liczGrupLab = $liczGrupLab - $laboratoriumLiczbaGodz;
  65. $sub_liczGrupWyk = $liczGrupWyk - $wykladLiczbaGodz;
  66. $sub_liczGrupCw = $liczGrupCw - $cwiczeniaLiczbaGodzin;
  67.  
  68. //dump($idPrzedmiot);
  69. //dump($laboratoriumLiczbaGodz, $singleHourLab); die();
  70. //dump($liczGrupCw, $liczGrupLab, $liczGrupWyk, $sub_liczGrupLab);
  71.  
  72.  
  73. $laboratoriumLiczbaGodz = $laboratoriumLiczbaGodz * $singleHourLab;
  74. $cwiczeniaLiczbaGodzin = $cwiczeniaLiczbaGodzin * $singleHourCw;
  75. $wykladLiczbaGodz = $wykladLiczbaGodz * $singleHourWyk;
  76.  
  77.  
  78.  
  79. $przydzial->setLaboratoriumLiczbaGodz($laboratoriumLiczbaGodz);
  80. $przydzial->setCwiczeniaLiczbaGodzin($cwiczeniaLiczbaGodzin);
  81. $przydzial->setWykladLiczbaGodz($wykladLiczbaGodz);
  82.  
  83.  
  84.  
  85. // $em->merge($przedmiot);
  86. $przedmiot = $em->getReference('AppBundle:Przedmiot', $idPrzedmiot);
  87. $przedmiot->setLiczGrupLab($sub_liczGrupLab);
  88. $przedmiot->setLiczGrupWyk($sub_liczGrupWyk);
  89. $przedmiot->setLiczGrupCw($sub_liczGrupCw);
  90. $em->flush();
  91.  
  92. $em->persist($przydzial);
  93. $em->flush($przydzial);
  94.  
  95.  
  96.  
  97.  
  98. return $this->redirectToRoute('przydzial_show', array('idPrzydzial' => $przydzial->getIdPrzydzial()));
  99.  
  100. }
  101.  
  102. return $this->render('przydzial/new.html.twig', array(
  103. 'przydzial' => $przydzial,
  104. 'form' => $form->createView(),
  105. ));
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement