public function getTopic() { if (!$this->topic) { $topicManager = new TopicManager($this->db); $this->topic = $topicManager->findById($this->id_topic); } return $this->topic; }
<?php $topicManager = new TopicManager($db); $topic = $topicManager->findById($_GET['id']); $userManager = new UserManager($db); $userTopic = $userManager->findById($topic->getIdAuthor()); try { $test = $topicManager->addVue($topic->getId()); $link = $userManager->deletLink($_SESSION['id'], $topic->getId()); } catch (Exception $e) { $errors = $e->getMessage(); echo $errors; } require "views/forum/topic.phtml";
<?php if (isset($_GET['id'])) { if (isset($_SESSION['id'])) { $manager = new TopicManager($db); $topic = $manager->findById(intval($_GET['id'])); if (is_string($topic)) { header('Location: index.php?page=error_404'); exit; } else { require 'views/create_post.phtml'; } } else { header('Location: index.php?page=login'); exit; } } else { header('Location: index.php?page=error_404'); exit; }
public function create($idTopic, $content) { $post = new Post(); $set = $post->setContent($content); if ($set === true) { $manager = new TopicManager($this->db); $topic = $manager->findById($idTopic); $set = $post->setIdTopic($topic); if ($set === true) { if (isset($_SESSION['id'])) { $manager = new UserManager($this->db); $user = $manager->getCurrent(); $set = $post->setIdAuthor($user); if ($set === true) { $idAuthor = intval($user->getId()); $idTopic = intval($post->getIdTopic()); $content = mysqli_real_escape_string($this->db, $post->getContent()); $query = "INSERT INTO post (id_author, id_topic, content) VALUES (" . $idAuthor . ", " . $idTopic . ", '" . $content . "')"; $result = mysqli_query($this->db, $query); if ($result) { $id = mysqli_insert_id($this->db); if ($id) { return $this->findById($id); } else { return "Erreur serveur."; } } else { return mysqli_error(); } } else { return $set; } } else { return "Utilisateur déconnecté."; } } else { return $set; } } else { return $set; } }