Auto stash before merge of "main" and "origin/main"

This commit is contained in:
2024-02-09 21:11:19 -06:00
parent f5d267ea98
commit d21d91b80e
17 changed files with 844 additions and 7 deletions

69
src/Settings/Settings.php Normal file
View File

@@ -0,0 +1,69 @@
<?php
namespace Hpz937\BillReminder\Settings;
use Hpz937\BillReminder\Database\DatabaseInterface;
use Exception;
class Settings
{
private $db;
public function __construct(DatabaseInterface $db)
{
$this->db = $db;
}
public function saveSettings($userId, $notificationPeriod)
{
// Check if settings already exist for the user
if ($this->settingsExist($userId)) {
// Update existing settings
$sql = "UPDATE settings SET notification_period = :notification_period WHERE user_id = :user_id";
} else {
// Insert new settings
$sql = "INSERT INTO settings (user_id, notification_period) VALUES (:user_id, :notification_period)";
}
$params = [
':user_id' => $userId,
':notification_period' => $notificationPeriod,
];
try {
$this->db->query($sql, $params);
return true;
} catch (Exception $e) {
// Handle or log the error appropriately
return false;
}
}
public function getSettings($userId)
{
$sql = "SELECT * FROM settings WHERE user_id = :user_id";
$params = [':user_id' => $userId];
try {
$settings = $this->db->query($sql, $params);
return $settings ? $settings[0] : null;
} catch (Exception $e) {
// Handle or log the error appropriately
return null;
}
}
private function settingsExist($userId)
{
$sql = "SELECT id FROM settings WHERE user_id = :user_id";
$params = [':user_id' => $userId];
try {
$result = $this->db->query($sql, $params);
return !empty($result);
} catch (Exception $e) {
// Handle or log the error appropriately
return false;
}
}
}