Skip to content

Commit

Permalink
Fixed post-spidol mess
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsDyze committed Aug 23, 2024
1 parent 31e5fc0 commit 5132904
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
6 changes: 6 additions & 0 deletions public/assets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,10 @@ a

.clickable{
cursor: pointer;
}

.custom-link {
color: #B3B3B3;
text-decoration: underline;
cursor: pointer;
}
4 changes: 3 additions & 1 deletion src/Controllers/Manage/ManageDVDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
20 changes: 10 additions & 10 deletions src/Models/DVDModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

7 changes: 3 additions & 4 deletions src/Services/DVDService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 11 additions & 2 deletions src/Services/DataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/Utils/PHPUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/Views/Manage/DVD/Detail/ManageDVDDetailView.template.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h2>
Manage <?php echo $data->DVD->TitleLocal; ?>
🎬 <?php echo $data->DVD->LocalTitle; ?> 🎬
</h2>
<a onclick="back()">Back to the list</a>
<a class="custom-link" onclick="history.back()">Back to the list</a>
<div class="dvd-form">

</div>

0 comments on commit 5132904

Please sign in to comment.