diff options
| author | Malf Furious <m@lfurio.us> | 2015-12-17 13:25:08 -0500 | 
|---|---|---|
| committer | Malf Furious <m@lfurio.us> | 2015-12-17 13:25:08 -0500 | 
| commit | c31231740866fc31f9f40f9cf53555efec032291 (patch) | |
| tree | b0d79899fb701eb990c9125c313156c9cbc757b6 | |
| parent | 0f9b65d812b601c5e047838b07b96098cbe8ad35 (diff) | |
| download | scrott-c31231740866fc31f9f40f9cf53555efec032291.tar.gz scrott-c31231740866fc31f9f40f9cf53555efec032291.zip  | |
+ Added abstract base class for Scrott database objects (implemented constructor and loadObj functions)
Diffstat (limited to '')
| -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]; +        } +    } +} + +?>  | 
