mirror of
https://github.com/Aviortheking/Blog_IMIE.git
synced 2025-06-14 11:09:19 +00:00
pouet
This commit is contained in:
89
assets/php/Controller/PostController.php
Normal file
89
assets/php/Controller/PostController.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Controller;
|
||||
use App\DB\Post;
|
||||
use App\DB\Tag;
|
||||
|
||||
|
||||
class PostController extends Controller {
|
||||
/**
|
||||
* @route /^\/post\/[0-9]+\/edit\/$/
|
||||
* @editor
|
||||
* @title Modification d'article
|
||||
*/
|
||||
public function postEdit() {
|
||||
if(isset($_GET["post"]) && isset($_GET["title"]) && isset($_GET["category"]) && isset($_GET["content"]) && isset($_GET["tags"])) {
|
||||
$post = Post::get($_GET["post"]);
|
||||
|
||||
$post->setTitle($_GET["title"]);
|
||||
$post->setContent($_GET["content"]);
|
||||
$post->setCategory($_GET["category"]);
|
||||
|
||||
$tags = explode(",", $_GET["tags"]);
|
||||
$tgs = array();
|
||||
foreach ($tags as $tag) {
|
||||
var_dump($tag);
|
||||
var_dump(Tag::getByName($tag));
|
||||
if(!(Tag::getByName($tag))) {
|
||||
$tgs[] = Tag::add((new Tag())->setName($tag))->getId();
|
||||
} else {
|
||||
$tgs[] = Tag::getByName($tag)->getId();
|
||||
}
|
||||
}
|
||||
|
||||
$post->setTags($tgs);
|
||||
$post->setAuthor($_SESSION["author"]->getId());
|
||||
Post::update($post);
|
||||
}
|
||||
return file_get_contents(DIR."/html/post_edit.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* @route /^\/post\/new\/*$/
|
||||
* @editor
|
||||
* @title Ajout d'Article
|
||||
*/
|
||||
public function postAdd() {
|
||||
|
||||
var_dump($_GET);
|
||||
// die;
|
||||
|
||||
if(isset($_GET["title"]) && isset($_GET["category"]) && isset($_GET["content"]) && isset($_GET["tags"])) {
|
||||
$post = new Post();
|
||||
|
||||
$post->setTitle($_GET["title"]);
|
||||
$post->setContent($_GET["content"]);
|
||||
$post->setCategory($_GET["category"]);
|
||||
// $post->setAuthor();
|
||||
$tags = explode(",", $_GET["tags"]);
|
||||
$tgs = array();
|
||||
foreach ($tags as $tag) {
|
||||
var_dump($tag);
|
||||
var_dump(Tag::getByName($tag));
|
||||
if(!(Tag::getByName($tag))) {
|
||||
$tgs[] = Tag::add((new Tag())->setName($tag))->getId();
|
||||
} else {
|
||||
$tgs[] = Tag::getByName($tag)->getId();
|
||||
}
|
||||
}
|
||||
// var_dump($tgs);
|
||||
// die;
|
||||
$post->setTags($tgs);
|
||||
$post->setAuthor($_SESSION["author"]->getId());
|
||||
Post::add($post);
|
||||
}
|
||||
|
||||
return file_get_contents(DIR."/html/post_new.html");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @route /^\/post\/[0-9]+\/$/
|
||||
* @title Article
|
||||
*/
|
||||
public function post() {
|
||||
return file_get_contents(DIR."/html/post.html");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user