changement dans l'architecture du projet

This commit is contained in:
2019-02-27 13:50:43 +01:00
parent 4c51764836
commit a0ee078501
46 changed files with 197 additions and 283 deletions

12
assets/php/db/Author.php Normal file
View File

@ -0,0 +1,12 @@
<?php
namespace App\DB;
class Author {
private $id;
private $username;
private $linkedin;
}

View File

@ -0,0 +1,99 @@
<?php
namespace App\DB;
use App\Functions;
use PDO;
class Categorie {
private $id;
private $name;
public function __construct($id, $name) {
$this->id = $id;
$this->name = $name;
}
public static function fromArray($array) {
return new Self($array["id"], $array["name"]);
}
/**
* Undocumented function
*
* @param boolean $recent sort by most recent of less recent
* @param int $limit
*
* @return Categorie[]
*/
public static function list($recent = true, $limit = 100) {
$sort = $recent ? "DESC" : "ASC";
$query = "SELECT * FROM categories ORDER BY " . $sort . " LIMIT " . $limit;
$pdo = Functions::connect();
$cats = $pdo->query($query)->fetchAll();
$res = array();
foreach ($cats as $cat) {
$res[] = new Categorie($cat["id"], $cat["name"]);
}
return $res;
}
public static function get(int $id) {
return Categorie::fromArray(Functions::connect()->query("SELECT * FROM categories WHERE id=" . $id)->fetch());
}
public static function add(Categorie $categorie) {
$query = "INSERT INTO categories (id, name)
VALUES (NULL, ':name');";
$pdo = Functions::connect();
$prepared = $pdo->prepare($query);
$prepared->bindParam(":name", $categorie->getName());
$prepared->execute();
}
public static function remove(Categorie $categorie) {
Functions::connect()->prepare("DELETE FROM categories WHERE id=" . $categorie->getName())->execute();
}
public static function update(Categorie $categorie) {
$query = ""
}
/**
* Get the value of name
*/
public function getName()
{
return $this->name;
}
/**
* Set the value of name
*
* @return self
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get the value of id
*/
public function getId()
{
return $this->id;
}
}

71
assets/php/db/Post.php Normal file
View File

@ -0,0 +1,71 @@
<?php
namespace App\DB;
class Post {
private $id;
private $title;
private $url;
private $content;
private $short;
private $categorie;
private $author;
private $dt;
/**
* list of posts
*
* @param boolean $recent sort by most recent or not
* @param integer $limit limit the number of result
*
* @return array(Post)
*/
public static function list($recent = true, $limit = 100) {
}
/**
*
* get a specific Post
*
* @param integer $id the id
*
* @return Post
*/
public static function get(int $id) {
}
/**
* add a post to the db
*
* @param Post $post
*
*/
public static function add(Post $post) {
}
/**
* remove the post
*
* @param Post $post
*
*/
public static function remove(Post $post) {}
/**
* update the post data on the db
*
* @param Post $post
*
* @return void
*/
public static function update(Post $post) {}
}

57
assets/php/db/Tag.php Normal file
View File

@ -0,0 +1,57 @@
<?php
namespace App\DB;
class Tag {
private $id;
private $name;
/**
* list of posts
*
* @param boolean $recent sort by most recent or not
* @param integer $limit limit the number of result
*
* @return array(Post)
*/
public static function list($recent = true, $limit = 100) {
}
/**
*
* get a specific Post
*
* @param integer $id the id
*
* @return Post
*/
public static function get(int $id) {
}
/**
* add a post to the db
*
* @param Post $post
*
*/
public static function add(Post $post) {
}
/**
* remove the post
*
* @param Post $post
*
*/
public static function remove(Post $post) {}
/**
* update the post data on the db
*
* @param Post $post
*
* @return void
*/
public static function update(Post $post) {}
}