Conflicts:
	lib/project.php
This commit is contained in:
Lex 2016-01-28 12:22:46 +01:00
commit db251d3cb2
2 changed files with 32 additions and 13 deletions

View file

@ -10,11 +10,11 @@
function getProjects($page = 1, $limit = 5)
{
if (!is_integer($page)) {
throw new InvalidArgumentException('The argument "page" must be an interger.');
throw new InvalidArgumentException('The argument "page" must be an integer.');
}
if (!is_integer($limit)) {
throw new InvalidArgumentException('The argument "limit" must be an interger.');
throw new InvalidArgumentException('The argument "limit" must be an integer.');
}
$from = ($page - 1) * $limit;
@ -42,7 +42,7 @@ function getProjects($page = 1, $limit = 5)
function getProject($id)
{
if (!is_integer($id)) {
throw new InvalidArgumentException('The argument "id" must be an interger.');
throw new InvalidArgumentException('The argument "id" must be an integer.');
}
$pdo = getDatabaseConnection();
@ -63,7 +63,7 @@ function getProject($id)
function getProjectNumberOfPages($maxPerPage)
{
if (!is_integer($maxPerPage)) {
throw new InvalidArgumentException('The argument "maxPerPage" must be an interger.');
throw new InvalidArgumentException('The argument "maxPerPage" must be an integer.');
}
$pdo = getDatabaseConnection();
@ -97,24 +97,34 @@ function getCommentsByProject($id)
return $query->fetchAll();
}
function createComment($name,$website,$email, DateTime $date, $content, $project_id)
/**
* Enregistre un nouveau commentaire
*
* @param string $name Nom de l'auteur
* @param string $email Email de l'auteur
* @param string $website Site web de l'auteur
* @param string $content Contenu du commentaire
* @param DateTime $date Date du commentaire
* @param int $projectId L'id du projet associé
*/
function createComment($name, $email, $website, $content, DateTime $date, $projectId)
{
$pdo = getDatabaseConnection();
$query = $pdo->prepare('insert into comment(name, email, website, content, date, project_id) value(:name, :email, :website, :content, :date, :project_id)');
$query = $pdo->prepare(
'insert into comment(name, email, website, content, date, project_id) value(:name, :email, :website, :content, :date, :project_id)'
);
$query->execute([
':name' => $name,
':email' => $email,
':website' => $website,
':content' => $content,
':date' => $date->format('Y-m-d H:i:s'),
':project_id' => $project_id
':project_id' => $projectId,
]);
}
/**
* Génère et retourne une pagination
*
@ -125,11 +135,11 @@ function createComment($name,$website,$email, DateTime $date, $content, $project
function getProjectsPager($page, $numberOfPages)
{
if (!is_integer($page)) {
throw new InvalidArgumentException('The argument "page" must be an interger.');
throw new InvalidArgumentException('The argument "page" must be an integer.');
}
if (!is_integer($numberOfPages)) {
throw new InvalidArgumentException('The argument "numberOfPages" must be an interger.');
throw new InvalidArgumentException('The argument "numberOfPages" must be an integer.');
}
$pages = [];

View file

@ -17,6 +17,15 @@ if (false === $project) {
die;
}
// createComment(
// 'Simon',
// 'simon@deblan.fr',
// 'https://www.deblan.io/',
// 'Mon second super commentaire !',
// new DateTime('now'),
// $id
// );
$comments = getCommentsByProject($id);
?>