Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace up2\main\news;
- use up2\main\UP2;
- use up2\main\users\User;
- class NewsEntry {
- protected $id;
- protected $author;
- protected $category;
- protected $title;
- protected $content;
- protected $time;
- public function __construct($id) {
- $this->id = $id;
- $stmt = UP2::getDB()->prepare("SELECT author, category, title, content, time FROM news WHERE id = ?");
- $stmt->bind_param("i", $this->id);
- $stmt->execute();
- $stmt->bind_result($author, $category, $title, $content, $time);
- if($stmt->fetch()) {
- $this->author = new User($author);
- $this->category = new NewsCategory($category);
- $this->title = $title;
- $this->content = $content;
- $this->time = $this;
- }
- $stmt->close();
- }
- public function getID() {
- return $this->id;
- }
- public function getAuthor() {
- return $this->author;
- }
- public function getCategory() {
- return $this->category;
- }
- public function getTitle() {
- return $this->title;
- }
- public function getContent() {
- return $this->content;
- }
- public function getTime() {
- return $this->time;
- }
- public function setCategory($category) {
- $this->category = $category;
- $cid = $this->category->getID();
- $stmt = UP2::getDB()->prepare("UPDATE news SET category = ? WHERE id = ?");
- $stmt->bind_param("ii", $cid, $this->id);
- $stmt->execute();
- $stmt->close();
- }
- public function setTitle($title) {
- $this->title = $title;
- $stmt = UP2::getDB()->prepare("UPDATE news SET title = ? WHERE id = ?");
- $stmt->bind_param("si", $this->title, $this->id);
- $stmt->execute();
- $stmt->close();
- }
- public function setContent($content) {
- $this->content = $content;
- $stmt = UP2::getDB()->prepare("UPDATE news SET content = ? WHERE id = ?");
- $stmt->bind_param("si", $this->content, $this->id);
- $stmt->execute();
- $stmt->close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement