Improve DatabaseTable for convenience
authorJoey Schulze <joey@infodrom.org>
Sun, 9 Jul 2017 11:29:45 +0000 (13:29 +0200)
committerJoey Schulze <joey@infodrom.org>
Mon, 10 Jul 2017 20:48:29 +0000 (22:48 +0200)
class/databasetable.class.php

index d4eb7c0..246d012 100644 (file)
@@ -6,6 +6,7 @@ abstract class DatabaseTable {
   protected $table;
   protected $data;
   protected $id;
+  protected $rootPath;
 
   public function __construct($table, $id=false, $column_or_db=false, $column=false)
   {
@@ -23,6 +24,15 @@ abstract class DatabaseTable {
 
     if ($id && !$col) $this->load($id);
     if ($id && $col) $this->loadByColumn($id,$col);
+
+    $path = substr($_SERVER['HTTP_REFERER'], strpos($_SERVER['HTTP_REFERER'], $_SERVER['SERVER_NAME'])+strlen($_SERVER['SERVER_NAME'])+1);
+
+    $pos = 0;
+    $this->rootPath = '';
+    while (($pos = strpos($path, '/', $pos)) !== false) {
+      $this->rootPath .= '../';
+      $pos++;
+    }
   }
 
   protected function postLoad() {}
@@ -81,6 +91,11 @@ abstract class DatabaseTable {
     $this->db->delete($this->table, $this->idcolumn, $id === false ? $this->id : $id);
   }
 
+  public function quote($string) { return $this->db->quote($string); }
+  public function execute($sql) { return $this->db->execute($sql); }
+  public function fetchValue($sql) { return $this->db->fetchValue($sql); }
+  public function fetchAssoc($sql) { return $this->db->fetchAssoc($sql); }
+  public function fetchAssocList($sql) { return $this->db->fetchAssocList($sql); }
+  public function fetchObject($sql) { return $this->db->fetchObject($sql); }
+  public function fetchObjectList($sql) { return $this->db->fetchObjectList($sql); }
 }
-
-?>
\ No newline at end of file