mirror of
https://github.com/kevinveenbirkenbach/coding-challenge-online-shop.git
synced 2024-11-22 18:21:04 +01:00
Implemented color filters to navbar
This commit is contained in:
parent
d480467615
commit
ae7c8b9278
@ -21,9 +21,10 @@ class AbstractDefaultController extends AbstractController
|
|||||||
private function addMenuItems(array $variables): array
|
private function addMenuItems(array $variables): array
|
||||||
{
|
{
|
||||||
if (array_key_exists('menu_items', $variables)) {
|
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;
|
return $variables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@ use repository\product\Product as ProductRepository;
|
|||||||
use core\Core;
|
use core\Core;
|
||||||
use router\link\Link;
|
use router\link\Link;
|
||||||
use controller\AbstractDefaultController;
|
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', [
|
$this->render('product/list.html.twig', [
|
||||||
'products' => $products,
|
'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) {
|
foreach ($this->productRepository->getColors() as $color) {
|
||||||
$parameters = $_GET;
|
$parameters = $_GET;
|
||||||
$parameters['color'] = $color['color'];
|
$parameters['color'] = $color['color'];
|
||||||
$colors[] = new Link($parameters, $color['color']);
|
$colors->add(new Link($parameters, $color['color']));
|
||||||
}
|
}
|
||||||
return $colors;
|
return $colors;
|
||||||
}
|
}
|
||||||
|
27
src/router/link/LinkCollection.php
Normal file
27
src/router/link/LinkCollection.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
namespace router\link;
|
||||||
|
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author kevinfrantz
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
final class LinkCollection extends ArrayCollection implements LinkCollectionInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $name;
|
||||||
|
|
||||||
|
public function __construct(string $name){
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
13
src/router/link/LinkCollectionInterface.php
Normal file
13
src/router/link/LinkCollectionInterface.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
namespace router\link;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author kevinfrantz
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
interface LinkCollectionInterface
|
||||||
|
{
|
||||||
|
public function getName():string;
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
|||||||
{% extends "base.html.twig" %}
|
{% extends "base.html.twig" %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{% include 'frames/structure/navbar.html.twig' with menu_items %}
|
{% include 'frames/structure/navbar.html.twig' with menu_items %}
|
||||||
|
<br />
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -1,32 +1,34 @@
|
|||||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||||
<a class="navbar-brand" href="/">Online Shop</a>
|
<a class="navbar-brand" href="/">Online Shop</a>
|
||||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
<button class="navbar-toggler" type="button" data-toggle="collapse"
|
||||||
<span class="navbar-toggler-icon"></span>
|
data-target="#navbarSupportedContent"
|
||||||
</button>
|
aria-controls="navbarSupportedContent" aria-expanded="false"
|
||||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
aria-label="Toggle navigation">
|
||||||
<ul class="navbar-nav mr-auto">
|
<span class="navbar-toggler-icon"></span>
|
||||||
{% for item in menu_items %}
|
</button>
|
||||||
<!--<li class="nav-item active">
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||||
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
|
<ul class="navbar-nav mr-auto">
|
||||||
</li>
|
{% for item in menu_items %}
|
||||||
-->
|
{% if item.name %}
|
||||||
<li class="nav-item {% if item.active %}active{% endif %}">
|
{% if item.url %}
|
||||||
<a class="nav-link" href="{{ item.url }}">{{ item.name }}</a>
|
<li class="nav-item {% if item.active %}active{% endif %}"><a
|
||||||
</li>
|
class="nav-link" href="{{ item.url }}"> {{ item.name }}
|
||||||
<!--
|
</a></li>
|
||||||
<li class="nav-item dropdown">
|
{% elseif item.toArray %}
|
||||||
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
<li class="nav-item dropdown"><a
|
||||||
Dropdown
|
class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
|
||||||
</a>
|
role="button" data-toggle="dropdown" aria-haspopup="true"
|
||||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
aria-expanded="false"> {{ item.name }}
|
||||||
<a class="dropdown-item" href="#">Action</a>
|
</a>
|
||||||
<a class="dropdown-item" href="#">Another action</a>
|
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||||
<div class="dropdown-divider"></div>
|
{%for link in item %}
|
||||||
<a class="dropdown-item" href="#">Something else here</a>
|
<a class="dropdown-item {% if link.active %}active{% endif %}" href="{{ link.url }}">{{ link.name }}</a>
|
||||||
</div>
|
{% endfor %}
|
||||||
</li>
|
</div></li>
|
||||||
-->
|
{% endif %}
|
||||||
{% endfor %}
|
{% endif %}
|
||||||
</ul>
|
|
||||||
</div>
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</nav>
|
</nav>
|
@ -1,17 +1,6 @@
|
|||||||
{% extends 'frames/default.html.twig' %}
|
{% extends 'frames/default.html.twig' %}
|
||||||
{% block title %}product overview{% endblock %}
|
{% block title %}product overview{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="dropdown">
|
|
||||||
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
||||||
filter by color:
|
|
||||||
</button>
|
|
||||||
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
|
|
||||||
{% for color in colors %}
|
|
||||||
<a class="dropdown-item" href="{{ color.getUrl }}">{{ color.getName }}</a>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<hr />
|
|
||||||
<div class="card-columns">
|
<div class="card-columns">
|
||||||
{% for product in products %}
|
{% for product in products %}
|
||||||
<div class="card" style="width: 18rem;">
|
<div class="card" style="width: 18rem;">
|
||||||
|
Loading…
Reference in New Issue
Block a user