Permalink
Browse files

Updated Entity handling/rendering

  • Loading branch information...
1 parent 6d60e1a commit 26ddc1f022dfc18922414bd4bc062a2b9f35b217 @Artazor Artazor committed Jun 5, 2012
@@ -58,13 +58,6 @@ public function getHeaders() {
return $result;
}
- public function rpc_UpdateCell($args) {
- $remote = $args->remote;
- $this->log($this->model->meta['keys']);
- return $args->remote;
- }
-
-
}
@@ -156,7 +156,7 @@ function commitEdit($cell) {
$cell.removeClass('edit-cell');
cell.editDiv = null;
if (original != current) {
- $this.remote('updateCell',{
+ $cell.remote('updateCell',{
original: original,
current: current,
remote: cell.editRemote,
@@ -1,6 +1,10 @@
<?
class Oxygen_Entity_Controller extends Oxygen_Controller {
+ public function rpc_UpdateCell($args) {
+ $this->model[$args->source]=$args->current;
+ return $this->model->__submit();
+ }
}
View
@@ -15,7 +15,24 @@ public function getDefaults() {
return array();
}
+ public function getData() {
+ return $this->current;
+ }
+
public function __submit() {
+ $conn = $this->scope->connection;
+ $update = array();
+ foreach ($this->current as $key => $value) {
+ if($this->original[$key] != $value) {
+ $update[$key] = $value;
+ }
+ }
+ $where = array();
+ foreach($this->owner->meta['keys'][0] as $c) {
+ $where[$c] = $this->original[$c];
+ }
+ $conn->rawQuery($this->owner->update($update,$where));
+ return $conn->lastAffectedRows();
}
public function __construct($owner, $original = false) {
@@ -119,6 +119,25 @@ public static function buildFilter($predicate) {
return $res;
}
+ public static function buildSet($updates) {
+ if(is_string($updates)) $updates = array($updates);
+ $res = '';
+ foreach($updates as $key=>$value) {
+ if (is_integer($key)) {
+ $c = $value;
+ } else {
+ $c = $key . '=\'' . mysql_real_escape_string($value) . '\'';
+ }
+ $res .= $res === ''
+ ? ''
+ : ', '
+ ;
+ $res .= $c;
+ }
+ return $res;
+ }
+
+
public static function buildOrder($order) {
return false;
@@ -158,18 +177,25 @@ public function buildSql($meta, $intent, $onlyCount = false) {
$select = self::buildColumns($meta['select'][$intent]);
}
- $from = self::buildDomain($meta['from']);
-
- $parts = array(
- 'select' => $select,
- 'from' => self::buildDomain($meta['from']),
- 'where' => self::buildFilter($meta['where'][$intent]),
- 'group by' => self::buildGroup($realGroup),
- 'having' => self::buildFilter($meta['having']),
- 'order by' => self::buildOrder($meta['order']),
- 'limit' => self::buildLimit($meta['limit']),
- 'offset' => self::buildOffset($meta['offset'])
- );
+ if ($intent === 'select') {
+ $parts = array(
+ 'select' => $select,
+ 'from' => self::buildDomain($meta['from']),
+ 'where' => self::buildFilter($meta['where'][$intent]),
+ 'group by' => self::buildGroup($realGroup),
+ 'having' => self::buildFilter($meta['having']),
+ 'order by' => self::buildOrder($meta['order']),
+ 'limit' => self::buildLimit($meta['limit']),
+ 'offset' => self::buildOffset($meta['offset'])
+ );
+ } else if($intent === 'update') {
+ $parts = array(
+ 'update' => self::buildDomain($meta['from']),
+ 'set' => self::buildSet($meta['set']),
+ 'where' => self::buildFilter($meta['where'][$intent]),
+ );
+ }
+
$sql = '';
foreach ($parts as $section => $content) {
if($content !== false) {
@@ -54,6 +54,14 @@ public function getRouter($pattern) {
return $this->scope->Router($pattern, $this);
}
+ public function toOptions() {
+ foreach($this as $key => $value) {
+ $this->flash($key);
+ $result[$key] = $value->getData();
+ }
+ return $result;
+ }
+
public function offsetGet($offset) {
if(!is_array($offset)) {
$ik = $this->getIterationKey();
@@ -96,6 +104,13 @@ public function where($condition) {
return $this->scope->DataSet($this->builder->addWhere($this->meta,$condition));
}
+ public function update($set, $where = array()) {
+ $meta = $this->builder->addWhere($this->meta, $where);
+ $meta['set'] = $set;
+ $sql = $this->builder->buildSql($meta, 'update');
+ return $sql;
+ }
+
public function slice($offset,$limit) {
return $this->scope->DataSet($this->builder->addSlice($this->meta, $offset, $limit));
}

0 comments on commit 26ddc1f

Please sign in to comment.