Add first classes
authorJoey Schulze <joey@infodrom.org>
Mon, 14 Dec 2015 21:10:47 +0000 (21:10 +0000)
committerJoey Schulze <joey@infodrom.org>
Mon, 14 Dec 2015 21:10:47 +0000 (21:10 +0000)
class/storage.class.php [new file with mode: 0644]
class/teachings.class.php [new file with mode: 0644]

diff --git a/class/storage.class.php b/class/storage.class.php
new file mode 100644 (file)
index 0000000..1bdc8e4
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+
+class Storage extends stdClass {
+  public function __construct($attributes=false)
+  {
+    if ($attributes !== false && is_array($attributes))
+      foreach ($attributes as $k => $v)
+       $this->$k = $v;
+  }
+}
diff --git a/class/teachings.class.php b/class/teachings.class.php
new file mode 100644 (file)
index 0000000..faa9372
--- /dev/null
@@ -0,0 +1,77 @@
+<?php
+
+define('TEACHINGS', '<root_prefix>/teachings.txt');
+
+class Teachings {
+  private static $instance = false;
+  private $list = array();
+
+  public static function instance()
+  {
+    if (self::$instance === false)
+      self::$instance = new Teachings(TEACHINGS);
+
+    return self::$instance;
+  }
+
+  private function __construct($path)
+  {
+    $this->import($path);
+  }
+
+  private function import($path)
+  {
+    if (($f = fopen($path, 'r')) === false) return;
+
+    while ($line = fgets($f)) {
+      $a = explode('|', chop($line));
+      $this->list[] = new Storage(array('start' => $a[0],
+                                       'end' => $a[1],
+                                       'location' => $a[2],
+                                       'title' => $a[3],
+                                       'url' => $a[4]));
+    }
+
+    fclose($f);
+  }
+
+  public function getCurrent()
+  {
+  }
+
+  public function getList()
+  {
+    $html = '';
+    foreach ($this->list as $row) {
+      if ($row->location != 'Linuxhotel') continue;
+
+      $dstart = explode('-', $row->start);
+      $dend = explode('-', $row->end);
+
+      if ($dstart[1] == $dend[1])
+       $date = sprintf('%d.-%d.%d.%d', $dstart[2], $dend[2], $dstart[1], $dstart[0]);
+      else
+       $date = sprintf('%d.%d.-%d.%d.%d', $dstart[2], $dstart[1], $dend[2], $dstart[1], $dstart[0]);
+
+      $link = strlen($row->url) ? sprintf('<a href="%s">Details / Buchen</a>', $row->url) : '';
+      $html .= sprintf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>',
+                      $date,
+                      $row->title,
+                      $link);
+    }
+
+    if (strlen($html)) {
+      $html = '<table class="teachings" width="100%">'
+       . '<tr>'
+       . '<th width="20%">Datum</th>'
+       . '<th width="60%" align="left">Beschreibung</th>'
+       . '<th width="20%">Link</th>'
+       . '</tr>'
+       . '<tr>'
+       . $html
+       . '</table>';
+    }
+    return $html;
+  }
+}
+