Commentaire et travail à réaliser

This commit is contained in:
Simon Vieille 2016-01-27 13:23:07 +01:00
parent 66f7fca498
commit 195282e4f2
3 changed files with 42 additions and 8 deletions

View File

@ -59,5 +59,13 @@ $projects = getProjects($page, $limit);
</article>
<?php endforeach ?>
</section>
<!--
Générer la pagination :
Première page | Précédent | 1 | 2 | 3 ... | Suivant | Dernière page
Mettre en avant la page courrante
-->
</body>
</html>

View File

@ -1,5 +1,8 @@
<?php
/**
* @return PDO Une instance PDO
*/
function getDatabaseConnection()
{
static $pdo;

View File

@ -1,11 +1,18 @@
<?php
function getProjects($page = 1, $limit = 5)
/**
* Retourne une liste de projets en fonction d'une pagination
*
* @param int $page La page courrante
* @param int $limit Nombre de projet par page
* @return array Les projets
*/
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.');
}
@ -15,7 +22,7 @@ function getProjects($page = 1, $limit = 5)
$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);
@ -24,7 +31,13 @@ function getProjects($page = 1, $limit = 5)
return $query->fetchAll();
}
function getProject($id)
/**
* Retourne un projet en fonction de son id
*
* @param int $id id du projet
* @return array|false Le projet
*/
function getProject($id)
{
if (!is_integer($id)) {
throw new InvalidArgumentException('The argument "id" must be an interger.');
@ -33,7 +46,7 @@ function getProject($id)
$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();
@ -41,12 +54,16 @@ function getProject($id)
return $query->fetch();
}
function getProjectNumberOfPages($maxPerPage)
/**
* @param int $maxPerPage Nombre de projets par page
* @return int Le nombre de pages
*/
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');
@ -58,7 +75,13 @@ function getProjectNumberOfPages($maxPerPage)
return ceil($result['total'] / $maxPerPage);
}
function getCommentsByProject($id)
/**
* Returne les commentaires d'un projet
*
* @param int $id L'id du projet
* @return array Les commentaire du projet
*/
function getCommentsByProject($id)
{
// À réaliser
}