init
commit
66f7fca498
@ -0,0 +1,2 @@
|
||||
tags
|
||||
*.swp
|
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>404</title>
|
||||
</head>
|
||||
<body>
|
||||
Page 404
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
After Width: | Height: | Size: 58 KiB |
Binary file not shown.
After Width: | Height: | Size: 44 KiB |
Binary file not shown.
After Width: | Height: | Size: 41 KiB |
Binary file not shown.
After Width: | Height: | Size: 52 KiB |
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
require 'lib/database.php';
|
||||
require 'lib/project.php';
|
||||
|
||||
$limit = 5;
|
||||
|
||||
$numberOfPages = getProjectNumberOfPages($limit);
|
||||
|
||||
if (isset($_GET['page'])) {
|
||||
$page = (int) $_GET['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
if ($page > $numberOfPages) {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$projects = getProjects($page, $limit);
|
||||
|
||||
?>
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="style.css" />
|
||||
<title>
|
||||
Mon super portfolio
|
||||
</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Mon super portfolio</h1>
|
||||
|
||||
<section>
|
||||
<?php foreach($projects as $project): ?>
|
||||
<article>
|
||||
<h2><?php echo $project['title'] ?></h2>
|
||||
|
||||
<figure>
|
||||
<img src="images/<?php echo $project['illustration'] ?>" alt="" width="130px" />
|
||||
</figure>
|
||||
|
||||
<p class="description">
|
||||
<?php echo $project['description'] ?>
|
||||
</p>
|
||||
|
||||
<?php $date = new DateTime($project['date']); ?>
|
||||
|
||||
<p>
|
||||
<a href="project.php?id=<?php echo $project['id'] ?>">En savoir plus</a>
|
||||
</p>
|
||||
|
||||
<p class="date">
|
||||
<time datetime="<?php echo $date->format(DateTime::W3C) ?>">
|
||||
<?php echo $date->format('d/m/Y') ?>
|
||||
</time>
|
||||
</p>
|
||||
</article>
|
||||
<?php endforeach ?>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
function getDatabaseConnection()
|
||||
{
|
||||
static $pdo;
|
||||
|
||||
if ($pdo !== null) {
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
$dsn = 'mysql:dbname=portfolio;host=localhost;charset=utf8';
|
||||
$user = 'portfolio';
|
||||
$password = 'portfolio';
|
||||
|
||||
$pdo = new PDO($dsn, $user, $password);
|
||||
|
||||
return $pdo;
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
function getProjects($page = 1, $limit = 5)
|
||||
{
|
||||
if (!is_integer($page)) {
|
||||
throw new InvalidArgumentException('The argument "page" must be an interger.');
|
||||
}
|
||||
|
||||
if (!is_integer($limit)) {
|
||||
throw new InvalidArgumentException('The argument "limit" must be an interger.');
|
||||
}
|
||||
|
||||
$from = ($page - 1) * $limit;
|
||||
|
||||
$pdo = getDatabaseConnection();
|
||||
|
||||
$query = $pdo->prepare('select id, title, illustration, description, date from project limit :from, :limit');
|
||||
|
||||
$query->bindParam(':from', $from, PDO::PARAM_INT);
|
||||
$query->bindParam(':limit', $limit, PDO::PARAM_INT);
|
||||
|
||||
$query->execute();
|
||||
|
||||
return $query->fetchAll();
|
||||
}
|
||||
|
||||
function getProject($id)
|
||||
{
|
||||
if (!is_integer($id)) {
|
||||
throw new InvalidArgumentException('The argument "id" must be an interger.');
|
||||
}
|
||||
|
||||
$pdo = getDatabaseConnection();
|
||||
|
||||
$query = $pdo->prepare('select id, title, illustration, description, date from project where id=:id');
|
||||
|
||||
$query->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
|
||||
$query->execute();
|
||||
|
||||
return $query->fetch();
|
||||
}
|
||||
|
||||
function getProjectNumberOfPages($maxPerPage)
|
||||
{
|
||||
if (!is_integer($maxPerPage)) {
|
||||
throw new InvalidArgumentException('The argument "maxPerPage" must be an interger.');
|
||||
}
|
||||
|
||||
$pdo = getDatabaseConnection();
|
||||
|
||||
$query = $pdo->prepare('select count(*) as total from project');
|
||||
|
||||
$query->execute();
|
||||
|
||||
$result = $query->fetch();
|
||||
|
||||
return ceil($result['total'] / $maxPerPage);
|
||||
}
|
||||
|
||||
function getCommentsByProject($id)
|
||||
{
|
||||
// À réaliser
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
require 'lib/database.php';
|
||||
require 'lib/project.php';
|
||||
|
||||
if (!isset($_GET['id'])) {
|
||||
include '404.php';
|
||||
die;
|
||||
}
|
||||
|
||||
$id = (int) $_GET['id'];
|
||||
|
||||
$project = getProject($id);
|
||||
|
||||
if (false === $project) {
|
||||
include '404.php';
|
||||
die;
|
||||
}
|
||||
|
||||
$comments = getCommentsByProject($project[''])
|
||||
|
||||
?>
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="style.css" />
|
||||
<title>
|
||||
Mon super portfolio - <?php echo $project['title'] ?>
|
||||
</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>
|
||||
<?php echo $project['title'] ?>
|
||||
</h1>
|
||||
|
||||
<section>
|
||||
<article>
|
||||
<figure>
|
||||
<img src="images/<?php echo $project['illustration'] ?>" alt="" width="130px" />
|
||||
</figure>
|
||||
|
||||
<p class="description">
|
||||
<?php echo $project['description'] ?>
|
||||
</p>
|
||||
|
||||
<?php $date = new DateTime($project['date']); ?>
|
||||
|
||||
<p class="date">
|
||||
<time datetime="<?php echo $date->format(DateTime::W3C) ?>">
|
||||
<?php echo $date->format('d/m/Y') ?>
|
||||
</time>
|
||||
</p>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<h2>Commentaires</h2>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,34 @@
|
||||
body {
|
||||
font-family: Verdana;
|
||||
}
|
||||
|
||||
article {
|
||||
border: 1px solid #ccc;
|
||||
padding: 15px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
border-bottom: 1px solid #ccc;
|
||||
margin: 0 0 15px 0;
|
||||
padding-bottom: 5px;
|
||||
font-size: 17px;
|
||||
}
|
||||
|
||||
time {
|
||||
color: #777;
|
||||
}
|
||||
|
||||
.date {
|
||||
clear: left;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
figure {
|
||||
margin: 0 10px 0 0;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.description {
|
||||
padding-left: 150px;
|
||||
}
|
Loading…
Reference in New Issue