Advertisement
Guest User

Untitled

a guest
May 27th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.96 KB | None | 0 0
  1. <?php
  2. namespace up2\main\news;
  3.  
  4. use up2\main\UP2;
  5. use up2\main\users\User;
  6.  
  7. class NewsEntry {
  8.  
  9.   protected $id;
  10.   protected $author;
  11.   protected $category;
  12.   protected $title;
  13.   protected $content;
  14.   protected $time;
  15.  
  16.   public function __construct($id) {
  17.     $this->id = $id;
  18.    
  19.     $stmt = UP2::getDB()->prepare("SELECT author, category, title, content, time FROM news WHERE id = ?");
  20.     $stmt->bind_param("i", $this->id);
  21.     $stmt->execute();
  22.     $stmt->bind_result($author, $category, $title, $content, $time);
  23.     if($stmt->fetch()) {
  24.       $this->author = new User($author);
  25.       $this->category = new NewsCategory($category);
  26.       $this->title = $title;
  27.       $this->content = $content;
  28.       $this->time = $this;
  29.     }
  30.     $stmt->close();
  31.   }
  32.  
  33.   public function getID() {
  34.     return $this->id;
  35.   }
  36.  
  37.   public function getAuthor() {
  38.     return $this->author;
  39.   }
  40.  
  41.   public function getCategory() {
  42.     return $this->category;
  43.   }
  44.  
  45.   public function getTitle() {
  46.     return $this->title;
  47.   }
  48.  
  49.   public function getContent() {
  50.     return $this->content;
  51.   }
  52.  
  53.   public function getTime() {
  54.     return $this->time;
  55.   }
  56.  
  57.   public function setCategory($category) {
  58.     $this->category = $category;
  59.     $cid = $this->category->getID();
  60.     $stmt = UP2::getDB()->prepare("UPDATE news SET category = ? WHERE id = ?");
  61.     $stmt->bind_param("ii", $cid, $this->id);
  62.     $stmt->execute();
  63.     $stmt->close();
  64.   }
  65.  
  66.   public function setTitle($title) {
  67.     $this->title = $title;
  68.     $stmt = UP2::getDB()->prepare("UPDATE news SET title = ? WHERE id = ?");
  69.     $stmt->bind_param("si", $this->title, $this->id);
  70.     $stmt->execute();
  71.     $stmt->close();
  72.   }
  73.  
  74.   public function setContent($content) {
  75.     $this->content = $content;
  76.     $stmt = UP2::getDB()->prepare("UPDATE news SET content = ? WHERE id = ?");
  77.     $stmt->bind_param("si", $this->content, $this->id);
  78.     $stmt->execute();
  79.     $stmt->close();
  80.   }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement