diff --git a/public/assets/styles.css b/public/assets/styles.css index 2d2e53a..f4331a7 100644 --- a/public/assets/styles.css +++ b/public/assets/styles.css @@ -65,4 +65,10 @@ a .clickable{ cursor: pointer; +} + +.custom-link { + color: #B3B3B3; + text-decoration: underline; + cursor: pointer; } \ No newline at end of file diff --git a/src/Controllers/Manage/ManageDVDController.php b/src/Controllers/Manage/ManageDVDController.php index e17b6fd..c2ca1f8 100644 --- a/src/Controllers/Manage/ManageDVDController.php +++ b/src/Controllers/Manage/ManageDVDController.php @@ -3,12 +3,14 @@ namespace Controllers\Manage { + use Models\DVDModel; use Models\Exceptions\BadRouteException; use Models\Exceptions\RouteNotFoundException; use Models\QueryModel\DVDQueryModel; use Models\ViewModels\ManageDVDDetailViewModel; use Models\ViewModels\ManageDVDListViewModel; use Services\DVDService; + use Utils\PHPUtils; use Views\Manage\DVD\Detail\ManageDVDDetailView; use Views\Manage\DVD\List\ManageDVDListView; @@ -55,7 +57,7 @@ private function indexDetail($dvd) $viewModel = new ManageDVDDetailViewModel(); $service = DVDService::getInstance(); - $viewModel->DVD = $service->getDVDById($dvd); + $viewModel->DVD = PHPUtils::objectToObject($service->getDVDById($dvd), DVDModel::class); new ManageDVDDetailView($viewModel); } diff --git a/src/Models/DVDModel.php b/src/Models/DVDModel.php index 949fcd1..255b85a 100644 --- a/src/Models/DVDModel.php +++ b/src/Models/DVDModel.php @@ -5,16 +5,16 @@ class DVDModel { public int $Id; - public string $Title; - public string $LocalTitle; - public string $Synopsis; - public int $Notation; - public string $Note; - public string $Certification; - public bool $IsOffered; - public int $Quantity; - public float $Price; - public int $Year; + public ?string $Title; + public ?string $LocalTitle; + public ?string $Synopsis; + public ?int $Notation; + public ?string $Note; + public ?string $Certification; + public ?bool $IsOffered; + public ?int $Quantity; + public ?float $Price; + public ?int $Year; } } diff --git a/src/Services/DVDService.php b/src/Services/DVDService.php index 64c9e83..bc91434 100644 --- a/src/Services/DVDService.php +++ b/src/Services/DVDService.php @@ -97,12 +97,11 @@ public function getDVDById($id) $query = $queryBuilder->getQuery(); - $queryResult = $this->fetchAllStatement($query->sql, $query->params); + $queryResult = $this->fetchStatement($query->sql, $query->params, DVDModel::class); - if($queryResult && count($queryResult) == 1) + if($queryResult ) { - - return (object)$queryResult[0]; + return $queryResult; } return null; diff --git a/src/Services/DataService.php b/src/Services/DataService.php index d6ab01d..484a157 100644 --- a/src/Services/DataService.php +++ b/src/Services/DataService.php @@ -103,13 +103,22 @@ protected function fetchValue($statement, $parameters) return $query->fetchColumn(); } - protected function fetchStatement($statement, $parameters) + protected function fetchStatement($statement, $parameters, $className = null) { $this->validateStatementAndParameters($statement, $parameters); $query = $this->GetDBContext()->prepare($statement); $query->execute($parameters); - return $query->fetch(PDO::FETCH_OBJ); + + if($className != null) + { + $query->setFetchMode(PDO::FETCH_CLASS, $className); + return $query->fetch(); + } + else + { + return $query->fetch(PDO::FETCH_OBJ); + } } protected function fetchAllStatement($statement, $parameters) diff --git a/src/Utils/PHPUtils.php b/src/Utils/PHPUtils.php index 91f1d08..f6e720b 100644 --- a/src/Utils/PHPUtils.php +++ b/src/Utils/PHPUtils.php @@ -14,6 +14,7 @@ public static function arrayToObject(array $array, $className) { } public static function objectToObject($instance, $className) { + return unserialize(sprintf( 'O:%d:"%s"%s', strlen($className), diff --git a/src/Views/Manage/DVD/Detail/ManageDVDDetailView.template.php b/src/Views/Manage/DVD/Detail/ManageDVDDetailView.template.php index b8268e8..b1bdfd9 100644 --- a/src/Views/Manage/DVD/Detail/ManageDVDDetailView.template.php +++ b/src/Views/Manage/DVD/Detail/ManageDVDDetailView.template.php @@ -1,7 +1,7 @@