Categories now have their background color and font color, which effects the client and admin side

This commit is contained in:
Gregorio Chiko Putra 2017-09-15 16:32:26 +07:00
parent ec548a46b7
commit 9ca1050979
6 changed files with 231 additions and 110 deletions

View File

@ -75,10 +75,10 @@ class Posts
{ {
$this->checkValid(); $this->checkValid();
$posts = []; $datas = [];
$post = $this->model->showAll([ $data = $this->model->showJoin([
['status', '=', 1] ['pengumuman.status', '=', 1]
]); ]);
$url = 'Data/pengumuman.html'; $url = 'Data/pengumuman.html';
@ -87,30 +87,31 @@ class Posts
$privilege = ''; $privilege = '';
if (Session::exists('userid')) { if (Session::exists('userid')) {
$post = $this->model->showAll(); $data = $this->model->showJoin();
if ($args != '') { if ($args != '') {
$post = $this->model->showAll([ $data = $this->model->showJoin([
['status', '=', $args] ['pengumuman.status', '=', $args]
]); ]);
} }
$privilege = Session::get('privilege'); $privilege = Session::get('privilege');
$status = 'loggedin'; $status = 'loggedin';
} }
if ($post !== false) { if ($data !== false) {
if (array_key_exists(0, $post)) { if (array_key_exists(0, $data)) {
$posts = $post; $datas = $data;
} else { } else {
$posts[] = $post; $datas[] = $data;
} }
// Replace \n or \r with <br /> // Replace \n or \r with <br />
for ($i=0; $i < count($posts); $i++) { for ($i=0; $i < count($datas); $i++) {
$posts[$i]['content'] = preg_replace('/\r\n/', '<br />', $posts[$i]['content']); $datas[$i]['content'] = preg_replace('/\r\n/', '<br />', $datas[$i]['content']);
} }
} }
View::render($url, [ View::render($url, [
'posts' => $posts, 'posts' => $datas,
'status' => $status, 'status' => $status,
'privilege' => $privilege, 'privilege' => $privilege,
'token' => Token::generate() 'token' => Token::generate()
@ -121,7 +122,7 @@ class Posts
{ {
if (Session::exists('userid')) { if (Session::exists('userid')) {
$date = new \DateTime(); $date = new \DateTime();
$now = $date->format("d-m-Y"); $now = $date->format("Y-m-d");
$get_categories = $this->model->showAll([], 'kategori'); $get_categories = $this->model->showAll([], 'kategori');
$categories = []; $categories = [];
@ -188,7 +189,7 @@ class Posts
], $table); ], $table);
$date = new \DateTime(); $date = new \DateTime();
$timestamp = $date->format("d-m-Y"); $timestamp = $date->format("Y-m-d");
View::render( View::render(
'Data/edit_pengumuman.html', 'Data/edit_pengumuman.html',

View File

@ -27,6 +27,8 @@ class Post extends \Core\Model
[ [
'id int(3) NOT NULL AUTO_INCREMENT', 'id int(3) NOT NULL AUTO_INCREMENT',
'category varchar(20) NOT NULL', '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', 'status tinyint(1) NOT NULL DEFAULT 1',
'PRIMARY KEY (id)' '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') public function entry($args, $table = 'pengumuman')
{ {
if (count($args)) { if (count($args)) {
@ -144,8 +196,6 @@ class Post extends \Core\Model
try { try {
$sql = "INSERT INTO {$table} ({$keys}) VALUES {$values}"; $sql = "INSERT INTO {$table} ({$keys}) VALUES {$values}";
var_dump($sql);
var_dump($args);
$db = static::connectDB(); $db = static::connectDB();

View File

@ -0,0 +1,20 @@
{% extends "base.html" %}
{% block title %}Ubah Kategori{% endblock %}
{% block body %}
<main class="documentation">
<section>
<form method="post">
<div class="flex four-600 two">
<h1>Kategori
</h1>
<h1>
<input type="text" name="category" value="{{ category.category }}">
</h1>
</form>
</section>
</main>
{% endblock %}

View File

@ -6,10 +6,64 @@
<main class="documentation"> <main class="documentation">
<section> <section>
<h1>Kategori</h1> <h1>Kategori</h1>
<div class="flex two-600 full grow">
<div>
<form method="post">
<h2>Tambah Kategori</h2>
<div class="flex three-600 two grow">
<div class="third-600 full">
<label for="category">Nama</label>
</div>
<div class="two-third-600 full">
<input type="text" name="category">
</div>
<div class="third-600 full">
<label for="background">Background</label>
</div>
<div class="two-third-600 full">
<input type="color" name="background">
</div>
<div class="third-600 full">
<label for="foreground">Teks</label>
</div>
<div class="two-third-600 full">
<input type="color" name="foreground">
</div>
<input type="hidden" name="_method" value="post">
<input type="hidden" name="_addon" value="kategori">
<input type="hidden" name="_token" value="{{ token }}">
<button type="submit" class="pseudo full">
<i class="fa fa-plus fa-fw" aria-hidden="true"></i>
<span style="font-size:smaller;">Tambah</span>
</button>
</div>
</form>
</div>
<div>
<h2>List</h2> <h2>List</h2>
<ul> <ul style="margin-top:0;">
{% for cat in categories %} {% for cat in categories %}
<li>{{ cat.category }} <li>
<div style="height:initial;text-align:center;border-radius:5px;background-color:{{ cat.background }};color:{{ cat.foreground }};">
<span>
{{ cat.category }}
</span>
</div>
<div class="flex two-600 full grow" style="margin:0;">
<div>
<a href="#" class="pseudo button full">
<i class="fa fa-edit fa-fw"></i>
<span style="font-size:smaller;">Ubah</span>
</a>
</div>
<div>
<form method="post"> <form method="post">
<input type="hidden" name="id" value="{{ cat.id }}"> <input type="hidden" name="id" value="{{ cat.id }}">
{% if cat.status == 1 %} {% if cat.status == 1 %}
@ -23,37 +77,26 @@
<input type="hidden" name="_addon" value="kategori"> <input type="hidden" name="_addon" value="kategori">
<input type="hidden" name="_token" value="{{ token }}"> <input type="hidden" name="_token" value="{{ token }}">
<button type="submit" class="shyButton <button type="submit" class="pseudo full" style="height:100%;">
{% if cat.status == 1 %} {% if cat.status == 1 %}
error">Nonaktifkan <i class="fa fa-times-circle-o fa-fw"></i>
<span class="font-size:smaller;">Matikan</span>
{% elseif cat.status == 0 %} {% elseif cat.status == 0 %}
success">Aktifkan <span class="font-size:smaller;">Matikan</span>
{% endif %} {% endif %}
</button> </button>
</form> </form>
</div>
</div>
<div class="fourth-600 none"></div>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
<form method="post">
<h2>Tambah</h2>
<div class="flex three grow">
<div class="third-600 full">
<input type="text" name="category" value="" placeholder="Kategori">
</div>
<div class="third-600 none"></div>
<div class="third-600 none"></div>
<input type="hidden" name="_method" value="post">
<input type="hidden" name="_addon" value="kategori">
<input type="hidden" name="_token" value="{{ token }}">
<div>
<button type="submit" class="third-600 full">
<i class="fa fa-plus fa-fw" aria-hidden="true"></i>
</button>
</div> </div>
</div> </div>
</form>
</section> </section>
</main> </main>
{% endblock %} {% endblock %}

View File

@ -22,24 +22,27 @@
{% block body %} {% block body %}
<main class="documentation"> <main class="documentation">
<div style="background:#fff;text-align:left;width:100%;padding:80px 0 0;"> <div style="text-align:left;width:100%;">
{% if privilege == "" %} {% if privilege == "" %}
<div id="slidr-div">
{% if not posts %} {% if not posts %}
<div style="background:#fff;text-align:left;width:100vw;padding:10vh 0 0;">
<h1 class="fitty">Tidak ada pengumuman</h1> <h1 class="fitty">Tidak ada pengumuman</h1>
</div>
{% else %} {% else %}
<div id="slidr-div">
{% for post in posts %} {% for post in posts %}
<div data-slidr="{{ post.id }}" style="width: 100%;"> <div data-slidr="{{ post.id }}" style="color:{{ post.foreground }};background-color:{{ post.background }};width:100%;height:100vh;padding:15vh 0;">
<div class="fitty" style="padding: 0 5rem"> <div class="fitty" style="padding:0 5rem">
{{ post.content|rendermd }} {{ post.content|rendermd }}
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
{% endif %}
</div> </div>
{% endif %}
{% else %} {% else %}
<div style="background:#fff;text-align:left;width:100vw;padding:10vh 0 0;">
<div class="filter flex six-600 four grow"> <div class="filter flex six-600 four grow">
<div class="sixth-600 none"></div> <div class="sixth-600 none"></div>
<a href="/" class="navy noFitty">Semua</a> <a href="/" class="navy noFitty">Semua</a>
@ -54,9 +57,9 @@
</a> </a>
{% for post in posts %} {% for post in posts %}
<div class="fourth-900 half-600 card box"> <div class="fourth-900 half-600 card box" style="background-color:{{ post.background }};">
<span class="stack" style="font-size:smaller;color:rgba(17,17,17,.4);margin-bottom:.6em;">[{{ post.valid_at|date("d/m/Y") }} - {{ post.expired_at|date("d/m/Y") }}]</span> <span class="stack" style="font-size:smaller;color:rgba(17,17,17,.4);margin-bottom:.6em;">[{{ post.valid_at|date("d/m/Y") }} - {{ post.expired_at|date("d/m/Y") }}]</span>
<span class="stack">{{ post.content|rendermd }}</span> <span class="stack" style="color:{{ post.foreground }};">{{ post.content|rendermd }}</span>
<form method="post"> <form method="post">
<footer class="flex full grow"> <footer class="flex full grow">
{% if post.status != 0 %} {% if post.status != 0 %}
@ -103,8 +106,8 @@
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
</div>
{% endif %} {% endif %}
</div> </div>
</main> </main>

View File

@ -24,6 +24,10 @@
padding-right: .6em; padding-right: .6em;
} }
.flex>h1 {
padding: 0;
}
nav.transparent { nav.transparent {
box-shadow: none; box-shadow: none;
background: none; background: none;