summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Dibb <beandog@gentoo.org>2010-02-11 20:17:46 -0700
committerSteve Dibb <beandog@gentoo.org>2010-02-11 20:17:46 -0700
commit32a7a5f8d8b36ae6acb6e566ff3d371b7a145c4b (patch)
treef9b8efa8def14998bc8f7a4fed123cc34c98f8db /class.db.package_use.php
parentZero (diff)
downloadznurt-org-frontend-32a7a5f8d8b36ae6acb6e566ff3d371b7a145c4b.tar.gz
znurt-org-frontend-32a7a5f8d8b36ae6acb6e566ff3d371b7a145c4b.tar.bz2
znurt-org-frontend-32a7a5f8d8b36ae6acb6e566ff3d371b7a145c4b.zip
initial commit
Diffstat (limited to 'class.db.package_use.php')
-rw-r--r--class.db.package_use.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/class.db.package_use.php b/class.db.package_use.php
new file mode 100644
index 0000000..4aef84e
--- /dev/null
+++ b/class.db.package_use.php
@@ -0,0 +1,71 @@
+<?
+
+ class DBPackageUse {
+
+ private $id;
+ private $package;
+ private $use;
+ private $description;
+
+ function __construct($package, $use) {
+
+ $db =& MDB2::singleton();
+
+ $this->name = $name;
+
+ // Find out as much as we can
+// $sql = "SELECT pu.* FROM package_use pu INNER JOIN use u ON pu.use = u.id WHERE u.name = ".$db->quote($name).";";
+ $sql = "SELECT * FROM package_use WHERE package = ".$db->quote($package)." AND use = ".$db->quote($use).";";
+ $row = $db->getRow($sql);
+
+ if(is_array($row) && count($row)) {
+ foreach($row as $key => $value)
+ $this->$key = $value;
+ } else {
+ $this->package = $package;
+ $this->use = $use;
+ $this->createNew();
+ }
+
+ }
+
+ public function __get($var) {
+ return $this->$var;
+ }
+
+ public function __set($var, $value) {
+
+ $db =& MDB2::singleton();
+
+ if(in_array($var, array('package', 'use', 'description'))) {
+
+ $arr_update = array(
+ $var => $value,
+ );
+
+ $db->autoExecute('package_use', $arr_update, MDB2_AUTOQUERY_UPDATE, "id = ".$db->quote($this->id));
+
+ $this->$var = $value;
+
+ }
+
+ }
+
+ private function createNew() {
+
+ $db =& MDB2::singleton();
+
+ $arr_insert = array(
+ 'package' => $this->package,
+ 'use' => $this->use,
+ );
+
+ $db->autoExecute('package_use', $arr_insert, MDB2_AUTOQUERY_INSERT);
+
+ $this->id = $db->lastInsertID();
+
+ }
+
+ }
+
+?> \ No newline at end of file