3 class archive
extends model
{
5 public $notes = array();
7 public function __construct() {
11 private function check_exists() {
12 $sql = "SELECT COUNT(*) FROM notes
14 $results = $this->query($sql, "s", $_GET['note']);
15 if ($results[0]["COUNT(*)"] != 1) {
20 public function display() {
22 require_once("view/archive.php");
25 public function fetch_notes() {
27 case (isset($_GET['year']) && !isset($_GET['month'])
28 && !isset($_GET['day'])):
29 $sql = "SELECT title, url, date_posted, text
30 FROM notes WHERE YEAR(date_posted) = ?
31 ORDER BY date_posted DESC";
32 $result = $this->query($sql, "d",
35 case (isset($_GET['year']) && isset($_GET['month'])
36 && !isset($_GET['day'])):
37 $sql = "SELECT title, url, date_posted, text
38 FROM notes WHERE YEAR(date_posted) = ?
39 AND MONTH(date_posted) = ?
40 ORDER BY date_posted DESC";
41 $result = $this->query($sql, "dd",
42 $_GET['year'], $_GET['month']);
44 case (isset($_GET['year']) && isset($_GET['month'])
45 && isset($_GET['day'])):
46 $sql = "SELECT title, url, date_posted, text
47 FROM notes WHERE YEAR(date_posted) = ?
48 AND MONTH(date_posted) = ?
49 AND DAY(date_posted) = ?
50 ORDER BY date_posted DESC";
51 $result = $this->query($sql, "ddd",
52 $_GET['year'], $_GET['month'],
56 foreach ($result as $row => $entry) {
57 $entry['url'] = '/note/' . $entry['url'];
58 $date_posted = explode("-", $entry['date_posted']);
59 $entry['year_posted'] = $date_posted[0];
60 $entry['month_posted'] = $date_posted[1];
61 $entry['datetime_posted'] = explode(' ', $date_posted[2]);
62 $entry['day_posted'] = $entry['date_posted'][0];
63 $this->notes
[$row] = $entry;