Skip to content

Commit dc3bc48

Browse files
Merge branch 'master' of github.com:DHTMLX/connector-php
2 parents 582b5b5 + 6078b93 commit dc3bc48

File tree

7 files changed

+517
-321
lines changed

7 files changed

+517
-321
lines changed

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,9 @@ and paging) as well as server-side sorting and filtering.
2323

2424
External links
2525
--------------
26-
* Documentation - http://docs.dhtmlx.com/doku.php?id=dhtmlxconnector:toc
27-
* Video introduction - http://dhtmlx.com/docs/products/dhtmlxConnector/index.shtml
28-
26+
* Documentation - http://docs.dhtmlx.com/connector__php__index.html
2927

3028
Other languages
3129
---------------
32-
* Java - [wiki](http://docs.dhtmlx.com/doku.php?id=dhtmlxconnectorjava:toc),
33-
[package](http://www.dhtmlx.com/x/download/regular/dhtmlxConnector_v09_java.zip)
34-
* .Net - [wiki](http://docs.dhtmlx.com/doku.php?id=dhtmlxconnectornet:toc),
35-
[package](http://www.dhtmlx.com/x/download/regular/dhtmlxConnector_v09_net.zip)
36-
* ColdFustion - [wiki](http://docs.dhtmlx.com/doku.php?id=dhtmlxconnectorcf:toc),
37-
[package](http://www.dhtmlx.com/x/download/regular/dhtmlxConnector_v10_cfm.zip)
30+
* Java - [documentation](http://docs.dhtmlx.com/connector__java__index.html),
31+
[github](https://github.com/DHTMLX/connector-java)

codebase/base_connector.php

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -282,38 +282,38 @@ public function to_xml_end(){
282282
Can be used on its own to provide raw data.
283283
**/
284284
class Connector {
285+
286+
private $id_seed=0; //!< default value, used to generate auto-IDs
287+
private $db; //!< db connection resource
288+
285289
protected $config;//DataConfig instance
286290
protected $request;//DataRequestConfig instance
287291
protected $names;//!< hash of names for used classes
288292
protected $encoding="utf-8";//!< assigned encoding (UTF-8 by default)
289293
protected $editing=false;//!< flag of edit mode ( response for dataprocessor )
294+
protected $updating=false;//!< flag of update mode ( response for data-update )
295+
protected $dload;//!< flag of dyn. loading mode
296+
protected $data_separator = "\n";
297+
protected $live_update = false; // actions table name for autoupdating
298+
protected $live_update_data_type = "DataUpdate";
299+
protected $extra_output="";//!< extra info which need to be sent to client side
300+
protected $options=array();//!< hash of OptionsConnector
301+
protected $as_string = false; // render() returns string, don't send result in response
302+
protected $simple = false; // render only data without any other info
303+
protected $filters;
304+
protected $sorts;
305+
protected $mix;
306+
protected $order = false;
290307

291308
public static $filter_var="dhx_filter";
292309
public static $sort_var="dhx_sort";
293310
public static $kids_var="dhx_kids";
294311

295-
public $model=false;
296-
297-
private $updating=false;//!< flag of update mode ( response for data-update )
298-
private $db; //!< db connection resource
299-
protected $dload;//!< flag of dyn. loading mode
300-
public $access; //!< AccessMaster instance
301-
protected $data_separator = "\n";
302-
303-
public $sql; //DataWrapper instance
304-
public $event; //EventMaster instance
305-
public $limit=false;
306-
307-
private $id_seed=0; //!< default value, used to generate auto-IDs
308-
protected $live_update = false; // actions table name for autoupdating
309-
protected $extra_output="";//!< extra info which need to be sent to client side
310-
protected $options=array();//!< hash of OptionsConnector
311-
protected $as_string = false; // render() returns string, don't send result in response
312-
protected $simple = false; // render only data without any other info
313-
protected $filters;
314-
protected $sorts;
315-
protected $mix;
316-
protected $order = false;
312+
public $model=false;
313+
public $access; //!< AccessMaster instance
314+
public $sql; //DataWrapper instance
315+
public $event; //EventMaster instance
316+
public $limit=false;
317317

318318
/*! constructor
319319
@@ -810,6 +810,10 @@ public function set_options($name,$options){
810810
$this->options[$name]=$options;
811811
}
812812

813+
public function get_options() {
814+
return $this->options;
815+
}
816+
813817

814818
public function insert($data) {
815819
$action = new DataAction('inserted', false, $data);
@@ -851,7 +855,7 @@ public function update($data) {
851855
url used for update notifications
852856
*/
853857
public function enable_live_update($table, $url=false){
854-
$this->live_update = new DataUpdate($this->sql, $this->config, $this->request, $table,$url);
858+
$this->live_update = new $this->live_update_data_type($this->sql, $this->config, $this->request, $table,$url, array("connector" => $this));
855859
$this->live_update->set_event($this->event,$this->names["item_class"]);
856860
$this->event->attach("beforeOutput", Array($this->live_update, "version_output"));
857861
$this->event->attach("beforeFiltering", Array($this->live_update, "get_updates"));

codebase/db_common.php

100644100755
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
/*! manager of data request
99
**/
1010
class DataRequestConfig{
11+
12+
private $action_mode = "";
1113
private $filters; //!< array of filtering rules
1214
private $relation=false; //!< ID or other element used for linking hierarchy
1315
private $sort_by; //!< sorting field
@@ -52,6 +54,7 @@ public function copy($proto){
5254
$this->relation =$proto->get_relation();
5355
$this->user = $proto->user;
5456
$this->version = $proto->version;
57+
$this->action_mode = $proto->action_mode;
5558
}
5659

5760
/*! convert self to string ( for logs )
@@ -69,6 +72,15 @@ public function __toString(){
6972
return $str;
7073
}
7174

75+
public function set_action_mode($action_mode) {
76+
$this->action_mode = $action_mode;
77+
return $this;
78+
}
79+
80+
public function get_action_mode() {
81+
return $this->action_mode;
82+
}
83+
7284
/*! returns set of filtering rules
7385
@return
7486
set of filtering rules

codebase/gantt_connector.php

100644100755
Lines changed: 83 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ public function to_xml_start(){
5555
**/
5656
class GanttConnector extends Connector{
5757

58+
private $action_mode = "";
59+
public $links_table = "";
60+
61+
protected $live_update_data_type = "GanttDataUpdate";
5862
protected $extra_output="";//!< extra info which need to be sent to client side
5963
protected $options=array();//!< hash of OptionsConnector
60-
protected $links_mode = false;
61-
6264

6365
/*! assign options collection to the column
6466
@@ -106,8 +108,14 @@ public function __construct($res,$type=false,$item_type=false,$data_type=false,$
106108
function parse_request(){
107109
parent::parse_request();
108110

109-
if (isset($_GET["gantt_mode"]) && $_GET["gantt_mode"] == "links")
110-
$this->links_mode = true;
111+
$action_links = "links";
112+
if(isset($_GET["gantt_mode"]) && $_GET["gantt_mode"] == $action_links) {
113+
$this->action_mode = $action_links;
114+
$this->request->set_action_mode($action_links);
115+
$this->options[$action_links]->request->set_action_mode($action_links);
116+
$this->options[$action_links]->request->set_user($this->request->get_user());
117+
}
118+
111119

112120
if (count($this->config->text)){
113121
if (isset($_GET["to"]))
@@ -138,10 +146,15 @@ function delete_related_links($action){
138146
}
139147
}
140148

141-
public function render_links($table,$id="",$fields=false,$extra=false,$relation_id=false) {
149+
public function render_links($table,$id="",$fields=false,$extra=false) {
142150
$links = new GanttLinksConnector($this->get_connection(),$this->names["db_class"]);
151+
152+
if($this->live_update)
153+
$links->enable_live_update($this->live_update->get_table());
154+
143155
$links->render_table($table,$id,$fields,$extra);
144156
$this->set_options("links", $links);
157+
$this->links_table = $table;
145158
}
146159

147160

@@ -157,10 +170,10 @@ public function render(){
157170
$this->set_relation();
158171

159172
if ($this->live_update !== false && $this->updating!==false) {
160-
$this->live_update->get_updates();
173+
$this->live_update->get_updates();
161174
} else {
162175
if ($this->editing){
163-
if ($this->links_mode && isset($this->options["links"])) {
176+
if (($this->action_mode == "links") && isset($this->options["links"])) {
164177
$this->options["links"]->save();
165178
} else {
166179
$dp = new $this->names["data_class"]($this,$this->config,$this->request);
@@ -247,6 +260,7 @@ function to_xml(){
247260
class JSONGanttConnector extends GanttConnector {
248261

249262
protected $data_separator = ",";
263+
protected $live_update_data_type = "JSONGanttDataUpdate";
250264

251265
/*! constructor
252266
@@ -340,6 +354,10 @@ protected function output_as_xml($res){
340354

341355
public function render_links($table,$id="",$fields=false,$extra=false,$relation_id=false) {
342356
$links = new JSONGanttLinksConnector($this->get_connection(),$this->names["db_class"]);
357+
358+
if($this->live_update)
359+
$links->enable_live_update($this->live_update->get_table());
360+
343361
$links->render_table($table,$id,$fields,$extra);
344362
$this->set_options("links", $links);
345363
}
@@ -348,6 +366,7 @@ public function render_links($table,$id="",$fields=false,$extra=false,$relation_
348366

349367

350368
class GanttLinksConnector extends OptionsConnector {
369+
protected $live_update_data_type = "GanttDataUpdate";
351370

352371
public function __construct($res,$type=false,$item_type=false,$data_type=false,$render_type=false){
353372
if (!$item_type) $item_type="GanttLinkDataItem";
@@ -372,6 +391,7 @@ public function save() {
372391

373392

374393
class JSONGanttLinksConnector extends JSONOptionsConnector {
394+
protected $live_update_data_type = "JSONGanttDataUpdate";
375395
public function render(){
376396
if (!$this->init_flag){
377397
$this->init_flag=true;
@@ -388,4 +408,60 @@ public function save() {
388408
}
389409
}
390410

411+
class JSONGanttDataUpdate extends JSONDataUpdate {
412+
413+
public function get_updates() {
414+
$updates = $this->get_data_updates();
415+
//ToDo: Add rendering for data.
416+
}
417+
418+
419+
private function get_data_updates() {
420+
$actions_table = $this->table;
421+
$version = $this->request->get_version();
422+
$user = $this->request->get_user();
423+
424+
$select_actions = "SELECT DATAID, TYPE, USER FROM {$actions_table}";
425+
$select_actions .= " WHERE {$actions_table}.ID > '{$version}' AND {$actions_table}.USER <> '{$user}'";
426+
427+
428+
$output = array();
429+
$index = 0;
430+
$actions_query = $this->sql->query($select_actions);
431+
while($action_data=$this->sql->get_next($actions_query)){
432+
$action_type = $action_data["TYPE"];
433+
$type_parts = explode("#", $action_type);
434+
$action_mode = $type_parts[1];
435+
if($action_mode == "links") {
436+
$data = $this->select_links_for_action($action_data["DATAID"]);
437+
$data = new DataItemUpdate($data, $this->config, $index, $this->item_class);
438+
}
439+
else {
440+
$data = $this->select_task_for_action($action_data["DATAID"]);
441+
$data = new DataItemUpdate($data, $this->config, $index, $this->item_class);
442+
}
443+
444+
array_push($output, $data);
445+
$index++;
446+
}
447+
448+
return $output;
449+
}
450+
451+
protected function select_task_for_action($taskId) {
452+
$tasks_table = $this->request->get_source();
453+
$field_task_id = $this->config->id['db_name'];
454+
$select_actions_tasks = "SELECT * FROM {$tasks_table} WHERE {$taskId} = {$tasks_table}.{$field_task_id}";
455+
return $this->sql->get_next($this->sql->query($select_actions_tasks));
456+
}
457+
458+
protected function select_links_for_action($taskId) {
459+
$links_connector_options = $this->options["connector"]->get_options();
460+
$links_table = $links_connector_options["links"]->get_request()->get_source();
461+
$field_task_id = $this->config->id['db_name'];
462+
$select_actions_tasks = "SELECT * FROM {$links_table} WHERE {$taskId} = {$links_table}.{$field_task_id}";
463+
return $this->sql->get_next($this->sql->query($select_actions_tasks));
464+
}
465+
}
466+
391467
?>

codebase/mixed_connector.php

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,53 @@
77

88
class MixedConnector extends Connector {
99

10-
protected $connectors = array();
11-
12-
public function add($name, $conn) {
13-
$this->connectors[$name] = $conn;
14-
}
15-
16-
public function render() {
17-
$result = "{";
18-
$parts = array();
19-
foreach($this->connectors as $name => $conn) {
20-
$conn->asString(true);
21-
$parts[] = "\"".$name."\":".($conn->render())."\n";
22-
}
23-
$result .= implode(",\n", $parts)."}";
24-
echo $result;
25-
}
10+
private $_data_type = null;
11+
12+
function __construct($dataType = "json") {
13+
$this->_data_type = $dataType;
14+
}
15+
16+
protected $attributes = array();
17+
protected $connectors = array();
18+
19+
public function add($name, $conn) {
20+
$this->connectors[$name] = $conn;
21+
$conn->simple = true;
22+
}
23+
24+
public function render() {
25+
if($this->_data_type == "json")
26+
$this->render_json();
27+
else
28+
$this->render_xml();
29+
}
30+
31+
private function render_json() {
32+
$result = "{";
33+
$parts = array();
34+
foreach($this->connectors as $name => $conn) {
35+
$conn->asString(true);
36+
$parts[] = "\"".$name."\":".($conn->render())."\n";
37+
}
38+
$result .= implode(",\n", $parts)."}";
39+
echo $result;
40+
}
41+
42+
private function render_xml() {
43+
$result = "";
44+
$parts = array();
45+
46+
foreach($this->connectors as $name => $conn) {
47+
$conn->asString(true);
48+
$parts[] = "<".$name.">".($conn->render())."</".$name.">\n";
49+
}
50+
$result .= implode("", $parts);
51+
$this->output_as_xml($result);
52+
}
53+
54+
protected function output_as_xml($res) {
55+
echo "<?xml version='1.0' encoding='".$this->encoding."' ?>".$this->xml_start().$res.$this->xml_end();
56+
}
2657
}
2758

2859
?>

codebase/scheduler_connector.php

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ function to_xml(){
136136
class JSONSchedulerConnector extends SchedulerConnector {
137137

138138
protected $data_separator = ",";
139+
protected $live_update_data_type = "JSONDataUpdate";
139140

140141
/*! constructor
141142

0 commit comments

Comments
 (0)