| @@ 211-297 (lines=87) @@ | ||
| 208 | * |
|
| 209 | * @return Response |
|
| 210 | */ |
|
| 211 | public function removeAction($id, Request $request, Application $app) |
|
| 212 | { |
|
| 213 | if ( |
|
| 214 | !$app['security']->isGranted('ROLE_POSTS_EDITOR') && |
|
| 215 | !$app['security']->isGranted('ROLE_ADMIN') |
|
| 216 | ) { |
|
| 217 | $app->abort(403); |
|
| 218 | } |
|
| 219 | ||
| 220 | $posts = array(); |
|
| 221 | $ids = $request->query->get('ids', false); |
|
| 222 | $idsExploded = explode(',', $ids); |
|
| 223 | foreach ($idsExploded as $singleId) { |
|
| 224 | $singleEntity = $app['orm.em']->find( |
|
| 225 | 'Application\Entity\PostEntity', |
|
| 226 | $singleId |
|
| 227 | ); |
|
| 228 | ||
| 229 | if ($singleEntity) { |
|
| 230 | $posts[] = $singleEntity; |
|
| 231 | } |
|
| 232 | } |
|
| 233 | ||
| 234 | $post = $app['orm.em']->find('Application\Entity\PostEntity', $id); |
|
| 235 | ||
| 236 | if ( |
|
| 237 | ( |
|
| 238 | !$post && |
|
| 239 | $ids === false |
|
| 240 | ) || |
|
| 241 | ( |
|
| 242 | empty($posts) && |
|
| 243 | $ids !== false |
|
| 244 | ) |
|
| 245 | ) { |
|
| 246 | $app->abort(404); |
|
| 247 | } |
|
| 248 | ||
| 249 | $confirmAction = $app['request']->query->has('action') && |
|
| 250 | $app['request']->query->get('action') == 'confirm' |
|
| 251 | ; |
|
| 252 | ||
| 253 | if ($confirmAction) { |
|
| 254 | try { |
|
| 255 | if (!empty($posts)) { |
|
| 256 | foreach ($posts as $post) { |
|
| 257 | $app['orm.em']->remove($post); |
|
| 258 | } |
|
| 259 | } else { |
|
| 260 | $app['orm.em']->remove($post); |
|
| 261 | } |
|
| 262 | ||
| 263 | $app['orm.em']->flush(); |
|
| 264 | ||
| 265 | $app['flashbag']->add( |
|
| 266 | 'success', |
|
| 267 | $app['translator']->trans( |
|
| 268 | 'members-area.posts.remove.successText' |
|
| 269 | ) |
|
| 270 | ); |
|
| 271 | } catch (\Exception $e) { |
|
| 272 | $app['flashbag']->add( |
|
| 273 | 'danger', |
|
| 274 | $app['translator']->trans( |
|
| 275 | $e->getMessage() |
|
| 276 | ) |
|
| 277 | ); |
|
| 278 | } |
|
| 279 | ||
| 280 | return $app->redirect( |
|
| 281 | $app['url_generator']->generate( |
|
| 282 | 'members-area.posts' |
|
| 283 | ) |
|
| 284 | ); |
|
| 285 | } |
|
| 286 | ||
| 287 | return new Response( |
|
| 288 | $app['twig']->render( |
|
| 289 | 'contents/members-area/posts/remove.html.twig', |
|
| 290 | array( |
|
| 291 | 'post' => $post, |
|
| 292 | 'posts' => $posts, |
|
| 293 | 'ids' => $ids, |
|
| 294 | ) |
|
| 295 | ) |
|
| 296 | ); |
|
| 297 | } |
|
| 298 | } |
|
| 299 | ||
| @@ 269-351 (lines=83) @@ | ||
| 266 | ); |
|
| 267 | } |
|
| 268 | ||
| 269 | public function removeAction($id, Request $request, Application $app) |
|
| 270 | { |
|
| 271 | if ( |
|
| 272 | !$app['security']->isGranted('ROLE_USERS_EDITOR') && |
|
| 273 | !$app['security']->isGranted('ROLE_ADMIN') |
|
| 274 | ) { |
|
| 275 | $app->abort(403); |
|
| 276 | } |
|
| 277 | ||
| 278 | $users = array(); |
|
| 279 | $ids = $request->query->get('ids', false); |
|
| 280 | $idsExploded = explode(',', $ids); |
|
| 281 | foreach ($idsExploded as $singleId) { |
|
| 282 | $singleEntity = $app['orm.em']->find( |
|
| 283 | 'Application\Entity\UserEntity', |
|
| 284 | $singleId |
|
| 285 | ); |
|
| 286 | ||
| 287 | if ($singleEntity) { |
|
| 288 | $users[] = $singleEntity; |
|
| 289 | } |
|
| 290 | } |
|
| 291 | ||
| 292 | $user = $app['orm.em']->find('Application\Entity\UserEntity', $id); |
|
| 293 | ||
| 294 | if ( |
|
| 295 | ( |
|
| 296 | !$user && |
|
| 297 | $ids === false |
|
| 298 | ) || |
|
| 299 | ( |
|
| 300 | empty($users) && |
|
| 301 | $ids !== false |
|
| 302 | ) |
|
| 303 | ) { |
|
| 304 | $app->abort(404); |
|
| 305 | } |
|
| 306 | ||
| 307 | $confirmAction = $app['request']->query->has('action') && $app['request']->query->get('action') == 'confirm'; |
|
| 308 | ||
| 309 | if ($confirmAction) { |
|
| 310 | try { |
|
| 311 | if (!empty($users)) { |
|
| 312 | foreach ($users as $user) { |
|
| 313 | $app['orm.em']->remove($user); |
|
| 314 | } |
|
| 315 | } else { |
|
| 316 | $app['orm.em']->remove($user); |
|
| 317 | } |
|
| 318 | ||
| 319 | $app['orm.em']->flush(); |
|
| 320 | ||
| 321 | $app['flashbag']->add( |
|
| 322 | 'success', |
|
| 323 | $app['translator']->trans( |
|
| 324 | 'members-area.users.remove.successText' |
|
| 325 | ) |
|
| 326 | ); |
|
| 327 | } catch (\Exception $e) { |
|
| 328 | $app['flashbag']->add( |
|
| 329 | 'danger', |
|
| 330 | $app['translator']->trans( |
|
| 331 | $e->getMessage() |
|
| 332 | ) |
|
| 333 | ); |
|
| 334 | } |
|
| 335 | ||
| 336 | return $app->redirect( |
|
| 337 | $app['url_generator']->generate('members-area.users') |
|
| 338 | ); |
|
| 339 | } |
|
| 340 | ||
| 341 | return new Response( |
|
| 342 | $app['twig']->render( |
|
| 343 | 'contents/members-area/users/remove.html.twig', |
|
| 344 | array( |
|
| 345 | 'user' => $user, |
|
| 346 | 'users' => $users, |
|
| 347 | 'ids' => $ids, |
|
| 348 | ) |
|
| 349 | ) |
|
| 350 | ); |
|
| 351 | } |
|
| 352 | } |
|
| 353 | ||