summaryrefslogtreecommitdiffstats
path: root/app/class/object.class.php
blob: 4d0000923c49da9f454e8578ab4551b2904c6376 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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];
        }
    }
}

?>