diff --git a/app/controllers/admin.php b/app/controllers/admin.php index d5d189ccf42563695cbe0381b6abbf8118db8855..407a0c9e35e19adf246f439723a6430950e08c2b 100644 --- a/app/controllers/admin.php +++ b/app/controllers/admin.php @@ -90,7 +90,7 @@ class Admin extends Controller { // Cek exist ato g usernya, cek string kosong ato ngga if (!in_array($newTitle, $array, true) && !(empty($newTitle) || empty($newContent) || ( empty ($newTitle) && empty($newContent) ))){ - $this->model('BookModel')->insertBook($newTitle, $newContent, $selectedAuthor, $selectedCategory); + $this->model('BookModel')->insertBook($newTitle, $newContent, $selectedAuthor, $selectedCategory, $fileAudio, $fileImage); move_uploaded_file($fileTmpAudio, $audioFilePath); move_uploaded_file($fileTmpImage, $imageFilePath); } @@ -164,7 +164,7 @@ class Admin extends Controller { $array = array_column($data['book'], "title"); // Cek title kosong atau udah exist di db atau gk diganti if(!empty($newTitle) && (!in_array($newTitle, $array, true) || $newTitle === $oldTitle) && (isset($fileAudio) && isset($fileImage))){ - $this->model('BookModel')->updateBook($bookid, $newTitle, $selectedAuthor, $newContent, $selectedCategory); + $this->model('BookModel')->updateBook($bookid, $newTitle, $selectedAuthor, $newContent, $selectedCategory, $fileAudio, $fileImage); move_uploaded_file($fileTmpAudio, $audioFilePath); move_uploaded_file($fileTmpImage, $imageFilePath); } diff --git a/app/core/Database.php b/app/core/Database.php index da9d771170ff462567980b1dd3dba7ad779efd36..d216756c392fcfe470d703bdb13c19ee58e705f9 100644 --- a/app/core/Database.php +++ b/app/core/Database.php @@ -3,14 +3,14 @@ require_once('tables.php'); class Database { - private $host = HOST; - private $db_name = DBNAME; - private $user = USER; - private $password = PASSWORD; - private $port = PORT; + public $host = HOST; + public $db_name = DBNAME; + public $user = USER; + public $password = PASSWORD; + public $port = PORT; - private $dbs; - private $statement; + public $dbs; + public $statement; public function __construct() { diff --git a/app/models/BookModel.php b/app/models/BookModel.php index a1a8eb3c64582ca647e21495c7f9a4fca0a411c5..e502a73ace0df53963f780097363081db09aaf45 100644 --- a/app/models/BookModel.php +++ b/app/models/BookModel.php @@ -39,10 +39,10 @@ class BookModel return $this->database->resultSet(); } - public function insertBook($newTitle, $newContent, $pickedAuthor, $pickedCategory){ + public function insertBook($newTitle, $newContent, $pickedAuthor, $pickedCategory, $newAudio, $newImage){ $this->database->query('INSERT IGNORE INTO book (id, title, content, author_id, audio_path, image_path, category) VALUES (NULL, :newTitle, :newContent, (SELECT id FROM author WHERE author.name = :pickedAuthor), :newAudio, :newImage, :pickedCategory)'); - $newAudio = "audioex.mp3"; - $newImage = "imageex.png"; + // $newAudio = "audioex.mp3"; + // $newImage = "imageex.png"; $this->database->bind('newTitle', $newTitle); $this->database->bind('newContent', $newContent); $this->database->bind('newAudio', $newAudio); @@ -51,11 +51,13 @@ class BookModel $this->database->bind('pickedCategory', $pickedCategory); $this->database->execute(); } - public function updateBook($bookid, $newTitle, $selectedAuthor, $newContent, $selectedCategory){ - $this->database->query('UPDATE book SET title = :newTitle, content = :newContent, author_id = (SELECT id FROM author WHERE author.name = :selectedAuthor), category = :newCategory WHERE book.id = :bookid'); + public function updateBook($bookid, $newTitle, $selectedAuthor, $newContent, $selectedCategory, $newAudio, $newImage){ + $this->database->query('UPDATE book SET title = :newTitle, content = :newContent, audio_path = :newAudio, image_path = :newImage, author_id = (SELECT id FROM author WHERE author.name = :selectedAuthor), category = :newCategory WHERE book.id = :bookid'); $this->database->bind('bookid', $bookid); $this->database->bind('newTitle', $newTitle); $this->database->bind('newContent', $newContent); + $this->database->bind('newAudio', $newAudio); + $this->database->bind('newImage', $newImage); $this->database->bind('selectedAuthor', $selectedAuthor); $this->database->bind('newCategory', $selectedCategory); $this->database->execute();