diff --git a/App/Controllers/Posts.php b/App/Controllers/Posts.php index adb73d4..af8e216 100644 --- a/App/Controllers/Posts.php +++ b/App/Controllers/Posts.php @@ -75,10 +75,10 @@ class Posts { $this->checkValid(); - $posts = []; + $datas = []; - $post = $this->model->showAll([ - ['status', '=', 1] + $data = $this->model->showJoin([ + ['pengumuman.status', '=', 1] ]); $url = 'Data/pengumuman.html'; @@ -87,30 +87,31 @@ class Posts $privilege = ''; if (Session::exists('userid')) { - $post = $this->model->showAll(); + $data = $this->model->showJoin(); if ($args != '') { - $post = $this->model->showAll([ - ['status', '=', $args] + $data = $this->model->showJoin([ + ['pengumuman.status', '=', $args] ]); } $privilege = Session::get('privilege'); $status = 'loggedin'; } - if ($post !== false) { - if (array_key_exists(0, $post)) { - $posts = $post; + if ($data !== false) { + if (array_key_exists(0, $data)) { + $datas = $data; } else { - $posts[] = $post; + $datas[] = $data; } // Replace \n or \r with
- for ($i=0; $i < count($posts); $i++) { - $posts[$i]['content'] = preg_replace('/\r\n/', '
', $posts[$i]['content']); + for ($i=0; $i < count($datas); $i++) { + $datas[$i]['content'] = preg_replace('/\r\n/', '
', $datas[$i]['content']); } } + View::render($url, [ - 'posts' => $posts, + 'posts' => $datas, 'status' => $status, 'privilege' => $privilege, 'token' => Token::generate() @@ -121,7 +122,7 @@ class Posts { if (Session::exists('userid')) { $date = new \DateTime(); - $now = $date->format("d-m-Y"); + $now = $date->format("Y-m-d"); $get_categories = $this->model->showAll([], 'kategori'); $categories = []; @@ -188,7 +189,7 @@ class Posts ], $table); $date = new \DateTime(); - $timestamp = $date->format("d-m-Y"); + $timestamp = $date->format("Y-m-d"); View::render( 'Data/edit_pengumuman.html', diff --git a/App/Models/Post.php b/App/Models/Post.php index b4d6e59..406891b 100644 --- a/App/Models/Post.php +++ b/App/Models/Post.php @@ -27,6 +27,8 @@ class Post extends \Core\Model [ 'id int(3) NOT NULL AUTO_INCREMENT', 'category varchar(20) NOT NULL', + 'background char(7) NOT NULL DEFAULT "#ffffff"', + 'foreground char(7) NOT NULL DEFAULT "#000000"', 'status tinyint(1) NOT NULL DEFAULT 1', 'PRIMARY KEY (id)' ], @@ -114,6 +116,56 @@ class Post extends \Core\Model } } + public function showJoin($conditions = []) + { + try { + $db = static::connectDB(); + + $sql = "SELECT pengumuman.id, kategori.background, kategori.foreground, pengumuman.valid_at, pengumuman.expired_at, pengumuman.content, pengumuman.status FROM pengumuman INNER JOIN kategori ON pengumuman.category=kategori.id"; + + if ($conditions) { + $sql .= " WHERE"; + foreach ($conditions as $condition) { + + $keys[] = $condition[0]; + $operators[] = $condition[1]; + $values[] = $condition[2]; + } + + $x = 0; + foreach ($keys as $key) { + $sql .= " $key $operators[$x] ?"; + $x++; + if ($x < count($keys)) { + $sql .= " AND"; + } + } + } + + $query = $db->prepare($sql); + if (count($conditions)) { + $x = 1; + foreach ($values as $value) { + $query->bindValue($x, $value); + $x++; + } + } + + $query->execute(); + if ($query->rowCount() == 1) { + $result = $query->fetch(\PDO::FETCH_ASSOC); + } elseif ($query->rowCount() > 1) { + $result = $query->fetchAll(\PDO::FETCH_ASSOC); + } else { + return false; + } + return $result; + } catch (PDOException $e) { + throw new \Exception($e->getMessage(), 444); + } + + } + public function entry($args, $table = 'pengumuman') { if (count($args)) { @@ -144,8 +196,6 @@ class Post extends \Core\Model try { $sql = "INSERT INTO {$table} ({$keys}) VALUES {$values}"; - var_dump($sql); - var_dump($args); $db = static::connectDB(); diff --git a/App/Views/Data/edit_kategori.html b/App/Views/Data/edit_kategori.html new file mode 100644 index 0000000..7245f11 --- /dev/null +++ b/App/Views/Data/edit_kategori.html @@ -0,0 +1,20 @@ +{% extends "base.html" %} + +{% block title %}Ubah Kategori{% endblock %} + +{% block body %} + +
+
+
+
+

Kategori +

+

+ +

+ +
+
+ +{% endblock %} diff --git a/App/Views/Data/kategori.html b/App/Views/Data/kategori.html index 9b58d02..62facf4 100644 --- a/App/Views/Data/kategori.html +++ b/App/Views/Data/kategori.html @@ -6,54 +6,97 @@

Kategori

-

List

- +
+ +
+
+ +
-
-

Tambah

-
-
- -
-
-
- - - - -
-
-
-
+ + + +
+

List

+
    + {% for cat in categories %} +
  • +
    + + {{ cat.category }} + +
    + +
    + +
    +
    + + {% if cat.status == 1 %} + + + {% elseif cat.status == 0 %} + + + {% endif %} + + + + + +
    +
    +
    + +
    +
  • + {% endfor %} +
+
+
{% endblock %} diff --git a/App/Views/Data/pengumuman.html b/App/Views/Data/pengumuman.html index 9130761..73b66b1 100644 --- a/App/Views/Data/pengumuman.html +++ b/App/Views/Data/pengumuman.html @@ -22,24 +22,27 @@ {% block body %}
-
+
{% if privilege == "" %} -
{% if not posts %} +

Tidak ada pengumuman

+
{% else %} +
{% for post in posts %} -
-
+
+
{{ post.content|rendermd }}
{% endfor %} - {% endif %}
+ {% endif %} {% else %} +
Semua @@ -54,57 +57,57 @@ {% for post in posts %} -
- [{{ post.valid_at|date("d/m/Y") }} - {{ post.expired_at|date("d/m/Y") }}] - {{ post.content|rendermd }} -
-
- {% if post.status != 0 %} - - {% else %} -
- Nonaktif -
- {% endif %} - {% if (post.status == 1 and editor_now.id == creator.id) %} -
- - - - - - - -
- {% elseif (post.status == 2 and editor_now.id == creator.id) %} -
- - - - - - - -
- {% endif %} -
-
+
+ [{{ post.valid_at|date("d/m/Y") }} - {{ post.expired_at|date("d/m/Y") }}] + {{ post.content|rendermd }} +
+ +
{% endfor %}
+
{% endif %} -
diff --git a/App/Views/base.html b/App/Views/base.html index 032232d..efdf6cf 100644 --- a/App/Views/base.html +++ b/App/Views/base.html @@ -24,6 +24,10 @@ padding-right: .6em; } + .flex>h1 { + padding: 0; + } + nav.transparent { box-shadow: none; background: none;