Skip to content

Commit

Permalink
Initial Commit & First Release
Browse files Browse the repository at this point in the history
  • Loading branch information
adam080880 committed Aug 8, 2019
0 parents commit f33451f
Show file tree
Hide file tree
Showing 16 changed files with 318 additions and 0 deletions.
1 change: 1 addition & 0 deletions Auth/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deny From All
1 change: 1 addition & 0 deletions Config/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deny From All
12 changes: 12 additions & 0 deletions Config/Koneksi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

abstract class Koneksi {
protected $koneksi;

protected function connect() {
$this->koneksi = new mysqli("localhost", "root", "", "login_sekolah");
return $this->koneksi;
}
}

?>
21 changes: 21 additions & 0 deletions Config/Loader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

class Load {

public static function model(string $string) {
require "./Models/$string.php";
return new $string();
}

public static function view(string $path, $data) {
extract($data, EXTR_PREFIX_SAME, "");
require "./Views/$path.php";
}

public static function public_file(string $path) {

}

}

?>
150 changes: 150 additions & 0 deletions Config/Model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php

class Model extends Koneksi {

public $conn;
protected $table;

public function __construct(){
$this->conn = parent::connect();
}

public static function find(int $id) {
$db = new Self;
$db->table = strtolower(get_called_class());
$res = $db->conn->query("SELECT * FROM $db->table WHERE id='$id'");

if($res->num_rows == 1) {
return $res->fetch_object();
} else {
return [];
}

}

public static function get(string $where='') {
$db = new Self;
$db->table = strtolower(get_called_class());

$condition = ($where != '') ? "WHERE ".trim($where) : "";
$res = $db->conn->query("SELECT * FROM $db->table $condition");

$result = [];

while($data = $res->fetch_object()) {
$result[] = $data;
}

return $result;
}

public static function insert(array $data) {
$db = new Self;
$db->table = strtolower(get_called_class());

$sql = "INSERT INTO $db->table SET ";

$a = 0;
foreach($data as $field => $res) {
$sql .= $field . "='" . $db->conn->real_escape_string( $res ) . "'";

if($a != count($data)-1) {
$sql .= ", ";
} else {
$sql .= ";";
}
$a++;
}

if($res = $db->conn->query($sql)) {
return [
'data' => $data,
'id' => $db->conn->insert_id,
'message' => 'Success',
'status' => true
];
} else {
return [
'data' => $data,
'message' => 'Failed',
'status' => false
];
}
}

public static function update(array $data, string $where) {
$db = new Self;
$db->table = strtolower(get_called_class());

$sql = "UPDATE $db->table SET ";

$a = 0;
foreach($data as $field => $res) {
$sql .= $field . "='" . $db->conn->real_escape_string( $res ) . "'";

if($a != count($data)-1) {
$sql .= ", ";
} else {
$sql .= " ";
}
$a++;
}

$sql .= "WHERE " . $where;
if($db->conn->query($sql)) {
return [
'data' => $data,
'where' => $where,
'message' => 'Success',
'status' => true
];
} else {
return [
'data' => $data,
'where' => $where,
'message' => 'Failed',
'status' => false
];
}
}

public static function delete(string $where) {
$db = new Self;
$db->table = strtolower(get_called_class());

$data = Self::get($where);
if(count($data) > 0) {
$data = $data[0];
} else {
return [
'data' => $data,
'where' => $where,
'message' => 'Failed',
'status' => false
];
}

$sql = "DELETE FROM $db->table WHERE " . $where;
if($db->conn->query($sql)) {
return [
'data' => $data,
'where' => $where,
'message' => 'Success',
'status' => true
];
} else {
return [
'data' => $data,
'where' => $where,
'message' => 'Failed',
'status' => false
];
}

}



}

?>
1 change: 1 addition & 0 deletions Controllers/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deny From All
10 changes: 10 additions & 0 deletions Controllers/Error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

class Errors {
public function get404()
{
echo "404";
}
}

?>
19 changes: 19 additions & 0 deletions Controllers/Home.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

class Home {
public function api_get() {
header("Content-Type: application/json");
$mapel = Load::model('Mapel')->get();

echo json_encode($mapel);
}

public function index() {
Load::view('index', [
'mapel' => Load::model('Mapel')->get(),
'no' => 1
]);
}
}

?>
1 change: 1 addition & 0 deletions Models/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deny From All
7 changes: 7 additions & 0 deletions Models/Dashbord.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

class Dashboard {

}

?>
7 changes: 7 additions & 0 deletions Models/Mapel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

class Mapel extends Model {

}

?>
7 changes: 7 additions & 0 deletions Models/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

class User extends Model {

}

?>
1 change: 1 addition & 0 deletions Views/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deny From All
16 changes: 16 additions & 0 deletions Views/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<table border=1 cellspacing=0 cellpadding=10>

<tr>
<th>No</th>
<th>Nama</th>
</tr>

<?php foreach($mapel as $field => $res): ?>
<tr>

<td><?= $no++ ?></td>
<td><?= $res->nama ?></td>

</tr>
<?php endforeach; ?>
</table>
8 changes: 8 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

require "Config/Koneksi.php";
require "Config/Model.php";
require "Config/Loader.php";
require "routes.php";

?>
56 changes: 56 additions & 0 deletions routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

class Route {
public $route_control;
public $route;
public $set404;

public function __construct($route_param) {
$this->route_control = $route_param;
}

public function acc404() {
require "./Controllers/Error.php";

$control = new Errors();
$control->get404();
}

public function read() {
$cond = false;
foreach($this->route as $path => $controllerPath) {
if($path == $this->route_control) {
$controller = explode("@", $controllerPath);
require "./Controllers/$controller[0]".".php";

$controllerString = $controller[0];
$methodString = $controller[1];

$control = new $controllerString();
$control->$methodString();
$cond = true;
break;
} else {
continue;
}
}

if(!$cond) {
$this->acc404();
}
}


}

$route = isset($_GET['page']) ? $_GET['page'] : "default";

$r = new Route($route);
$r->route['default'] = "Home@index";
$r->route['api.mapel'] = "Home@api_get";

$r->set404 = "Error@get404";
$r->read();


?>

0 comments on commit f33451f

Please sign in to comment.