Skip to content
Snippets Groups Projects
Commit f010614f authored by AustinPardosi's avatar AustinPardosi
Browse files

fix: delete aman

parent 1d15454b
Branches
Tags
No related merge requests found
......@@ -241,12 +241,14 @@ abstract class BaseRepository
$primaryKey = $model->get('_primary_key');
if (is_array($primaryKey)) {
$sql .= implode(" AND ", array_map(function ($key, $value) {
return "$value = :key$key";
}, array_keys($primaryKey), array_values($primaryKey)));
$stmt = $this->pdo->prepare($sql);
foreach ($primaryKey as $key => $value) {
$stmt->bindValue(":key$key", $model->get($value), PDO::PARAM_STR);
}
return "$value = :$value"; // Menggunakan nama parameter yang sesuai
}, array_keys($primaryKey), array_values($primaryKey)));
$stmt = $this->pdo->prepare($sql);
foreach ($primaryKey as $key => $value) {
$stmt->bindValue(":$value", $model->get($value), PDO::PARAM_STR); // Menggunakan nama parameter yang sesuai
}
} else {
$sql .= "$primaryKey = :primaryKey";
$stmt = $this->pdo->prepare($sql);
......
......@@ -27,9 +27,13 @@ class ReviewController extends BaseController {
$urlParams["reviews"] = $reviews;
if (isset($_SESSION['user_id'])) {
try {
// echo 'MASUK';
$user_id = $_SESSION['user_id'];
$user_review = $this->service->getReviewByUserFilmId($user_id, $film_id);
$urlParams["user_review"] = $user_review;
// var_dump($user_review);
if (isset($user_review->user_id, $user_review->film_id)) {
$urlParams["user_review"] = $user_review;
}
} catch (Exception $e) {
echo $e;
}
......@@ -42,7 +46,6 @@ class ReviewController extends BaseController {
if (isset($_POST['action'])) {
$action = $_POST['action'];
if ($action == 'edit') {
echo 'EDIT';
try {
$user_id = $_SESSION['user_id'];
$film_id = 1;
......@@ -51,34 +54,30 @@ class ReviewController extends BaseController {
$rating = $review->rating;
$notes = $review->notes;
$published_time = $review->published_time;
$review ->set('rating', $rating) ->set('notes', $notes)->set('published_time', $published_time);
$response = $this->service->update($review);
if ($response == 1) {
$msg = "Review updated successfully!";
$urlParams['msg'] = $msg;
}
parent::redirect('/film-detail', $urlParams);
parent::redirect('/review', $urlParams);
} catch (Exception $e) {
$msg = $e->getMessage();
$urlParams['errorMsg'] = $msg;
parent::redirect("/review", $urlParams);
}
} elseif ($action == 'delete') {
echo "DELETEE";
try {
$user_id = $_SESSION['user_id'];
$film_id = 1;
$notes = $this->service->getReviewByUserFilmId($user_id, $film_id);
// var_dump($notes);
$response = $this->service->deleteByUserFilmId($notes->user_id, $notes->film_id);
// echo ($response);
if ($response == 1) {
$msg = "Review deleted successfully";
$urlParams['msg'] = $msg;
}
parent::redirect("/review", $urlParams);
// parent::render($urlParams, 'film-detail', 'layouts/base');
} catch (Exception $e){
$msg = $e->getMessage();
$urlParams['errorMsg'] = $msg;
......@@ -86,21 +85,21 @@ class ReviewController extends BaseController {
}
}
} else {
try {
// GET DATA
$user_id = $_SESSION['user_id'];
// $film_id = $urlParams['film_id'];
$film_id = 1;
$rating = $_POST['rating'];
$notes = $_POST['notes'];
date_default_timezone_set('Asia/Jakarta');
$published_time = date('Y-m-d H:i:s');
$response = $this->service->create($user_id, $film_id, $rating, $notes, $published_time);
} catch (Exception $e) {
$msg = $e->getMessage();
parent::render(['errorMsg' => $msg], 'film-detail', 'layouts/base');
try {
// GET DATA
$user_id = $_SESSION['user_id'];
// $film_id = $urlParams['film_id'];
$film_id = 1;
$rating = $_POST['rating'];
$notes = $_POST['notes'];
date_default_timezone_set('Asia/Jakarta');
$published_time = date('Y-m-d H:i:s');
$response = $this->service->create($user_id, $film_id, $rating, $notes, $published_time);
} catch (Exception $e) {
$msg = $e->getMessage();
parent::render(['errorMsg' => $msg], 'film-detail', 'layouts/base');
}
}
}
parent::render($urlParams, 'film-detail', 'layouts/base');
} else {
// parent::render($urlParams, 'login', 'layouts/base');
......
......@@ -16,12 +16,14 @@ class ReviewModel extends BaseModel {
}
public function constructFromArray($array) {
$this->user_id = $array['user_id'];
$this->film_id = $array['film_id'];
$this->rating = $array['rating'];
$this->notes = $array['notes'];
$this->published_time = $array['published_time'];
return $this;
if (isset($array['user_id'], $array['film_id'], $array['rating'], $array['notes'], $array['published_time'])) {
$this->user_id = $array['user_id'];
$this->film_id = $array['film_id'];
$this->rating = $array['rating'];
$this->notes = $array['notes'];
$this->published_time = $array['published_time'];
return $this;
}
}
public function toResponse() {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment