ProjectsManager.php 2.05 KB
Newer Older
1 2 3
<?php
class ProjectManager extends Base
{
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
	private $name;
	private $link;
	private $content;
	private $shortContent;
	private $id;

	function __construct($name, $link, $content, $shortContent, $id){
		$this->name = htmlspecialchars($name); 
		$this->link = htmlspecialchars($link);
		$this->content = htmlspecialchars($content);
		$this->shortContent = htmlspecialchars($shortContent);
		$this->id = htmlspecialchars($id);
	}

	public function getProjects()
	{
		$db = $this->dbConnect();
		$req = $db->query('SELECT * FROM l3m_projects ORDER BY id DESC');

		return $req;
	}
25

26 27 28 29
	public function get($link)
	{
		$link = htmlspecialchars($link);
		$name = str_replace("-", " ", $link);
30

31 32 33 34
		$db = $this->dbConnect();
		$req = $db->prepare('SELECT * FROM l3m_projects WHERE name = ?');
		$req->execute(array($name));
		$project = $req->fetch();
35

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
		if($project == false)
			return false;
		
		return $project;
	}

    // todo vérifier qu'on poste pas un truc vide
	public function update(){
		$db = $this->dbConnect();
		$req = $db->prepare('UPDATE l3m_projects SET name = :name, link = :link, content = :content, shortContent = :shortContent WHERE id = :id');
		$req->execute(array(
			'name' => $this->name,
			'link' => $this->link,
			'content' => $this->content,
			'shortContent' => $this->shortContent,
			'id' => $this->id
		));
	}

	public function send(){
		if(strlen($this->name) < 1){
			header("Location:/patate");
			exit();
		}
		if(strlen($this->shortContent) < 1){
			$this->shortContent = "Pas de description.";
		}
63
        $db = $this->dbConnect();
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
        $req = $db->prepare('INSERT INTO l3m_projects(name, link, content, shortcontent) VALUES(:name, :link, :content, :shortContent)');
        $req->execute(array(
			'name' => $this->name,
			'link' => $this->link,
			'content' => $this->content,
			'shortContent' => $this->shortContent
        ));
	}

	public function delete($link){
		$title = str_replace("-", " ", $link);

		$db = $this->dbConnect();
		$req = $db->prepare('DELETE FROM l3m_projects WHERE name = :name');
		$req->execute(array(
			'name' => $title
		));
	}
82
}