From 2fac8546534e35607627e21323bcc477110b1978 Mon Sep 17 00:00:00 2001 From: Egor Date: Thu, 18 Jun 2015 17:02:14 +0300 Subject: [PATCH 01/16] Updated gantt connector for xml data processing. --- codebase/gantt_connector.php | 129 +++++++++++++++++++++-------------- 1 file changed, 78 insertions(+), 51 deletions(-) diff --git a/codebase/gantt_connector.php b/codebase/gantt_connector.php index 3577835..f8c62cf 100644 --- a/codebase/gantt_connector.php +++ b/codebase/gantt_connector.php @@ -31,6 +31,25 @@ function to_xml(){ } } +class GanttLinkDataItem extends DataItem { + + public function to_xml_start(){ + $str="config->data); $i++){ + $name=$this->config->data[$i]["name"]; + $db_name=$this->config->data[$i]["db_name"]; + $str.=" ".$name."='".$this->xmlentities($this->data[$name])."'"; + } + //output custom data + if ($this->userdata !== false) + foreach ($this->userdata as $key => $value){ + $str.=" ".$key."='".$this->xmlentities($value)."'"; + } + + return $str.">"; + } + +} /*! Connector class for dhtmlxGantt **/ @@ -124,6 +143,60 @@ public function render_links($table,$id="",$fields=false,$extra=false,$relation_ $links->render_table($table,$id,$fields,$extra); $this->set_options("links", $links); } + + + /*! render self + process commands, output requested data as XML + */ + public function render(){ + $this->event->trigger("onInit", $this); + EventMaster::trigger_static("connectorInit",$this); + + if (!$this->as_string) + $this->parse_request(); + $this->set_relation(); + + if ($this->live_update !== false && $this->updating!==false) { + $this->live_update->get_updates(); + } else { + if ($this->editing){ + if ($this->links_mode && isset($this->options["links"])) { + $this->options["links"]->save(); + } else { + $dp = new $this->names["data_class"]($this,$this->config,$this->request); + $dp->process($this->config,$this->request); + } + } else { + if (!$this->access->check("read")){ + LogMaster::log("Access control: read operation blocked"); + echo "Access denied"; + die(); + } + $wrap = new SortInterface($this->request); + $this->apply_sorts($wrap); + $this->event->trigger("beforeSort",$wrap); + $wrap->store(); + + $wrap = new FilterInterface($this->request); + $this->apply_filters($wrap); + $this->event->trigger("beforeFilter",$wrap); + $wrap->store(); + + if ($this->model && method_exists($this->model, "get")){ + $this->sql = new ArrayDBDataWrapper(); + $result = new ArrayQueryWrapper(call_user_func(array($this->model, "get"), $this->request)); + $out = $this->output_as_xml($result); + } else { + $out = $this->output_as_xml($this->get_resource()); + + if ($out !== null) return $out; + } + + } + } + $this->end_run(); + } + } /*! DataProcessor class for Gantt component @@ -271,62 +344,16 @@ public function render_links($table,$id="",$fields=false,$extra=false,$relation_ $this->set_options("links", $links); } +} - /*! render self - process commands, output requested data as XML - */ - public function render(){ - $this->event->trigger("onInit", $this); - EventMaster::trigger_static("connectorInit",$this); - - if (!$this->as_string) - $this->parse_request(); - $this->set_relation(); - - if ($this->live_update !== false && $this->updating!==false) { - $this->live_update->get_updates(); - } else { - if ($this->editing){ - if ($this->links_mode && isset($this->options["links"])) { - $this->options["links"]->save(); - } else { - $dp = new $this->names["data_class"]($this,$this->config,$this->request); - $dp->process($this->config,$this->request); - } - } else { - if (!$this->access->check("read")){ - LogMaster::log("Access control: read operation blocked"); - echo "Access denied"; - die(); - } - $wrap = new SortInterface($this->request); - $this->apply_sorts($wrap); - $this->event->trigger("beforeSort",$wrap); - $wrap->store(); - - $wrap = new FilterInterface($this->request); - $this->apply_filters($wrap); - $this->event->trigger("beforeFilter",$wrap); - $wrap->store(); - - if ($this->model && method_exists($this->model, "get")){ - $this->sql = new ArrayDBDataWrapper(); - $result = new ArrayQueryWrapper(call_user_func(array($this->model, "get"), $this->request)); - $out = $this->output_as_xml($result); - } else { - $out = $this->output_as_xml($this->get_resource()); - if ($out !== null) return $out; - } +class GanttLinksConnector extends OptionsConnector { - } - } - $this->end_run(); + public function __construct($res,$type=false,$item_type=false,$data_type=false,$render_type=false){ + if (!$item_type) $item_type="GanttLinkDataItem"; + parent::__construct($res,$type,$item_type,$data_type,$render_type); } -} - -class GanttLinksConnector extends OptionsConnector { public function render(){ if (!$this->init_flag){ $this->init_flag=true; From 86847eea2e8d01e93158185f285f9d709c6df113 Mon Sep 17 00:00:00 2001 From: Egor Date: Thu, 18 Jun 2015 17:30:25 +0300 Subject: [PATCH 02/16] Updated connectors for CI2 and YII1. --- codebase/db_phpci2.php | 2 +- codebase/db_phpyii1.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 codebase/db_phpci2.php mode change 100644 => 100755 codebase/db_phpyii1.php diff --git a/codebase/db_phpci2.php b/codebase/db_phpci2.php old mode 100644 new mode 100755 index 9d10d99..220a126 --- a/codebase/db_phpci2.php +++ b/codebase/db_phpci2.php @@ -9,7 +9,7 @@ if you plan to use it for Oracle - use Oracle connection type instead **/ -class PHPCIDBDataWrapper extends DBDataWrapper{ +class PHPCI2DBDataWrapper extends DBDataWrapper{ private $last_result;//!< store result or last operation public function query($sql){ diff --git a/codebase/db_phpyii1.php b/codebase/db_phpyii1.php old mode 100644 new mode 100755 index 616d7f3..bbbd943 --- a/codebase/db_phpyii1.php +++ b/codebase/db_phpyii1.php @@ -6,7 +6,7 @@ require_once("db_common.php"); -class PHPYiiDBDataWrapper extends ArrayDBDataWrapper{ +class PHPYii1DBDataWrapper extends ArrayDBDataWrapper{ public function select($sql){ if (is_array($this->connection)) //result of findAll $res = $this->connection; From 4c65fb8cff4847804ced68b52d0c8d2a23de94c0 Mon Sep 17 00:00:00 2001 From: Egor Date: Thu, 18 Jun 2015 17:45:00 +0300 Subject: [PATCH 03/16] Fixed bug with configurating model. --- codebase/base_connector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 codebase/base_connector.php diff --git a/codebase/base_connector.php b/codebase/base_connector.php old mode 100644 new mode 100755 index 26f1f8b..05a885e --- a/codebase/base_connector.php +++ b/codebase/base_connector.php @@ -419,7 +419,7 @@ public function configure($table,$id="",$fields=false,$extra=false,$relation_id= $id = $info["key"]; } $this->config->init($id,$fields,$extra,$relation_id); - if (strpos(trim($table), " ")!==false) + if (is_string($table) && strpos(trim($table), " ")!==false) $this->request->parse_sql($table); else $this->request->set_source($table); From 7704800362fb043d21beca5d3d3ac1548921f1cd Mon Sep 17 00:00:00 2001 From: Stanislau Wolski Date: Wed, 24 Jun 2015 20:20:36 +0300 Subject: [PATCH 04/16] [fix] using live_updates and render_sql --- codebase/update.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/codebase/update.php b/codebase/update.php index dacc211..45a2837 100644 --- a/codebase/update.php +++ b/codebase/update.php @@ -207,7 +207,8 @@ public function get_updates() { $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)); + $table = explode(" ", $this->request->get_source()); + $sub_request->parse_sql($this->select_update($this->table, $table[0], $this->config->id['db_name'], $version, $user)); $sub_request->set_relation(false); $output = $this->render_set($this->sql->select($sub_request), $this->item_class); From d66c1ce799ea4d773699e73f934db27e764d3f17 Mon Sep 17 00:00:00 2001 From: Egor Date: Thu, 25 Jun 2015 16:35:37 +0300 Subject: [PATCH 05/16] Added rendering data in xml for mix connector. --- codebase/mixed_connector.php | 63 +++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/codebase/mixed_connector.php b/codebase/mixed_connector.php index 461d6ec..bbef8d4 100644 --- a/codebase/mixed_connector.php +++ b/codebase/mixed_connector.php @@ -7,22 +7,53 @@ class MixedConnector extends Connector { - protected $connectors = array(); - - public function add($name, $conn) { - $this->connectors[$name] = $conn; - } - - public function render() { - $result = "{"; - $parts = array(); - foreach($this->connectors as $name => $conn) { - $conn->asString(true); - $parts[] = "\"".$name."\":".($conn->render())."\n"; - } - $result .= implode(",\n", $parts)."}"; - echo $result; - } + private $_data_type = null; + + function __construct($dataType = "json") { + $this->_data_type = $dataType; + } + + protected $attributes = array(); + protected $connectors = array(); + + public function add($name, $conn) { + $this->connectors[$name] = $conn; + $conn->simple = true; + } + + public function render() { + if($this->_data_type == "json") + $this->render_json(); + else + $this->render_xml(); + } + + private function render_json() { + $result = "{"; + $parts = array(); + foreach($this->connectors as $name => $conn) { + $conn->asString(true); + $parts[] = "\"".$name."\":".($conn->render())."\n"; + } + $result .= implode(",\n", $parts)."}"; + echo $result; + } + + private function render_xml() { + $result = ""; + $parts = array(); + + foreach($this->connectors as $name => $conn) { + $conn->asString(true); + $parts[] = "<".$name.">".($conn->render())."\n"; + } + $result .= implode("", $parts); + $this->output_as_xml($result); + } + + protected function output_as_xml($res) { + echo "encoding."' ?>".$this->xml_start().$res.$this->xml_end(); + } } ?> \ No newline at end of file From 533642bcb15e84ae1e21007152a87cd35cda3775 Mon Sep 17 00:00:00 2001 From: Egor Date: Sun, 19 Jul 2015 21:01:43 +0300 Subject: [PATCH 06/16] Updated live update functionality. --- codebase/base_connector.php | 50 +-- codebase/db_common.php | 12 + codebase/gantt_connector.php | 90 ++++- codebase/scheduler_connector.php | 1 + codebase/update.php | 610 +++++++++++++++++-------------- 5 files changed, 467 insertions(+), 296 deletions(-) mode change 100644 => 100755 codebase/db_common.php mode change 100644 => 100755 codebase/gantt_connector.php mode change 100644 => 100755 codebase/scheduler_connector.php mode change 100644 => 100755 codebase/update.php diff --git a/codebase/base_connector.php b/codebase/base_connector.php index 05a885e..4e033b2 100755 --- a/codebase/base_connector.php +++ b/codebase/base_connector.php @@ -282,38 +282,38 @@ public function to_xml_end(){ Can be used on its own to provide raw data. **/ class Connector { + + private $id_seed=0; //!< default value, used to generate auto-IDs + private $db; //!< db connection resource + protected $config;//DataConfig instance protected $request;//DataRequestConfig instance protected $names;//!< hash of names for used classes protected $encoding="utf-8";//!< assigned encoding (UTF-8 by default) protected $editing=false;//!< flag of edit mode ( response for dataprocessor ) + protected $updating=false;//!< flag of update mode ( response for data-update ) + protected $dload;//!< flag of dyn. loading mode + protected $data_separator = "\n"; + protected $live_update = false; // actions table name for autoupdating + protected $live_update_data_type = "DataUpdate"; + protected $extra_output="";//!< extra info which need to be sent to client side + protected $options=array();//!< hash of OptionsConnector + protected $as_string = false; // render() returns string, don't send result in response + protected $simple = false; // render only data without any other info + protected $filters; + protected $sorts; + protected $mix; + protected $order = false; public static $filter_var="dhx_filter"; public static $sort_var="dhx_sort"; public static $kids_var="dhx_kids"; - public $model=false; - - private $updating=false;//!< flag of update mode ( response for data-update ) - private $db; //!< db connection resource - protected $dload;//!< flag of dyn. loading mode - public $access; //!< AccessMaster instance - protected $data_separator = "\n"; - - public $sql; //DataWrapper instance - public $event; //EventMaster instance - public $limit=false; - - private $id_seed=0; //!< default value, used to generate auto-IDs - protected $live_update = false; // actions table name for autoupdating - protected $extra_output="";//!< extra info which need to be sent to client side - protected $options=array();//!< hash of OptionsConnector - protected $as_string = false; // render() returns string, don't send result in response - protected $simple = false; // render only data without any other info - protected $filters; - protected $sorts; - protected $mix; - protected $order = false; + public $model=false; + public $access; //!< AccessMaster instance + public $sql; //DataWrapper instance + public $event; //EventMaster instance + public $limit=false; /*! constructor @@ -810,6 +810,10 @@ public function set_options($name,$options){ $this->options[$name]=$options; } + public function get_options() { + return $this->options; + } + public function insert($data) { $action = new DataAction('inserted', false, $data); @@ -851,7 +855,7 @@ public function update($data) { url used for update notifications */ public function enable_live_update($table, $url=false){ - $this->live_update = new DataUpdate($this->sql, $this->config, $this->request, $table,$url); + $this->live_update = new $this->live_update_data_type($this->sql, $this->config, $this->request, $table,$url, array("connector" => $this)); $this->live_update->set_event($this->event,$this->names["item_class"]); $this->event->attach("beforeOutput", Array($this->live_update, "version_output")); $this->event->attach("beforeFiltering", Array($this->live_update, "get_updates")); diff --git a/codebase/db_common.php b/codebase/db_common.php old mode 100644 new mode 100755 index f6391d2..67c14c0 --- a/codebase/db_common.php +++ b/codebase/db_common.php @@ -8,6 +8,8 @@ /*! manager of data request **/ class DataRequestConfig{ + + private $action_mode = ""; private $filters; //!< array of filtering rules private $relation=false; //!< ID or other element used for linking hierarchy private $sort_by; //!< sorting field @@ -52,6 +54,7 @@ public function copy($proto){ $this->relation =$proto->get_relation(); $this->user = $proto->user; $this->version = $proto->version; + $this->action_mode = $proto->action_mode; } /*! convert self to string ( for logs ) @@ -69,6 +72,15 @@ public function __toString(){ return $str; } + public function set_action_mode($action_mode) { + $this->action_mode = $action_mode; + return $this; + } + + public function get_action_mode() { + return $this->action_mode; + } + /*! returns set of filtering rules @return set of filtering rules diff --git a/codebase/gantt_connector.php b/codebase/gantt_connector.php old mode 100644 new mode 100755 index f8c62cf..9bd9422 --- a/codebase/gantt_connector.php +++ b/codebase/gantt_connector.php @@ -55,10 +55,12 @@ public function to_xml_start(){ **/ class GanttConnector extends Connector{ + private $action_mode = ""; + public $links_table = ""; + + protected $live_update_data_type = "GanttDataUpdate"; protected $extra_output="";//!< extra info which need to be sent to client side protected $options=array();//!< hash of OptionsConnector - protected $links_mode = false; - /*! assign options collection to the column @@ -106,8 +108,14 @@ public function __construct($res,$type=false,$item_type=false,$data_type=false,$ function parse_request(){ parent::parse_request(); - if (isset($_GET["gantt_mode"]) && $_GET["gantt_mode"] == "links") - $this->links_mode = true; + $action_links = "links"; + if(isset($_GET["gantt_mode"]) && $_GET["gantt_mode"] == $action_links) { + $this->action_mode = $action_links; + $this->request->set_action_mode($action_links); + $this->options[$action_links]->request->set_action_mode($action_links); + $this->options[$action_links]->request->set_user($this->request->get_user()); + } + if (count($this->config->text)){ if (isset($_GET["to"])) @@ -138,10 +146,15 @@ function delete_related_links($action){ } } - public function render_links($table,$id="",$fields=false,$extra=false,$relation_id=false) { + public function render_links($table,$id="",$fields=false,$extra=false) { $links = new GanttLinksConnector($this->get_connection(),$this->names["db_class"]); + + if($this->live_update) + $links->enable_live_update($this->live_update->get_table()); + $links->render_table($table,$id,$fields,$extra); $this->set_options("links", $links); + $this->links_table = $table; } @@ -157,10 +170,10 @@ public function render(){ $this->set_relation(); if ($this->live_update !== false && $this->updating!==false) { - $this->live_update->get_updates(); + $this->live_update->get_updates(); } else { if ($this->editing){ - if ($this->links_mode && isset($this->options["links"])) { + if (($this->action_mode == "links") && isset($this->options["links"])) { $this->options["links"]->save(); } else { $dp = new $this->names["data_class"]($this,$this->config,$this->request); @@ -247,6 +260,7 @@ function to_xml(){ class JSONGanttConnector extends GanttConnector { protected $data_separator = ","; + protected $live_update_data_type = "JSONGanttDataUpdate"; /*! constructor @@ -340,6 +354,10 @@ protected function output_as_xml($res){ public function render_links($table,$id="",$fields=false,$extra=false,$relation_id=false) { $links = new JSONGanttLinksConnector($this->get_connection(),$this->names["db_class"]); + + if($this->live_update) + $links->enable_live_update($this->live_update->get_table()); + $links->render_table($table,$id,$fields,$extra); $this->set_options("links", $links); } @@ -348,6 +366,7 @@ public function render_links($table,$id="",$fields=false,$extra=false,$relation_ class GanttLinksConnector extends OptionsConnector { + protected $live_update_data_type = "GanttDataUpdate"; public function __construct($res,$type=false,$item_type=false,$data_type=false,$render_type=false){ if (!$item_type) $item_type="GanttLinkDataItem"; @@ -372,6 +391,7 @@ public function save() { class JSONGanttLinksConnector extends JSONOptionsConnector { + protected $live_update_data_type = "JSONGanttDataUpdate"; public function render(){ if (!$this->init_flag){ $this->init_flag=true; @@ -388,4 +408,60 @@ public function save() { } } +class JSONGanttDataUpdate extends JSONDataUpdate { + + public function get_updates() { + $updates = $this->get_data_updates(); + //ToDo: Add rendering for data. + } + + + private function get_data_updates() { + $actions_table = $this->table; + $version = $this->request->get_version(); + $user = $this->request->get_user(); + + $select_actions = "SELECT DATAID, TYPE, USER FROM {$actions_table}"; + $select_actions .= " WHERE {$actions_table}.ID > '{$version}' AND {$actions_table}.USER <> '{$user}'"; + + + $output = array(); + $index = 0; + $actions_query = $this->sql->query($select_actions); + while($action_data=$this->sql->get_next($actions_query)){ + $action_type = $action_data["TYPE"]; + $type_parts = explode("#", $action_type); + $action_mode = $type_parts[1]; + if($action_mode == "links") { + $data = $this->select_links_for_action($action_data["DATAID"]); + $data = new DataItemUpdate($data, $this->config, $index, $this->item_class); + } + else { + $data = $this->select_task_for_action($action_data["DATAID"]); + $data = new DataItemUpdate($data, $this->config, $index, $this->item_class); + } + + array_push($output, $data); + $index++; + } + + return $output; + } + + protected function select_task_for_action($taskId) { + $tasks_table = $this->request->get_source(); + $field_task_id = $this->config->id['db_name']; + $select_actions_tasks = "SELECT * FROM {$tasks_table} WHERE {$taskId} = {$tasks_table}.{$field_task_id}"; + return $this->sql->get_next($this->sql->query($select_actions_tasks)); + } + + protected function select_links_for_action($taskId) { + $links_connector_options = $this->options["connector"]->get_options(); + $links_table = $links_connector_options["links"]->get_request()->get_source(); + $field_task_id = $this->config->id['db_name']; + $select_actions_tasks = "SELECT * FROM {$links_table} WHERE {$taskId} = {$links_table}.{$field_task_id}"; + return $this->sql->get_next($this->sql->query($select_actions_tasks)); + } +} + ?> \ No newline at end of file diff --git a/codebase/scheduler_connector.php b/codebase/scheduler_connector.php old mode 100644 new mode 100755 index ee0cd20..b7049db --- a/codebase/scheduler_connector.php +++ b/codebase/scheduler_connector.php @@ -136,6 +136,7 @@ function to_xml(){ class JSONSchedulerConnector extends SchedulerConnector { protected $data_separator = ","; + protected $live_update_data_type = "JSONDataUpdate"; /*! constructor diff --git a/codebase/update.php b/codebase/update.php old mode 100644 new mode 100755 index 45a2837..9ef12ac --- a/codebase/update.php +++ b/codebase/update.php @@ -1,267 +1,345 @@ -config=$config; - $this->data=$data; - $this->index=$index; - $this->skip=false; - $this->child = new $type($data, $config, $index); - } - - /*! returns parent_id (for Tree and TreeGrid components) - */ - public function get_parent_id(){ - if (method_exists($this->child, 'get_parent_id')) { - return $this->child->get_parent_id(); - } else { - return ''; - } - } - - - /*! generate XML on the data hash base - */ - public function to_xml(){ - $str= "data['type'].'" '; - $str .= 'id="'.$this->data['dataId'].'" '; - $str .= 'parent="'.$this->get_parent_id().'"'; - $str .= '>'; - $str .= $this->child->to_xml(); - $str .= ''; - return $str; - } - - /*! return starting tag for XML string - */ - public function to_xml_start(){ - $str="data['type'].'" '; - $str .= 'id="'.$this->data['dataId'].'" '; - $str .= 'parent="'.$this->get_parent_id().'"'; - $str .= '>'; - $str .= $this->child->to_xml_start(); - return $str; - } - - /*! return ending tag for XML string - */ - public function to_xml_end(){ - $str = $this->child->to_xml_end(); - $str .= ''; - return $str; - } - - /*! returns false for outputing only current item without child items - */ - public function has_kids(){ - return false; - } - - /*! sets count of child items - @param value - count of child items - */ - public function set_kids($value){ - if (method_exists($this->child, 'set_kids')) { - $this->child->set_kids($value); - } - } - - /*! sets attribute for item - */ - public function set_attribute($name, $value){ - if (method_exists($this->child, 'set_attribute')) { - LogMaster::log("setting attribute: \nname = {$name}\nvalue = {$value}"); - $this->child->set_attribute($name, $value); - } else { - LogMaster::log("set_attribute method doesn't exists"); - } - } -} - - -class DataUpdate{ - - protected $table; //!< table , where actions are stored - protected $url; //!< url for notification service, optional - protected $sql; //!< DB wrapper object - protected $config; //!< DBConfig object - protected $request; //!< DBRequestConfig object - protected $event; - protected $item_class; - protected $demu; - - //protected $config;//!< DataConfig instance - //protected $request;//!< DataRequestConfig instance - - /*! constructor - - @param connector - Connector object - @param config - DataConfig object - @param request - DataRequestConfig object - */ - function __construct($sql, $config, $request, $table, $url){ - $this->config= $config; - $this->request= $request; - $this->sql = $sql; - $this->table=$table; - $this->url=$url; - $this->demu = false; - } - - public function set_demultiplexor($path){ - $this->demu = $path; - } - - public function set_event($master, $name){ - $this->event = $master; - $this->item_class = $name; - } - - private function select_update($actions_table, $join_table, $id_field_name, $version, $user) { - $sql = "SELECT * FROM {$actions_table}"; - $sql .= " LEFT OUTER JOIN {$join_table} ON "; - $sql .= "{$actions_table}.DATAID = {$join_table}.{$id_field_name} "; - $sql .= "WHERE {$actions_table}.ID > '{$version}' AND {$actions_table}.USER <> '{$user}'"; - return $sql; - } - - private function get_update_max_version() { - $sql = "SELECT MAX(id) as VERSION FROM {$this->table}"; - $res = $this->sql->query($sql); - $data = $this->sql->get_next($res); - - if ($data == false || $data['VERSION'] == false) - return 1; - else - return $data['VERSION']; - } - - private function log_update_action($actions_table, $dataId, $status, $user) { - $sql = "INSERT INTO {$actions_table} (DATAID, TYPE, USER) VALUES ('{$dataId}', '{$status}', '{$user}')"; - $this->sql->query($sql); - if ($this->demu) - file_get_contents($this->demu); - } - - - - - /*! records operations in actions_table - @param action - DataAction object - */ - public function log_operations($action) { - $type = $this->sql->escape($action->get_status()); - $dataId = $this->sql->escape($action->get_new_id()); - $user = $this->sql->escape($this->request->get_user()); - if ($type!="error" && $type!="invalid" && $type !="collision") { - $this->log_update_action($this->table, $dataId, $type, $user); - } - } - - - /*! return action version in XMl format - */ - public function get_version() { - $version = $this->get_update_max_version(); - return "".$version.""; - } - - - /*! adds action version in output XML as userdata - */ - public function version_output($conn, $out) { - $out->add($this->get_version()); - } - - - /*! create update actions in XML-format and sends it to output - */ - public function get_updates() { - $sub_request = new DataRequestConfig($this->request); - $version = $this->request->get_version(); - $user = $this->request->get_user(); - - $table = explode(" ", $this->request->get_source()); - $sub_request->parse_sql($this->select_update($this->table, $table[0], $this->config->id['db_name'], $version, $user)); - $sub_request->set_relation(false); - - $output = $this->render_set($this->sql->select($sub_request), $this->item_class); - - ob_clean(); - header("Content-type:text/xml"); - - echo $this->updates_start(); - echo $this->get_version(); - echo $output; - echo $this->updates_end(); - } - - - protected function render_set($res, $name){ - $output=""; - $index=0; - while ($data=$this->sql->get_next($res)){ - $data = new DataItemUpdate($data,$this->config,$index, $name); - $this->event->trigger("beforeRender",$data); - $output.=$data->to_xml(); - $index++; - } - return $output; - } - - /*! returns update start string - */ - protected function updates_start() { - $start = ''; - return $start; - } - - /*! returns update end string - */ - protected function updates_end() { - $start = ''; - return $start; - } - - /*! checks if action version given by client is deprecated - @param action - DataAction object - */ - public function check_collision($action) { - $version = $this->sql->escape($this->request->get_version()); - //$user = $this->sql->escape($this->request->get_user()); - $last_version = $this->get_update_max_version(); - if (($last_version > $version)&&($action->get_status() == 'update')) { - $action->error(); - $action->set_status('collision'); - } - } -} - +config=$config; + $this->data=$data; + $this->index=$index; + $this->skip=false; + $this->child = new $type($data, $config, $index); + } + + /*! returns parent_id (for Tree and TreeGrid components) + */ + public function get_parent_id(){ + if (method_exists($this->child, 'get_parent_id')) { + return $this->child->get_parent_id(); + } else { + return ''; + } + } + + + /*! generate XML on the data hash base + */ + public function to_xml(){ + $str= "data['action_table_type'].'" '; + $str .= 'id="'.$this->data['dataId'].'" '; + $str .= 'parent="'.$this->get_parent_id().'"'; + $str .= '>'; + $str .= $this->child->to_xml(); + $str .= ''; + return $str; + } + + /*! return starting tag for XML string + */ + public function to_xml_start(){ + $str="data['action_table_type'].'" '; + $str .= 'id="'.$this->data['dataId'].'" '; + $str .= 'parent="'.$this->get_parent_id().'"'; + $str .= '>'; + $str .= $this->child->to_xml_start(); + return $str; + } + + /*! return ending tag for XML string + */ + public function to_xml_end(){ + $str = $this->child->to_xml_end(); + $str .= ''; + return $str; + } + + /*! returns false for outputing only current item without child items + */ + public function has_kids(){ + return false; + } + + /*! sets count of child items + @param value + count of child items + */ + public function set_kids($value){ + if (method_exists($this->child, 'set_kids')) { + $this->child->set_kids($value); + } + } + + /*! sets attribute for item + */ + public function set_attribute($name, $value){ + if (method_exists($this->child, 'set_attribute')) { + LogMaster::log("setting attribute: \nname = {$name}\nvalue = {$value}"); + $this->child->set_attribute($name, $value); + } else { + LogMaster::log("set_attribute method doesn't exists"); + } + } +} + +class DataUpdate{ + + protected $table; //!< table , where actions are stored + protected $url; //!< url for notification service, optional + protected $sql; //!< DB wrapper object + protected $config; //!< DBConfig object + protected $request; //!< DBRequestConfig object + protected $event; + protected $item_class; + protected $demu; + + //protected $config;//!< DataConfig instance + //protected $request;//!< DataRequestConfig instance + + /*! constructor + + @param connector + Connector object + @param config + DataConfig object + @param request + DataRequestConfig object + */ + function __construct($sql, $config, $request, $table, $url, $options){ + $this->config= $config; + $this->request= $request; + $this->sql = $sql; + $this->table=$table; + $this->url=$url; + $this->demu = false; + $this->options = $options; + } + + public function set_demultiplexor($path){ + $this->demu = $path; + } + + public function set_event($master, $name){ + $this->event = $master; + $this->item_class = $name; + } + + protected function select_update($actions_table, $join_table, $id_field_name, $version, $user) { + $sql = "SELECT $join_table.*, {$actions_table}.id, {$actions_table}.dataId, {$actions_table}.type as action_table_type, {$actions_table}.user FROM {$actions_table}"; + $sql .= " LEFT OUTER JOIN {$join_table} ON "; + $sql .= "{$actions_table}.DATAID = {$join_table}.{$id_field_name} "; + $sql .= "WHERE {$actions_table}.ID > '{$version}' AND {$actions_table}.USER <> '{$user}'"; + return $sql; + } + + protected function get_update_max_version() { + $sql = "SELECT MAX(id) as VERSION FROM {$this->table}"; + $res = $this->sql->query($sql); + $data = $this->sql->get_next($res); + + if ($data == false || $data['VERSION'] == false) + return 1; + else + return $data['VERSION']; + } + + private function log_update_action($actions_table, $dataId, $status, $user) { + $sql = "INSERT INTO {$actions_table} (DATAID, TYPE, USER) VALUES ('{$dataId}', '{$status}', '{$user}')"; + $this->sql->query($sql); + if ($this->demu) + file_get_contents($this->demu); + } + + public function get_table() { + return $this->table; + } + + /*! records operations in actions_table + @param action + DataAction object + */ + public function log_operations($action) { + $type = $this->sql->escape($action->get_status()); + $dataId = $this->sql->escape($action->get_new_id()); + $user = $this->sql->escape($this->request->get_user()); + if ($type!="error" && $type!="invalid" && $type !="collision") { + $action_mode = $this->request->get_action_mode(); + if(!empty($action_mode)) + $type .= "#".$action_mode; + + $this->log_update_action($this->table, $dataId, $type, $user); + } + } + + + /*! return action version in XMl format + */ + public function get_version() { + $version = $this->get_update_max_version(); + return "".$version.""; + } + + + /*! adds action version in output XML as userdata + */ + public function version_output($conn, $out) { + $out->add($this->get_version()); + } + + + /*! create update actions in XML-format and sends it to output + */ + 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); + + ob_clean(); + header("Content-type:text/xml"); + + echo $this->updates_start(); + echo $this->get_version(); + echo $output; + echo $this->updates_end(); + } + + + protected function render_set($res, $name){ + $output=""; + $index=0; + while ($data=$this->sql->get_next($res)){ + $data = new DataItemUpdate($data,$this->config,$index, $name); + $this->event->trigger("beforeRender",$data); + $output.=$data->to_xml(); + $index++; + } + return $output; + } + + /*! returns update start string + */ + protected function updates_start() { + $start = ''; + return $start; + } + + /*! returns update end string + */ + protected function updates_end() { + $start = ''; + return $start; + } + + /*! checks if action version given by client is deprecated + @param action + DataAction object + */ + public function check_collision($action) { + $version = $this->sql->escape($this->request->get_version()); + //$user = $this->sql->escape($this->request->get_user()); + $last_version = $this->get_update_max_version(); + if (($last_version > $version)&&($action->get_status() == 'update')) { + $action->error(); + $action->set_status('collision'); + } + } +} + + +class JSONDataItemUpdate extends DataItemUpdate { + + public function to_xml() { + return array( + "status" => $this->data["action_table_type"], + "id" => $this->data["dataId"], + "parent" => $this->get_parent_id(), + "data" => $this->child->to_xml() + ); + } + +} + +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 From 6078b93f3f3b2f2b4a1c8471c9d43e0af9fd21f3 Mon Sep 17 00:00:00 2001 From: Stanislau Wolski Date: Wed, 12 Aug 2015 21:37:35 +0300 Subject: [PATCH 07/16] [update] links in readme --- README.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 969d5f3..95032eb 100644 --- a/README.md +++ b/README.md @@ -23,15 +23,9 @@ and paging) as well as server-side sorting and filtering. External links -------------- - * Documentation - http://docs.dhtmlx.com/doku.php?id=dhtmlxconnector:toc - * Video introduction - http://dhtmlx.com/docs/products/dhtmlxConnector/index.shtml - + * Documentation - http://docs.dhtmlx.com/connector__php__index.html Other languages --------------- - * Java - [wiki](http://docs.dhtmlx.com/doku.php?id=dhtmlxconnectorjava:toc), - [package](http://www.dhtmlx.com/x/download/regular/dhtmlxConnector_v09_java.zip) - * .Net - [wiki](http://docs.dhtmlx.com/doku.php?id=dhtmlxconnectornet:toc), - [package](http://www.dhtmlx.com/x/download/regular/dhtmlxConnector_v09_net.zip) - * ColdFustion - [wiki](http://docs.dhtmlx.com/doku.php?id=dhtmlxconnectorcf:toc), - [package](http://www.dhtmlx.com/x/download/regular/dhtmlxConnector_v10_cfm.zip) + * Java - [documentation](http://docs.dhtmlx.com/connector__java__index.html), + [github](https://github.com/DHTMLX/connector-java) From 582b5b5355dafaf4fe427fe7bf98e2b38f07fba3 Mon Sep 17 00:00:00 2001 From: Stanislau Wolski Date: Mon, 24 Aug 2015 20:20:22 +0300 Subject: [PATCH 08/16] [update] minor typos in samples, latest DHTMLX --- samples/combo/01_basic.html | 11 +- samples/combo/02_sql.html | 11 +- samples/dataview/01_static_loading.html | 4 +- samples/dataview/02_dynamic_loading.html | 4 +- samples/dataview/03_adding.html | 4 +- samples/dhtmlx/dhtmlx.css | 8 +- samples/dhtmlx/dhtmlx.js | 8 +- .../dhxcarousel_cell_progress.gif | Bin 0 -> 2608 bytes .../imgs/dhxgrid_skyblue/combo_select.gif | Bin 0 -> 76 bytes .../combo_select_dhx_skyblue.gif | Bin 0 -> 76 bytes .../combo_select_dhx_skyblue_normal.png | Bin 0 -> 538 bytes .../combo_select_dhx_skyblue_red_corner.png | Bin 0 -> 582 bytes .../dhxsidebar_arrow_down.gif | Bin 0 -> 54 bytes .../dhxsidebar_arrow_up.gif | Bin 0 -> 54 bytes .../dhxsidebar_cell_progress.gif | Bin 0 -> 2608 bytes samples/grid/01_basic.html | 20 +- samples/grid/01a_sql_basic.html | 23 +- samples/grid/02_rendering.html | 19 +- samples/grid/03_validation.html | 19 +- samples/grid/04_custom_sql.html | 19 +- samples/grid/05_select_filter.html | 20 +- samples/grid/05a_select_filter.html | 19 +- samples/grid/06_combo.html | 19 +- samples/grid/06a_combo.html | 63 - .../grid/09_server_side_configuration.html | 23 +- samples/grid/10_auto_config.html | 19 +- samples/grid/11_auto_config_filters.html | 19 +- samples/grid/12_attach_header_server.html | 20 +- .../grid/13_filesystem_grid_connector.html | 23 +- samples/grid/some.txt | 106 + samples/grid/xx_adodb.html | 14 +- samples/grid/xx_sample_mssql.html | 14 +- samples/grid/xx_sample_mysqli.html | 3 +- samples/grid/xx_sample_oracle.html | 14 +- samples/grid/xx_sample_pdo.html | 14 +- samples/grid/xx_sample_pdo_pg.html | 14 +- samples/grid/xx_sample_postgresql.html | 14 +- samples/grid/xx_sample_sasql.html | 14 +- samples/scheduler/01_basic_init.html | 8 +- samples/scheduler/02_dynamic_loading.html | 16 +- samples/scheduler/03_connector_options.html | 7 +- samples/scheduler/04_recurring_events.html | 8 +- samples/scheduler/05_json.html | 8 +- .../scheduler/06_json_connector_options.html | 7 +- samples/scheduler/07_array_connector.html | 7 +- samples/scheduler/index.html | 2 + samples/tree/01_basic.html | 18 +- samples/tree/01p_basic.html | 18 +- samples/tree/02_dynamic_loading.html | 18 +- samples/tree/03_sql_config.html | 18 +- samples/tree/04_custom_styles.html | 18 +- samples/tree/05_save.html | 20 +- samples/tree/06_validation.html | 19 +- samples/tree/08_tree_group_connector.html | 16 +- .../tree/09_tree_multitable_connector.html | 16 +- samples/treegrid/01_basic.html | 19 +- samples/treegrid/02_dynamic_loading.html | 17 +- samples/treegrid/03_sql_config.html | 17 +- samples/treegrid/04_custom_styles.html | 17 +- samples/treegrid/05_live_update.html | 19 +- samples/treegrid/05_live_update_connector.php | 13 + .../treegrid/06_treegrid_group_connector.html | 17 +- .../07_treegrid_multitable_connector.html | 18 +- samples/treegrid/index.html | 1 + samples/treegrid/temp.log | 4499 +++++++++++++++++ 65 files changed, 4943 insertions(+), 500 deletions(-) create mode 100644 samples/dhtmlx/imgs/dhxcarousel_skyblue/dhxcarousel_cell_progress.gif create mode 100644 samples/dhtmlx/imgs/dhxgrid_skyblue/combo_select.gif create mode 100644 samples/dhtmlx/imgs/dhxgrid_skyblue/combo_select_dhx_skyblue.gif create mode 100644 samples/dhtmlx/imgs/dhxgrid_skyblue/combo_select_dhx_skyblue_normal.png create mode 100644 samples/dhtmlx/imgs/dhxgrid_skyblue/combo_select_dhx_skyblue_red_corner.png create mode 100644 samples/dhtmlx/imgs/dhxsidebar_skyblue/dhxsidebar_arrow_down.gif create mode 100644 samples/dhtmlx/imgs/dhxsidebar_skyblue/dhxsidebar_arrow_up.gif create mode 100644 samples/dhtmlx/imgs/dhxsidebar_skyblue/dhxsidebar_cell_progress.gif delete mode 100644 samples/grid/06a_combo.html create mode 100644 samples/treegrid/05_live_update_connector.php create mode 100644 samples/treegrid/temp.log diff --git a/samples/combo/01_basic.html b/samples/combo/01_basic.html index 129140a..10c3ea2 100644 --- a/samples/combo/01_basic.html +++ b/samples/combo/01_basic.html @@ -1,15 +1,14 @@ - + Filtering and Autocomplete mode + + + + - - - - -
diff --git a/samples/combo/02_sql.html b/samples/combo/02_sql.html index 9740cf3..5705526 100644 --- a/samples/combo/02_sql.html +++ b/samples/combo/02_sql.html @@ -1,15 +1,14 @@ - + Filtering and Autocomplete mode + + + + - - - - -
diff --git a/samples/dataview/01_static_loading.html b/samples/dataview/01_static_loading.html index 45ece36..76b48a4 100644 --- a/samples/dataview/01_static_loading.html +++ b/samples/dataview/01_static_loading.html @@ -1,10 +1,10 @@ - + Static loading + diff --git a/samples/dataview/02_dynamic_loading.html b/samples/dataview/02_dynamic_loading.html index 4a846fa..5c0866e 100644 --- a/samples/dataview/02_dynamic_loading.html +++ b/samples/dataview/02_dynamic_loading.html @@ -1,10 +1,10 @@ - + Dynamic loading + diff --git a/samples/dataview/03_adding.html b/samples/dataview/03_adding.html index 6c08152..7f8cd0e 100644 --- a/samples/dataview/03_adding.html +++ b/samples/dataview/03_adding.html @@ -1,5 +1,4 @@ - +