Skip to content

Commit

Permalink
Merge pull request #8 from thomas-claireau/create-uml-diagrams
Browse files Browse the repository at this point in the history
add uml diagrams -> use case and sequence
  • Loading branch information
thomas-claireau committed Feb 16, 2020
2 parents 6ef109f + 671f7f1 commit 6b687b1
Show file tree
Hide file tree
Showing 52 changed files with 516 additions and 61 deletions.
9 changes: 8 additions & 1 deletion .gitignore
@@ -1,8 +1,15 @@
wireframes.pdf
CDC.pdf
deploy

# Public image
public/images/figures
public/images/figures/*
!public/images/fixtures/image-1.jpg
!public/images/fixtures/image-2.jpg
!public/images/fixtures/image-3.jpg
!public/images/fixtures/image-4.jpg
!public/images/fixtures/image-5.jpg
!public/images/fixtures/image-6.jpg

# Files ignored
composer.lock
Expand Down
75 changes: 65 additions & 10 deletions README.md
@@ -1,9 +1,64 @@
# [PHP] - P6 Openclassrooms - Développez de A à Z le site communautaire SnowTricks

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/38908a1ea0204cd39996400db31ba8eb)](https://www.codacy.com/manual/thomas-claireau/PHP-P6-Openclassrooms?utm_source=github.com&utm_medium=referral&utm_content=thomas-claireau/PHP-P6-Openclassrooms&utm_campaign=Badge_Grade)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/38908a1ea0204cd39996400db31ba8eb)](https://www.codacy.com/manual/thomas-claireau/PHP-P6-Openclassrooms?utm_source=github.com&utm_medium=referral&utm_content=thomas-claireau/PHP-P6-Openclassrooms&utm_campaign=Badge_Grade)

[![Maintainability](https://api.codeclimate.com/v1/badges/56882df21a146f2e28bf/maintainability)](https://codeclimate.com/github/thomas-claireau/PHP-P6-Openclassrooms/maintainability)

Démo du projet, [c'est par ici 👋](http://snowtricks.thomas-claireau.fr/)

## Installation du projet

Via Composer :

```text
composer create-project thomas-claireau/snowtricks:dev-master
```

Dans le cas où vous téléchargez directement le projet (ou encore avec `git clone`), effectuez un `composer install` à la racine du projet.

Installez ensuite les dépendances front du projet. Placez-vous à la racine du projet :

```text
npm install
```

### Remarque

#### Accès base de données

Le projet est livré sur Packagist sans base de données. Cela signifie qu'il faut que vous ajoutiez votre configuration, dans le fichier `.env`, dans la partie `DATABASE_URL`.

#### Injection SQL et structure du projet

Pour obtenir une structure similaire à mon projet au niveau de la base de données, je vous joins aussi dans le dossier `~src/Migrations/` les versions de migrations que j'ai utilisées. Vous pouvez donc recréer la base de données en effectuant la commande suivante, à la racine du projet :

```text
php bin/console doctrine:migrations:migrate
```

Après avoir créer votre base de données, vous pouvez également injecter un jeu de données en effectuant la commande suivante :

```text
php bin/console doctrine:fixtures:load
```

### Lancer le projet

A la racine du projet :

- Pour lancer le serveur de développement, effectuez un `npm run dev-server`.
- Pour lancer le serveur de symfony, effectuez un `php bin/console server:run`.

### Site en production

Pour voir une version du site en production, suivez l'[url suivante](http://snowtricks.thomas-claireau.fr/).

### Envoi des mails

Si vous souhaitez utiliser un serveur de mail afin d'envoyer des mails, vous pouvez le configurer dans le fichier `.env` à la racine du projet, dans la partie `MAILER_URL`

Sachez que vous pouvez aussi utiliser [maildev](https://www.npmjs.com/package/maildev) pour simuler l'envoi des mails.

## Contexte

Jimmy Sweat est un entrepreneur ambitieux passionné de snowboard. Son objectif est la création d'un site collaboratif pour faire connaitre ce sport auprès du grand public et aider à l'apprentissage des figures (tricks).
Expand All @@ -14,18 +69,18 @@ Pour ce projet, nous allons nous concentrer sur la création technique du site p

## Description du besoin

Vous êtes chargé de développer le site répondant aux besoins de Jimmy. Vous devez ainsi implémenter les fonctionnalités suivantes :
Vous êtes chargé de développer le site répondant aux besoins de Jimmy. Vous devez ainsi implémenter les fonctionnalités suivantes :

- un annuaire des figures de snowboard. Vous pouvez vous inspirer de la liste des figures sur Wikipédia. Contentez-vous d'intégrer 10 figures, le reste sera saisi par les internautes ;
- la gestion des figures (création, modification, consultation) ;
- un espace de discussion commun à toutes les figures.
- un annuaire des figures de snowboard. Vous pouvez vous inspirer de la liste des figures sur Wikipédia. Contentez-vous d'intégrer 10 figures, le reste sera saisi par les internautes ;
- la gestion des figures (création, modification, consultation) ;
- un espace de discussion commun à toutes les figures.

Pour implémenter ces fonctionnalités, vous devez créer les pages suivantes :

- la page d’accueil où figurera la liste des figures ;
- la page de création d'une nouvelle figure ;
- la page de modification d'une figure ;
- la page de présentation d’une figure (contenant l’espace de discussion commun autour d’une figure).
- la page d’accueil où figurera la liste des figures ;
- la page de création d'une nouvelle figure ;
- la page de modification d'une figure ;
- la page de présentation d’une figure (contenant l’espace de discussion commun autour d’une figure).

## Nota Bene

Expand All @@ -37,6 +92,6 @@ Le design du site web est laissé complètement libre, attention cependant à re

En premier lieu il vous faudra écrire l’ensemble des issues/tickets afin de découper votre travail méthodiquement et vous assurer que l’ensemble du besoin client soit bien compris avec votre mentor. Les tickets/issues seront écrits dans un repository Github que vous aurez créé au préalable.

L’ensemble des figures de snowboard doivent être présentes à l’initialisation de l’application web. Vous utiliserez un bundle externe pour charger ces données.
L’ensemble des figures de snowboard doivent être présentes à l’initialisation de l’application web. Vous utiliserez un bundle externe pour charger ces données.

## ⌛ Projet en cours...
4 changes: 4 additions & 0 deletions assets/css/app.scss
Expand Up @@ -22,6 +22,10 @@ h1 {
}
}

.hide {
display: none;
}

.lead {
font-size: 1.75rem;

Expand Down
Binary file added assets/images/image-1.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/image-2.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/image-3.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/image-4.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/image-5.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/image-6.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions assets/js/app.js
Expand Up @@ -48,3 +48,16 @@ $('.scroll').on('click', function(event) {
$(document).ready(function() {
$('select').select2();
});

document.onreadystatechange = function() {
if (document.readyState == 'complete') {
// ===== FOOTER TOUJOURS EN BAS DE L'ECRAN ===== //
const footer = document.querySelector('footer');

if (footer) {
var heightFooter = document.querySelector('footer').offsetHeight;
var contentPage = document.querySelector('#page-body');
contentPage.style.minHeight = 'calc(100vh - ' + heightFooter + 'px)';
}
}
};
12 changes: 8 additions & 4 deletions composer.json
@@ -1,6 +1,6 @@
{
"name": "thomas-claireau/developpez-le-site-communautaire-snowtricks",
"version": "0.9.0",
"name": "thomas-claireau/snowtricks",
"version": "1.0.0",
"description": "package manager for my project",
"type": "project",
"keywords": [
Expand All @@ -19,6 +19,7 @@
"role": "Fullstack web developer"
}
],
"minimum-stability": "dev",
"require": {
"php": "^7.1.3",
"ext-ctype": "*",
Expand All @@ -28,13 +29,16 @@
"knplabs/knp-paginator-bundle": "4.1.1",
"liip/imagine-bundle": "2.0.0",
"sensio/framework-extra-bundle": "^5.1",
"symfony/apache-pack": "dev-master",
"symfony/asset": "4.2.*",
"symfony/cache": "4.2.12",
"symfony/console": "4.2.*",
"symfony/dotenv": "4.2.*",
"symfony/expression-language": "4.2.*",
"symfony/flex": "^1.3.1",
"symfony/form": "4.2.*",
"symfony/framework-bundle": "4.2.*",
"symfony/http-foundation": "4.2.12",
"symfony/monolog-bundle": "^3.1",
"symfony/orm-pack": "*",
"symfony/process": "4.2.*",
Expand All @@ -48,8 +52,8 @@
"symfony/webpack-encore-bundle": "^1.7",
"symfony/yaml": "4.2.*",
"vich/uploader-bundle": "1.11.0",
"symfony/http-foundation": "4.2.12",
"symfony/cache": "4.2.12"
"doctrine/doctrine-migrations-bundle": "^2.0",
"doctrine/migrations": "2.1"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "3.0.2",
Expand Down
66 changes: 66 additions & 0 deletions public/.htaccess
@@ -0,0 +1,66 @@
# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex index.php

# By default, Apache does not evaluate symbolic links if you did not enable this
# feature in your server configuration. Uncomment the following line if you
# install assets as symlinks or if you experience problems related to symlinks
# when compiling LESS/Sass/CoffeScript assets.
# Options FollowSymlinks

# Disabling MultiViews prevents unwanted negotiation, e.g. "/index" should not resolve
# to the front controller "/index.php" but be rewritten to "/index.php/index".
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On

# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the index.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]

# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]

# Redirect to URI without front controller to prevent duplicate content
# (with and without `/index.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the start page because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]

# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
# Rewrite all other queries to the front controller.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 307 ^/$ /index.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
3 changes: 3 additions & 0 deletions src/Controller/Admin/AdminFigureController.php
Expand Up @@ -52,8 +52,11 @@ public function new(Request $request)
return $this->redirectToRoute('home');
}

$lastId = $this->repository->getLastId()->getId();

return $this->render('admin/figure/new.html.twig', [
'figure' => $figure,
'idFigure' => $lastId + 1,
'form' => $form->createView(),
'current_menu' => 'admin.figure.new',
]);
Expand Down
9 changes: 5 additions & 4 deletions src/Controller/FigureController.php
Expand Up @@ -46,8 +46,8 @@ public function __construct(CommentRepository $commentRepository, FiguresReposit
public function show(Figures $figure, string $slug, Request $request): Response
{
$user = $this->getUser();
$comments = $this->commentRepository->findItems();
$nbGroups = round($this->commentRepository->countAll() / 10);
$comments = $this->commentRepository->findItems(1, $figure->getId());
$nbGroups = round($this->commentRepository->countAll($figure->getId()) / 10);

if ($user) {
$comment = new Comment();
Expand Down Expand Up @@ -102,10 +102,11 @@ public function ajaxLoadItems(Request $request)
{
$params = $request->attributes->get('_route_params');
$index = (int) $params['index'];
$nbGroups = round($this->commentRepository->countAll() / 10);
$idFigure = $params['id'];
$nbGroups = round($this->commentRepository->countAll($idFigure) / 10);

if (is_int($index) && $index > 1) {
$moreComments = (array) $this->commentRepository->findMoreItems($index);
$moreComments = (array) $this->commentRepository->findMoreItems($index, $idFigure);
$htmlData = [];

if ($moreComments) {
Expand Down
1 change: 1 addition & 0 deletions src/DataFixtures/FiguresFixtures.php
Expand Up @@ -82,6 +82,7 @@ public function load(ObjectManager $manager)
$figure->setUpdatedAt($date);
$figure->setDescription($faker->sentences(15, true));
$figure->addCategory($categoriesObj[random_int(0, 3)]);
$figure->setMainImage('image-' . random_int(1, 6) . '.jpg');
$manager->persist($figure);

for ($i = 1; $i <= 3; $i++) {
Expand Down
20 changes: 13 additions & 7 deletions src/Repository/CommentRepository.php
Expand Up @@ -30,32 +30,34 @@ public function resetIndex()
/**
* @return Comment[]
*/
public function findItems(int $index = 1): array
public function findItems(int $index = 1, $idFigure): array
{
return $this->getQueryDesc($index)
return $this->getQueryDesc($index, $idFigure)
->getQuery()
->getResult();
}

