aboutsummaryrefslogtreecommitdiffstats
path: root/Controller.php
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mekanisti.fi>2009-11-17 09:49:44 +0200
committerFilipp Lepalaan <filipp@mekanisti.fi>2009-11-17 09:49:44 +0200
commita14477fd1140d09c3079b3477be265cc5e1410da (patch)
tree9affa0e48f341c317414be895552b6f436ba274a /Controller.php
parent6ce2a6c65c9c9eba1e7660d151b6a709ecfa625f (diff)
downloadmain-a14477fd1140d09c3079b3477be265cc5e1410da.tar.gz
main-a14477fd1140d09c3079b3477be265cc5e1410da.tar.bz2
main-a14477fd1140d09c3079b3477be265cc5e1410da.zip
More fixes
Diffstat (limited to 'Controller.php')
-rw-r--r--Controller.php33
1 files changed, 30 insertions, 3 deletions
diff --git a/Controller.php b/Controller.php
index 5e14f4b..14b7900 100644
--- a/Controller.php
+++ b/Controller.php
@@ -24,15 +24,20 @@ class Controller
// Child classes should always have the same name as their tables
$this->class = get_class($this);
$this->table = eval("return {$this->class}::TableName;");
+
+ $this->view = new MainView();
+
+ // Table name not defined, default to class name
if (!$this->table) {
$this->table = strtolower($this->class);
}
+
$this->result = null;
+
if ($id) {
return $this->get($id);
}
- $this->view = new MainView();
return $this;
}
@@ -40,9 +45,15 @@ class Controller
/**
* Get One Thing
*/
- public function get($id)
+ public function get($where)
{
- return $this->find(array('id' => $id));
+ if (!is_array($where)) {
+ $where = array('id' => $where);
+ }
+
+ $this->find($where);
+ return current($this->data);
+
}
public function db()
@@ -292,6 +303,7 @@ class Controller
}
$query = ""; $values = array();
+ $data = array_merge($data, $where);
foreach ($data as $k => $v) {
$query .= "`$k` = :$k, ";
@@ -373,6 +385,21 @@ class Controller
return App::db()->query($sql);
}
+
+ /**
+ * Insert or update
+ */
+ public function upsert($data, $where = null)
+ {
+ if(!$this->get($where)) {
+ $out = $this->insert($data);
+ } else {
+ $out = $this->update($data, $where);
+ }
+
+ return $out;
+
+ }
}