formatting, indent projects etc
[dylansserver.git] / model / archive.php
1 <?php
2
3 class archive extends model {
4
5 public $notes = array();
6
7 public function __construct() {
8 parent::__construct();
9 }
10
11 private function check_exists() {
12 $sql = "SELECT COUNT(*) FROM notes
13 WHERE url = ?";
14 $results = $this->query($sql, "s", $_GET['note']);
15 if ($results[0]["COUNT(*)"] != 1) {
16 $this->not_found();
17 }
18 }
19
20 public function display() {
21 $this->fetch_notes();
22 require_once("view/archive.php");
23 }
24
25 public function fetch_notes() {
26 switch (true) {
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",
33 $_GET['year']);
34 break;
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']);
43 break;
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'],
53 $_GET['day']);
54 break;
55 }
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;
64 }
65 }
66
67 }
68
69 ?>