diff --git a/src/controller/product/Product.php b/src/controller/product/Product.php index 3483521..a2c5701 100644 --- a/src/controller/product/Product.php +++ b/src/controller/product/Product.php @@ -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 {} diff --git a/src/entity/image/ImageInterface.php b/src/entity/image/ImageInterface.php index c9d306e..5e84171 100644 --- a/src/entity/image/ImageInterface.php +++ b/src/entity/image/ImageInterface.php @@ -21,6 +21,6 @@ interface ImageInterface /** * @return string */ - public function getImageThumbnail():string; + public function getThumbnail():string; } diff --git a/src/entity/image/UrlImage.php b/src/entity/image/UrlImage.php index 0f8fe0d..eff0d14 100644 --- a/src/entity/image/UrlImage.php +++ b/src/entity/image/UrlImage.php @@ -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 diff --git a/src/entity/image/UrlImageTest.php b/src/entity/image/UrlImageTest.php index 48e83af..a0526e6 100644 --- a/src/entity/image/UrlImageTest.php +++ b/src/entity/image/UrlImageTest.php @@ -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()); } } diff --git a/src/repository/product/Product.php b/src/repository/product/Product.php index 5e94dd8..bc1e219 100644 --- a/src/repository/product/Product.php +++ b/src/repository/product/Product.php @@ -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 {} } \ No newline at end of file diff --git a/src/repository/product/ProductInterface.php b/src/repository/product/ProductInterface.php index c781d75..7c6c036 100644 --- a/src/repository/product/ProductInterface.php +++ b/src/repository/product/ProductInterface.php @@ -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; diff --git a/src/router/Button.php b/src/router/Button.php new file mode 100644 index 0000000..54cf207 --- /dev/null +++ b/src/router/Button.php @@ -0,0 +1,18 @@ +link; + } +} + diff --git a/src/router/Link.php b/src/router/Link.php index 0a7668a..4c3c544 100644 --- a/src/router/Link.php +++ b/src/router/Link.php @@ -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 ;) diff --git a/src/router/Router.php b/src/router/Router.php index 8a69f50..7143a8a 100644 --- a/src/router/Router.php +++ b/src/router/Router.php @@ -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(); diff --git a/src/setup/monking/product.csv b/src/setup/monking/product.csv index f315e49..ce21563 100644 --- a/src/setup/monking/product.csv +++ b/src/setup/monking/product.csv @@ -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 diff --git a/src/template/product/basket/basket.html.php b/src/template/product/basket/basket.html.php deleted file mode 100644 index e69de29..0000000 diff --git a/src/template/product/basket/list.html.php b/src/template/product/basket/list.html.php deleted file mode 100644 index b3d9bbc..0000000 --- a/src/template/product/basket/list.html.php +++ /dev/null @@ -1 +0,0 @@ - + {% for product in products %} +
+ Card image cap +
+
+ {{ product.getName }} ({{ product.getColor }}) +
+ + price: +
    +
  • {{ product.getPrice.getNetto.getFloat }} {{ product.getPrice.getNetto.getSymbol }} (net)
  • +
  • {{ product.getPrice.getGross.getFloat }} {{ product.getPrice.getGross.getSymbol }} (gross)
  • +
+
+ Add to basket +
+
+ {% endfor %} + +{% endblock %} \ No newline at end of file diff --git a/src/template/product/overview/list.html.php b/src/template/product/overview/list.html.php deleted file mode 100644 index b3d9bbc..0000000 --- a/src/template/product/overview/list.html.php +++ /dev/null @@ -1 +0,0 @@ -