diff options
author | Egor <egor.26.93@gmail.com> | 2015-07-19 23:15:08 +0300 |
---|---|---|
committer | Egor <egor.26.93@gmail.com> | 2015-07-19 23:15:08 +0300 |
commit | 50ff8ab2720fabea8a815b96071b6bab3e3a5dbb (patch) | |
tree | 422338359e04b5b86eeb680cd2043493a0faa939 /codebase/Dhtmlx/Connector/Data/JSONDataUpdate.php | |
parent | 8255a94f15a0722c8789a9b363962ca943e51d6b (diff) | |
download | connector-php-50ff8ab2720fabea8a815b96071b6bab3e3a5dbb.zip connector-php-50ff8ab2720fabea8a815b96071b6bab3e3a5dbb.tar.gz connector-php-50ff8ab2720fabea8a815b96071b6bab3e3a5dbb.tar.bz2 |
Updated live update functionality.
Diffstat (limited to 'codebase/Dhtmlx/Connector/Data/JSONDataUpdate.php')
-rw-r--r-- | codebase/Dhtmlx/Connector/Data/JSONDataUpdate.php | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/codebase/Dhtmlx/Connector/Data/JSONDataUpdate.php b/codebase/Dhtmlx/Connector/Data/JSONDataUpdate.php new file mode 100644 index 0000000..ea84e8d --- /dev/null +++ b/codebase/Dhtmlx/Connector/Data/JSONDataUpdate.php @@ -0,0 +1,62 @@ +<?php +namespace Dhtmlx\Connector\Data; + +class JSONDataUpdate extends DataUpdate { + + /*! adds action version in output XML as userdata +*/ + public function version_output($conn, $out) { + $outJson = json_decode($out->__toString(), true); + if(!isset($outJson["userdata"])) + $outJson["userdata"] = array(); + + $outJson["userdata"] = array_merge($outJson["userdata"], $this->get_version()); + $out->reset(); + $out->add(json_encode($outJson)); + } + + /*! return action version in XMl format + */ + public function get_version() { + $version = array("version" => $this->get_update_max_version()); + return $version; + } + + public function get_updates() { + $sub_request = new DataRequestConfig($this->request); + $version = $this->request->get_version(); + $user = $this->request->get_user(); + + $sub_request->parse_sql($this->select_update($this->table, $this->request->get_source(), $this->config->id['db_name'], $version, $user)); + $sub_request->set_relation(false); + + $output = $this->render_set($this->sql->select($sub_request), $this->item_class); + + if(!isset($output["userdata"])) + $output["userdata"] = array(); + + $output["userdata"] = array_merge($output["userdata"], $this->get_version()); + $this->output(json_encode($output)); + } + + protected function render_set($res, $name){ + $output = array(); + $index = 0; + while($data = $this->sql->get_next($res)) { + $data = new JSONDataItemUpdate($data, $this->config, $index, $name); + $this->event->trigger("beforeRender", $data); + array_push($output, $data->to_xml()); + $index++; + } + + return array("updates" => $output); + } + + protected function output($res){ + $out = new OutputWriter($res, ""); + $out->set_type("json"); + $this->event->trigger("beforeOutput", $this, $out); + $out->output("", true, $this->encoding); + } + +}
\ No newline at end of file |