| 1: | <?php |
| 2: | namespace TIC\DemoBundle\Controller; |
| 3: | |
| 4: | use TIC\CoreBundle\Base\TICController as BaseController; |
| 5: | use TIC\DormBundle\Traits\ControllerItemable; |
| 6: | use TIC\TwigBundle\Traits\ControllerViewable; |
| 7: | |
| 8: | use Symfony\Component\Routing\Annotation\Route; |
| 9: | use Symfony\Component\HttpFoundation\Request; |
| 10: | use Symfony\Component\HttpFoundation\Response; |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | class FormulaireController extends BaseController |
| 16: | { |
| 17: | use ControllerItemable, ControllerViewable; |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | public function list(Request $request): Response |
| 25: | { |
| 26: | return $this->renderAction('list', [ |
| 27: | 'items' => $this->getRepo()->findAll(), |
| 28: | ]); |
| 29: | } |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | public function show(Request $request, $id): Response |
| 36: | { |
| 37: | return $this->renderAction('show', [ |
| 38: | 'item' => $this->getItem($id), |
| 39: | ]); |
| 40: | } |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | public function form(Request $request, $id = null): Response |
| 48: | { |
| 49: | $item = $this->getItem($id); |
| 50: | $form = $this->getForm($item, $request, []); |
| 51: | |
| 52: | if ($form->isSubmitted() && $form->isValid()) { |
| 53: | return $this->saveItem($item, true, true); |
| 54: | } |
| 55: | return $this->renderAction('form', [ |
| 56: | 'item' => $item, |
| 57: | 'form' => $form, |
| 58: | ]); |
| 59: | } |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | public function delete(Request $request, $id): Response |
| 66: | { |
| 67: | $item = $this->getItem($id); |
| 68: | |
| 69: | if (false === $this->checkCSRF('delete'.$id, $request)) |
| 70: | return $this->alert('danger', "error.csrf.invalid", $item); |
| 71: | |
| 72: | return $this->deleteItem($item, true, true); |
| 73: | } |
| 74: | |
| 75: | } |
| 76: | |