moved sorting logic from template to sorter.

This commit is contained in:
Paweł Jędrzejewski 2011-11-10 21:31:03 +01:00
parent b525265d88
commit 7b7d4d3021
3 changed files with 15 additions and 1 deletions

View file

@ -42,7 +42,8 @@ class AddressController extends ContainerAware
return $this->container->get('templating')->renderResponse('SyliusAddressingBundle:Backend/Address:list.html.twig', array(
'addresses' => $addresses,
'paginator' => $paginator
'paginator' => $paginator,
'sorter' => $addressSorter
));
}

View file

@ -54,4 +54,16 @@ class AddressSorter extends ContainerAware implements SorterInterface
/** @var QueryBuilder */
$sortable->orderBy('a.' . $sortProperty, $sortOrder);
}
public function getOrder()
{
$sortOrder = $this->container->get('request')->query->get('order', 'ASC');
if (!in_array($sortOrder, array('ASC', 'DESC'))) {
return;
}
return ($sortOrder == 'ASC') ? 'DESC' : 'ASC';
}
}

View file

@ -19,4 +19,5 @@ namespace Sylius\Bundle\AddressingBundle\Sorting;
interface SorterInterface
{
function sort($sortable);
function getOrder();
}