diff options
| -rw-r--r-- | app/class/object.class.php | 71 | 
1 files changed, 71 insertions, 0 deletions
| 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 @@ +<?php + +require_once "class/framework.class.php"; + +/* + * Base class for Scrott database objects + */ +abstract class Object extends Framework +{ +    /* +     * Constructor +     */ +    function __construct($childTable, $childCols) +    { +        $this->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]; +        } +    } +} + +?> | 
