summaryrefslogtreecommitdiffstats
path: root/codebase
diff options
context:
space:
mode:
authorDmitry <dmitry@dhtmlx.com>2012-05-11 17:01:49 +0200
committerDmitry <dmitry@dhtmlx.com>2012-05-11 17:01:49 +0200
commitccf852543a3b2c56d6537e59ba877078a9018bbe (patch)
treee3cc5a8e69197e3826ded57ddd3e8b28077dbf73 /codebase
parentc9fcb91534cb423ec47e1b403c6a1786d6a7cd59 (diff)
downloadconnector-php-ccf852543a3b2c56d6537e59ba877078a9018bbe.zip
connector-php-ccf852543a3b2c56d6537e59ba877078a9018bbe.tar.gz
connector-php-ccf852543a3b2c56d6537e59ba877078a9018bbe.tar.bz2
improve group connectors + DataGroupConn + JSONDataGroupConn
Diffstat (limited to 'codebase')
-rw-r--r--codebase/strategy.php40
-rw-r--r--codebase/treedatagroup_connector.php89
-rw-r--r--codebase/treegridgroup_connector.php10
-rw-r--r--codebase/treegroup_connector.php10
4 files changed, 137 insertions, 12 deletions
diff --git a/codebase/strategy.php b/codebase/strategy.php
index 3caeaeb..b1cae36 100644
--- a/codebase/strategy.php
+++ b/codebase/strategy.php
@@ -360,4 +360,44 @@ class GroupRenderStrategy extends RenderStrategy {
}
+class JSONGroupRenderStrategy extends GroupRenderStrategy {
+
+ public function render_set($res, $name, $dload, $sep){
+ $output=array();
+ $index=0;
+ $conn = $this->conn;
+ $config = $conn->get_config();
+ while ($data=$conn->sql->get_next($res)){
+ if (isset($data[$config->id['name']])) {
+ $has_kids = false;
+ } else {
+ $data[$config->id['name']] = $data['value'].$this->id_postfix;
+ $data[$config->text[0]['name']] = $data['value'];
+ $has_kids = true;
+ }
+ $data = new $name($data,$config,$index);
+ $conn->event->trigger("beforeRender",$data);
+ if ($has_kids === false) {
+ $data->set_kids(false);
+ }
+
+ if ($data->has_kids()===-1 && $dload)
+ $data->set_kids(true);
+ $record = $data->to_xml_start();
+ if (($data->has_kids()===-1 || ( $data->has_kids()==true && !$dload))&&($has_kids == true)){
+ $sub_request = new DataRequestConfig($conn->get_request());
+ $sub_request->set_relation(str_replace($this->id_postfix, "", $data->get_id()));
+ $temp = $this->render_set($conn->sql->select($sub_request), $name, $dload, $sep);
+ if (sizeof($temp))
+ $record["data"] = $temp;
+ }
+ $output[] = $record;
+ $index++;
+ }
+ return $output;
+ }
+
+}
+
+
?> \ No newline at end of file
diff --git a/codebase/treedatagroup_connector.php b/codebase/treedatagroup_connector.php
new file mode 100644
index 0000000..336915a
--- /dev/null
+++ b/codebase/treedatagroup_connector.php
@@ -0,0 +1,89 @@
+<?php
+/*
+ @author dhtmlx.com
+ @license GPL, see license.txt
+*/
+require_once("data_connector.php");
+
+class TreeDataGroupConnector extends TreeDataConnector{
+
+ public function __construct($res,$type=false,$item_type=false,$data_type=false,$render_type=false){
+ if (!$render_type) $render_type="GroupRenderStrategy";
+ parent::__construct($res,$type,$item_type,$data_type,$render_type);
+ }
+
+ /*! if not isset $_GET[id] then it's top level
+ */
+ protected function set_relation() {
+ if (!isset($_GET[$this->parent_name])) $this->request->set_relation(false);
+ }
+
+ /*! if it's first level then distinct level
+ * else select by parent
+ */
+ protected function get_resource() {
+ $resource = null;
+ if (isset($_GET[$this->parent_name]))
+ $resource = $this->sql->select($this->request);
+ else
+ $resource = $this->sql->get_variants($this->config->relation_id['name'], $this->request);
+ return $resource;
+ }
+
+
+ /*! renders self as xml, starting part
+ */
+ public function xml_start(){
+ if (isset($_GET[$this->parent_name])) {
+ return "<data parent='".$_GET[$this->parent_name].$this->render->get_postfix()."'>";
+ } else {
+ return "<data parent='0'>";
+ }
+ }
+
+}
+
+
+
+
+class JSONTreeDataGroupConnector extends JSONTreeDataConnector{
+
+ public function __construct($res,$type=false,$item_type=false,$data_type=false,$render_type=false){
+ if (!$render_type) $render_type="JSONGroupRenderStrategy";
+ parent::__construct($res,$type,$item_type,$data_type,$render_type);
+ }
+
+ /*! if not isset $_GET[id] then it's top level
+ */
+ protected function set_relation() {
+ if (!isset($_GET[$this->parent_name])) $this->request->set_relation(false);
+ }
+
+ /*! if it's first level then distinct level
+ * else select by parent
+ */
+ protected function get_resource() {
+ $resource = null;
+ if (isset($_GET[$this->parent_name]))
+ $resource = $this->sql->select($this->request);
+ else
+ $resource = $this->sql->get_variants($this->config->relation_id['name'], $this->request);
+ return $resource;
+ }
+
+
+ /*! renders self as xml, starting part
+ */
+ public function xml_start(){
+ if (isset($_GET[$this->parent_name])) {
+ return "<data parent='".$_GET[$this->parent_name].$this->render->get_postfix()."'>";
+ } else {
+ return "<data parent='0'>";
+ }
+ }
+
+}
+
+
+
+?> \ No newline at end of file
diff --git a/codebase/treegridgroup_connector.php b/codebase/treegridgroup_connector.php
index 9900bba..cd8fdf2 100644
--- a/codebase/treegridgroup_connector.php
+++ b/codebase/treegridgroup_connector.php
@@ -10,14 +10,12 @@ class TreeGridGroupConnector extends TreeGridConnector{
public function __construct($res,$type=false,$item_type=false,$data_type=false,$render_type=false){
if (!$render_type) $render_type="GroupRenderStrategy";
parent::__construct($res,$type,$item_type,$data_type,$render_type);
- $this->event->attach("beforeProcessing", Array($this->render, 'check_id'));
- $this->event->attach("onInit", Array($this->render, 'replace_postfix'));
}
/*! if not isset $_GET[id] then it's top level
*/
protected function set_relation() {
- if (!isset($_GET['id'])) $this->request->set_relation(false);
+ if (!isset($_GET[$this->parent_name])) $this->request->set_relation(false);
}
/*! if it's first level then distinct level
@@ -25,7 +23,7 @@ class TreeGridGroupConnector extends TreeGridConnector{
*/
protected function get_resource() {
$resource = null;
- if (isset($_GET['id']))
+ if (isset($_GET[$this->parent_name]))
$resource = $this->sql->select($this->request);
else
$resource = $this->sql->get_variants($this->config->relation_id['name'], $this->request);
@@ -36,8 +34,8 @@ class TreeGridGroupConnector extends TreeGridConnector{
/*! renders self as xml, starting part
*/
protected function xml_start(){
- if (isset($_GET['id'])) {
- return "<rows parent='".$_GET['id'].$this->render->get_postfix()."'>";
+ if (isset($_GET[$this->parent_name])) {
+ return "<rows parent='".$_GET[$this->parent_name].$this->render->get_postfix()."'>";
} else {
return "<rows parent='0'>";
}
diff --git a/codebase/treegroup_connector.php b/codebase/treegroup_connector.php
index 09638fa..5266d0b 100644
--- a/codebase/treegroup_connector.php
+++ b/codebase/treegroup_connector.php
@@ -10,14 +10,12 @@ class TreeGroupConnector extends TreeConnector{
public function __construct($res,$type=false,$item_type=false,$data_type=false,$render_type=false){
if (!$render_type) $render_type="GroupRenderStrategy";
parent::__construct($res,$type,$item_type,$data_type,$render_type);
- $this->event->attach("beforeProcessing", Array($this->render, 'check_id'));
- $this->event->attach("onInit", Array($this->render, 'replace_postfix'));
}
/*! if not isset $_GET[id] then it's top level
*/
protected function set_relation() {
- if (!isset($_GET['id'])) $this->request->set_relation(false);
+ if (!isset($_GET[$this->parent_name])) $this->request->set_relation(false);
}
/*! if it's first level then distinct level
@@ -25,7 +23,7 @@ class TreeGroupConnector extends TreeConnector{
*/
protected function get_resource() {
$resource = null;
- if (isset($_GET['id']))
+ if (isset($_GET[$this->parent_name]))
$resource = $this->sql->select($this->request);
else
$resource = $this->sql->get_variants($this->config->relation_id['name'], $this->request);
@@ -36,8 +34,8 @@ class TreeGroupConnector extends TreeConnector{
/*! renders self as xml, starting part
*/
public function xml_start(){
- if (isset($_GET['id'])) {
- return "<tree id='".$_GET['id'].$this->render->get_postfix()."'>";
+ if (isset($_GET[$this->parent_name])) {
+ return "<tree id='".$_GET[$this->parent_name].$this->render->get_postfix()."'>";
} else {
return "<tree id='0'>";
}