| @@ 33-192 (lines=160) @@ | ||
| 30 | * |
|
| 31 | * @Route("/articles") |
|
| 32 | */ |
|
| 33 | class ArticleController extends AbstractController |
|
| 34 | { |
|
| 35 | /** |
|
| 36 | * Lists all Article entities. |
|
| 37 | * |
|
| 38 | * @Route("/", name="articles") |
|
| 39 | * @Method("GET") |
|
| 40 | * @Template() |
|
| 41 | */ |
|
| 42 | public function indexAction(Request $request) |
|
| 43 | { |
|
| 44 | $em = $this->getDoctrine()->getManager(); |
|
| 45 | $qb = $em->getRepository('AppBundle:Article')->createQueryBuilder('a'); |
|
| 46 | $this->addQueryBuilderSort($qb, 'article'); |
|
| 47 | $paginator = $this->get('knp_paginator')->paginate($qb, $request->query->get('page', 1), 5); |
|
| 48 | ||
| 49 | return array( |
|
| 50 | 'paginator' => $paginator, |
|
| 51 | ); |
|
| 52 | } |
|
| 53 | ||
| 54 | /** |
|
| 55 | * Finds and displays a Article entity. |
|
| 56 | * |
|
| 57 | * @Route("/{slug}/show", name="articles_show") |
|
| 58 | * @Method("GET") |
|
| 59 | * @Template() |
|
| 60 | */ |
|
| 61 | public function showAction(Article $article) |
|
| 62 | { |
|
| 63 | $deleteForm = $this->createDeleteForm($article->getId(), 'articles_delete'); |
|
| 64 | ||
| 65 | return array( |
|
| 66 | 'article' => $article, |
|
| 67 | 'delete_form' => $deleteForm->createView(), |
|
| 68 | ); |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * Displays a form to create a new Article entity. |
|
| 73 | * |
|
| 74 | * @Route("/new", name="articles_new") |
|
| 75 | * @Method("GET") |
|
| 76 | * @Template() |
|
| 77 | */ |
|
| 78 | public function newAction() |
|
| 79 | { |
|
| 80 | $article = new Article(); |
|
| 81 | $form = $this->createForm(new ArticleType(), $article); |
|
| 82 | ||
| 83 | return array( |
|
| 84 | 'article' => $article, |
|
| 85 | 'form' => $form->createView(), |
|
| 86 | ); |
|
| 87 | } |
|
| 88 | ||
| 89 | /** |
|
| 90 | * Creates a new Article entity. |
|
| 91 | * |
|
| 92 | * @Route("/create", name="articles_create") |
|
| 93 | * @Method("POST") |
|
| 94 | * @Template("AppBundle:Article:new.html.twig") |
|
| 95 | */ |
|
| 96 | public function createAction(Request $request) |
|
| 97 | { |
|
| 98 | $article = new Article(); |
|
| 99 | $form = $this->createForm(new ArticleType(), $article); |
|
| 100 | if ($form->handleRequest($request)->isValid()) { |
|
| 101 | $em = $this->getDoctrine()->getManager(); |
|
| 102 | $em->persist($article); |
|
| 103 | $em->flush(); |
|
| 104 | ||
| 105 | return $this->redirectToRoute('articles_show', array('slug' => $article->getSlug())); |
|
| 106 | } |
|
| 107 | ||
| 108 | return array( |
|
| 109 | 'article' => $article, |
|
| 110 | 'form' => $form->createView(), |
|
| 111 | ); |
|
| 112 | } |
|
| 113 | ||
| 114 | /** |
|
| 115 | * Displays a form to edit an existing Article entity. |
|
| 116 | * |
|
| 117 | * @Route("/{slug}/edit", name="articles_edit") |
|
| 118 | * @Method("GET") |
|
| 119 | * @Template() |
|
| 120 | */ |
|
| 121 | public function editAction(Article $article) |
|
| 122 | { |
|
| 123 | $editForm = $this->createForm(new ArticleType(), $article, array( |
|
| 124 | 'action' => $this->generateUrl('articles_update', array('slug' => $article->getSlug())), |
|
| 125 | 'method' => 'PUT', |
|
| 126 | )); |
|
| 127 | $deleteForm = $this->createDeleteForm($article->getId(), 'articles_delete'); |
|
| 128 | ||
| 129 | return array( |
|
| 130 | 'article' => $article, |
|
| 131 | 'edit_form' => $editForm->createView(), |
|
| 132 | 'delete_form' => $deleteForm->createView(), |
|
| 133 | ); |
|
| 134 | } |
|
| 135 | ||
| 136 | /** |
|
| 137 | * Edits an existing Article entity. |
|
| 138 | * |
|
| 139 | * @Route("/{slug}/update", name="articles_update") |
|
| 140 | * @Method("PUT") |
|
| 141 | * @Template("AppBundle:Article:edit.html.twig") |
|
| 142 | */ |
|
| 143 | public function updateAction(Article $article, Request $request) |
|
| 144 | { |
|
| 145 | $editForm = $this->createForm(new ArticleType(), $article, array( |
|
| 146 | 'action' => $this->generateUrl('articles_update', array('slug' => $article->getSlug())), |
|
| 147 | 'method' => 'PUT', |
|
| 148 | )); |
|
| 149 | if ($editForm->handleRequest($request)->isValid()) { |
|
| 150 | $this->getDoctrine()->getManager()->flush(); |
|
| 151 | ||
| 152 | return $this->redirectToRoute('articles_edit', array('slug' => $article->getSlug())); |
|
| 153 | } |
|
| 154 | $deleteForm = $this->createDeleteForm($article->getId(), 'articles_delete'); |
|
| 155 | ||
| 156 | return array( |
|
| 157 | 'article' => $article, |
|
| 158 | 'edit_form' => $editForm->createView(), |
|
| 159 | 'delete_form' => $deleteForm->createView(), |
|
| 160 | ); |
|
| 161 | } |
|
| 162 | ||
| 163 | ||
| 164 | /** |
|
| 165 | * Save order. |
|
| 166 | * |
|
| 167 | * @Route("/order/{field}/{type}", name="articles_sort") |
|
| 168 | */ |
|
| 169 | public function sortAction($field, $type) |
|
| 170 | { |
|
| 171 | $this->setOrder('article', $field, $type); |
|
| 172 | ||
| 173 | return $this->redirect($this->generateUrl('articles')); |
|
| 174 | } |
|
| 175 | /** |
|
| 176 | * Deletes a Article entity. |
|
| 177 | * |
|
| 178 | * @Route("/{id}/delete", name="articles_delete", requirements={"id"="\d+"}) |
|
| 179 | * @Method("DELETE") |
|
| 180 | */ |
|
| 181 | public function deleteAction(Article $article, Request $request) |
|
| 182 | { |
|
| 183 | $form = $this->createDeleteForm($article->getId(), 'articles_delete'); |
|
| 184 | if ($form->handleRequest($request)->isValid()) { |
|
| 185 | $em = $this->getDoctrine()->getManager(); |
|
| 186 | $em->remove($article); |
|
| 187 | $em->flush(); |
|
| 188 | } |
|
| 189 | ||
| 190 | return $this->redirectToRoute('articles'); |
|
| 191 | } |
|
| 192 | } |
|
| 193 | ||
| @@ 32-191 (lines=160) @@ | ||
| 29 | * |
|
| 30 | * @Route("/suppliers") |
|
| 31 | */ |
|
| 32 | class SupplierController extends AbstractController |
|
| 33 | { |
|
| 34 | /** |
|
| 35 | * Lists all Supplier entities. |
|
| 36 | * |
|
| 37 | * @Route("/", name="suppliers") |
|
| 38 | * @Method("GET") |
|
| 39 | * @Template() |
|
| 40 | */ |
|
| 41 | public function indexAction(Request $request) |
|
| 42 | { |
|
| 43 | $em = $this->getDoctrine()->getManager(); |
|
| 44 | $qb = $em->getRepository('AppBundle:Supplier')->createQueryBuilder('s'); |
|
| 45 | $this->addQueryBuilderSort($qb, 'supplier'); |
|
| 46 | $paginator = $this->get('knp_paginator')->paginate($qb, $request->query->get('page', 1), 20); |
|
| 47 | ||
| 48 | return array( |
|
| 49 | 'paginator' => $paginator, |
|
| 50 | ); |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Finds and displays a Supplier entity. |
|
| 55 | * |
|
| 56 | * @Route("/{slug}/show", name="suppliers_show") |
|
| 57 | * @Method("GET") |
|
| 58 | * @Template() |
|
| 59 | */ |
|
| 60 | public function showAction(Supplier $supplier) |
|
| 61 | { |
|
| 62 | $deleteForm = $this->createDeleteForm($supplier->getId(), 'suppliers_delete'); |
|
| 63 | ||
| 64 | return array( |
|
| 65 | 'supplier' => $supplier, |
|
| 66 | 'delete_form' => $deleteForm->createView(), |
|
| 67 | ); |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * Displays a form to create a new Supplier entity. |
|
| 72 | * |
|
| 73 | * @Route("/new", name="suppliers_new") |
|
| 74 | * @Method("GET") |
|
| 75 | * @Template() |
|
| 76 | */ |
|
| 77 | public function newAction() |
|
| 78 | { |
|
| 79 | $supplier = new Supplier(); |
|
| 80 | $form = $this->createForm(new SupplierType(), $supplier); |
|
| 81 | ||
| 82 | return array( |
|
| 83 | 'supplier' => $supplier, |
|
| 84 | 'form' => $form->createView(), |
|
| 85 | ); |
|
| 86 | } |
|
| 87 | ||
| 88 | /** |
|
| 89 | * Creates a new Supplier entity. |
|
| 90 | * |
|
| 91 | * @Route("/create", name="suppliers_create") |
|
| 92 | * @Method("POST") |
|
| 93 | * @Template("AppBundle:Supplier:new.html.twig") |
|
| 94 | */ |
|
| 95 | public function createAction(Request $request) |
|
| 96 | { |
|
| 97 | $supplier = new Supplier(); |
|
| 98 | $form = $this->createForm(new SupplierType(), $supplier); |
|
| 99 | if ($form->handleRequest($request)->isValid()) { |
|
| 100 | $em = $this->getDoctrine()->getManager(); |
|
| 101 | $em->persist($supplier); |
|
| 102 | $em->flush(); |
|
| 103 | ||
| 104 | return $this->redirectToRoute('suppliers_show', array('slug' => $supplier->getSlug())); |
|
| 105 | } |
|
| 106 | ||
| 107 | return array( |
|
| 108 | 'supplier' => $supplier, |
|
| 109 | 'form' => $form->createView(), |
|
| 110 | ); |
|
| 111 | } |
|
| 112 | ||
| 113 | /** |
|
| 114 | * Displays a form to edit an existing Supplier entity. |
|
| 115 | * |
|
| 116 | * @Route("/{slug}/edit", name="suppliers_edit") |
|
| 117 | * @Method("GET") |
|
| 118 | * @Template() |
|
| 119 | */ |
|
| 120 | public function editAction(Supplier $supplier) |
|
| 121 | { |
|
| 122 | $editForm = $this->createForm(new SupplierType(), $supplier, array( |
|
| 123 | 'action' => $this->generateUrl('suppliers_update', array('slug' => $supplier->getSlug())), |
|
| 124 | 'method' => 'PUT', |
|
| 125 | )); |
|
| 126 | $deleteForm = $this->createDeleteForm($supplier->getId(), 'suppliers_delete'); |
|
| 127 | ||
| 128 | return array( |
|
| 129 | 'supplier' => $supplier, |
|
| 130 | 'edit_form' => $editForm->createView(), |
|
| 131 | 'delete_form' => $deleteForm->createView(), |
|
| 132 | ); |
|
| 133 | } |
|
| 134 | ||
| 135 | /** |
|
| 136 | * Edits an existing Supplier entity. |
|
| 137 | * |
|
| 138 | * @Route("/{slug}/update", name="suppliers_update") |
|
| 139 | * @Method("PUT") |
|
| 140 | * @Template("AppBundle:Supplier:edit.html.twig") |
|
| 141 | */ |
|
| 142 | public function updateAction(Supplier $supplier, Request $request) |
|
| 143 | { |
|
| 144 | $editForm = $this->createForm(new SupplierType(), $supplier, array( |
|
| 145 | 'action' => $this->generateUrl('suppliers_update', array('slug' => $supplier->getSlug())), |
|
| 146 | 'method' => 'PUT', |
|
| 147 | )); |
|
| 148 | if ($editForm->handleRequest($request)->isValid()) { |
|
| 149 | $this->getDoctrine()->getManager()->flush(); |
|
| 150 | $this->addFlash('info', 'gestock.edit.ok'); |
|
| 151 | } |
|
| 152 | $deleteForm = $this->createDeleteForm($supplier->getId(), 'suppliers_delete'); |
|
| 153 | ||
| 154 | return array( |
|
| 155 | 'supplier' => $supplier, |
|
| 156 | 'edit_form' => $editForm->createView(), |
|
| 157 | 'delete_form' => $deleteForm->createView(), |
|
| 158 | ); |
|
| 159 | } |
|
| 160 | ||
| 161 | ||
| 162 | /** |
|
| 163 | * Save order. |
|
| 164 | * |
|
| 165 | * @Route("/order/{field}/{type}", name="suppliers_sort") |
|
| 166 | */ |
|
| 167 | public function sortAction($field, $type) |
|
| 168 | { |
|
| 169 | $this->setOrder('supplier', $field, $type); |
|
| 170 | ||
| 171 | return $this->redirectToRoute('suppliers'); |
|
| 172 | } |
|
| 173 | ||
| 174 | /** |
|
| 175 | * Deletes a Supplier entity. |
|
| 176 | * |
|
| 177 | * @Route("/{id}/delete", name="suppliers_delete", requirements={"id"="\d+"}) |
|
| 178 | * @Method("DELETE") |
|
| 179 | */ |
|
| 180 | public function deleteAction(Supplier $supplier, Request $request) |
|
| 181 | { |
|
| 182 | $form = $this->createDeleteForm($supplier->getId(), 'suppliers_delete'); |
|
| 183 | if ($form->handleRequest($request)->isValid()) { |
|
| 184 | $em = $this->getDoctrine()->getManager(); |
|
| 185 | $em->remove($supplier); |
|
| 186 | $em->flush(); |
|
| 187 | } |
|
| 188 | ||
| 189 | return $this->redirectToRoute('suppliers'); |
|
| 190 | } |
|
| 191 | } |
|
| 192 | ||