X-Git-Url: https://disinclined.org/git/?a=blobdiff_plain;f=model%2Fnote.php;h=8e863f12eb05934b7ce589bce36ee22b323be5c4;hb=08d7e1f799b17025cc1066b1e9b09e1b44c66a67;hp=01338be29f03aec67d2537f68b94452abe5d2985;hpb=4db3a80e869ec8b8c3e0c3f8401c8df12ff5c553;p=dylansserver.git diff --git a/model/note.php b/model/note.php index 01338be..8e863f1 100644 --- a/model/note.php +++ b/model/note.php @@ -12,6 +12,7 @@ class note extends model { public $day_posted; public $text; public $number_of_comments; + public $comments; public function __construct() { parent::__construct(); @@ -23,6 +24,11 @@ class note extends model { $url = substr($url, 0, (strlen($url)-6)); } $this->url = $url; + $this->fetch_note(); + $this->fetch_comments(); + } + + public function fetch_note() { $sql = "SELECT title, date_posted, text, id FROM notes WHERE url = ?"; $result = $this->query($sql, "s", @@ -40,6 +46,9 @@ class note extends model { } else { throw new notFound(); } + } + + public function fetch_comments() { $sql = "SELECT COUNT(*) FROM comments WHERE note = $this->id"; $result = $this->db->query($sql); @@ -54,6 +63,40 @@ class note extends model { require_once("view/note.php"); } + public function display_comment_link() { + if ($this->number_of_comments > 0) { + $anchor_text = "comments($this->number_of_comments)/"; + } else { + $anchor_text = "comment?"; + } + if (substr($this->url, (strlen($this->url)-1), strlen($this->url)) == '/') { + $url = $this->url . 'comments/'; + } else { + $url = $this->url . '/comments/'; + } + echo "$anchor_text"; + } + + public function display_comments() { + $sql= "SELECT date_posted, author, text + FROM comments WHERE note = ? + ORDER BY date_posted DESC"; + $result = $this->query($sql, 'd', $this->id); + $i = 0; + foreach ($result as $row => $entry) { + $this->comment[$i]['date_posted'] = $entry['date_posted']; + $this->comment[$i]['author'] = $entry['author']; + $this->comment[$i]['text'] = htmlspecialchars($entry['text']); + $this->comment[$i]['head'] = "
" . htmlspecialchars($author) . "
"; - echo "