- Introduced new `SettingsRepository` and `CacheRepository` classes in the `autoload\Domain` namespace. - Updated `SettingsController` in the `admin\Controllers` namespace to enhance settings management. - Added new templates for settings in `admin\templates\settings` and `admin\templates\site`. - Improved overall structure and organization of settings-related files.
77 lines
2.0 KiB
PHP
77 lines
2.0 KiB
PHP
<?php
|
|
namespace admin\Controllers;
|
|
|
|
use Domain\Banner\BannerRepository;
|
|
|
|
/**
|
|
* Kontroler banerów w panelu administratora (nowa architektura)
|
|
*
|
|
* Porównanie z starym kontrolerem admin\controls\Banners:
|
|
* - Używa Dependency Injection zamiast global $mdb
|
|
* - Deleguje logikę do Domain\Banner\BannerRepository
|
|
* - Kontroler zajmuje się TYLKO obsługą requestów i odpowiedzi
|
|
*/
|
|
class BannerController
|
|
{
|
|
private BannerRepository $repository;
|
|
|
|
public function __construct(BannerRepository $repository)
|
|
{
|
|
$this->repository = $repository;
|
|
}
|
|
|
|
/**
|
|
* Lista banerów
|
|
*/
|
|
public function list(): string
|
|
{
|
|
// Widok nie zmienia się - nadal używamy starego systemu szablonów
|
|
return \admin\view\Banners::banners_list();
|
|
}
|
|
|
|
/**
|
|
* Edycja banera
|
|
*/
|
|
public function edit(): string
|
|
{
|
|
$bannerId = (int)\S::get('id');
|
|
$banner = $this->repository->find($bannerId);
|
|
$languages = \admin\factory\Languages::languages_list();
|
|
|
|
return \admin\view\Banners::banner_edit($banner, $languages);
|
|
}
|
|
|
|
/**
|
|
* Zapisanie banera (AJAX)
|
|
*/
|
|
public function save(): void
|
|
{
|
|
$response = ['status' => 'error', 'msg' => 'Podczas zapisywania baneru wystąpił błąd. Proszę spróbować ponownie.'];
|
|
|
|
$values = json_decode(\S::get('values'), true);
|
|
$bannerId = $this->repository->save($values);
|
|
if ($bannerId) {
|
|
\S::delete_dir('../temp/');
|
|
$response = ['status' => 'ok', 'msg' => 'Baner został zapisany.', 'id' => $bannerId];
|
|
}
|
|
|
|
echo json_encode($response);
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Usunięcie banera
|
|
*/
|
|
public function delete(): void
|
|
{
|
|
$bannerId = (int)\S::get('id');
|
|
if ($this->repository->delete($bannerId)) {
|
|
\S::delete_dir('../temp/');
|
|
\S::alert('Baner został usunięty.');
|
|
}
|
|
|
|
header('Location: /admin/banners/view_list/');
|
|
exit;
|
|
}
|
|
}
|