Anonymous
So speichern Sie Ereignisse, die mehrere Tage in einer Datenbank mit Fullcalendar [geschlossen] dauern.
Post
by Anonymous » 21 May 2025, 12:42
Ich habe einen Kalender und verschiedene Arten von Ereignissen. Ich kann diese Ereignisse in meinen Kalender ziehen und fallen lassen. Mein
Problem ist, dass wenn ich eine meiner Ereignisse, egal ob ich das Ereignis kürzer oder länger mache -, den Startdatum einen Tag zuvor verändert. Weiß jemand, warum dies geschieht oder wo das
Problem sein könnte?
Code: Select all
CREATE TABLE "event_entwicklung" (
"id" INTEGER,
"title" TEXT NOT NULL,
"start" TEXT NOT NULL,
"end" TEXT,
"description" TEXT,
"background_color" TEXT,
PRIMARY KEY("id" AUTOINCREMENT)
);
< /code>
Dies ist die JS-Datei: < /p>
drop: function(info) {
const eventData = JSON.parse(info.draggedEl.dataset.event);
const newEvent = {
title: eventData.title,
start: info.dateStr,
end: null,
description: eventData.description || '',
background_color: eventData.backgroundColor || null,
calendarType: calendarType,
};
fetch('../../API/save_event.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(newEvent)
})
.then(response => response.json())
},
eventDrop: function(info) {
fetch('../../API/update_event.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
id: info.event.id,
title: info.event.title,
description: info.event.extendedProps.description || '',
calendarType: calendarType,
start: info.event.start ? info.event.start.toISOString().slice(0, 10) : null,
end: info.event.end ? info.event.end.toISOString().slice(0, 10) : null,
background_color: info.event.backgroundColor || null
})
});
},
eventResize: function(info) {
let newStart = null;
let newEnd = null;
if (info.startDelta && info.startDelta.valueOf() !== 0) {
newStart = info.event.start ? info.event.start.toISOString().slice(0, 10) : null;
newEnd = info.event.end ? info.event.end.toISOString().slice(0, 10) : null;
} else if (info.endDelta && info.endDelta.valueOf() !== 0) {
newStart = null;
newEnd = info.event.end ? info.event.end.toISOString().slice(0, 10) : null;
}
fetch('../../API/update_event.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
id: info.event.id,
title: info.event.title,
description: info.event.extendedProps.description || '',
calendarType: calendarType,
start: newStart,
end: newEnd,
background_color: info.event.backgroundColor || null
})
});
},
< /code>
Dies ist die Datenbankdatei: < /p>
class Database {
private static $connection = null;
function __construct() {
if (self::$connection == null) {
$env = parse_ini_file(__DIR__ . '/../.env');
self::$connection = new SQLite3($env["DATABASE_PATH"], SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
self::$connection->enableExceptions(true);
}
}
public function saveEvent($title, $start, $end = null, $description = null, $background_color = null, $calendarType = 'entwicklung') {
$table = $this->getEventTable($calendarType);
$startDate = $start ? substr($start, 0, 10) : null;
$endDate = $end ? substr($end, 0, 10) : $startDate;
$stmt = self::$connection->prepare("INSERT INTO $table (title, start, end, description, background_color) VALUES (:title, :start, :end, :description, :background_color)");
$stmt->bindValue(':title', $title, SQLITE3_TEXT);
$stmt->bindValue(':start', $startDate, SQLITE3_TEXT);
$stmt->bindValue(':end', $endDate, SQLITE3_TEXT);
$stmt->bindValue(':description', $description, SQLITE3_TEXT);
$stmt->bindValue(':background_color', $background_color, SQLITE3_TEXT);
$stmt->execute();
}
public function getEvents($calendarType = 'entwicklung') {
if ($calendarType === 'gesamt') {
$query = "SELECT id, title, start, end, description, background_color, 'entwicklung' as calendarType FROM event_entwicklung
UNION ALL
SELECT id, title, start, end, description, background_color, 'support' as calendarType FROM event_support";
$result = self::$connection->query($query);
} else {
$table = $this->getEventTable($calendarType);
$stmt = self::$connection->prepare("SELECT id, title, start, end, description, background_color FROM $table");
$result = $stmt->execute();
}
$events = [];
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
if (isset($row['background_color'])) {
$row['backgroundColor'] = $row['background_color'];
unset($row['background_color']);
}
if (isset($row['end']) && $row['end'] !== null && $row['end'] !== '') {
if (isset($row['start']) && $row['start'] === $row['end']) {
unset($row['end']);
} else {
$endDate = DateTime::createFromFormat('Y-m-d', $row['end']);
if ($endDate) {
$endDate->modify('+1 day');
$row['end'] = $endDate->format('Y-m-d');
}
}
} else {
unset($row['end']);
}
$events[] = $row;
}
return $events;
}
< /code>
Dies ist die Datei Save_Event: < /p>
< /code>
Dies ist die Datei get_event: < /p>
1747824153
Anonymous
Ich habe einen Kalender und verschiedene Arten von Ereignissen. Ich kann diese Ereignisse in meinen Kalender ziehen und fallen lassen. Mein [url=viewtopic.php?t=20324]Problem[/url] ist, dass wenn ich eine meiner Ereignisse, egal ob ich das Ereignis kürzer oder länger mache -, den Startdatum einen Tag zuvor verändert. Weiß jemand, warum dies geschieht oder wo das [url=viewtopic.php?t=20324]Problem[/url] sein könnte?[code]CREATE TABLE "event_entwicklung" ( "id" INTEGER, "title" TEXT NOT NULL, "start" TEXT NOT NULL, "end" TEXT, "description" TEXT, "background_color" TEXT, PRIMARY KEY("id" AUTOINCREMENT) ); < /code> Dies ist die JS-Datei: < /p> drop: function(info) { const eventData = JSON.parse(info.draggedEl.dataset.event); const newEvent = { title: eventData.title, start: info.dateStr, end: null, description: eventData.description || '', background_color: eventData.backgroundColor || null, calendarType: calendarType, }; fetch('../../API/save_event.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(newEvent) }) .then(response => response.json()) }, eventDrop: function(info) { fetch('../../API/update_event.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id: info.event.id, title: info.event.title, description: info.event.extendedProps.description || '', calendarType: calendarType, start: info.event.start ? info.event.start.toISOString().slice(0, 10) : null, end: info.event.end ? info.event.end.toISOString().slice(0, 10) : null, background_color: info.event.backgroundColor || null }) }); }, eventResize: function(info) { let newStart = null; let newEnd = null; if (info.startDelta && info.startDelta.valueOf() !== 0) { newStart = info.event.start ? info.event.start.toISOString().slice(0, 10) : null; newEnd = info.event.end ? info.event.end.toISOString().slice(0, 10) : null; } else if (info.endDelta && info.endDelta.valueOf() !== 0) { newStart = null; newEnd = info.event.end ? info.event.end.toISOString().slice(0, 10) : null; } fetch('../../API/update_event.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id: info.event.id, title: info.event.title, description: info.event.extendedProps.description || '', calendarType: calendarType, start: newStart, end: newEnd, background_color: info.event.backgroundColor || null }) }); }, < /code> Dies ist die Datenbankdatei: < /p> class Database { private static $connection = null; function __construct() { if (self::$connection == null) { $env = parse_ini_file(__DIR__ . '/../.env'); self::$connection = new SQLite3($env["DATABASE_PATH"], SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE); self::$connection->enableExceptions(true); } } public function saveEvent($title, $start, $end = null, $description = null, $background_color = null, $calendarType = 'entwicklung') { $table = $this->getEventTable($calendarType); $startDate = $start ? substr($start, 0, 10) : null; $endDate = $end ? substr($end, 0, 10) : $startDate; $stmt = self::$connection->prepare("INSERT INTO $table (title, start, end, description, background_color) VALUES (:title, :start, :end, :description, :background_color)"); $stmt->bindValue(':title', $title, SQLITE3_TEXT); $stmt->bindValue(':start', $startDate, SQLITE3_TEXT); $stmt->bindValue(':end', $endDate, SQLITE3_TEXT); $stmt->bindValue(':description', $description, SQLITE3_TEXT); $stmt->bindValue(':background_color', $background_color, SQLITE3_TEXT); $stmt->execute(); } public function getEvents($calendarType = 'entwicklung') { if ($calendarType === 'gesamt') { $query = "SELECT id, title, start, end, description, background_color, 'entwicklung' as calendarType FROM event_entwicklung UNION ALL SELECT id, title, start, end, description, background_color, 'support' as calendarType FROM event_support"; $result = self::$connection->query($query); } else { $table = $this->getEventTable($calendarType); $stmt = self::$connection->prepare("SELECT id, title, start, end, description, background_color FROM $table"); $result = $stmt->execute(); } $events = []; while ($row = $result->fetchArray(SQLITE3_ASSOC)) { if (isset($row['background_color'])) { $row['backgroundColor'] = $row['background_color']; unset($row['background_color']); } if (isset($row['end']) && $row['end'] !== null && $row['end'] !== '') { if (isset($row['start']) && $row['start'] === $row['end']) { unset($row['end']); } else { $endDate = DateTime::createFromFormat('Y-m-d', $row['end']); if ($endDate) { $endDate->modify('+1 day'); $row['end'] = $endDate->format('Y-m-d'); } } } else { unset($row['end']); } $events[] = $row; } return $events; } < /code> Dies ist die Datei Save_Event: < /p> < /code> Dies ist die Datei get_event: < /p> [/code]