...
 
Commits (5)
......@@ -7,3 +7,8 @@ To init database, dependencies etc run
```
./bin/init
```
User / Pass
```
admin / admin
```
......@@ -26,7 +26,8 @@
"symfony/twig-bundle": "*",
"symfony/validator": "*",
"symfony/web-link": "*",
"symfony/yaml": "*"
"symfony/yaml": "*",
"twig/extensions": "^1.5"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0",
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "1c594b6349eec66d9dd6839436128bea",
"content-hash": "af2501860dcde1250ed95de106bf1011",
"packages": [
{
"name": "doctrine/annotations",
......@@ -5205,6 +5205,61 @@
"homepage": "https://symfony.com",
"time": "2018-08-18T16:52:46+00:00"
},
{
"name": "twig/extensions",
"version": "v1.5.2",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig-extensions.git",
"reference": "2c1a86526d0044065220d1b51ac08348bea5ca82"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig-extensions/zipball/2c1a86526d0044065220d1b51ac08348bea5ca82",
"reference": "2c1a86526d0044065220d1b51ac08348bea5ca82",
"shasum": ""
},
"require": {
"twig/twig": "^1.27|^2.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^3.4",
"symfony/translation": "^2.7|^3.4"
},
"suggest": {
"symfony/translation": "Allow the time_diff output to be translated"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.5-dev"
}
},
"autoload": {
"psr-0": {
"Twig_Extensions_": "lib/"
},
"psr-4": {
"Twig\\Extensions\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
}
],
"description": "Common additional features for Twig that do not directly belong in core",
"keywords": [
"i18n",
"text"
],
"time": "2018-05-22T13:26:07+00:00"
},
{
"name": "twig/twig",
"version": "v2.5.0",
......
knp_paginator:
template:
pagination: '@KnpPaginator/Pagination/twitter_bootstrap_v4_pagination.html.twig'
......@@ -2,3 +2,5 @@ twig:
paths: ['%kernel.project_dir%/templates']
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
form_themes: ['bootstrap_4_layout.html.twig']
services:
_defaults:
public: false
autowire: true
autoconfigure: true
# Uncomment any lines below to activate that Twig extension
#Twig\Extensions\ArrayExtension: ~
#Twig\Extensions\DateExtension: ~
Twig\Extensions\IntlExtension: ~
#Twig\Extensions\TextExtension: ~
......@@ -7,6 +7,7 @@ namespace App\Controller;
use App\Entity\Product;
use App\Product\Command\AddNewProduct;
use Doctrine\ORM\EntityManager;
use Knp\Component\Pager\Paginator;
use League\Tactician\CommandBus;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
......@@ -21,14 +22,19 @@ class IndexController extends Controller
$doctrine = $this->get("doctrine.orm.entity_manager");
$query = $doctrine->createQuery("SELECT p FROM " . Product::class . " p");
/** @var Paginator $paginator */
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$query, /* query NOT result */
$request->query->getInt('page', 1)/*page number*/,
10/*limit per page*/
10,/*limit per page*/
["defaultSortFieldName" => "p.creationTime", "defaultSortDirection" => "desc"]
);
return $this->render("products.html.twig", ["pagination" => $pagination]);
return $this->render("products.html.twig", [
"pagination" => $pagination,
"currency" => $this->getCurrencyCode($request)
]);
}
public function form(Request $request, CommandBus $commandBus) {
......
......@@ -16,6 +16,8 @@ class Product
private $description = "";
/** @var int */
private $price = 0;
/** @var float */
private $creationTime;
/**
* Product constructor.
......@@ -24,6 +26,7 @@ class Product
*/
public function __construct(Uuid $uuid = null) {
$this->id = $uuid ?: Uuid::uuid4();
$this->creationTime = \microtime(true);
}
/**
......@@ -75,4 +78,11 @@ class Product
$this->price = $price;
}
/**
* @return float
*/
public function getCreationTime(): float {
return $this->creationTime;
}
}
<?php declare(strict_types=1);
namespace App\Infrastructure\Doctrine\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20180906185706 extends AbstractMigration
{
public function up(Schema $schema) : void
{
$table = $schema->getTable("products");
$table->addColumn("creation_time", "float", ["default" => "0"]);
}
public function down(Schema $schema) : void
{
$schema->getTable("products")->dropColumn("creation_time");
}
}
......@@ -11,5 +11,6 @@
<field name="name"/>
<field name="description"/>
<field name="price" type="integer"/>
<field name="creationTime" type="float" column="creation_time"/>
</entity>
</doctrine-mapping>
......@@ -428,6 +428,15 @@
"symfony/yaml": {
"version": "v4.1.4"
},
"twig/extensions": {
"version": "1.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "1.0",
"ref": "ddb2e0a77773b7fd75d8d649545f174e664500ab"
}
},
"twig/twig": {
"version": "v2.5.0"
},
......
{% extends "base.html.twig" %}
{% block body%}
{% block body %}
<div class="row">
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}
<div class="col">
<h3>Adding new product</h3>
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}
</div>
</div>
{% endblock %}
......@@ -20,7 +20,7 @@
<td>{{ product.id }}</td>
<td>{{ product.name }}</td>
<td>{{ product.description }}</td>
<td>{{ product.price }}</td>
<td>{{ product.price|localizedcurrency(currency) }}</td>
</tr>
{% endfor %}
</tbody>
......