Rename calendar class
authorJoey Schulze <joey@infodrom.org>
Thu, 27 Jul 2017 10:34:54 +0000 (12:34 +0200)
committerJoey Schulze <joey@infodrom.org>
Sat, 6 Oct 2018 17:30:25 +0000 (19:30 +0200)
class/calendar.class.php [new file with mode: 0644]
class/calendar_item.class.php [deleted file]
src/Infodrom/calendar/index.wml
src/Infodrom/calendar/submenu.inc

diff --git a/class/calendar.class.php b/class/calendar.class.php
new file mode 100644 (file)
index 0000000..68ca9b8
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+
+class Calendar extends DatabaseTable {
+
+  public function __construct($id=false)
+  {
+    $db = new Database(DBDRIVER, DBHOST, DAV_DBNAME, DBUSER, DBPASS);
+
+    parent::__construct('calendar_item', $id, $db, 'dav_id');
+  }
+
+  public static function pgTimestamp($timestamp)
+  {
+    if (is_string($timestamp))
+      return $timestamp;
+    elseif (is_int($timestamp))
+      return date('Y-m-d H:i:s', $timestamp);
+    elseif (is_object($timestamp) && is_a($timestamp, 'DateTime'))
+      return $timestamp->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 (file)
index ffac6bb..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-<?php
-
-class Calendar_Item extends DatabaseTable {
-
-  public function __construct($id=false)
-  {
-    $db = new Database(DBDRIVER, DBHOST, DAV_DBNAME, DBUSER, DBPASS);
-
-    parent::__construct('calendar_item', $id, $db, 'dav_id');
-  }
-
-  public static function pgTimestamp($timestamp)
-  {
-    if (is_string($timestamp))
-      return $timestamp;
-    elseif (is_int($timestamp))
-      return date('Y-m-d H:i:s', $timestamp);
-    elseif (is_object($timestamp) && is_a($timestamp, 'DateTime'))
-      return $timestamp->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);
-  }
-
-}
index b8979ae..7a71044 100644 (file)
@@ -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 : '&nbsp;',
-          Calendar_Item::formatTimespan($row->dtstart, $row->dtend),
+          Calendar::formatTimespan($row->dtstart, $row->dtend),
           utf8_decode($tooltip),
           utf8_decode($row->summary),
           utf8_decode($row->location));
index 20a7503..41af6ef 100644 (file)
@@ -2,7 +2,7 @@
 
 <?php
   printf('&nbsp;<a href="index.php">Aktuell</a><br>');
-  $item = new Calendar_Item();
+  $item = new Calendar();
   foreach ($item->getYears() as $row) {
     printf('&nbsp;&nbsp;<a href="index.php?year=%d">%d</a><br>', $row->year, $row->year);
   }