Guest User

Untitled

a guest
Dec 27th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. //QUERY
  2. public function findForPanelEdit($id)
  3. {
  4. return $this->getEntityManager()->createQueryBuilder()
  5. ->select('a.id, a.name, a.description, a.dateFrom AS date_from, a.dateTo AS date_to')
  6. ->from(Auction::class, 'a')
  7. ->where('a.id = :id')
  8. ->setParameter(':id', $id)
  9. ->addSelect('i.name AS image_name, i.extension AS image_extension')
  10. ->leftJoin(Cover::class, 'i', Join::WITH, 'a.cover = i')
  11. ->addSelect('pdf.name AS pdf_name, pdf.extension AS pdf_extension')
  12. ->leftJoin(Catalog::class, 'pdf', Join::WITH, 'a.catalog = pdf')
  13. ->addSelect('p.name AS place_name, p.street AS place_street')
  14. ->leftJoin(Place::class, 'p', Join::WITH, 'a.place = p')
  15. ->addSelect('c.name AS contact_name, c.phone AS contact_phone, c.email AS contact_email')
  16. ->join(ContactPerson::class, 'c')
  17. ->groupBy('a')
  18. ->getQuery()
  19. ->getResult();
  20. }
  21.  
  22. //Controller
  23. /**
  24. * @Route("/panel/admin/edit/auction/{uuid}", name="panel_update_auction")
  25. */
  26. public function update($uuid, Request $request): Response
  27. {
  28. $auction = $this->getDoctrine()->getRepository(Auction::class)->find($uuid);
  29. $form = $this->createForm(CreateAuctionForm::class, $auction);
  30. $form->handleRequest($request);
  31.  
  32. if ($form->isSubmitted() && $form->isValid()) {
  33. $this->addFlash('success', 'Aukcja zaktualizowana!');
  34.  
  35. return $this->redirectToRoute('panel_list_auction');
  36. }
  37.  
  38. return $this->render('admin/auction/update.html.twig', [
  39. 'form' => $form->createView(),
  40. 'auctions' => $this->getDoctrine()->getRepository(Auction::class)->findForPanelEdit($uuid)
  41. ]);
  42. }
  43.  
  44. //Update Twig
  45. {% extends 'admin/admin.html.twig' %}
  46.  
  47. {% block content %}
  48. <header class="header">
  49. <h1 class="header__title">Edytuj aukcję</h1>
  50. </header>
  51. {% form_theme form 'bootstrap_4_layout.html.twig' %}
  52.  
  53. <div style="width:500px; margin: 0 auto;">
  54. {{ form_start(form) }}
  55. {{ form_widget(form) }}
  56. {{ form_end(form) }}
  57. </div>
  58. {% endblock %}
  59.  
  60. //Link to edit
  61. <table class="list table table-striped table-bordered" style="width:100%">
  62. <thead>
  63. <tr class="list__item">
  64. <th>Nazwa</th>
  65. <th>Data</th>
  66. <th>Miejsce</th>
  67. <th></th>
  68. </tr>
  69. </thead>
  70. <tbody>
  71. {% for auction in auctions %}
  72. <tr class="list__item">
  73. <td>{{ auction.name }}</td>
  74. <td>{{ auction.date }}</td>
  75. <td>{{ auction.place }}</td>
  76. <td class="list__action"><a href="{{ path('panel_update_auction', {'uuid': auction.id}) }}"><i class="fa fa-pen"></i></a> <a href="#"><i class="fa fa-eye"></i></a></td>
  77. </tr>
  78. {% endfor %}
  79. </tbody>
  80. </table>
Advertisement
Add Comment
Please, Sign In to add comment