blob: 4d0000923c49da9f454e8578ab4551b2904c6376 (
plain) (
tree)
|
|
<?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];
}
}
}
?>
|