Files
shopPRO/autoload/admin/Controllers/SettingsController.php
Jacek Pyziak 1c88f8adfa Add new settings and cache repository files, update admin settings controller and templates
- 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.
2026-02-05 23:32:48 +01:00

89 lines
2.2 KiB
PHP

<?php
namespace admin\Controllers;
use Domain\Settings\SettingsRepository;
/**
* Kontroler ustawień w panelu administratora (nowa architektura)
*
* Używa Dependency Injection zamiast static methods
* Deleguje logikę do Domain\Settings\SettingsRepository
*/
class SettingsController
{
private SettingsRepository $settingsRepository;
public function __construct(SettingsRepository $settingsRepository)
{
$this->settingsRepository = $settingsRepository;
}
/**
* Czyszczenie cache
*/
public function clearCache(): void
{
\S::delete_dir( '../temp/' );
\S::delete_dir( '../thumbs/' );
$redis = \RedisConnection::getInstance()->getConnection();
if ( $redis )
$redis->flushAll();
\S::alert( 'Cache został wyczyszczony.' );
\S::htacces();
header( 'Location: /admin/dashboard/main_view/' );
exit;
}
/**
* Czyszczenie cache (AJAX)
*/
public function clearCacheAjax(): void
{
try {
\S::delete_dir( '../temp/' );
\S::delete_dir( '../thumbs/' );
$redis = \RedisConnection::getInstance()->getConnection();
if ( $redis )
$redis->flushAll();
\S::htacces();
echo json_encode( [ 'status' => 'success', 'message' => 'Cache został wyczyszczony.' ] );
} catch ( \Exception $e ) {
echo json_encode( [ 'status' => 'error', 'message' => 'Błąd podczas czyszczenia cache: ' . $e->getMessage() ] );
}
exit;
}
/**
* Zapis ustawień (AJAX)
*/
public function save(): void
{
$values = json_decode( \S::get( 'values' ), true );
$response = $this->settingsRepository->saveSettings( $values );
\S::delete_dir( '../temp/' );
\S::htacces();
echo json_encode( $response );
exit;
}
/**
* Widok ustawień
*/
public function view(): string
{
return \Tpl::view( 'settings/settings', [
'languages' => \admin\factory\Languages::languages_list(),
'settings' => $this->settingsRepository->getSettings()
] );
}
}