Commentaire et travail à réaliser
This commit is contained in:
parent
66f7fca498
commit
195282e4f2
|
@ -59,5 +59,13 @@ $projects = getProjects($page, $limit);
|
||||||
</article>
|
</article>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</section>
|
</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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return PDO Une instance PDO
|
||||||
|
*/
|
||||||
function getDatabaseConnection()
|
function getDatabaseConnection()
|
||||||
{
|
{
|
||||||
static $pdo;
|
static $pdo;
|
||||||
|
|
|
@ -1,11 +1,18 @@
|
||||||
<?php
|
<?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)) {
|
if (!is_integer($page)) {
|
||||||
throw new InvalidArgumentException('The argument "page" must be an interger.');
|
throw new InvalidArgumentException('The argument "page" must be an interger.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_integer($limit)) {
|
if (!is_integer($limit)) {
|
||||||
throw new InvalidArgumentException('The argument "limit" must be an interger.');
|
throw new InvalidArgumentException('The argument "limit" must be an interger.');
|
||||||
}
|
}
|
||||||
|
@ -15,7 +22,7 @@ function getProjects($page = 1, $limit = 5)
|
||||||
$pdo = getDatabaseConnection();
|
$pdo = getDatabaseConnection();
|
||||||
|
|
||||||
$query = $pdo->prepare('select id, title, illustration, description, date from project limit :from, :limit');
|
$query = $pdo->prepare('select id, title, illustration, description, date from project limit :from, :limit');
|
||||||
|
|
||||||
$query->bindParam(':from', $from, PDO::PARAM_INT);
|
$query->bindParam(':from', $from, PDO::PARAM_INT);
|
||||||
$query->bindParam(':limit', $limit, PDO::PARAM_INT);
|
$query->bindParam(':limit', $limit, PDO::PARAM_INT);
|
||||||
|
|
||||||
|
@ -24,7 +31,13 @@ function getProjects($page = 1, $limit = 5)
|
||||||
return $query->fetchAll();
|
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)) {
|
if (!is_integer($id)) {
|
||||||
throw new InvalidArgumentException('The argument "id" must be an interger.');
|
throw new InvalidArgumentException('The argument "id" must be an interger.');
|
||||||
|
@ -33,7 +46,7 @@ function getProject($id)
|
||||||
$pdo = getDatabaseConnection();
|
$pdo = getDatabaseConnection();
|
||||||
|
|
||||||
$query = $pdo->prepare('select id, title, illustration, description, date from project where id=:id');
|
$query = $pdo->prepare('select id, title, illustration, description, date from project where id=:id');
|
||||||
|
|
||||||
$query->bindParam(':id', $id, PDO::PARAM_INT);
|
$query->bindParam(':id', $id, PDO::PARAM_INT);
|
||||||
|
|
||||||
$query->execute();
|
$query->execute();
|
||||||
|
@ -41,12 +54,16 @@ function getProject($id)
|
||||||
return $query->fetch();
|
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)) {
|
if (!is_integer($maxPerPage)) {
|
||||||
throw new InvalidArgumentException('The argument "maxPerPage" must be an interger.');
|
throw new InvalidArgumentException('The argument "maxPerPage" must be an interger.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$pdo = getDatabaseConnection();
|
$pdo = getDatabaseConnection();
|
||||||
|
|
||||||
$query = $pdo->prepare('select count(*) as total from project');
|
$query = $pdo->prepare('select count(*) as total from project');
|
||||||
|
@ -58,7 +75,13 @@ function getProjectNumberOfPages($maxPerPage)
|
||||||
return ceil($result['total'] / $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
|
// À réaliser
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue