| @@ 122-152 (lines=31) @@ | ||
| 119 | $message = 'You want to delete role "' . $role->getName() . '" (id: ' . $id . '). '; |
|
| 120 | $message .= 'Related records: users (count: ' . $countUsers . '). '; |
|
| 121 | ||
| 122 | if ($countUsers == 0) { |
|
| 123 | $message .= 'Are you sure, you want to continue?'; |
|
| 124 | ||
| 125 | $form = $this->createFormBuilder($role) |
|
| 126 | ->setAction($this->generateUrl('roleDelete', ['id' => $id])) |
|
| 127 | ->setMethod('POST') |
|
| 128 | ->add('delete', SubmitType::class, array( |
|
| 129 | 'label' => 'Continue', |
|
| 130 | 'attr' => [ |
|
| 131 | 'class' => 'btn btn-default' |
|
| 132 | ], |
|
| 133 | ) |
|
| 134 | ) |
|
| 135 | ->getForm(); |
|
| 136 | ||
| 137 | if ($request->getMethod() == 'POST') { |
|
| 138 | $form->handleRequest($request); |
|
| 139 | if ($form->isValid()) { |
|
| 140 | $em->remove($role); |
|
| 141 | $em->flush(); |
|
| 142 | ||
| 143 | return $this->redirectToRoute('rolesAdmin'); |
|
| 144 | } |
|
| 145 | } |
|
| 146 | ||
| 147 | $renderedForm = $form->createView(); |
|
| 148 | } |
|
| 149 | else { |
|
| 150 | $message .= 'You must to delete related records before.'; |
|
| 151 | $renderedForm = ''; |
|
| 152 | } |
|
| 153 | ||
| 154 | return [ |
|
| 155 | 'message' => $message, |
|
| @@ 124-154 (lines=31) @@ | ||
| 121 | $message .= 'Related records: articles (count: ' . $countArticles . '), '; |
|
| 122 | $message .= 'comments (count: ' . $countComments . '). '; |
|
| 123 | ||
| 124 | if ($countArticles == 0 or $countComments == 0) { |
|
| 125 | $message .= 'Are you sure, you want to continue?'; |
|
| 126 | ||
| 127 | $form = $this->createFormBuilder($user) |
|
| 128 | ->setAction($this->generateUrl('userDelete', ['id' => $id])) |
|
| 129 | ->setMethod('POST') |
|
| 130 | ->add('delete', SubmitType::class, array( |
|
| 131 | 'label' => 'Continue', |
|
| 132 | 'attr' => [ |
|
| 133 | 'class' => 'btn btn-default' |
|
| 134 | ], |
|
| 135 | ) |
|
| 136 | ) |
|
| 137 | ->getForm(); |
|
| 138 | ||
| 139 | if ($request->getMethod() == 'POST') { |
|
| 140 | $form->handleRequest($request); |
|
| 141 | if ($form->isValid()) { |
|
| 142 | $em->remove($user); |
|
| 143 | $em->flush(); |
|
| 144 | ||
| 145 | return $this->redirectToRoute('usersAdmin'); |
|
| 146 | } |
|
| 147 | } |
|
| 148 | ||
| 149 | $renderedForm = $form->createView(); |
|
| 150 | } |
|
| 151 | else { |
|
| 152 | $message .= 'You must to delete related records before.'; |
|
| 153 | $renderedForm = ''; |
|
| 154 | } |
|
| 155 | ||
| 156 | return [ |
|
| 157 | 'message' => $message, |
|