From ae7c8b92782fdc11f021ee0d06091a0d7cbfa0d1 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sun, 15 Jul 2018 08:53:15 +0200 Subject: [PATCH] Implemented color filters to navbar --- src/controller/AbstractDefaultController.php | 5 +- src/controller/product/Product.php | 11 ++-- src/router/link/LinkCollection.php | 27 ++++++++ src/router/link/LinkCollectionInterface.php | 13 ++++ src/template/frames/default.html.twig | 1 + .../frames/structure/navbar.html.twig | 62 ++++++++++--------- src/template/product/list.html.twig | 11 ---- 7 files changed, 83 insertions(+), 47 deletions(-) create mode 100644 src/router/link/LinkCollection.php create mode 100644 src/router/link/LinkCollectionInterface.php diff --git a/src/controller/AbstractDefaultController.php b/src/controller/AbstractDefaultController.php index a1e5c2d..95c5665 100644 --- a/src/controller/AbstractDefaultController.php +++ b/src/controller/AbstractDefaultController.php @@ -21,9 +21,10 @@ class AbstractDefaultController extends AbstractController private function addMenuItems(array $variables): array { if (array_key_exists('menu_items', $variables)) { - throw new \Exception('You aren\'t allowed to define this key!'); + $variables['menu_items'] = array_merge($this->getMenuItems(),$variables['menu_items']); + }else{ + $variables['menu_items'] = $this->getMenuItems(); } - $variables['menu_items'] = $this->getMenuItems(); return $variables; } diff --git a/src/controller/product/Product.php b/src/controller/product/Product.php index 8410e71..56ee5ad 100644 --- a/src/controller/product/Product.php +++ b/src/controller/product/Product.php @@ -5,6 +5,8 @@ use repository\product\Product as ProductRepository; use core\Core; use router\link\Link; use controller\AbstractDefaultController; +use Doctrine\Common\Collections\ArrayCollection; +use router\link\LinkCollection; /** * @@ -35,17 +37,18 @@ final class Product extends AbstractDefaultController implements ProductInterfac } $this->render('product/list.html.twig', [ 'products' => $products, - 'colors' => $this->getColors() + 'colors' => $this->getColors(), + 'menu_items'=>[$this->getColors()] ]); } - private function getColors(): array + private function getColors(): ArrayCollection { - $colors = []; + $colors = new LinkCollection('color filter'); foreach ($this->productRepository->getColors() as $color) { $parameters = $_GET; $parameters['color'] = $color['color']; - $colors[] = new Link($parameters, $color['color']); + $colors->add(new Link($parameters, $color['color'])); } return $colors; } diff --git a/src/router/link/LinkCollection.php b/src/router/link/LinkCollection.php new file mode 100644 index 0000000..3c4da2c --- /dev/null +++ b/src/router/link/LinkCollection.php @@ -0,0 +1,27 @@ +name = $name; + } + + public function getName(): string + { + return $this->name; + } +} + diff --git a/src/router/link/LinkCollectionInterface.php b/src/router/link/LinkCollectionInterface.php new file mode 100644 index 0000000..d2c3895 --- /dev/null +++ b/src/router/link/LinkCollectionInterface.php @@ -0,0 +1,13 @@ +
{% block content %} {% endblock %} diff --git a/src/template/frames/structure/navbar.html.twig b/src/template/frames/structure/navbar.html.twig index b0687c2..6bbe9e1 100644 --- a/src/template/frames/structure/navbar.html.twig +++ b/src/template/frames/structure/navbar.html.twig @@ -1,32 +1,34 @@ \ No newline at end of file diff --git a/src/template/product/list.html.twig b/src/template/product/list.html.twig index 349c65c..1bde3a3 100644 --- a/src/template/product/list.html.twig +++ b/src/template/product/list.html.twig @@ -1,17 +1,6 @@ {% extends 'frames/default.html.twig' %} {% block title %}product overview{% endblock %} {% block content %} - -
{% for product in products %}