Skip to content
Snippets Groups Projects
Commit 14223823 authored by GROSJEAN Herve's avatar GROSJEAN Herve
Browse files

Ajout de commentaire

parent 6d36ca1d
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@ use \App\Application\Actions\User\MonCompteAction as MonCompteAction;
use \App\Application\Actions\User\ModifierInfosUtilisateurAction as ModifierInfosUtilisateurAction;
use \App\Application\Actions\Galerie\GalerieListAction as GalerieListAction;
use \App\Application\Actions\Photos\AjoutPhotoAction as AjoutPhotoAction;
use \App\Application\Actions\Photos\CommentaireAction as CommentaireAction;
use \App\Application\Actions\Photos\AfficherPhotoAction as AfficherPhotoAction;
use \App\Application\Actions\Photos\DeletePhotoAction as DeletePhotoAction;
use \App\Application\Actions\Photos\UpdatePhotoAction as UpdatePhotoAction;
......@@ -95,5 +96,7 @@ return function (App $app) {
//update photo
$app->get('/photoUpdate/{id}',UpdatePhotoAction::class)->setName("getPhotoUpdate");
$app->post('/photoUpdate/{id}',UpdatePhotoAction::class)->setName("postPhotoUpdate");
//send the message
$app->post('/sendMessage/{id}', CommentaireAction::class)->setName("postMessage");
};
-- phpMyAdmin SQL Dump
-- version 5.0.4
-- version 5.0.2
-- https://www.phpmyadmin.net/
--
-- Hôte : db
-- Généré le : jeu. 05 nov. 2020 à 14:56
-- Version du serveur : 8.0.22
-- Généré le : lun. 09 nov. 2020 à 13:08
-- Version du serveur : 8.0.21
-- Version de PHP : 7.4.11
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
......@@ -23,6 +23,27 @@ SET time_zone = "+00:00";
-- --------------------------------------------------------
--
-- Structure de la table `commentaire`
--
CREATE TABLE `commentaire` (
`id_commentaire` int NOT NULL,
`id_photo` int NOT NULL,
`id_user` int NOT NULL,
`content` varchar(255) NOT NULL,
`date` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
--
-- Déchargement des données de la table `commentaire`
--
INSERT INTO `commentaire` (`id_commentaire`, `id_photo`, `id_user`, `content`, `date`) VALUES
(2, 1, 5, 'Belle photo', '2020-11-09');
-- --------------------------------------------------------
--
-- Structure de la table `galerie`
--
......@@ -89,18 +110,17 @@ CREATE TABLE `user` (
`id_user` int NOT NULL,
`nom` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`password` varchar(250) NOT NULL,
`infos` varchar(500)
`password` varchar(250) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
--
-- Déchargement des données de la table `user`
--
INSERT INTO `user` (`id_user`, `nom`,`email`, `password`, `infos`) VALUES
(5, 'a','a@a.fr', '$2y$10$ATzdGJMl2833mNHi3DAGiu6TiQJH5sjx2JucsMZ9loS7B/4VkYdJe', 'Ceci est une information sur ma personne'),
(6, 'aa','aa@a.fr', '$2y$10$ed9GqIqYylpxqjwYsnQVdeKZDGWy6L7bhAT597wpF4qMUi0uYmTVO', ''),
(7, 'b','b@b.fr', '$2y$10$01unVL2rqFRPk0GSZIDSQOX3cfI65BG3BYQ0fjmMIzm2YElTFWVDy', '');
INSERT INTO `user` (`id_user`, `nom`, `email`, `password`) VALUES
(5, 'a', 'a@a.fr', '$2y$10$ATzdGJMl2833mNHi3DAGiu6TiQJH5sjx2JucsMZ9loS7B/4VkYdJe'),
(6, 'aa', 'aa@a.fr', '$2y$10$ed9GqIqYylpxqjwYsnQVdeKZDGWy6L7bhAT597wpF4qMUi0uYmTVO'),
(7, 'b', 'b@b.fr', '$2y$10$01unVL2rqFRPk0GSZIDSQOX3cfI65BG3BYQ0fjmMIzm2YElTFWVDy');
-- --------------------------------------------------------
......@@ -119,19 +139,27 @@ CREATE TABLE `user_2_galerie` (
--
INSERT INTO `user_2_galerie` (`id_user`, `id_galerie`, `acces`) VALUES
(5, 1, 2),
(5, 5, 2),
(6, 2, 0),
(7, 6, 2),
(7, 7, 2),
(7, 9, 2),
(7, 10, 2),
(7, 11, 2);
(5, 1, 3),
(5, 5, 3),
(6, 2, 3),
(7, 6, 3),
(7, 7, 3),
(7, 9, 3),
(7, 10, 3),
(7, 11, 3);
--
-- Index pour les tables déchargées
--
--
-- Index pour la table `commentaire`
--
ALTER TABLE `commentaire`
ADD PRIMARY KEY (`id_commentaire`),
ADD KEY `FK_id_user2` (`id_user`),
ADD KEY `FK_id_photo2` (`id_photo`);
--
-- Index pour la table `galerie`
--
......@@ -162,17 +190,23 @@ ALTER TABLE `user_2_galerie`
-- AUTO_INCREMENT pour les tables déchargées
--
--
-- AUTO_INCREMENT pour la table `commentaire`
--
ALTER TABLE `commentaire`
MODIFY `id_commentaire` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
--
-- AUTO_INCREMENT pour la table `galerie`
--
ALTER TABLE `galerie`
MODIFY `id_galerie` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=12;
MODIFY `id_galerie` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=13;
--
-- AUTO_INCREMENT pour la table `photos`
--
ALTER TABLE `photos`
MODIFY `id_photo` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;
MODIFY `id_photo` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=12;
--
-- AUTO_INCREMENT pour la table `user`
......@@ -184,6 +218,13 @@ ALTER TABLE `user`
-- Contraintes pour les tables déchargées
--
--
-- Contraintes pour la table `commentaire`
--
ALTER TABLE `commentaire`
ADD CONSTRAINT `FK_id_photo2` FOREIGN KEY (`id_photo`) REFERENCES `photos` (`id_photo`) ON DELETE RESTRICT ON UPDATE RESTRICT,
ADD CONSTRAINT `FK_id_user2` FOREIGN KEY (`id_user`) REFERENCES `user` (`id_user`) ON DELETE RESTRICT ON UPDATE RESTRICT;
--
-- Contraintes pour la table `photos`
--
......
......@@ -65,6 +65,7 @@ class AfficherPhotoAction
}
$url['getPhotoDelete'] = "../photoDelete/{$id}";
$url['getPhotoUpdate'] = "../photoUpdate/{$id}";
$url['postMessage'] = "../sendMessage/$id}";
$photo = Photos::where("id_photo","=",$id)->get();
$photoNext = Photos::where("id_galerie","=",$photo[0]->id_galerie)->where("id_photo",">",$id)->first();
......
<?php
namespace App\Application\Actions\Photos;
use App\Domain\Galerie;
use App\Domain\User;
use App\Domain\Photos;
use App\Domain\User2galerie;
use App\Domain\Commentaire;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Psr7\Message;
use Slim\Views\Twig;
class CommentaireAction
{
public function __invoke(Request $request, Response $response, $args): Response
{
$id = intval($args['id']);
$url['getAccueil'] = ['route' => '/', 'name' => 'Accueil', 'method' => 'GET'];
$url['getGalerieList'] = ['route' => '../galeries', 'name' => 'Galerie', 'method' => 'GET'];
if(isset($_SESSION['user']) && !is_null($_SESSION['user'])) {
$user = User::where('email', '=', $_SESSION['user'])->first();
$id_user = $user->id_user;
$url['getMonCompte'] = ['route' => "../monCompte/$id_user", 'name' => 'mon compte', 'method' => 'GET'];
$url['deconnexionPost'] = ['route' => '../deconnexion', 'name' => 'Deconnexion', 'method' => 'POST'];
} else {
$url['inscriptionGet'] = ['route' => '../inscription', 'name' => 'Inscription', 'method' => 'GET'];
$url['connexionGet'] = ['route' => '../connexion', 'name' => 'Connexion', 'method' => 'GET'];
}
if(isset($_SESSION['user']) && !is_null($_SESSION['user'])) {
if($_SERVER['REQUEST_METHOD'] === 'POST') {
$user = User::where('email', '=', $_SESSION['user'])->first();
$content = filter_var($_POST['message-input-content'], FILTER_SANITIZE_STRING);
$today = date("Y-m-d H:i:s");
Commentaire::create($id, $user->id_user, $content, $today);
header("Location: ../img/$id");
exit;
}
header('Location: ../galeries');
exit;
} else {
header('Location: ../connexion');
exit;
}
}
}
\ No newline at end of file
<?php
namespace App\Domain;
use Illuminate\Database\Eloquent\Model;
class Commentaire extends Model
{
protected $table = 'commentaire';
protected $primaryKey = 'id_commentaire';
public $timestamps = false ;
public static function create($id_photo, $id_user, $content, $date){
// Variables
$commentaire = new Commentaire();
$commentaire->id_photo = $id_photo;
$commentaire->id_user = $id_user;
$commentaire->content = $content;
$commentaire->date = $date;
$commentaire->save();
// retourne le tuple créé
return $commentaire;
}
}
\ No newline at end of file
......@@ -48,5 +48,13 @@
</div>
{% endfor %}
</div>
<div>
<form action="{{ urls.postMessage }}" method="post">
<div class="form-group">
<input class="form-control" id="message-input-content" name="message-input-content" type="text" placeholder="Message">
<input class="btn btn-primary btn-block btn-lg mt-1 mb-2" style='margin-bottom: 9px;' type="submit" value="Envoyer">
</div>
</form>
</div>
</body>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment