mirror of
https://github.com/Aviortheking/Blog_IMIE.git
synced 2025-06-15 03:29:19 +00:00
commit
This commit is contained in:
@ -70,7 +70,7 @@ class Author {
|
||||
|
||||
public static function list($recent = true, $limit = 100) {
|
||||
$sort = $recent ? "DESC" : "ASC";
|
||||
$query = "SELECT * FROM author ORDER BY " . $sort . " LIMIT " . $limit;
|
||||
$query = "SELECT * FROM users ORDER BY id " . $sort . " LIMIT " . $limit;
|
||||
|
||||
$pdo = Functions::connect();
|
||||
$cats = $pdo->query($query)->fetchAll();
|
||||
|
@ -3,6 +3,8 @@
|
||||
namespace App\DB;
|
||||
|
||||
use App\Functions;
|
||||
use DateTime;
|
||||
use PDO;
|
||||
|
||||
class Post {
|
||||
|
||||
@ -11,12 +13,8 @@ class Post {
|
||||
|
||||
private $title;
|
||||
|
||||
private $url;
|
||||
|
||||
private $content;
|
||||
|
||||
private $short;
|
||||
|
||||
private $category;
|
||||
|
||||
private $author;
|
||||
@ -34,19 +32,10 @@ class Post {
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
|
||||
public function setUrl($url) {
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
public function setContent($content) {
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function setShort($short) {
|
||||
$this->short = $short;
|
||||
}
|
||||
|
||||
public function setCategory($category) {
|
||||
$this->category = $category;
|
||||
}
|
||||
@ -75,18 +64,10 @@ class Post {
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function getUrl() {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
public function getContent() {
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function getShort() {
|
||||
return $this->short;
|
||||
}
|
||||
|
||||
public function getCategory() {
|
||||
return Category::get($this->category);
|
||||
}
|
||||
@ -135,9 +116,7 @@ class Post {
|
||||
$post = new Post();
|
||||
$post->setId($array["id"]);
|
||||
$post->setTitle($array["title"]);
|
||||
$post->setUrl($array["url"]);
|
||||
$post->setContent($array["content"]);
|
||||
$post->setShort($array["short"]);
|
||||
if(isset($array["category"])) $post->setCategory($array["category"]);
|
||||
$post->setAuthor($array["author"]);
|
||||
$post->setDateTime($array["dt"]);
|
||||
@ -240,19 +219,33 @@ class Post {
|
||||
*
|
||||
*/
|
||||
public static function add(Post $post) {
|
||||
$query = "INSERT INTO posts (id, title, url, content, short, categorie, author, dt)
|
||||
VALUES (NULL, ':title', ':url', ':content', ':short', ':categorie', ':author', ':dt');";
|
||||
$query = "INSERT INTO posts (id, title, content, categorie, author, dt)
|
||||
VALUES (NULL, ':title', ':content', ':category', ':author', ':dt');";
|
||||
|
||||
$title = $post->getTitle());
|
||||
$content = $post->getContent());
|
||||
$category = $post->getCategory()->getId(), PDO::PARAM_INT);
|
||||
$author = $post->getAuthor()->getId(), PDO::PARAM_INT);
|
||||
$dt = (new DateTime())->format("d/m/Y h:i:s"));
|
||||
|
||||
|
||||
$pdo = Functions::connect();
|
||||
$prepared = $pdo->prepare($query);
|
||||
$prepared->bindParam(":title", $post->getTitle());
|
||||
$prepared->bindParam(":url", $post->getUrl());
|
||||
$prepared->bindParam(":content", $post->getContent());
|
||||
$prepared->bindParam(":short", $post->getShort());
|
||||
$prepared->bindParam(":categorie", $post->getCategory());
|
||||
$prepared->bindParam(":author", $post->getAuthor());
|
||||
$prepared->bindParam(":dt", $post->getDateTime());
|
||||
$prepared->execute();
|
||||
$prepared->bindParam(":category", $post->getCategory()->getId(), PDO::PARAM_INT);
|
||||
$prepared->bindParam(":author", $post->getAuthor()->getId(), PDO::PARAM_INT);
|
||||
$prepared->bindParam(":dt", (new DateTime())->format("d/m/Y h:i:s"));
|
||||
|
||||
var_dump($prepared->execute(array(
|
||||
":title" => $post->getTitle(),
|
||||
":content" => $post->getContent(),
|
||||
":category" => $post->getCategory()->getId(),
|
||||
":author" => $post->getAuthor()->getId(),
|
||||
":dt" => (new DateTime())->format("d/m/Y h:i:s"),
|
||||
)));
|
||||
var_dump("t");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -279,11 +272,9 @@ class Post {
|
||||
*
|
||||
*/
|
||||
public static function update(Post $post) {
|
||||
Functions::connect()->prepare("UPDATE posts SET title=':title', url=':url', content=':content', short=':short', category=':category', author=':author', dt=':dt' WHERE id=:id")->execute(array(
|
||||
Functions::connect()->prepare("UPDATE posts SET title=':title', content=':content', category=':category', author=':author', dt=':dt' WHERE id=:id")->execute(array(
|
||||
":title" => $post->getTitle(),
|
||||
":url" => $post->getUrl(),
|
||||
":content" => $post->getContent(),
|
||||
":short" => $post->getShort(),
|
||||
":categorie" => $post->getCategorie(),
|
||||
":author" => $post->getAuthor(),
|
||||
":dt" => $post->getDt(),
|
||||
|
@ -49,14 +49,24 @@ class Tag {
|
||||
return Tag::fromArray(Functions::connect()->query("SELECT * FROM tag WHERE id=" . $id)->fetch());
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return Tag
|
||||
*/
|
||||
public static function add(Tag $tag) {
|
||||
$query = "INSERT INTO tag (id, name)
|
||||
VALUES (NULL, ':name');";
|
||||
VALUES (NULL, :name);";
|
||||
|
||||
// var_dump($tag);
|
||||
|
||||
$pdo = Functions::connect();
|
||||
$prepared = $pdo->prepare($query);
|
||||
$prepared->bindParam(":name", $tag->getName());
|
||||
$prepared->execute();
|
||||
$prepared->execute(array(":name" => $tag->getName()));
|
||||
|
||||
return Tag::list(true, 1)[0];
|
||||
}
|
||||
|
||||
public static function remove(Tag $tag) {
|
||||
|
Reference in New Issue
Block a user