Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //QUERY
- public function findForPanelEdit($id)
- {
- return $this->getEntityManager()->createQueryBuilder()
- ->select('a.id, a.name, a.description, a.dateFrom AS date_from, a.dateTo AS date_to')
- ->from(Auction::class, 'a')
- ->where('a.id = :id')
- ->setParameter(':id', $id)
- ->addSelect('i.name AS image_name, i.extension AS image_extension')
- ->leftJoin(Cover::class, 'i', Join::WITH, 'a.cover = i')
- ->addSelect('pdf.name AS pdf_name, pdf.extension AS pdf_extension')
- ->leftJoin(Catalog::class, 'pdf', Join::WITH, 'a.catalog = pdf')
- ->addSelect('p.name AS place_name, p.street AS place_street')
- ->leftJoin(Place::class, 'p', Join::WITH, 'a.place = p')
- ->addSelect('c.name AS contact_name, c.phone AS contact_phone, c.email AS contact_email')
- ->join(ContactPerson::class, 'c')
- ->groupBy('a')
- ->getQuery()
- ->getResult();
- }
- //Controller
- /**
- * @Route("/panel/admin/edit/auction/{uuid}", name="panel_update_auction")
- */
- public function update($uuid, Request $request): Response
- {
- $auction = $this->getDoctrine()->getRepository(Auction::class)->find($uuid);
- $form = $this->createForm(CreateAuctionForm::class, $auction);
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid()) {
- $this->addFlash('success', 'Aukcja zaktualizowana!');
- return $this->redirectToRoute('panel_list_auction');
- }
- return $this->render('admin/auction/update.html.twig', [
- 'form' => $form->createView(),
- 'auctions' => $this->getDoctrine()->getRepository(Auction::class)->findForPanelEdit($uuid)
- ]);
- }
- //Update Twig
- {% extends 'admin/admin.html.twig' %}
- {% block content %}
- <header class="header">
- <h1 class="header__title">Edytuj aukcję</h1>
- </header>
- {% form_theme form 'bootstrap_4_layout.html.twig' %}
- <div style="width:500px; margin: 0 auto;">
- {{ form_start(form) }}
- {{ form_widget(form) }}
- {{ form_end(form) }}
- </div>
- {% endblock %}
- //Link to edit
- <table class="list table table-striped table-bordered" style="width:100%">
- <thead>
- <tr class="list__item">
- <th>Nazwa</th>
- <th>Data</th>
- <th>Miejsce</th>
- <th></th>
- </tr>
- </thead>
- <tbody>
- {% for auction in auctions %}
- <tr class="list__item">
- <td>{{ auction.name }}</td>
- <td>{{ auction.date }}</td>
- <td>{{ auction.place }}</td>
- <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>
- </tr>
- {% endfor %}
- </tbody>
- </table>
Advertisement
Add Comment
Please, Sign In to add comment