public function findAllComments()
 {
     $stmt = $this->dtb->prepare('SELECT * FROM comments');
     $stmt->execute();
     $data = array();
     $UM = new PdoUserManager();
     $PM = new PdoPostManager();
     while ($d = $stmt->fetch(PDO::FETCH_OBJ)) {
         $c = new Comment();
         $c->setId($d->id);
         $c->setBody($d->body);
         $c->setPost($PM->findPostById($d->postID));
         $c->setUser($UM->findUserById($d->userID));
         $c->setPublicationDate($d->publicationDate);
         $data[] = $c;
     }
     $stmt->closeCursor();
     return $data;
 }
示例#2
0
 public function findAllCommentsForPostId($pid)
 {
     $stmt = $this->dtb->prepare('SELECT * FROM comments WHERE postID = :pid');
     $stmt->bindValue(':pid', $pid, PDO::PARAM_INT);
     $stmt->execute();
     $data = array();
     $um = new PdoUserManager();
     $pm = new PdoPostManager();
     while ($d = $stmt->fetch(PDO::FETCH_OBJ)) {
         $c = new Comment();
         $c->setId($d->id);
         $c->setBody($d->body);
         $c->setPost($pm->findPostById($d->postID));
         $c->setUser($um->findUserById($d->userID));
         $c->setPublicationDate($d->publicationDate);
         $data[] = $c;
     }
     $stmt->closeCursor();
     return $data;
 }
示例#3
0
<?php

require_once __DIR__ . '/classes/manager/PdoPostManager.class.php';
require_once __DIR__ . '/classes/entities/User.class.php';
session_start();
if (!isset($_SESSION['user'])) {
    header('Location: ./login.php');
} else {
    $PM = new PdoPostManager();
    $post = $PM->findPostById($_GET['id']);
    ?>

<!doctype html>
<head>
	<title>Posts list</title>
	<meta charset="utf-8" />
</head>
<body>
	<?php 
    include './inc/menu.php';
    ?>
	<h1><?php 
    echo $post->getTitle();
    ?>
</h1>
	<em>by <?php 
    echo $post->getUser()->firstname . ' ' . $post->getUser()->lastname;
    ?>
 on <?php 
    echo date('d/m/Y H:i:s', $post->getPublicationDate());
    ?>
示例#4
0
 public function __construct()
 {
     if (is_null(self::$dtb)) {
         self::$dtb = new PDO(DB_DSN, DB_USER, DB_PASSWD);
     }
 }
示例#5
0
<?php

require_once __DIR__ . '/classes/manager/PdoPostManager.class.php';
require_once __DIR__ . '/classes/entities/User.class.php';
session_start();
if (!isset($_SESSION['user'])) {
    header('Location: ./login.php');
} else {
    $PM = new PdoPostManager();
    ?>

<!doctype html>
<head>
	<title>Posts list</title>
	<meta charset="utf-8" />
</head>
<body>
	<h1>Posts List Page</h1>
	<?php 
    include './inc/menu.php';
    ?>
	<table>
		<tr>
			<th>Title</th>
			<th>Body</th>
			<th>Date</th>
			<th>User</th>
			<th>Action</th>
		</tr>
		<?php 
    foreach ($PM->findAllPosts() as $post) {
示例#6
0
<?php

require_once __DIR__ . '/classes/manager/PdoPostManager.class.php';
session_start();
if (!isset($_SESSION['user'])) {
    header('Location: ./login.php');
} else {
    $PM = new PdoPostManager();
    // si le champs submit est présent, alors le formulaire a été envoyé
    if (isset($_POST['submit'])) {
        $title = isset($_POST['title']) ? $_POST['title'] : '';
        $body = isset($_POST['body']) ? $_POST['body'] : '';
        $PM->addPost($title, $body, $_SESSION['user']);
        header('Location: ./postList.php');
    }
    ?>

<!doctype html>
<head>
	<title>Add Post</title>
</head>
<body>
	<h1>Add Post Page</h1>
	<?php 
    include './inc/menu.php';
    ?>
	<form action="#" method="post">
		<label for="title">Title:</label>
		<input type="text" id="title" name="title" value="" />
		<br />
		<label for="body">Body:</label>