ver 0.250: migrate settings to form-edit and cleanup legacy settings classes
This commit is contained in:
@@ -89,7 +89,7 @@ shop\product:{product_id}:{lang_id}:{permutation_hash}
|
||||
- **Lokalizacja UI:** `admin/templates/site/main-layout.php:172`
|
||||
- **JavaScript:** `admin/templates/site/main-layout.php:235-274`
|
||||
- **Endpoint AJAX:** `/admin/settings/clear_cache_ajax/`
|
||||
- **Kontroler:** `autoload/admin/controls/class.Settings.php:20-42`
|
||||
- **Kontroler:** `autoload/admin/Controllers/SettingsController.php:43-60`
|
||||
- **Działanie:**
|
||||
1. Pokazuje spinner "Czyszczę cache..."
|
||||
2. Czyści katalogi: `temp/`, `thumbs/`
|
||||
|
||||
@@ -2,65 +2,159 @@
|
||||
namespace Domain\Settings;
|
||||
|
||||
/**
|
||||
* Repozytorium ustawień - deleguje do admin\factory\Settings (legacy)
|
||||
*
|
||||
* Krok pośredni migracji: wyodrębnia logikę zapisu z kontrolera.
|
||||
* Docelowo zastąpi factory bezpośrednim dostępem do bazy (jak BannerRepository).
|
||||
* Repozytorium ustawien panelu administratora.
|
||||
*/
|
||||
class SettingsRepository
|
||||
{
|
||||
private $db;
|
||||
|
||||
public function __construct($db = null)
|
||||
{
|
||||
if ($db) {
|
||||
$this->db = $db;
|
||||
return;
|
||||
}
|
||||
|
||||
global $mdb;
|
||||
$this->db = $mdb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zapis ustawień
|
||||
* Zapis ustawien.
|
||||
*
|
||||
* @param array $values Tablica wartości z formularza
|
||||
* @return array Odpowiedź z factory ['status' => string, 'msg' => string]
|
||||
* @param array $values Tablica wartosci z formularza
|
||||
* @return array ['status' => string, 'msg' => string]
|
||||
*/
|
||||
public function saveSettings(array $values): array
|
||||
{
|
||||
$settings = \admin\factory\Settings::settings_details();
|
||||
$currentSettings = $this->getSettings();
|
||||
|
||||
$response = \admin\factory\Settings::settings_save(
|
||||
$values['firm_name'], $values['firm_adress'], $values['additional_info'], $values['contact_form'], $values['contact_email'], $values['email_host'],
|
||||
$values['email_port'], $values['email_login'], $values['email_password'], $values['google_maps'], $values['facebook_link'], $values['statistic_code'], $values['htaccess'],
|
||||
$values['robots'], $values['shop_bank_account_info'], $values['update'], $values['boot_animation'], $settings['newsletter_header'], $settings['newsletter_footer'], $values['hotpay_api']
|
||||
);
|
||||
$settingsToSave = [
|
||||
'firm_name' => $values['firm_name'] ?? '',
|
||||
'firm_adress' => $values['firm_adress'] ?? '',
|
||||
'additional_info' => $values['additional_info'] ?? '',
|
||||
'contact_form' => $this->isEnabled($values['contact_form'] ?? null) ? 1 : 0,
|
||||
'contact_email' => $values['contact_email'] ?? '',
|
||||
'email_host' => $values['email_host'] ?? '',
|
||||
'email_port' => $values['email_port'] ?? '',
|
||||
'email_login' => $values['email_login'] ?? '',
|
||||
'email_password' => $values['email_password'] ?? '',
|
||||
'google_maps' => $values['google_maps'] ?? '',
|
||||
'facebook_link' => $values['facebook_link'] ?? '',
|
||||
'statistic_code' => $values['statistic_code'] ?? '',
|
||||
'htaccess' => $values['htaccess'] ?? '',
|
||||
'robots' => $values['robots'] ?? '',
|
||||
'shop_bank_account_info' => $values['shop_bank_account_info'] ?? '',
|
||||
'update' => $this->isEnabled($values['update'] ?? null) ? 1 : 0,
|
||||
'boot_animation' => $values['boot_animation'] ?? '',
|
||||
// Te pola sa edytowane w module newsletter i musza zostac zachowane.
|
||||
'newsletter_header' => $currentSettings['newsletter_header'] ?? '',
|
||||
'newsletter_footer' => $currentSettings['newsletter_footer'] ?? '',
|
||||
'hotpay_api' => $values['hotpay_api'] ?? '',
|
||||
|
||||
\admin\factory\Settings::settings_update( 'devel', $values['devel'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'ssl', $values['ssl'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'htaccess_cache', $values['htaccess_cache'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'free_delivery', $values['free_delivery'] );
|
||||
\admin\factory\Settings::settings_update( 'przelewy24_sandbox', $values['przelewy24_sandbox'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'przelewy24_merchant_id', $values['przelewy24_merchant_id'] );
|
||||
\admin\factory\Settings::settings_update( 'przelewy24_crc_key', $values['przelewy24_crc_key'] );
|
||||
\admin\factory\Settings::settings_update( 'update_key', $values['update_key'] );
|
||||
\admin\factory\Settings::settings_update( 'tpay_id', $values['tpay_id'] );
|
||||
\admin\factory\Settings::settings_update( 'tpay_sandbox', $values['tpay_sandbox'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'tpay_security_code', $values['tpay_security_code'] );
|
||||
\admin\factory\Settings::settings_update( 'piksel', $values['piksel'] );
|
||||
\admin\factory\Settings::settings_update( 'generate_webp', $values['generate_webp'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'lazy_loading', $values['lazy_loading'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'orlen_paczka_map_token', $values['orlen_paczka_map_token'] );
|
||||
\admin\factory\Settings::settings_update( 'google_tag_manager_id', $values['google_tag_manager_id'] );
|
||||
\admin\factory\Settings::settings_update( 'infinitescroll', $values['infinitescroll'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'own_gtm_js', $values['own_gtm_js'] );
|
||||
\admin\factory\Settings::settings_update( 'own_gtm_html', $values['own_gtm_html'] );
|
||||
'devel' => $this->isEnabled($values['devel'] ?? null) ? 1 : 0,
|
||||
'ssl' => $this->isEnabled($values['ssl'] ?? null) ? 1 : 0,
|
||||
'htaccess_cache' => $this->isEnabled($values['htaccess_cache'] ?? null) ? 1 : 0,
|
||||
'free_delivery' => $values['free_delivery'] ?? '',
|
||||
'przelewy24_sandbox' => $this->isEnabled($values['przelewy24_sandbox'] ?? null) ? 1 : 0,
|
||||
'przelewy24_merchant_id' => $values['przelewy24_merchant_id'] ?? '',
|
||||
'przelewy24_crc_key' => $values['przelewy24_crc_key'] ?? '',
|
||||
'update_key' => $values['update_key'] ?? '',
|
||||
'tpay_id' => $values['tpay_id'] ?? '',
|
||||
'tpay_sandbox' => $this->isEnabled($values['tpay_sandbox'] ?? null) ? 1 : 0,
|
||||
'tpay_security_code' => $values['tpay_security_code'] ?? '',
|
||||
'piksel' => $values['piksel'] ?? '',
|
||||
'generate_webp' => $this->isEnabled($values['generate_webp'] ?? null) ? 1 : 0,
|
||||
'lazy_loading' => $this->isEnabled($values['lazy_loading'] ?? null) ? 1 : 0,
|
||||
'orlen_paczka_map_token' => $values['orlen_paczka_map_token'] ?? '',
|
||||
'google_tag_manager_id' => $values['google_tag_manager_id'] ?? '',
|
||||
'infinitescroll' => $this->isEnabled($values['infinitescroll'] ?? null) ? 1 : 0,
|
||||
'own_gtm_js' => $values['own_gtm_js'] ?? '',
|
||||
'own_gtm_html' => $values['own_gtm_html'] ?? '',
|
||||
];
|
||||
|
||||
foreach ( $values['warehouse_message_zero'] as $key => $val )
|
||||
\admin\factory\Settings::settings_update( 'warehouse_message_zero_' . $key, $val );
|
||||
$warehouseMessageZero = $values['warehouse_message_zero'] ?? [];
|
||||
if (is_array($warehouseMessageZero)) {
|
||||
foreach ($warehouseMessageZero as $key => $value) {
|
||||
$settingsToSave['warehouse_message_zero_' . $key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $values['warehouse_message_nonzero'] as $key => $val )
|
||||
\admin\factory\Settings::settings_update( 'warehouse_message_nonzero_' . $key, $val );
|
||||
$warehouseMessageNonZero = $values['warehouse_message_nonzero'] ?? [];
|
||||
if (is_array($warehouseMessageNonZero)) {
|
||||
foreach ($warehouseMessageNonZero as $key => $value) {
|
||||
$settingsToSave['warehouse_message_nonzero_' . $key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
// Zachowanie zgodne z dotychczasowym flow: pelna podmiana zestawu ustawien.
|
||||
$this->db->query('TRUNCATE pp_settings');
|
||||
$this->updateSettings($settingsToSave);
|
||||
|
||||
\S::set_message('Ustawienia zostaly zapisane');
|
||||
|
||||
return ['status' => 'ok', 'msg' => 'Ustawienia zostaly zapisane.'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Pobranie wszystkich ustawień
|
||||
* Aktualizacja pojedynczego parametru.
|
||||
*/
|
||||
public function updateSetting(string $param, $value): bool
|
||||
{
|
||||
$this->db->delete('pp_settings', ['param' => $param]);
|
||||
$this->db->insert('pp_settings', ['param' => $param, 'value' => $value]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualizacja wielu parametrow przez jedna sciezke.
|
||||
*/
|
||||
public function updateSettings(array $settings): bool
|
||||
{
|
||||
foreach ($settings as $param => $value) {
|
||||
$this->updateSetting((string)$param, $value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pobranie wszystkich ustawien.
|
||||
*
|
||||
* @return array Tablica ustawień [param => value]
|
||||
* @return array Tablica ustawien [param => value]
|
||||
*/
|
||||
public function getSettings(): array
|
||||
{
|
||||
return \admin\factory\Settings::settings_details() ?? [];
|
||||
$results = $this->db->select('pp_settings', '*', ['ORDER' => ['id' => 'ASC']]);
|
||||
$settings = [];
|
||||
|
||||
if (is_array($results)) {
|
||||
foreach ($results as $row) {
|
||||
if (isset($row['param'])) {
|
||||
$settings[$row['param']] = $row['value'] ?? '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
private function isEnabled($value): bool
|
||||
{
|
||||
if (is_bool($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (is_int($value) || is_float($value)) {
|
||||
return (int)$value === 1;
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
$normalized = strtolower(trim($value));
|
||||
return in_array($normalized, ['1', 'on', 'true', 'yes'], true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,87 +2,375 @@
|
||||
namespace admin\Controllers;
|
||||
|
||||
use Domain\Settings\SettingsRepository;
|
||||
use admin\ViewModels\Forms\FormEditViewModel;
|
||||
use admin\ViewModels\Forms\FormField;
|
||||
use admin\ViewModels\Forms\FormTab;
|
||||
use admin\ViewModels\Forms\FormAction;
|
||||
use admin\Support\Forms\FormRequestHandler;
|
||||
|
||||
/**
|
||||
* Kontroler ustawień w panelu administratora (nowa architektura)
|
||||
*
|
||||
* Używa Dependency Injection zamiast static methods
|
||||
* Deleguje logikę do Domain\Settings\SettingsRepository
|
||||
* Kontroler ustawien w panelu administratora.
|
||||
*/
|
||||
class SettingsController
|
||||
{
|
||||
private SettingsRepository $settingsRepository;
|
||||
private FormRequestHandler $formHandler;
|
||||
|
||||
public function __construct(SettingsRepository $settingsRepository)
|
||||
{
|
||||
$this->settingsRepository = $settingsRepository;
|
||||
$this->formHandler = new FormRequestHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Czyszczenie cache
|
||||
* Czyszczenie cache.
|
||||
*/
|
||||
public function clearCache(): void
|
||||
{
|
||||
\S::delete_dir( '../temp/' );
|
||||
\S::delete_dir( '../thumbs/' );
|
||||
\S::delete_dir('../temp/');
|
||||
\S::delete_dir('../thumbs/');
|
||||
|
||||
$redis = \RedisConnection::getInstance()->getConnection();
|
||||
if ( $redis )
|
||||
if ($redis) {
|
||||
$redis->flushAll();
|
||||
}
|
||||
|
||||
\S::alert( 'Cache został wyczyszczony.' );
|
||||
\S::alert('Cache został wyczyszczony.');
|
||||
\S::htacces();
|
||||
|
||||
header( 'Location: /admin/dashboard/main_view/' );
|
||||
header('Location: /admin/dashboard/main_view/');
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Czyszczenie cache (AJAX)
|
||||
* Czyszczenie cache (AJAX).
|
||||
*/
|
||||
public function clearCacheAjax(): void
|
||||
{
|
||||
try {
|
||||
\S::delete_dir( '../temp/' );
|
||||
\S::delete_dir( '../thumbs/' );
|
||||
\S::delete_dir('../temp/');
|
||||
\S::delete_dir('../thumbs/');
|
||||
|
||||
$redis = \RedisConnection::getInstance()->getConnection();
|
||||
if ( $redis )
|
||||
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() ] );
|
||||
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)
|
||||
* Zapis ustawien (AJAX).
|
||||
*/
|
||||
public function save(): void
|
||||
{
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
// Kompatybilnosc wsteczna dla legacy gridEdit (values jako JSON).
|
||||
$legacyValues = \S::get('values');
|
||||
if ($legacyValues) {
|
||||
$values = json_decode($legacyValues, true);
|
||||
$result = $this->settingsRepository->saveSettings(is_array($values) ? $values : []);
|
||||
|
||||
$response = $this->settingsRepository->saveSettings( $values );
|
||||
\S::delete_dir('../temp/');
|
||||
\S::htacces();
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
echo json_encode($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
$languages = \admin\factory\Languages::languages_list();
|
||||
$settings = $this->settingsRepository->getSettings();
|
||||
$viewModel = $this->buildFormViewModel($settings, $languages);
|
||||
|
||||
$result = $this->formHandler->handleSubmit($viewModel, $_POST);
|
||||
if (!$result['success']) {
|
||||
$_SESSION['form_errors'][$this->getFormId()] = $result['errors'];
|
||||
echo json_encode(['success' => false, 'errors' => $result['errors']]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$values = $this->transformFormDataToSettings($result['data']);
|
||||
$saveResult = $this->settingsRepository->saveSettings($values);
|
||||
|
||||
\S::delete_dir('../temp/');
|
||||
\S::htacces();
|
||||
|
||||
echo json_encode( $response );
|
||||
echo json_encode([
|
||||
'success' => ($saveResult['status'] ?? '') === 'ok',
|
||||
'message' => $saveResult['msg'] ?? 'Ustawienia zostały zapisane.',
|
||||
'errors' => (($saveResult['status'] ?? '') === 'ok') ? [] : ['general' => ($saveResult['msg'] ?? 'Błąd zapisu.')],
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Widok ustawień
|
||||
* Widok ustawien.
|
||||
*/
|
||||
public function view(): string
|
||||
{
|
||||
return \Tpl::view( 'settings/settings', [
|
||||
'languages' => \admin\factory\Languages::languages_list(),
|
||||
'settings' => $this->settingsRepository->getSettings()
|
||||
] );
|
||||
$languages = \admin\factory\Languages::languages_list();
|
||||
$settings = $this->settingsRepository->getSettings();
|
||||
|
||||
$validationErrors = $_SESSION['form_errors'][$this->getFormId()] ?? null;
|
||||
if ($validationErrors) {
|
||||
unset($_SESSION['form_errors'][$this->getFormId()]);
|
||||
}
|
||||
|
||||
$viewModel = $this->buildFormViewModel($settings, $languages, $validationErrors);
|
||||
|
||||
return \Tpl::view('components/form-edit', ['form' => $viewModel]);
|
||||
}
|
||||
|
||||
private function buildFormViewModel(array $settings, array $languages, ?array $errors = null): FormEditViewModel
|
||||
{
|
||||
$data = $this->transformSettingsToFormData($settings, $languages);
|
||||
|
||||
$tabs = [
|
||||
new FormTab('contact', 'Dane kontaktowe', 'fa-paper-plane'),
|
||||
new FormTab('shop', 'Sklep', 'fa-dollar'),
|
||||
new FormTab('products', 'Produkty', 'fa-shopping-cart'),
|
||||
new FormTab('mail', 'Poczta', 'fa-envelope'),
|
||||
new FormTab('other', 'Pozostałe', 'fa-bars'),
|
||||
new FormTab('system', 'System', 'fa-cog'),
|
||||
new FormTab('conversions', 'Konwersje', 'fa-line-chart'),
|
||||
];
|
||||
|
||||
$fields = [
|
||||
FormField::text('firm_name', [
|
||||
'label' => 'Nazwa firmy',
|
||||
'tab' => 'contact',
|
||||
]),
|
||||
FormField::editor('additional_info', [
|
||||
'label' => 'Dodatkowe informacje',
|
||||
'tab' => 'contact',
|
||||
'height' => 150,
|
||||
]),
|
||||
FormField::switch('google_maps', [
|
||||
'label' => 'Mapa',
|
||||
'tab' => 'contact',
|
||||
]),
|
||||
FormField::textarea('firm_adress', [
|
||||
'label' => 'Mapa - adres',
|
||||
'tab' => 'contact',
|
||||
]),
|
||||
|
||||
FormField::editor('shop_bank_account_info', [
|
||||
'label' => 'Dane do przelewu',
|
||||
'tab' => 'shop',
|
||||
'height' => 200,
|
||||
]),
|
||||
FormField::text('hotpay_api', [
|
||||
'label' => 'Klucz API HotPay',
|
||||
'tab' => 'shop',
|
||||
]),
|
||||
FormField::switch('tpay_sandbox', [
|
||||
'label' => 'Tpay.com - tryb sandbox',
|
||||
'tab' => 'shop',
|
||||
]),
|
||||
FormField::text('tpay_id', [
|
||||
'label' => 'Tpay.com ID',
|
||||
'tab' => 'shop',
|
||||
]),
|
||||
FormField::text('tpay_security_code', [
|
||||
'label' => 'Tpay.com - kod bezpieczeństwa',
|
||||
'tab' => 'shop',
|
||||
]),
|
||||
FormField::switch('przelewy24_sandbox', [
|
||||
'label' => 'Przelewy24.pl - tryb sandbox',
|
||||
'tab' => 'shop',
|
||||
]),
|
||||
FormField::text('przelewy24_merchant_id', [
|
||||
'label' => 'Przelewy24.pl - merchant ID',
|
||||
'tab' => 'shop',
|
||||
]),
|
||||
FormField::text('przelewy24_crc_key', [
|
||||
'label' => 'Przelewy24.pl - klucz CRC',
|
||||
'tab' => 'shop',
|
||||
]),
|
||||
FormField::text('free_delivery', [
|
||||
'label' => 'Darmowa dostawa od',
|
||||
'tab' => 'shop',
|
||||
'attributes' => ['class' => 'number-format'],
|
||||
]),
|
||||
FormField::text('orlen_paczka_map_token', [
|
||||
'label' => 'Orlen Paczka map token',
|
||||
'tab' => 'shop',
|
||||
]),
|
||||
|
||||
FormField::langSection('warehouse_messages', 'products', [
|
||||
FormField::text('warehouse_message_zero', [
|
||||
'label' => 'Komunikat gdy stan magazynowy równy 0',
|
||||
]),
|
||||
FormField::text('warehouse_message_nonzero', [
|
||||
'label' => 'Komunikat gdy stan magazynowy większy niż 0',
|
||||
]),
|
||||
]),
|
||||
|
||||
FormField::switch('contact_form', [
|
||||
'label' => 'Formularz kontaktowy',
|
||||
'tab' => 'mail',
|
||||
]),
|
||||
FormField::text('contact_email', [
|
||||
'label' => 'Email kontaktowy',
|
||||
'tab' => 'mail',
|
||||
]),
|
||||
FormField::text('email_host', [
|
||||
'label' => 'Email - host',
|
||||
'tab' => 'mail',
|
||||
]),
|
||||
FormField::text('email_port', [
|
||||
'label' => 'Email - port',
|
||||
'tab' => 'mail',
|
||||
]),
|
||||
FormField::text('email_login', [
|
||||
'label' => 'Email - login',
|
||||
'tab' => 'mail',
|
||||
]),
|
||||
FormField::text('email_password', [
|
||||
'label' => 'Email - hasło',
|
||||
'tab' => 'mail',
|
||||
]),
|
||||
|
||||
FormField::text('facebook_link', [
|
||||
'label' => 'Facebook link',
|
||||
'tab' => 'other',
|
||||
]),
|
||||
FormField::text('piksel', [
|
||||
'label' => 'Piksel Facebook',
|
||||
'tab' => 'other',
|
||||
]),
|
||||
FormField::textarea('statistic_code', [
|
||||
'label' => 'Kod statystyk',
|
||||
'tab' => 'other',
|
||||
'rows' => 10,
|
||||
]),
|
||||
FormField::textarea('htaccess', [
|
||||
'label' => 'Własne reguły htacess',
|
||||
'tab' => 'other',
|
||||
'rows' => 10,
|
||||
]),
|
||||
FormField::textarea('robots', [
|
||||
'label' => 'Własne reguły robots.txt',
|
||||
'tab' => 'other',
|
||||
'rows' => 10,
|
||||
]),
|
||||
|
||||
FormField::switch('update', [
|
||||
'label' => 'Aktualizacja',
|
||||
'tab' => 'system',
|
||||
]),
|
||||
FormField::text('update_key', [
|
||||
'label' => 'Numer licencji',
|
||||
'tab' => 'system',
|
||||
]),
|
||||
FormField::switch('devel', [
|
||||
'label' => 'Strona konstrukcyjna',
|
||||
'tab' => 'system',
|
||||
]),
|
||||
FormField::switch('lazy_loading', [
|
||||
'label' => 'Lazy loading obrazów',
|
||||
'tab' => 'system',
|
||||
]),
|
||||
FormField::switch('generate_webp', [
|
||||
'label' => 'Generowanie obrazków WEBP',
|
||||
'tab' => 'system',
|
||||
]),
|
||||
FormField::switch('infinitescroll', [
|
||||
'label' => 'Infinitescroll',
|
||||
'tab' => 'system',
|
||||
]),
|
||||
FormField::switch('htaccess_cache', [
|
||||
'label' => 'Htaccess cache',
|
||||
'tab' => 'system',
|
||||
]),
|
||||
|
||||
FormField::text('google_tag_manager_id', [
|
||||
'label' => 'Google Tag Manager - ID',
|
||||
'tab' => 'conversions',
|
||||
]),
|
||||
FormField::textarea('own_gtm_js', [
|
||||
'label' => 'Własny kod GTM JS (bez tagu script)',
|
||||
'tab' => 'conversions',
|
||||
'rows' => 10,
|
||||
]),
|
||||
FormField::textarea('own_gtm_html', [
|
||||
'label' => 'Własny kod GTM HTML',
|
||||
'tab' => 'conversions',
|
||||
'rows' => 10,
|
||||
]),
|
||||
];
|
||||
|
||||
$actions = [
|
||||
FormAction::save('/admin/settings/settings_save/', ''),
|
||||
];
|
||||
|
||||
return new FormEditViewModel(
|
||||
$this->getFormId(),
|
||||
'Edycja ustawień',
|
||||
$data,
|
||||
$fields,
|
||||
$tabs,
|
||||
$actions,
|
||||
'POST',
|
||||
'/admin/settings/settings_save/',
|
||||
null,
|
||||
false,
|
||||
[],
|
||||
$languages,
|
||||
$errors
|
||||
);
|
||||
}
|
||||
|
||||
private function getFormId(): string
|
||||
{
|
||||
return 'settings-edit';
|
||||
}
|
||||
|
||||
private function transformSettingsToFormData(array $settings, array $languages): array
|
||||
{
|
||||
$data = $settings;
|
||||
$data['languages'] = [];
|
||||
|
||||
foreach ($languages as $lang) {
|
||||
if (!($lang['status'] ?? false)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$langId = (string)$lang['id'];
|
||||
$data['languages'][$langId] = [
|
||||
'warehouse_message_zero' => $settings['warehouse_message_zero_' . $langId] ?? '',
|
||||
'warehouse_message_nonzero' => $settings['warehouse_message_nonzero_' . $langId] ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function transformFormDataToSettings(array $data): array
|
||||
{
|
||||
if (!isset($data['warehouse_messages']) || !is_array($data['warehouse_messages'])) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$data['warehouse_message_zero'] = [];
|
||||
$data['warehouse_message_nonzero'] = [];
|
||||
|
||||
foreach ($data['warehouse_messages'] as $langId => $langValues) {
|
||||
if (!is_array($langValues)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data['warehouse_message_zero'][$langId] = $langValues['warehouse_message_zero'] ?? '';
|
||||
$data['warehouse_message_nonzero'][$langId] = $langValues['warehouse_message_nonzero'] ?? '';
|
||||
}
|
||||
|
||||
unset($data['warehouse_messages']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,8 +214,10 @@ class Site
|
||||
);
|
||||
},
|
||||
'Settings' => function() {
|
||||
global $mdb;
|
||||
|
||||
return new \admin\Controllers\SettingsController(
|
||||
new \Domain\Settings\SettingsRepository()
|
||||
new \Domain\Settings\SettingsRepository( $mdb )
|
||||
);
|
||||
},
|
||||
'ProductArchive' => function() {
|
||||
|
||||
@@ -10,7 +10,7 @@ class Newsletter
|
||||
|
||||
public static function send()
|
||||
{
|
||||
if ( \admin\factory\Newsletter::send( \S::get( 'dates' ), \S::get('template')) )
|
||||
if ( \admin\factory\Newsletter::send( \S::get( 'dates' ), \S::get( 'template' ) ) )
|
||||
\S::alert( 'Newsletter został dodany do kolejki wysyłania.' );
|
||||
|
||||
header( 'Location: /admin/newsletter/prepare/' );
|
||||
@@ -26,11 +26,11 @@ class Newsletter
|
||||
|
||||
public static function settings_save()
|
||||
{
|
||||
$settings = \admin\factory\Settings::settings_details();
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
$settingsRepository = new \Domain\Settings\SettingsRepository();
|
||||
|
||||
\admin\factory\Settings::settings_update( 'newsletter_footer', $values['newsletter_footer'] );
|
||||
\admin\factory\Settings::settings_update( 'newsletter_header', $values['newsletter_header'] );
|
||||
$settingsRepository -> updateSetting( 'newsletter_footer', $values['newsletter_footer'] ?? '' );
|
||||
$settingsRepository -> updateSetting( 'newsletter_header', $values['newsletter_header'] ?? '' );
|
||||
|
||||
\S::alert( 'Ustawienia zostały zapisane.' );
|
||||
|
||||
@@ -40,8 +40,10 @@ class Newsletter
|
||||
|
||||
public static function settings()
|
||||
{
|
||||
$settingsRepository = new \Domain\Settings\SettingsRepository();
|
||||
|
||||
return \admin\view\Newsletter::settings(
|
||||
\admin\factory\Settings::settings_details()
|
||||
$settingsRepository -> getSettings()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
<?
|
||||
namespace admin\controls;
|
||||
|
||||
class Settings
|
||||
{
|
||||
/**
|
||||
* @deprecated Routing kieruje do admin\Controllers\SettingsController::clearCache().
|
||||
* Ta metoda pozostaje tylko jako fallback dla starej architektury.
|
||||
*/
|
||||
static public function clear_cache()
|
||||
{
|
||||
\S::delete_dir( '../temp/' );
|
||||
\S::delete_dir( '../thumbs/' );
|
||||
|
||||
$redis = \RedisConnection::getInstance() -> getConnection();
|
||||
if ( $redis )
|
||||
$redis -> flushAll();
|
||||
|
||||
\S::alert( 'Cache został wyczyszczony.' );
|
||||
header( 'Location: /admin/dashboard/main_view/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Routing kieruje do admin\Controllers\SettingsController::clearCacheAjax().
|
||||
* Ta metoda pozostaje tylko jako fallback dla starej architektury.
|
||||
*/
|
||||
static public function clear_cache_ajax()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Czyszczenie katalogów cache
|
||||
\S::delete_dir( '../temp/' );
|
||||
\S::delete_dir( '../thumbs/' );
|
||||
|
||||
// Czyszczenie Redis cache
|
||||
$redis = \RedisConnection::getInstance() -> getConnection();
|
||||
if ( $redis )
|
||||
$redis -> flushAll();
|
||||
|
||||
// Zwróć odpowiedź JSON
|
||||
echo json_encode( [ 'status' => 'success', 'message' => 'Cache został wyczyszczony.' ] );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
// W przypadku błędu
|
||||
echo json_encode( [ 'status' => 'error', 'message' => 'Błąd podczas czyszczenia cache: ' . $e->getMessage() ] );
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Routing kieruje do admin\Controllers\SettingsController::save().
|
||||
* Ta metoda pozostaje tylko jako fallback dla starej architektury.
|
||||
*/
|
||||
public static function settings_save()
|
||||
{
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
$settings = \admin\factory\Settings::settings_details( true );
|
||||
|
||||
$response = \admin\factory\Settings::settings_save(
|
||||
$values['firm_name'], $values['firm_adress'], $values['additional_info'], $values['contact_form'], $values['contact_email'], $values['email_host'],
|
||||
$values['email_port'], $values['email_login'], $values['email_password'], $values['google_maps'], $values['facebook_link'], $values['statistic_code'], $values['htaccess'],
|
||||
$values['robots'], $values['shop_bank_account_info'], $values['update'], $values['boot_animation'], $settings['newsletter_header'], $settings['newsletter_footer'], $values['hotpay_api']
|
||||
);
|
||||
|
||||
\admin\factory\Settings::settings_update( 'devel', $values['devel'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'ssl', $values['ssl'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'htaccess_cache', $values['htaccess_cache'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'free_delivery', $values['free_delivery'] );
|
||||
\admin\factory\Settings::settings_update( 'przelewy24_sandbox', $values['przelewy24_sandbox'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'przelewy24_merchant_id', $values['przelewy24_merchant_id'] );
|
||||
\admin\factory\Settings::settings_update( 'przelewy24_crc_key', $values['przelewy24_crc_key'] );
|
||||
\admin\factory\Settings::settings_update( 'update_key', $values['update_key'] );
|
||||
\admin\factory\Settings::settings_update( 'tpay_id', $values['tpay_id'] );
|
||||
\admin\factory\Settings::settings_update( 'tpay_sandbox', $values['tpay_sandbox'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'tpay_security_code', $values['tpay_security_code'] );
|
||||
\admin\factory\Settings::settings_update( 'piksel', $values['piksel'] );
|
||||
\admin\factory\Settings::settings_update( 'generate_webp', $values['generate_webp'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'lazy_loading', $values['lazy_loading'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'orlen_paczka_map_token', $values['orlen_paczka_map_token'] );
|
||||
\admin\factory\Settings::settings_update( 'google_tag_manager_id', $values['google_tag_manager_id'] );
|
||||
\admin\factory\Settings::settings_update( 'infinitescroll', $values['infinitescroll'] == 'on' ? 1 : 0 );
|
||||
// own_gtm_js
|
||||
\admin\factory\Settings::settings_update( 'own_gtm_js', $values['own_gtm_js'] );
|
||||
// own_gtm_html
|
||||
\admin\factory\Settings::settings_update( 'own_gtm_html', $values['own_gtm_html'] );
|
||||
|
||||
foreach ( $values[ 'warehouse_message_zero'] as $key => $val )
|
||||
\admin\factory\Settings::settings_update( 'warehouse_message_zero_' . $key, $val );
|
||||
|
||||
foreach ( $values[ 'warehouse_message_nonzero'] as $key => $val )
|
||||
\admin\factory\Settings::settings_update( 'warehouse_message_nonzero_' . $key, $val );
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
\S::htacces();
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Routing kieruje do admin\Controllers\SettingsController::view().
|
||||
* Ta metoda pozostaje tylko jako fallback dla starej architektury.
|
||||
*/
|
||||
public static function view()
|
||||
{
|
||||
return \Tpl::view( 'settings/settings', [
|
||||
'languages' => \admin\factory\Languages::languages_list(),
|
||||
'settings' => \admin\factory\Settings::settings_details()
|
||||
] );
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,104 +0,0 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
|
||||
class Settings
|
||||
{
|
||||
public static function settings_update( $param, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$mdb -> delete( 'pp_settings', [ 'param' => $param ] );
|
||||
$mdb -> insert( 'pp_settings', [ 'param' => $param, 'value' => $value ] );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function settings_save(
|
||||
$firm_name, $firm_adress, $additional_info, $contact_form, $contact_email, $email_host, $email_port, $email_login, $email_password, $google_maps, $facebook_link, $statistic_code, $htaccess,
|
||||
$robots, $shop_bank_account_info, $update, $boot_animation, $newsletter_header, $newsletter_footer, $hotpay_api
|
||||
)
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$mdb -> query( 'TRUNCATE pp_settings' );
|
||||
|
||||
$mdb -> insert( 'pp_settings', [
|
||||
[
|
||||
'param' => 'firm_name',
|
||||
'value' => $firm_name,
|
||||
], [
|
||||
'param' => 'firm_adress',
|
||||
'value' => $firm_adress
|
||||
], [
|
||||
'param' => 'additional_info',
|
||||
'value' => $additional_info
|
||||
], [
|
||||
'param' => 'contact_form',
|
||||
'value' => $contact_form == 'on' ? 1 : 0
|
||||
], [
|
||||
'param' => 'contact_email',
|
||||
'value' => $contact_email
|
||||
], [
|
||||
'param' => 'email_host',
|
||||
'value' => $email_host
|
||||
], [
|
||||
'param' => 'email_port',
|
||||
'value' => $email_port
|
||||
], [
|
||||
'param' => 'email_login',
|
||||
'value' => $email_login
|
||||
], [
|
||||
'param' => 'email_password',
|
||||
'value' => $email_password
|
||||
], [
|
||||
'param' => 'google_maps',
|
||||
'value' => $google_maps
|
||||
], [
|
||||
"param" => 'facebook_link',
|
||||
'value' => $facebook_link
|
||||
], [
|
||||
'param' => 'statistic_code',
|
||||
'value' => $statistic_code
|
||||
], [
|
||||
'param' => 'htaccess',
|
||||
'value' => $htaccess
|
||||
], [
|
||||
'param' => 'robots',
|
||||
'value' => $robots
|
||||
], [
|
||||
'param' => 'shop_bank_account_info',
|
||||
'value' => $shop_bank_account_info
|
||||
], [
|
||||
'param' => 'update',
|
||||
'value' => $update == 'on' ? 1 : 0
|
||||
], [
|
||||
'param' => 'boot_animation',
|
||||
'value' => $boot_animation
|
||||
], [
|
||||
'param' => 'newsletter_header',
|
||||
'value' => $newsletter_header
|
||||
], [
|
||||
'param' => 'newsletter_footer',
|
||||
'value' => $newsletter_footer
|
||||
], [
|
||||
'param' => 'hotpay_api',
|
||||
'value' => $hotpay_api
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
\S::set_message( 'Ustawienia zostały zapisane' );
|
||||
|
||||
return $response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.' ];
|
||||
}
|
||||
|
||||
public static function settings_details()
|
||||
{
|
||||
global $mdb;
|
||||
$results = $mdb -> select( 'pp_settings', '*', [ 'ORDER' => [ 'id' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$settings[ $row['param'] ] = $row['value'];
|
||||
return $settings;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,13 +0,0 @@
|
||||
<?
|
||||
namespace admin\view;
|
||||
|
||||
class Settings
|
||||
{
|
||||
public static function view( $settings )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> settings = $settings;
|
||||
return $tpl -> render( 'settings/settings' );
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,16 +0,0 @@
|
||||
<?
|
||||
namespace front\factory;
|
||||
class Dictionaries
|
||||
{
|
||||
static public function get_name_by_id( int $unit_id, $lang_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$unit_name = \Cache::fetch( "get_name_by_id:$unit_id:$lang_id", "dictionaries" ) )
|
||||
{
|
||||
$unit_name = $mdb -> get( 'pp_units_langs', 'text', [ 'AND' => [ 'unit_id' => $unit_id, 'lang_id' => $lang_id ] ] );
|
||||
\Cache::store( "get_name_by_id:$unit_id:$lang_id", $unit_name, 86400, "dictionaries" );
|
||||
}
|
||||
return $unit_name;
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,8 @@ class Newsletter
|
||||
public static function newsletter_send( $limit = 5 )
|
||||
{
|
||||
global $mdb, $settings, $lang;
|
||||
$settingsRepository = new \Domain\Settings\SettingsRepository( $mdb );
|
||||
$settingsDetails = $settingsRepository -> getSettings();
|
||||
|
||||
$results = $mdb -> query( 'SELECT * FROM pp_newsletter_send ORDER BY id ASC LIMIT ' . $limit ) -> fetchAll();
|
||||
if ( is_array( $results ) and !empty( $results ) )
|
||||
@@ -36,7 +38,7 @@ class Newsletter
|
||||
|
||||
$text = \admin\view\Newsletter::preview(
|
||||
\admin\factory\Articles::articles_by_date_add( $dates[0], $dates[1] ),
|
||||
\admin\factory\Settings::settings_details(),
|
||||
$settingsDetails,
|
||||
\admin\factory\Newsletter::email_template_detalis($row['id_template'])
|
||||
);
|
||||
|
||||
@@ -119,4 +121,4 @@ class Newsletter
|
||||
return $mdb -> delete( 'pp_newsletter', [ 'email' => $email ] );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
|
||||
$prefixes = [
|
||||
'Domain\\' => __DIR__ . '/../autoload/Domain/',
|
||||
'admin\\Controllers\\' => __DIR__ . '/../autoload/admin/Controllers/',
|
||||
'admin\\Support\\Forms\\' => __DIR__ . '/../autoload/admin/Support/Forms/',
|
||||
'admin\\ViewModels\\Forms\\' => __DIR__ . '/../autoload/admin/ViewModels/Forms/',
|
||||
'admin\\Validation\\' => __DIR__ . '/../autoload/admin/Validation/',
|
||||
];
|
||||
|
||||
foreach ($prefixes as $prefix => $baseDir) {
|
||||
|
||||
BIN
updates/0.20/ver_0.250.zip
Normal file
BIN
updates/0.20/ver_0.250.zip
Normal file
Binary file not shown.
3
updates/0.20/ver_0.250_files.txt
Normal file
3
updates/0.20/ver_0.250_files.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
F: ../autoload/admin/controls/class.Settings.php
|
||||
F: ../autoload/admin/factory/class.Settings.php
|
||||
F: ../autoload/admin/view/class.Settings.php
|
||||
@@ -1,4 +1,12 @@
|
||||
<b>ver. 0.249</b><br />
|
||||
<b>ver. 0.250</b><br />
|
||||
- UPDATE - refaktoryzacja Settings: `Domain\\Settings\\SettingsRepository` ma bezposredni dostep do bazy (bez delegacji do `admin\\factory\\Settings`)
|
||||
- UPDATE - przepieto pozostale uzycia `admin\\factory\\Settings` na `Domain\\Settings\\SettingsRepository` (`admin\\controls\\Settings`, `admin\\controls\\Newsletter`, `front\\factory\\Newsletter`)
|
||||
- UPDATE - DI dla SettingsController: repozytorium otrzymuje `$mdb` w `admin\\Site`
|
||||
- UPDATE - Settings: widok edycji przeniesiony na nowy mechanizm formularza (`FormEditViewModel` + `components/form-edit`) jak w banerach
|
||||
- UPDATE - usunieto nieuzywana legacy klase `autoload/admin/factory/class.Settings.php`
|
||||
- UPDATE - usunieto legacy fallback kontrolera `autoload/admin/controls/class.Settings.php`
|
||||
- UPDATE - usunieto nieuzywana klase widoku `autoload/admin/view/class.Settings.php`
|
||||
<hr><b>ver. 0.249</b><br />
|
||||
- FIX - banner edit: poprawiono zapisywanie danych jezykowych i synchronizacje CKEditor przed zapisem
|
||||
- FIX - banner edit: naprawiono hash zakladek (usunieto `undefined` w URL)
|
||||
- FIX - filemanager: przywrocono dzialanie popupa wyboru obrazka z banera
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?
|
||||
$current_ver = 249;
|
||||
$current_ver = 250;
|
||||
|
||||
for ($i = 1; $i <= $current_ver; $i++)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user