From: Joey Schulze Date: Sat, 6 May 2017 17:16:18 +0000 (+0200) Subject: Add view to davical data X-Git-Url: https://git.infodrom.org/?p=infodrom.org%2Fservice.infodrom.org;a=commitdiff_plain;h=c670f961016a875389abb32bc82abdd194c74019;ds=sidebyside Add view to davical data --- diff --git a/class/calendar_item.class.php b/class/calendar_item.class.php new file mode 100644 index 0000000..ffac6bb --- /dev/null +++ b/class/calendar_item.class.php @@ -0,0 +1,75 @@ +format('Y-m-d H:i:s'); + else + return NULL; + } + + public static function formatTimespan($dtstart, $dtend=false) + { + $start = new DateTime($dtstart); + + if ($dtend !== false) { + $end = new DateTime($dtend); + + if ($start->format('Y-m-d') == $end->format('Y-m-d')) { + if ($start->format('i') == '00' && $end->format('i') == '00') + return $start->format('d.m. H') . '-' . $end->format('H') . ' Uhr'; + else + return $start->format('d.m. H:i') . '-' . $end->format('H:i'); + } + + if ($start->format('H:i:s') == '00:00:00' && $end->format('H:i:s') == '00:00:00') { + $end->sub(new DateInterval('P1D')); + if ($start->format('Y-m-d') == $end->format('Y-m-d')) + return $start->format('d.m.'); + else + return $start->format('d.m.') . '-' . $end->format('d.m.'); + } + + if ($start->format('Y-m-') == $end->format('Y-m-')) { + return $start->format('d.m. H:i') . '-' . $end->format('d.m. H:i'); + } + } + + return 'timespan'; + } + + public function getYears() + { + $sql = sprintf("SELECT DISTINCT extract(year from dtstart) AS year FROM calendar_item WHERE user_no = %d ORDER BY year", + DAV_USER_NO); + return $this->db->fetchObjectList($sql); + } + + public function getItems($from=false, $to=false) + { + $sql = sprintf("SELECT dav_id,dtstart,dtend,EXTRACT(WEEK FROM dtstart) AS kw,summary,location,description FROM calendar_item WHERE user_no = %d", + DAV_USER_NO); + if ($from) + $sql .= sprintf(" AND dtstart >= %s", $this->db->quote(self::pgTimestamp($from))); + if ($to) + $sql .= sprintf(" AND dtstart <= %s", $this->db->quote(self::pgTimestamp($to))); + + $sql .= " ORDER BY dtstart"; + + return $this->db->fetchObjectList($sql); + } + +} diff --git a/src/Infodrom/calendar/index.wml b/src/Infodrom/calendar/index.wml new file mode 100644 index 0000000..62590d2 --- /dev/null +++ b/src/Infodrom/calendar/index.wml @@ -0,0 +1,86 @@ +#include + + + + + + + + + + + + + + +getItems($from, $to) as $row) { + $start = new DateTime($row->dtstart); + $newmonth = $start->format('F Y'); + if ($month != $newmonth) { + $month = $newmonth; + printf('', + $start->format('Y-m'), $month); + $kw = ''; + } + + $tooltip = ''; + if (strlen($row->description)) + $tooltip = sprintf(' title="%s"', htmlspecialchars($row->description)); + + $class = 'row'; + if ($row->dtstart >= $now && $row->dtstart < $pivot) + $class .= ' current'; + if (strlen($kw) && $kw != $row->kw) + $class .= ' newkw'; + + printf('%s', + $row->dav_id, + $class, + $kw != $row->kw ? $row->kw : ' ', + Calendar_Item::formatTimespan($row->dtstart, $row->dtend), + utf8_decode($tooltip), + utf8_decode($row->summary), + utf8_decode($row->location)); + $kw = $row->kw; + } + +?> + +
KWDatumBeschreibungLocation
%s
%s%s%s
+ +
+ +# Local variables: +# mode: text +# mode: auto-fill +# mode: iso-accents +# end: diff --git a/src/Infodrom/calendar/submenu.inc b/src/Infodrom/calendar/submenu.inc new file mode 100644 index 0000000..20a7503 --- /dev/null +++ b/src/Infodrom/calendar/submenu.inc @@ -0,0 +1,13 @@ +Menu
+ +Aktuell
'); + $item = new Calendar_Item(); + foreach ($item->getYears() as $row) { + printf('  %d
', $row->year, $row->year); + } +?> + + + +#include "../functions.inc" prefix="../" diff --git a/src/Infodrom/functions.inc b/src/Infodrom/functions.inc index a5b93df..38aeb43 100644 --- a/src/Infodrom/functions.inc +++ b/src/Infodrom/functions.inc @@ -10,3 +10,4 @@  Todo
 Zeitungen
 Ticker
Termine