Implemented product list

This commit is contained in:
Kevin Frantz 2018-07-14 23:14:06 +02:00
parent 560c70de38
commit 1bc7219caa
17 changed files with 92 additions and 50 deletions

View File

@ -2,6 +2,7 @@
namespace controller\product;
use controller\AbstractController;
use repository\product\Product as ProductRepository;
/**
*
@ -11,7 +12,10 @@ use controller\AbstractController;
final class Product extends AbstractController implements ProductInterface
{
public function list(): void
{}
{
$productRepository = new ProductRepository($this->core->getDatabase());
$this->render('product/list.html.twig',['products'=>$productRepository->getAllProducts()->toArray()]);
}
public function colorFilter(string $color): void
{}

View File

@ -21,6 +21,6 @@ interface ImageInterface
/**
* @return string
*/
public function getImageThumbnail():string;
public function getThumbnail():string;
}

View File

@ -17,9 +17,9 @@ final class UrlImage implements ImageInterface
* {@inheritDoc}
* @see \entity\image\ImageInterface::getImageThumbnail()
*/
public function getImageThumbnail(): string
public function getThumbnail(): string
{
return $this->path;
return str_replace('200/300', '200/200', $this->path);
}
public function getImage(): string

View File

@ -10,7 +10,9 @@ use PHPUnit\Framework\TestCase;
*/
class UrlImageTest extends TestCase
{
const IMAGE_URL = 'http://dummy.image/test.jpg';
const IMAGE_URL = 'http://dummy.image/200/300/test.jpg';
const IMAGE_THUMB_URL = 'http://dummy.image/200/200/test.jpg';
/**
* @var UrlImage
@ -27,7 +29,7 @@ class UrlImageTest extends TestCase
}
public function testThumbnail():void{
$this->assertEquals(self::IMAGE_URL, $this->urlImage->getImageThumbnail());
$this->assertEquals(self::IMAGE_THUMB_URL, $this->urlImage->getThumbnail());
}
}

View File

@ -37,23 +37,30 @@ final class Product extends AbstractRepository implements ProductInterface
$statement->execute([
$product->getName(),
$product->getColor(),
$product->getPrice()->getNetto()->getCents(),
$product->getPrice()->getTax(),
$product->getImage()->getImage(),
$product->getPrice()
->getNetto()
->getCents(),
$product->getPrice()
->getTax(),
$product->getImage()
->getImage()
]);
}
}
public function getAllProducts(): ArrayCollection
{
$statement = $this->database->prepare('SELECT * FROM '.self::TABLE.';');
$statement = $this->database->prepare('SELECT * FROM ' . self::TABLE . ';');
$statement->execute();
foreach ($statement->fetchAll() as $product){
$products = new ArrayCollection();
foreach ($statement->fetchAll() as $product) {
$products->add($this->createProduct($product['name'], $product['color'], $product['price'], $product['tax'], $product['image']));
}
return $products;
}
static public function createProduct(string $name, string $color, int $cents, int $tax, string $imagePath):ProductEntity{
static public function createProduct(string $name, string $color, int $cents, int $tax, string $imagePath): ProductEntity
{
$product = new ProductEntity();
$product->setName($name);
$product->setColor($color);
@ -69,9 +76,6 @@ final class Product extends AbstractRepository implements ProductInterface
return $product;
}
public function deleteAllProducts(): void
{}
public function getProductById(int $id): ProductEntityInterface
{}
}

View File

@ -12,11 +12,6 @@ interface ProductInterface
{
public function getAllProducts():ArrayCollection;
/**
* Just exists for maintaining reasons ;)
*/
public function deleteAllProducts():void;
public function addProducts(ArrayCollection $products):void;
public function getProductById(int $id):ProductEntityInterface;

18
src/router/Button.php Normal file
View File

@ -0,0 +1,18 @@
<?php
namespace router;
/**
* A button containes out of a link and post parameters
* @author kevinfrantz
* @deprecated
*
*/
class Button
{
private $link;
public function __construct(Link $link,array $post){
$this->link;
}
}

View File

@ -2,11 +2,11 @@
namespace router;
/**
*
* A link containes out of get parameters
* @author kevinfrantz
*
*/
class Link
final class Link
{
/**
* ArrayCollection would be nicer but I have to save time ;)

View File

@ -50,7 +50,7 @@ final class Router implements RouterInterface
return $userController->register();
}
case 'product':
$productController = new Product();
$productController = new Product($this->core);
switch ($this->get['action']) {
case 'list':
return $productController->list();

View File

@ -1,21 +1,21 @@
name,color,price_eur,tax,image
Continental,Goldenrod,73.19,19,https://picsum.photos/200/300/?random
Mustang,Goldenrod,49.75,20,https://picsum.photos/200/300/?random
Grand Vitara,Turquoise,19.06,21,https://picsum.photos/200/300/?random
Pajero,Puce,35.7,22,https://picsum.photos/200/300/?random
EXP,Aquamarine,26.13,23,https://picsum.photos/200/300/?random
Golf,Fuscia,50.64,24,https://picsum.photos/200/300/?random
Explorer Sport Trac,Puce,76.08,25,https://picsum.photos/200/300/?random
Rally Wagon 2500,Red,56.14,26,https://picsum.photos/200/300/?random
J,Turquoise,44.02,27,https://picsum.photos/200/300/?random
Astro,Turquoise,33.65,28,https://picsum.photos/200/300/?random
Sierra 2500,Purple,26.97,29,https://picsum.photos/200/300/?random
Continental GT,Fuscia,30.26,30,https://picsum.photos/200/300/?random
Continental GT,Mauv,63.78,31,https://picsum.photos/200/300/?random
Esteem,Goldenrod,61.47,32,https://picsum.photos/200/300/?random
LS,Aquamarine,23.38,33,https://picsum.photos/200/300/?random
Outlook,Teal,66.99,34,https://picsum.photos/200/300/?random
911,Orange,25.83,35,https://picsum.photos/200/300/?random
Jetta,Green,42.49,36,https://picsum.photos/200/300/?random
Bronco,Pink,60.81,37,https://picsum.photos/200/300/?random
Savana,Yellow,63.5,38,https://picsum.photos/200/300/?random
Continental,Goldenrod,73.19,19,https://picsum.photos/200/300/?image=1
Mustang,Goldenrod,49.75,20,https://picsum.photos/200/300/?image=2
Grand Vitara,Turquoise,19.06,21,https://picsum.photos/200/300/?image=3
Pajero,Puce,35.7,22,https://picsum.photos/200/300/?image=4
EXP,Aquamarine,26.13,23,https://picsum.photos/200/300/?image=5
Golf,Fuscia,50.64,24,https://picsum.photos/200/300/?image=6
Explorer Sport Trac,Puce,76.08,25,https://picsum.photos/200/300/?image=7
Rally Wagon 2500,Red,56.14,26,https://picsum.photos/200/300/?image=8
J,Turquoise,44.02,27,https://picsum.photos/200/300/?image=9
Astro,Turquoise,33.65,28,https://picsum.photos/200/300/?image=10
Sierra 2500,Purple,26.97,29,https://picsum.photos/200/300/?image=11
Continental GT,Fuscia,30.26,30,https://picsum.photos/200/300/?image=12
Continental GT,Mauv,63.78,31,https://picsum.photos/200/300/?image=13
Esteem,Goldenrod,61.47,32,https://picsum.photos/200/300/?image=14
LS,Aquamarine,23.38,33,https://picsum.photos/200/300/?image=15
Outlook,Teal,66.99,34,https://picsum.photos/200/300/?image=16
911,Orange,25.83,35,https://picsum.photos/200/300/?image=17
Jetta,Green,42.49,36,https://picsum.photos/200/300/?image=18
Bronco,Pink,60.81,37,https://picsum.photos/200/300/?image=19
Savana,Yellow,63.5,38,https://picsum.photos/200/300/?image=20

1 name color price_eur tax image
2 Continental Goldenrod 73.19 19 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=1
3 Mustang Goldenrod 49.75 20 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=2
4 Grand Vitara Turquoise 19.06 21 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=3
5 Pajero Puce 35.7 22 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=4
6 EXP Aquamarine 26.13 23 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=5
7 Golf Fuscia 50.64 24 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=6
8 Explorer Sport Trac Puce 76.08 25 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=7
9 Rally Wagon 2500 Red 56.14 26 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=8
10 J Turquoise 44.02 27 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=9
11 Astro Turquoise 33.65 28 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=10
12 Sierra 2500 Purple 26.97 29 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=11
13 Continental GT Fuscia 30.26 30 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=12
14 Continental GT Mauv 63.78 31 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=13
15 Esteem Goldenrod 61.47 32 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=14
16 LS Aquamarine 23.38 33 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=15
17 Outlook Teal 66.99 34 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=16
18 911 Orange 25.83 35 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=17
19 Jetta Green 42.49 36 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=18
20 Bronco Pink 60.81 37 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=19
21 Savana Yellow 63.5 38 https://picsum.photos/200/300/?random https://picsum.photos/200/300/?image=20

View File

@ -1 +0,0 @@
<?php

View File

@ -1 +0,0 @@
<?php

View File

@ -0,0 +1,24 @@
{% extends 'frames/default.html.twig' %}
{% block title %}product overview{% endblock %}
{% block content %}
<div class="card-columns">
{% for product in products %}
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="{{ product.getImage.getThumbnail }}" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">
{{ product.getName }} <i>({{ product.getColor }})</i>
</h5>
<span class="card-text">
<b>price:</b>
<ul>
<li>{{ product.getPrice.getNetto.getFloat }} {{ product.getPrice.getNetto.getSymbol }} <i>(net)</i></li>
<li>{{ product.getPrice.getGross.getFloat }} {{ product.getPrice.getGross.getSymbol }} <i>(gross)</i></li>
</ul>
</span>
<a href="#" class="btn btn-primary">Add to basket</a>
</div>
</div>
{% endfor %}
</div>
{% endblock %}

View File

@ -1 +0,0 @@
<?php

View File

@ -1 +0,0 @@
<?php

View File

@ -1 +0,0 @@
<?php