-
Notifications
You must be signed in to change notification settings - Fork 13
Úkol 2 - Vojtěch Havlíček #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <div class="col-sm-12 col-md-12 col-lg-12"> | ||
| {% if totalPages > 1 %} | ||
| <ul class="pagination pagination-md"> | ||
| {% for i in 1..totalPages %} | ||
| <li {{ currentPage==i ? "class=\"active\"" }}> | ||
| <a href="{{ path("homepage", {"page":i}) }}">{{i}}</a> | ||
| </li> | ||
| {% endfor %} | ||
| </ul> | ||
| {% endif %} | ||
| </div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,21 @@ | |
| # Dump of table category | ||
| # ------------------------------------------------------------ | ||
|
|
||
| DROP TABLE IF EXISTS `category`; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Právě kvůli tomu slouží bin/console doctrine:schema:create a bin/console doctrine:schema:drop. To ti umožňuje vždy generovat správnou strukturu DB a tohle ti potom jen naplní daty tabulky. |
||
|
|
||
| CREATE TABLE `category` ( | ||
| `id` int(11) NOT NULL AUTO_INCREMENT, | ||
| `parent_category_id` int(11) NOT NULL, | ||
| `top_category_id` int(11) NOT NULL, | ||
| `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL, | ||
| `slug` varchar(255) COLLATE utf8_unicode_ci NOT NULL, | ||
| `rank` int(11) NOT NULL, | ||
| `left` int(11) NOT NULL, | ||
| `right` int(11) NOT NULL, | ||
| `level` int(11) NOT NULL, | ||
| PRIMARY KEY (`id`) | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; | ||
|
|
||
| LOCK TABLES `category` WRITE; | ||
| /*!40000 ALTER TABLE `category` DISABLE KEYS */; | ||
|
|
||
|
|
@@ -54,6 +69,19 @@ UNLOCK TABLES; | |
| # Dump of table product | ||
| # ------------------------------------------------------------ | ||
|
|
||
| DROP TABLE IF EXISTS `product`; | ||
|
|
||
| CREATE TABLE `product` ( | ||
| `id` int(11) NOT NULL AUTO_INCREMENT, | ||
| `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL, | ||
| `image` varchar(255) COLLATE utf8_unicode_ci NOT NULL, | ||
| `slug` varchar(255) COLLATE utf8_unicode_ci NOT NULL, | ||
| `description` varchar(255) COLLATE utf8_unicode_ci NOT NULL, | ||
| `price` double NOT NULL, | ||
| `rank` int(11) NOT NULL, | ||
| PRIMARY KEY (`id`) | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; | ||
|
|
||
| LOCK TABLES `product` WRITE; | ||
| /*!40000 ALTER TABLE `product` DISABLE KEYS */; | ||
|
|
||
|
|
@@ -111,6 +139,14 @@ UNLOCK TABLES; | |
| # Dump of table product_category | ||
| # ------------------------------------------------------------ | ||
|
|
||
| DROP TABLE IF EXISTS `product_category`; | ||
|
|
||
| CREATE TABLE `product_category` ( | ||
| `product_id` int(11) NOT NULL, | ||
| `category_id` int(11) NOT NULL, | ||
| PRIMARY KEY (`product_id`) | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; | ||
|
|
||
| LOCK TABLES `product_category` WRITE; | ||
| /*!40000 ALTER TABLE `product_category` DISABLE KEYS */; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,25 +5,36 @@ | |
| use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | ||
| use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
| use Symfony\Component\Routing\Annotation\Route; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
|
|
||
| /** | ||
| * @author Jan Klat <jenik@klatys.cz> | ||
| */ | ||
| class HomepageController extends Controller | ||
| { | ||
| /** | ||
| * @Route("/", name="homepage") | ||
| * @Route("/{page}", name="homepage") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pozor na tohle, http://localhost:8000/a ti spadne |
||
| * @Template("homepage/homepage.html.twig") | ||
| * | ||
| * @param Request $request | ||
| * @return array | ||
| */ | ||
| public function homepageAction() | ||
| public function homepageAction(Request $request) | ||
| { | ||
| $perPage = 6; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tohle je hodnota, která by měla být spíše v konfiguraci |
||
| $currentPage = $request->attributes->get("page"); | ||
| $totalProducts = $this->getDoctrine()->getRepository(Product::class)->findBy([]); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tady pozor, taháš celé produkty jen na to abys je spočítal... teď jich je 44, když jich bude x tisíc, bude to drahé... |
||
| $totalPages = ceil(count($totalProducts)/$perPage); | ||
|
|
||
|
|
||
| return [ | ||
| "products" => $this->getDoctrine()->getRepository(Product::class)->findBy( | ||
| [], | ||
| [ | ||
| "rank" => "desc" | ||
| ], | ||
| 21 | ||
| $perPage, // limit of products per page | ||
| $perPage * ($currentPage - 1) // offset of products | ||
| ), | ||
| "categories" => $this->getDoctrine()->getRepository(Category::class)->findBy( | ||
| [ | ||
|
|
@@ -33,7 +44,9 @@ public function homepageAction() | |
| "rank" => "desc", | ||
| ] | ||
| ), | ||
| "totalPages" => $totalPages, | ||
| "currentPage" => $currentPage, | ||
| ]; | ||
| } | ||
|
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Asi bych takový argument nepředával - spíš pak někde uděláš chybu, navíc url
/1není nijak hezká