From: Joey Schulze Date: Thu, 27 Jul 2017 10:34:54 +0000 (+0200) Subject: Rename calendar class X-Git-Url: https://git.infodrom.org/?p=infodrom.org%2Fservice.infodrom.org;a=commitdiff_plain;h=7455c1815c84bc2375c4f5fa7f31b20347a4fd0c;hp=01ac1a720bec619fa767aa7f2defddf1f36f9dc0 Rename calendar class --- diff --git a/class/calendar.class.php b/class/calendar.class.php new file mode 100644 index 0000000..68ca9b8 --- /dev/null +++ b/class/calendar.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/class/calendar_item.class.php b/class/calendar_item.class.php deleted file mode 100644 index ffac6bb..0000000 --- a/class/calendar_item.class.php +++ /dev/null @@ -1,75 +0,0 @@ -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 index b8979ae..7a71044 100644 --- a/src/Infodrom/calendar/index.wml +++ b/src/Infodrom/calendar/index.wml @@ -35,7 +35,7 @@ table#calendar tr.current { $now = date('Y-m-d H:i:s'); $pivot = date('Y-m-d H:i:s', time()+(7*24*60*60)); - $item = new Calendar_Item(); + $item = new Calendar(); $month = ''; if (empty($_GET['year'])) { @@ -70,7 +70,7 @@ table#calendar tr.current { $row->dav_id, $class, $kw != $row->kw ? $row->kw : ' ', - Calendar_Item::formatTimespan($row->dtstart, $row->dtend), + Calendar::formatTimespan($row->dtstart, $row->dtend), utf8_decode($tooltip), utf8_decode($row->summary), utf8_decode($row->location)); diff --git a/src/Infodrom/calendar/submenu.inc b/src/Infodrom/calendar/submenu.inc index 20a7503..41af6ef 100644 --- a/src/Infodrom/calendar/submenu.inc +++ b/src/Infodrom/calendar/submenu.inc @@ -2,7 +2,7 @@ Aktuell
'); - $item = new Calendar_Item(); + $item = new Calendar(); foreach ($item->getYears() as $row) { printf('  %d
', $row->year, $row->year); }