first commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.idea
|
||||
14
App.php
Normal file
14
App.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . "/Model/TodoList.php";
|
||||
require_once __DIR__ . "/BusinessLogic/ShowTodoList.php";
|
||||
require_once __DIR__ . "/BusinessLogic/AddTodoList.php";
|
||||
require_once __DIR__ . "/BusinessLogic/RemoveTodoList.php";
|
||||
require_once __DIR__ . "/View/ViewShowTodoList.php";
|
||||
require_once __DIR__ . "/View/ViewAddTodoList.php";
|
||||
require_once __DIR__ . "/View/ViewRemoveTodoList.php";
|
||||
require_once __DIR__ . "/Helper/Input.php";
|
||||
|
||||
echo "Aplikasi Todolist" . PHP_EOL;
|
||||
|
||||
viewShowTodoList();
|
||||
13
BusinessLogic/AddTodoList.php
Normal file
13
BusinessLogic/AddTodoList.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Menambah todo ke list
|
||||
*/
|
||||
function addTodoList(string $todo)
|
||||
{
|
||||
global $todoList;
|
||||
|
||||
$number = sizeof($todoList) + 1;
|
||||
|
||||
$todoList[$number] = $todo;
|
||||
}
|
||||
21
BusinessLogic/RemoveTodoList.php
Normal file
21
BusinessLogic/RemoveTodoList.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Menghapus todo di list
|
||||
*/
|
||||
function removeTodoList(int $number): bool
|
||||
{
|
||||
global $todoList;
|
||||
|
||||
if ($number > sizeof($todoList)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for ($i = $number; $i < sizeof($todoList); $i++) {
|
||||
$todoList[$i] = $todoList[$i + 1];
|
||||
}
|
||||
|
||||
unset($todoList[sizeof($todoList)]);
|
||||
|
||||
return true;
|
||||
}
|
||||
15
BusinessLogic/ShowTodoList.php
Normal file
15
BusinessLogic/ShowTodoList.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Menampilkan todo di list
|
||||
*/
|
||||
function showTodoList()
|
||||
{
|
||||
global $todoList;
|
||||
|
||||
echo "TODOLIST" . PHP_EOL;
|
||||
|
||||
foreach ($todoList as $number => $value) {
|
||||
echo "$number. $value" . PHP_EOL;
|
||||
}
|
||||
}
|
||||
8
Helper/Input.php
Normal file
8
Helper/Input.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
function input(string $info): string
|
||||
{
|
||||
echo "$info : ";
|
||||
$result = fgets(STDIN);
|
||||
return trim($result);
|
||||
}
|
||||
3
Model/TodoList.php
Normal file
3
Model/TodoList.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
$todoList = array();
|
||||
11
Test/TestAddTodoList.php
Normal file
11
Test/TestAddTodoList.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
require_once "../Model/TodoList.php";
|
||||
require_once "../BusinessLogic/AddTodoList.php";
|
||||
|
||||
|
||||
addTodoList("Eko");
|
||||
addTodoList("Kurniawan");
|
||||
addTodoList("Khannedy");
|
||||
|
||||
var_dump($todoList);
|
||||
9
Test/TestInput.php
Normal file
9
Test/TestInput.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
require_once "../Helper/Input.php";
|
||||
|
||||
$name = input("Name");
|
||||
echo "Hello $name" . PHP_EOL;
|
||||
|
||||
$channel = input("Channel");
|
||||
echo $channel . PHP_EOL;
|
||||
28
Test/TestRemoveTodoList.php
Normal file
28
Test/TestRemoveTodoList.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
require_once "../Model/TodoList.php";
|
||||
require_once "../BusinessLogic/AddTodoList.php";
|
||||
require_once "../BusinessLogic/ShowTodoList.php";
|
||||
require_once "../BusinessLogic/RemoveTodoList.php";
|
||||
|
||||
|
||||
addTodoList("Eko");
|
||||
addTodoList("Kurniawan");
|
||||
addTodoList("Khannedy");
|
||||
addTodoList("Budi");
|
||||
addTodoList("Joko");
|
||||
|
||||
showTodoList();
|
||||
|
||||
removeTodoList(3);
|
||||
|
||||
showTodoList();
|
||||
|
||||
removeTodoList(2);
|
||||
|
||||
showTodoList();
|
||||
|
||||
$success = removeTodoList(4);
|
||||
var_dump($success);
|
||||
|
||||
showTodoList();
|
||||
10
Test/TestShowTodoList.php
Normal file
10
Test/TestShowTodoList.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
require_once "../Model/TodoList.php";
|
||||
require_once "../BusinessLogic/ShowTodoList.php";
|
||||
|
||||
$todoList[1] = "Belajar PHP Dasar";
|
||||
$todoList[2] = "Belajar PHP OOP";
|
||||
$todoList[3] = "Belajar PHP Database";
|
||||
|
||||
showTodoList();
|
||||
17
Test/TestViewAddTodoList.php
Normal file
17
Test/TestViewAddTodoList.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
require_once "../View/ViewAddTodoList.php";
|
||||
require_once "../BusinessLogic/ShowTodoList.php";
|
||||
require_once "../BusinessLogic/AddTodoList.php";
|
||||
|
||||
addTodoList("Eko");
|
||||
addTodoList("Kurniawan");
|
||||
addTodoList("Khannedy");
|
||||
|
||||
viewAddTodoList();
|
||||
|
||||
showTodoList();
|
||||
|
||||
viewAddTodoList();
|
||||
|
||||
showTodoList();
|
||||
19
Test/TestViewRemoveTodoList.php
Normal file
19
Test/TestViewRemoveTodoList.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
require_once "../Model/TodoList.php";
|
||||
require_once "../View/ViewRemoveTodoList.php";
|
||||
require_once "../BusinessLogic/AddTodoList.php";
|
||||
require_once "../BusinessLogic/ShowTodoList.php";
|
||||
|
||||
addTodoList("Eko");
|
||||
addTodoList("Kurniwan");
|
||||
addTodoList("Khannedy");
|
||||
addTodoList("Programmer");
|
||||
addTodoList("Zaman");
|
||||
addTodoList("Now");
|
||||
|
||||
showTodoList();
|
||||
|
||||
viewRemoveTodoList();
|
||||
|
||||
showTodoList();
|
||||
13
Test/TestViewShowTodoList.php
Normal file
13
Test/TestViewShowTodoList.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
require_once "../View/ViewShowTodoList.php";
|
||||
require_once "../BusinessLogic/AddTodoList.php";
|
||||
|
||||
addTodoList("Eko");
|
||||
addTodoList("Kurniawan");
|
||||
addTodoList("Khannedy");
|
||||
addTodoList("Programmer");
|
||||
addTodoList("Zaman");
|
||||
addTodoList("Now");
|
||||
|
||||
viewShowTodoList();
|
||||
18
View/ViewAddTodoList.php
Normal file
18
View/ViewAddTodoList.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . "/../Model/TodoList.php";
|
||||
require_once __DIR__ . "/../Helper/Input.php";
|
||||
require_once __DIR__ . "/../BusinessLogic/AddTodoList.php";
|
||||
|
||||
function viewAddTodoList()
|
||||
{
|
||||
echo "MENAMBAH TODO" . PHP_EOL;
|
||||
|
||||
$todo = input("Todo (x untuk batal)");
|
||||
|
||||
if ($todo == "x") {
|
||||
echo "Batal menambah todo" . PHP_EOL;
|
||||
} else {
|
||||
addTodoList($todo);
|
||||
}
|
||||
}
|
||||
23
View/ViewRemoveTodoList.php
Normal file
23
View/ViewRemoveTodoList.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . "/../Helper/Input.php";
|
||||
require_once __DIR__ . "/../BusinessLogic/RemoveTodoList.php";
|
||||
|
||||
function viewRemoveTodoList()
|
||||
{
|
||||
echo "MENGHAPUS TODO" . PHP_EOL;
|
||||
|
||||
$pilihan = input("Nomor (x untuk batalkan)");
|
||||
|
||||
if ($pilihan == "x") {
|
||||
echo "Batal menghapus todo" . PHP_EOL;
|
||||
} else {
|
||||
$success = removeTodoList($pilihan);
|
||||
|
||||
if ($success) {
|
||||
echo "Sukses menghapus todo nomor $pilihan" . PHP_EOL;
|
||||
} else {
|
||||
echo "Gagal menghapus todo nomor $pilihan" . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
33
View/ViewShowTodoList.php
Normal file
33
View/ViewShowTodoList.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . "/../Model/TodoList.php";
|
||||
require_once __DIR__ . "/../BusinessLogic/ShowTodoList.php";
|
||||
require_once __DIR__ . "/../View/ViewAddTodoList.php";
|
||||
require_once __DIR__ . "/../View/ViewRemoveTodoList.php";
|
||||
require_once __DIR__ . "/../Helper/Input.php";
|
||||
|
||||
function viewShowTodoList()
|
||||
{
|
||||
while (true) {
|
||||
showTodoList();
|
||||
|
||||
echo "MENU" . PHP_EOL;
|
||||
echo "1. Tambah Todo" . PHP_EOL;
|
||||
echo "2. Hapus Todo" . PHP_EOL;
|
||||
echo "x. Keluar" . PHP_EOL;
|
||||
|
||||
$pilihan = input("Pilih");
|
||||
|
||||
if ($pilihan == "1") {
|
||||
viewAddTodoList();
|
||||
} else if ($pilihan == "2") {
|
||||
viewRemoveTodoList();
|
||||
} else if ($pilihan == "x") {
|
||||
break;
|
||||
} else {
|
||||
echo "Pilihan tidak dimengerti" . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
echo "Sampai Jumpa Lagi" . PHP_EOL;
|
||||
}
|
||||
Reference in New Issue
Block a user