Skip to content

Commit

Permalink
Merge pull request #14 from tharindu-dm/developement
Browse files Browse the repository at this point in the history
Developement
  • Loading branch information
tharindu-dm authored Oct 25, 2024
2 parents 8454ce7 + a51d4b4 commit 3c06ccf
Show file tree
Hide file tree
Showing 11 changed files with 869 additions and 67 deletions.
34 changes: 30 additions & 4 deletions app/controllers/BookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public function index()
} else {
$this->view('error');
}

break;

case 'Chapter':
Expand All @@ -28,11 +27,20 @@ public function index()
} else {
$this->view('error');
}

break;

case 'List':
$this->addToList($_POST['List_uid'], $_POST['List_bid'], $_POST['list']);
switch ($URL[2]) {
case 'update':
$this->updateList($_POST['List_bid'], $_POST['chapterCount'], $_POST['status']);
break;
case 'delete':
$this->deleteFromList($_POST['List_bid']);
break;
default:
$this->addToList($_POST['List_uid'], $_POST['List_bid'], $_POST['list']);
break;
}
break;
default:
$this->view('error');
Expand Down Expand Up @@ -63,7 +71,25 @@ private function viewChapter($chapterID)
private function addToList($uid, $bookID, $status)
{
$list = new BookList(); //get chapter to be added to the list
$list->addToList($uid,$bookID, $status);
$list->addToList($uid, $bookID, $status);
$this->viewBook($bookID);
}

private function updateList($bookID, $chapterCount, $BookStatus)
{
$list = new BookList();

$uid = $_SESSION['user_id'];
$list->updateList($uid, $bookID, $chapterCount, $BookStatus);
$this->viewBook($bookID);
}

private function deleteFromList($bookID)
{
$list = new BookList();

$uid = $_SESSION['user_id'];
$list->deleteFromList($uid, $bookID);
$this->viewBook($bookID);
}
}
47 changes: 44 additions & 3 deletions app/controllers/BookListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,51 @@ class BookListController extends Controller
public function index()
{
//echo "this is the List Controller\n";
$list = new BookList;
$URL = splitURL();

$this->view("BookList"); //calling the view function in /includes/Controller.php to view the Listpage
if (count($URL) == 2) {
switch ($URL[1]) {
case 'Reading':
case 'Completed':
case 'Onhold':
case 'Dropped':
case 'Planned':
$this->listPage($URL[1]);
break;
default:
$this->view('error');
break;
}

} else {
$this->view('login');
}
}

private function listPage($listType)
{
if(!isset($_SESSION['user_id'])){
$this->view('login');
return;
}
$uid = $_SESSION['user_id'];
$Booklist = new BookList(); //List Table

$Reading = $Booklist->getUserBookList($uid, 'reading');
$Completed = $Booklist->getUserBookList($uid, 'completed');
$Onhold = $Booklist->getUserBookList($uid, 'hold');
$Dropped = $Booklist->getUserBookList($uid, 'dropped');
$Planned = $Booklist->getUserBookList($uid, 'planned');


$this->view('myBookList', [ //view the list of books
'readingList' => $Reading,
'completedList' => $Completed,
'onholdList' => $Onhold,
'droppedList' => $Dropped,
'plannedList' => $Planned
]);
}


}
2 changes: 1 addition & 1 deletion app/controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public function index()

if (count($URL) == 2) {
switch ($URL[1]) {
case 'profile':
case 'Profile':
$this->userProfile();
break;
default:
Expand Down
33 changes: 33 additions & 0 deletions app/models/BookList.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,37 @@ public function addToList($userID, $bookID, $AddStatus)
{ //$chapter to be added to the list : edit the query to add the chapter to the list
return $this->insert(['user' => $userID, 'book' => $bookID, 'status' => $AddStatus]);
}

public function getUserBookList($userID, $staus)
{ //get the list of books of the user with the status

$query = "SELECT b.[bookID], b.[title], l.chapterProgress, l.[status],
c.[name] AS cover_image FROM [Book] b
LEFT JOIN [BookList] l ON b.bookID = l.[book]
LEFT JOIN [CoverImage] c ON b.[coverImage] = c.covID
WHERE l.[user] = $userID AND l.[status] = '$staus';";

//show($query);

return $this->query($query);
}


public function updateList($uid, $bid, $chaps, $status)
{
$query = "UPDATE [BookList] SET [chapterProgress] = $chaps, [status] = '$status' WHERE [user] = $uid AND [book] = $bid;";

//show($query);

return $this->query($query);
}

public function deleteFromList($uid, $bid)
{
$query = "DELETE FROM [BookList] WHERE [user] = $uid AND [book] = $bid;";

//show($query);

return $this->query($query);
}
}
56 changes: 3 additions & 53 deletions app/views/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,9 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>404 Error - Page Not Found</title>
<link rel="icon" type="image/x-icon" href="/images/FeatherIcon.ico">
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f0f2f5;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
color: #333;
}
.container {
text-align: center;
background-color: white;
padding: 3rem;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
max-width: 500px;
}
h1 {
font-size: 4rem;
margin: 0;
color: #e74c3c;
}
h2 {
font-size: 2rem;
margin-top: 0;
}
p {
font-size: 1.1rem;
line-height: 1.6;
margin-bottom: 2rem;
}
.btn {
display: inline-block;
padding: 0.8rem 1.5rem;
background-color: #ffd700;
color: #000;
text-decoration: none;
border-radius: 5px;
transition: background-color 0.3s ease;
}
.btn:hover {
background-color: #000;
color: #ffd700;
}
.feather {
width: 100px;
height: 100px;
margin-bottom: 2rem;
}
</style>
<link rel="icon" type="image/x-icon" href="/images/FeatherIcon.ico">
<link rel="stylesheet" href="/Free-Write/public/css/error.css">
</head>
<body>
<div class="container">
Expand Down
Loading

0 comments on commit 3c06ccf

Please sign in to comment.