From c31231740866fc31f9f40f9cf53555efec032291 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Thu, 17 Dec 2015 13:25:08 -0500 Subject: + Added abstract base class for Scrott database objects (implemented constructor and loadObj functions) --- app/class/object.class.php | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 app/class/object.class.php diff --git a/app/class/object.class.php b/app/class/object.class.php new file mode 100644 index 0000000..4d00009 --- /dev/null +++ b/app/class/object.class.php @@ -0,0 +1,71 @@ +db = $this->getDbConnection(); + + $this->table = "object"; + $this->cols = array( + "guid", + "perms", + "owner", + "parent", + "name", + "timeCreated", + "timeUpdated", + "type" + ); + + $this->childTable = $this->db->esc($childTable); + $this->childCols = array(); + + if (is_array($childCols)) + { + foreach ($childCols as $col) + $this->childCols[] = $this->db->esc($col); + } + } + + /* + * Populate this object with data from the DB with a given GUID + */ + function loadObj($guid) + { + if (is_null($guid)) + return; + + $escdGuid = $this->db->esc($guid); + + /* Common fields */ + $query = "SELECT * FROM `" . $this->table . "` WHERE `guid` = '" . $escdGuid . "'"; + $result = $this->db->query($query)[0]; + + foreach ($this->cols as $col) + { + if (isset($result[$col])) + $this->$col = $result[$col]; + } + + /* Child Table fields */ + $query = "SELECT * FROM `" . $this->childTable . "` WHERE `guid` = '" . $escdGuid . "'"; + $result = $this->db->query($query)[0]; + + foreach ($this->childCols as $col) + { + if (isset($result[$col])) + $this->$col = $result[$col]; + } + } +} + +?> -- cgit v1.2.3