diff options
author | Egor <egor.26.93@gmail.com> | 2015-07-19 21:01:43 +0300 |
---|---|---|
committer | Egor <egor.26.93@gmail.com> | 2015-07-19 21:01:43 +0300 |
commit | 533642bcb15e84ae1e21007152a87cd35cda3775 (patch) | |
tree | 2d8bbb7c59abda444147a5f805e6ebb67256641c /codebase/gantt_connector.php | |
parent | d66c1ce799ea4d773699e73f934db27e764d3f17 (diff) | |
download | connector-php-533642bcb15e84ae1e21007152a87cd35cda3775.zip connector-php-533642bcb15e84ae1e21007152a87cd35cda3775.tar.gz connector-php-533642bcb15e84ae1e21007152a87cd35cda3775.tar.bz2 |
Updated live update functionality.
Diffstat (limited to 'codebase/gantt_connector.php')
-rwxr-xr-x[-rw-r--r--] | codebase/gantt_connector.php | 90 |
1 files changed, 83 insertions, 7 deletions
diff --git a/codebase/gantt_connector.php b/codebase/gantt_connector.php index f8c62cf..9bd9422 100644..100755 --- a/codebase/gantt_connector.php +++ b/codebase/gantt_connector.php @@ -55,10 +55,12 @@ class GanttLinkDataItem extends DataItem { **/ 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 @@ 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"])) @@ -138,10 +146,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; } @@ -157,10 +170,10 @@ class GanttConnector extends Connector{ $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 @@ class JSONGanttDataItem extends GanttDataItem{ class JSONGanttConnector extends GanttConnector { protected $data_separator = ","; + protected $live_update_data_type = "JSONGanttDataUpdate"; /*! constructor @@ -340,6 +354,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); } @@ -348,6 +366,7 @@ class JSONGanttConnector extends GanttConnector { 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 @@ class GanttLinksConnector extends OptionsConnector { 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 @@ class JSONGanttLinksConnector extends JSONOptionsConnector { } } +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 |