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 | |
parent | 8255a94f15a0722c8789a9b363962ca943e51d6b (diff) | |
download | connector-php-50ff8ab2720fabea8a815b96071b6bab3e3a5dbb.zip connector-php-50ff8ab2720fabea8a815b96071b6bab3e3a5dbb.tar.gz connector-php-50ff8ab2720fabea8a815b96071b6bab3e3a5dbb.tar.bz2 |
Updated live update functionality.
-rwxr-xr-x | codebase/Dhtmlx/Connector/Connector.php | 37 | ||||
-rw-r--r-- | codebase/Dhtmlx/Connector/Data/DataItemUpdate.php | 4 | ||||
-rw-r--r-- | codebase/Dhtmlx/Connector/Data/DataRequestConfig.php | 12 | ||||
-rw-r--r-- | codebase/Dhtmlx/Connector/Data/DataUpdate.php | 16 | ||||
-rw-r--r-- | codebase/Dhtmlx/Connector/Data/JSONDataItemUpdate.php | 15 | ||||
-rw-r--r-- | codebase/Dhtmlx/Connector/Data/JSONDataUpdate.php | 62 | ||||
-rw-r--r-- | codebase/Dhtmlx/Connector/Data/JSONGanttDataUpdate.php | 58 | ||||
-rwxr-xr-x | codebase/Dhtmlx/Connector/GanttConnector.php | 22 | ||||
-rw-r--r-- | codebase/Dhtmlx/Connector/GanttLinksConnector.php | 2 | ||||
-rwxr-xr-x | codebase/Dhtmlx/Connector/JSONGanttConnector.php | 5 | ||||
-rw-r--r-- | codebase/Dhtmlx/Connector/JSONGanttLinksConnector.php | 2 | ||||
-rwxr-xr-x | codebase/Dhtmlx/Connector/JSONSchedulerConnector.php | 1 |
12 files changed, 209 insertions, 27 deletions
diff --git a/codebase/Dhtmlx/Connector/Connector.php b/codebase/Dhtmlx/Connector/Connector.php index 14521a2..6f45153 100755 --- a/codebase/Dhtmlx/Connector/Connector.php +++ b/codebase/Dhtmlx/Connector/Connector.php @@ -17,30 +17,19 @@ use Dhtmlx\Connector\Event\FilterInterface; use Dhtmlx\Connector\DataStorage\ArrayQueryWrapper; 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 ) - - 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 $updating=false;//!< flag of update mode ( response for data-update ) 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 $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 @@ -50,6 +39,16 @@ class Connector { 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; + public $access; //!< AccessMaster instance + public $sql; //DataWrapper instance + public $event; //EventMaster instance + public $limit=false; + /*! constructor Here initilization of all Masters occurs, execution timer initialized @@ -551,6 +550,10 @@ class Connector { $this->options[$name]=$options; } + public function get_options() { + return $this->options; + } + public function insert($data) { $action = new DataAction('inserted', false, $data); @@ -592,7 +595,7 @@ class Connector { 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/Dhtmlx/Connector/Data/DataItemUpdate.php b/codebase/Dhtmlx/Connector/Data/DataItemUpdate.php index c77451c..3dcee14 100644 --- a/codebase/Dhtmlx/Connector/Data/DataItemUpdate.php +++ b/codebase/Dhtmlx/Connector/Data/DataItemUpdate.php @@ -47,7 +47,7 @@ class DataItemUpdate extends DataItem { */ public function to_xml(){ $str= "<update "; - $str .= 'status="'.$this->data['type'].'" '; + $str .= 'status="'.$this->data['action_table_type'].'" '; $str .= 'id="'.$this->data['dataId'].'" '; $str .= 'parent="'.$this->get_parent_id().'"'; $str .= '>'; @@ -60,7 +60,7 @@ class DataItemUpdate extends DataItem { */ public function to_xml_start(){ $str="<update "; - $str .= 'status="'.$this->data['type'].'" '; + $str .= 'status="'.$this->data['action_table_type'].'" '; $str .= 'id="'.$this->data['dataId'].'" '; $str .= 'parent="'.$this->get_parent_id().'"'; $str .= '>'; diff --git a/codebase/Dhtmlx/Connector/Data/DataRequestConfig.php b/codebase/Dhtmlx/Connector/Data/DataRequestConfig.php index e2b709c..91752fe 100644 --- a/codebase/Dhtmlx/Connector/Data/DataRequestConfig.php +++ b/codebase/Dhtmlx/Connector/Data/DataRequestConfig.php @@ -5,6 +5,8 @@ use \Exception; /*! 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 @@ -49,6 +51,7 @@ class DataRequestConfig { $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 ) @@ -66,6 +69,15 @@ class DataRequestConfig { 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/Dhtmlx/Connector/Data/DataUpdate.php b/codebase/Dhtmlx/Connector/Data/DataUpdate.php index 7db2261..7c00297 100644 --- a/codebase/Dhtmlx/Connector/Data/DataUpdate.php +++ b/codebase/Dhtmlx/Connector/Data/DataUpdate.php @@ -24,13 +24,14 @@ class DataUpdate { @param request DataRequestConfig object */ - function __construct($sql, $config, $request, $table, $url){ + 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){ @@ -42,15 +43,15 @@ class DataUpdate { $this->item_class = $name; } - private function select_update($actions_table, $join_table, $id_field_name, $version, $user) { - $sql = "SELECT * FROM {$actions_table}"; + 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; } - private function get_update_max_version() { + 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); @@ -68,6 +69,9 @@ class DataUpdate { file_get_contents($this->demu); } + public function get_table() { + return $this->table; + } @@ -80,6 +84,10 @@ class DataUpdate { $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); } } diff --git a/codebase/Dhtmlx/Connector/Data/JSONDataItemUpdate.php b/codebase/Dhtmlx/Connector/Data/JSONDataItemUpdate.php new file mode 100644 index 0000000..bb6ec47 --- /dev/null +++ b/codebase/Dhtmlx/Connector/Data/JSONDataItemUpdate.php @@ -0,0 +1,15 @@ +<?php +namespace Dhtmlx\Connector\Data; + +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() + ); + } + +}
\ No newline at end of file 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 diff --git a/codebase/Dhtmlx/Connector/Data/JSONGanttDataUpdate.php b/codebase/Dhtmlx/Connector/Data/JSONGanttDataUpdate.php new file mode 100644 index 0000000..eba380f --- /dev/null +++ b/codebase/Dhtmlx/Connector/Data/JSONGanttDataUpdate.php @@ -0,0 +1,58 @@ +<?php +namespace Dhtmlx\Connector\Data; + +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/Dhtmlx/Connector/GanttConnector.php b/codebase/Dhtmlx/Connector/GanttConnector.php index 6017522..e581386 100755 --- a/codebase/Dhtmlx/Connector/GanttConnector.php +++ b/codebase/Dhtmlx/Connector/GanttConnector.php @@ -11,7 +11,10 @@ use Dhtmlx\Connector\DataStorage\ArrayQueryWrapper; /*! Connector class for dhtmlxGantt **/ class GanttConnector extends Connector { + private $action_mode = ""; + public $links_table = ""; + protected $live_update_data_type = "Dhtmlx\\Connector\\Data\\GanttDataUpdate"; protected $extra_output="";//!< extra info which need to be sent to client side protected $options=array();//!< hash of OptionsConnector protected $links_mode = false; @@ -63,8 +66,14 @@ class GanttConnector extends Connector { 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"])) @@ -95,10 +104,15 @@ class GanttConnector extends Connector { } } - 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; } /*! render self @@ -116,7 +130,7 @@ class GanttConnector extends Connector { $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); diff --git a/codebase/Dhtmlx/Connector/GanttLinksConnector.php b/codebase/Dhtmlx/Connector/GanttLinksConnector.php index 9790f69..bdf2047 100644 --- a/codebase/Dhtmlx/Connector/GanttLinksConnector.php +++ b/codebase/Dhtmlx/Connector/GanttLinksConnector.php @@ -2,6 +2,8 @@ namespace Dhtmlx\Connector; class GanttLinksConnector extends OptionsConnector { + protected $live_update_data_type = "Dhtmlx\\Connector\\Data\\GanttDataUpdate"; + public function __construct($res,$type=false,$item_type=false,$data_type=false,$render_type=false){ if (!$item_type) $item_type="Dhtmlx\\Connector\\Data\\GanttLinkDataItem"; parent::__construct($res,$type,$item_type,$data_type,$render_type); diff --git a/codebase/Dhtmlx/Connector/JSONGanttConnector.php b/codebase/Dhtmlx/Connector/JSONGanttConnector.php index f708b6e..3198d25 100755 --- a/codebase/Dhtmlx/Connector/JSONGanttConnector.php +++ b/codebase/Dhtmlx/Connector/JSONGanttConnector.php @@ -5,6 +5,7 @@ use Dhtmlx\Connector\Output\OutputWriter; class JSONGanttConnector extends GanttConnector { protected $data_separator = ","; + protected $live_update_data_type = "Dhtmlx\\Connector\\Data\\JSONGanttDataUpdate"; /*! constructor @@ -98,6 +99,10 @@ class JSONGanttConnector extends GanttConnector { 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); } diff --git a/codebase/Dhtmlx/Connector/JSONGanttLinksConnector.php b/codebase/Dhtmlx/Connector/JSONGanttLinksConnector.php index c08b451..899fd11 100644 --- a/codebase/Dhtmlx/Connector/JSONGanttLinksConnector.php +++ b/codebase/Dhtmlx/Connector/JSONGanttLinksConnector.php @@ -2,6 +2,8 @@ namespace Dhtmlx\Connector; class JSONGanttLinksConnector extends JSONOptionsConnector { + protected $live_update_data_type = "Dhtmlx\\Connector\\Data\\JSONGanttDataUpdate"; + public function render(){ if (!$this->init_flag){ $this->init_flag=true; diff --git a/codebase/Dhtmlx/Connector/JSONSchedulerConnector.php b/codebase/Dhtmlx/Connector/JSONSchedulerConnector.php index a84bf68..443dbcc 100755 --- a/codebase/Dhtmlx/Connector/JSONSchedulerConnector.php +++ b/codebase/Dhtmlx/Connector/JSONSchedulerConnector.php @@ -5,6 +5,7 @@ use Dhtmlx\Connector\Output\OutputWriter; class JSONSchedulerConnector extends SchedulerConnector { protected $data_separator = ","; + protected $live_update_data_type = "JSONDataUpdate"; /*! constructor |