diff options
author | Steve Dibb <beandog@gentoo.org> | 2010-02-11 20:17:46 -0700 |
---|---|---|
committer | Steve Dibb <beandog@gentoo.org> | 2010-02-11 20:17:46 -0700 |
commit | 32a7a5f8d8b36ae6acb6e566ff3d371b7a145c4b (patch) | |
tree | f9b8efa8def14998bc8f7a4fed123cc34c98f8db /class.db.use.php | |
parent | Zero (diff) | |
download | znurt-org-frontend-32a7a5f8d8b36ae6acb6e566ff3d371b7a145c4b.tar.gz znurt-org-frontend-32a7a5f8d8b36ae6acb6e566ff3d371b7a145c4b.tar.bz2 znurt-org-frontend-32a7a5f8d8b36ae6acb6e566ff3d371b7a145c4b.zip |
initial commit
Diffstat (limited to 'class.db.use.php')
-rw-r--r-- | class.db.use.php | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/class.db.use.php b/class.db.use.php new file mode 100644 index 0000000..4458eb4 --- /dev/null +++ b/class.db.use.php @@ -0,0 +1,81 @@ +<? + + class DBUse { + + private $id; + private $name; + private $description; + private $prefix; + private $cp; + private $type; + + function __construct($name, $type = 'global', $key = '') { + + $db =& MDB2::singleton(); + + $this->name = $name; + $this->type = $type; + + // Find out as much as we can + $sql = "SELECT * FROM use WHERE name = ".$db->quote($name)." $where;"; + $row = $db->getRow($sql); + + if(is_array($row) && count($row)) { + foreach($row as $key => $value) + $this->$key = $value; + } else { + + if($this->type == 'local') { + $this->cp = $key; +// $sql = "SELECT package FROM view_package WHERE cp = ".$db->quote($this->cp).";"; +// $this->package = $db->getOne($sql); + } elseif($this->type == 'expand') { + $this->prefix = $key; + } + + $this->createNew(); + + } + + } + + public function __get($var) { + return $this->$var; + } + + public function __set($var, $value) { + + $db =& MDB2::singleton(); + + if(in_array($var, array('name', 'description', 'prefix'))) { + + $arr_update = array( + $var => $value, + ); + + $db->autoExecute('use', $arr_update, MDB2_AUTOQUERY_UPDATE, "id = ".$db->quote($this->id)); + + $this->$var = $value; + + } + + } + + private function createNew() { + + $db =& MDB2::singleton(); + + $arr_insert = array('name' => $this->name); + + if($this->type == 'expand' && $this->prefix) + $arr_insert['prefix'] = $this->prefix; + + $db->autoExecute('use', $arr_insert, MDB2_AUTOQUERY_INSERT); + + $this->id = $db->lastInsertID(); + + } + + } + +?>
\ No newline at end of file |