@@ 404-435 (lines=32) @@ | ||
401 | * |
|
402 | * @return RedirectResponse |
|
403 | */ |
|
404 | protected function doMoveUpAction(AbstractAdminListConfigurator $configurator, $entityId, Request $request) |
|
405 | { |
|
406 | $em = $this->getEntityManager(); |
|
407 | $sortableField = $configurator->getSortableField(); |
|
408 | $repo = $em->getRepository($configurator->getRepositoryName()); |
|
409 | $item = $repo->find($entityId); |
|
410 | ||
411 | $setter = "set".ucfirst($sortableField); |
|
412 | $getter = "get".ucfirst($sortableField); |
|
413 | ||
414 | $nextItem = $repo->createQueryBuilder('i') |
|
415 | ->where('i.'.$sortableField.' < :weight') |
|
416 | ->setParameter('weight', $item->$getter()) |
|
417 | ->orderBy('i.'.$sortableField, 'DESC') |
|
418 | ->setMaxResults(1) |
|
419 | ->getQuery() |
|
420 | ->getOneOrNullResult(); |
|
421 | if ($nextItem) { |
|
422 | $nextItem->$setter($item->$getter()); |
|
423 | $em->persist($nextItem); |
|
424 | $item->$setter($item->$getter() - 1); |
|
425 | ||
426 | $em->persist($item); |
|
427 | $em->flush(); |
|
428 | } |
|
429 | ||
430 | $indexUrl = $configurator->getIndexUrl(); |
|
431 | ||
432 | return new RedirectResponse( |
|
433 | $this->generateUrl($indexUrl['path'], isset($indexUrl['params']) ? $indexUrl['params'] : array()) |
|
434 | ); |
|
435 | } |
|
436 | ||
437 | protected function doMoveDownAction(AbstractAdminListConfigurator $configurator, $entityId, Request $request) |
|
438 | { |
|
@@ 437-468 (lines=32) @@ | ||
434 | ); |
|
435 | } |
|
436 | ||
437 | protected function doMoveDownAction(AbstractAdminListConfigurator $configurator, $entityId, Request $request) |
|
438 | { |
|
439 | $em = $this->getEntityManager(); |
|
440 | $sortableField = $configurator->getSortableField(); |
|
441 | $repo = $em->getRepository($configurator->getRepositoryName()); |
|
442 | $item = $repo->find($entityId); |
|
443 | ||
444 | $setter = "set".ucfirst($sortableField); |
|
445 | $getter = "get".ucfirst($sortableField); |
|
446 | ||
447 | $nextItem = $repo->createQueryBuilder('i') |
|
448 | ->where('i.'.$sortableField.' > :weight') |
|
449 | ->setParameter('weight', $item->$getter()) |
|
450 | ->orderBy('i.'.$sortableField, 'ASC') |
|
451 | ->setMaxResults(1) |
|
452 | ->getQuery() |
|
453 | ->getOneOrNullResult(); |
|
454 | if ($nextItem) { |
|
455 | $nextItem->$setter($item->$getter()); |
|
456 | $em->persist($nextItem); |
|
457 | $item->$setter($item->$getter() + 1); |
|
458 | ||
459 | $em->persist($item); |
|
460 | $em->flush(); |
|
461 | } |
|
462 | ||
463 | $indexUrl = $configurator->getIndexUrl(); |
|
464 | ||
465 | return new RedirectResponse( |
|
466 | $this->generateUrl($indexUrl['path'], isset($indexUrl['params']) ? $indexUrl['params'] : array()) |
|
467 | ); |
|
468 | } |
|
469 | ||
470 | private function getMaxSortableField($repo, $sort) |
|
471 | { |