File manager - Edit - /home/webapp69.cm.in.th/u69319090028/Shop/app/Models/PlatformSetting.php
Back
<?php /** * PlatformSetting Model * Maps to `platform_settings` table * Key-value store for admin-configurable platform settings */ require_once __DIR__ . '/../Core/Model.php'; class PlatformSetting extends Model { protected string $table = 'platform_settings'; private static array $cache = []; public function get(string $key, $default = null) { if (isset(self::$cache[$key])) { return self::$cache[$key]; } $row = $this->fetchOne("SELECT setting_value FROM `platform_settings` WHERE setting_key = :k LIMIT 1", [':k' => $key]); $val = $row ? $row['setting_value'] : $default; self::$cache[$key] = $val; return $val; } public function set(string $key, string $value, int $updatedBy): void { $sql = "INSERT INTO `platform_settings` (setting_key, setting_value, updated_by, updated_at) VALUES (:key, :val, :by, NOW()) ON DUPLICATE KEY UPDATE setting_value = :val2, updated_by = :by2, updated_at = NOW()"; $this->query($sql, [ ':key' => $key, ':val' => $value, ':by' => $updatedBy, ':val2' => $value, ':by2' => $updatedBy, ]); self::$cache[$key] = $value; } public function getGroup(string $group): array { $rows = $this->fetchAll( "SELECT * FROM `platform_settings` WHERE setting_group = :g ORDER BY setting_key ASC", [':g' => $group] ); return $rows; } public function getAll(): array { $rows = $this->fetchAll("SELECT * FROM `platform_settings` ORDER BY setting_group ASC, setting_key ASC"); $grouped = []; foreach ($rows as $row) { $grouped[$row['setting_group']][] = $row; } return $grouped; } public function getAllFlat(): array { $rows = $this->fetchAll("SELECT setting_key, setting_value FROM `platform_settings`"); $result = []; foreach ($rows as $row) { $result[$row['setting_key']] = $row['setting_value']; } return $result; } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.24 |
proxy
|
phpinfo
|
Settings