public function findMoreItems(int $index): array
public function findMoreItems(int $index, $idFigure): array
{
if ($index !== 1) {
return $this->getQueryDesc($index)
return $this->getQueryDesc($index, $idFigure)
->getQuery()
->getResult(Query::HYDRATE_ARRAY);
}
}

public function countAll()
public function countAll($idFigure)
{
return intval($this->createQueryBuilder('p')
->select('COUNT(p)')
->where('p.figure = :id_figure')
->setParameter('id_figure', $idFigure)
->getQuery()->getSingleScalarResult());
}

private function getQueryDesc(int $index)
private function getQueryDesc(int $index, $idFigure)
{
$total = $this->countAll();
$total = $this->countAll($idFigure);
$nbResultsPerPage = 10;


Expand All @@ -66,6 +68,8 @@ private function getQueryDesc(int $index)
if (!$total || !$nbGroups) {
return $this->createQueryBuilder('p')
->orderBy('p.created_at', 'DESC')
->where('p.figure = :id_figure')
->setParameter('id_figure', $idFigure)
->setMaxResults($nbResultsPerPage);
}

Expand All @@ -81,6 +85,8 @@ private function getQueryDesc(int $index)

return $this->createQueryBuilder('p')
->orderBy('p.created_at', 'DESC')
->where('p.figure = :id_figure')
->setParameter('id_figure', $idFigure)
->setFirstResult($interval['start'])
->setMaxResults($nbResultsPerPage);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Repository/FiguresRepository.php
Expand Up @@ -52,6 +52,11 @@ public function countAll()
->getQuery()->getSingleScalarResult());
}

public function getLastId()
{
return $this->findOneBy([], ['id' => 'desc']);
}


private function getQueryDesc(int $index)
{
Expand Down

0 comments on commit 6b687b1

Please sign in to comment.