summaryrefslogtreecommitdiffstats
path: root/codebase/treegridmultitable_connector.php
diff options
context:
space:
mode:
authorDmitry <dmitry@dhtmlx.com>2012-05-10 13:23:30 +0200
committerDmitry <dmitry@dhtmlx.com>2012-05-10 13:23:30 +0200
commitfbdaeeb0158c38937782ee8a19a84fa077a2f224 (patch)
tree656f7c12d94e028a89322695dd31b540e117060c /codebase/treegridmultitable_connector.php
parent92c66f4e9362beb467720fd4e15d269b405e04bc (diff)
downloadconnector-php-fbdaeeb0158c38937782ee8a19a84fa077a2f224.zip
connector-php-fbdaeeb0158c38937782ee8a19a84fa077a2f224.tar.gz
connector-php-fbdaeeb0158c38937782ee8a19a84fa077a2f224.tar.bz2
refactor tree/treegrid multitable connectors
Diffstat (limited to 'codebase/treegridmultitable_connector.php')
-rw-r--r--codebase/treegridmultitable_connector.php121
1 files changed, 20 insertions, 101 deletions
diff --git a/codebase/treegridmultitable_connector.php b/codebase/treegridmultitable_connector.php
index 4e7f38a..ec75fcd 100644
--- a/codebase/treegridmultitable_connector.php
+++ b/codebase/treegridmultitable_connector.php
@@ -7,136 +7,52 @@ require_once("treegrid_connector.php");
class TreeGridMultitableConnector extends TreeGridConnector{
- private $level = 0;
private $max_level = null;
-
public function __construct($res,$type=false,$item_type=false,$data_type=false,$render_type=false){
$data_type="TreeGridMultitableDataProcessor";
if (!$render_type) $render_type="MultitableRenderStrategy";
parent::__construct($res,$type,$item_type,$data_type,$render_type);
- $this->event->attach("beforeProcessing", Array($this, 'id_translate_before'));
- $this->event->attach("afterProcessing", Array($this, 'id_translate_after'));
+ $this->event->attach("beforeProcessing", Array($this->render, 'id_translate_before'));
+ $this->event->attach("afterProcessing", Array($this->render, 'id_translate_after'));
}
public function render(){
- $this->parse_request();
$this->dload = true;
- if ((isset($_GET["editing"]))||(isset($_POST["ids"]))) {
- $this->editing=true;
- } else {
- $this->editing = false;
- }
-
- if ($this->editing){
- $dp = new $this->names["data_class"]($this,$this->config,$this->request);
- $dp->process($this->config,$this->request);
- } else {
- $wrap = new SortInterface($this->request);
- $this->event->trigger("beforeSort",$wrap);
- $wrap->store();
-
- $wrap = new FilterInterface($this->request);
- $this->event->trigger("beforeFilter",$wrap);
- $wrap->store();
+ return parent::render();
+ }
- if (isset($_GET['id'])) {
- $this->output_as_xml( $this->sql->select($this->request) );
- } else {
- $this->request->set_relation(false);
- $this->output_as_xml( $this->sql->select($this->request) );
- }
- }
- $this->end_run();
+ /*! sets relation for rendering */
+ protected function set_relation() {
+ if (!isset($_GET['id']))
+ $this->request->set_relation(false);
}
+ /*! gets resource for rendering */
+ protected function get_resource() {
+ return $this->sql->select($this->request);
+ }
public function xml_start(){
if (isset($_GET['id'])) {
- return "<rows parent='".($this->level - 1).'%23'.$_GET['id']."'>";
+ return "<rows parent='".$this->render->level_id($_GET['id'], $this->render->get_level() - 1)."'>";
} else {
return "<rows parent=''>";
}
}
-
- public function get_level() {
- if ($this->level) return $this->level;
- if (!isset($_GET['id'])) {
- if (isset($_POST['ids'])) {
- $ids = explode(",",$_POST["ids"]);
- $id = $this->parse_id($ids[0]);
- $this->level--;
- }
- $this->request->set_relation(false);
- } else {
- $id = $this->parse_id($_GET['id']);
- $_GET['id'] = $id;
- }
- return $this->level;
- }
-
-
- public function parse_id($id, $set_level = true) {
- $result = Array();
- preg_match('/^(.+)((#)|(%23))/', $id, $result);
- if ($set_level === true) {
- $this->level = $result[1] + 1;
- }
- preg_match('/^(.+)((#)|(%23))(.*)$/', $id, $result);
- $id = $result[5];
- return $id;
- }
-
-
- public function level_id($id) {
- return $this->level.'%23'.$id;
- }
-
-
/*! set maximum level of tree
@param max_level
maximum level
*/
public function setMaxLevel($max_level) {
- $this->max_level = $max_level;
+ $this->render->set_max_level($max_level);
}
-
- /*! gets maximum level of tree
- */
- public function getMaxLevel() {
- return $this->max_level;
- }
-
-
- /*! remove level prefix from id, parent id and set new id before processing
- @param action
- DataAction object
- */
- public function id_translate_before($action) {
- $this->request->set_relation(false);
- $id = $action->get_id();
- $id = $this->parse_id($id, false);
- $action->set_id($id);
- $action->set_value('gr_id', $id);
- $action->set_new_id($id);
- $pid = $action->get_value($this->config->relation_id['db_name']);
- $pid = $this->parse_id($pid, false);
- $action->set_value($this->config->relation_id['db_name'], $pid);
+ public function get_level() {
+ return $this->render->get_level();
}
- /*! add level prefix in id and new id after processing
- @param action
- DataAction object
- */
- public function id_translate_after($action) {
- $id = $action->get_id();
- $action->set_id($this->level_id($id));
- $id = $action->get_new_id();
- $action->success($this->level_id($id));
- }
-
}
@@ -145,7 +61,10 @@ class TreeGridMultitableDataProcessor extends DataProcessor {
function name_data($data){
if ($data=="gr_pid")
return $this->config->relation_id["name"];
- preg_match('/^c(\d+)$/', $data, $data_num);
+ if ($data=="gr_id")
+ return $this->config->id["name"];
+ preg_match('/^c([%\d]+)$/', $data, $data_num);
+ if (!isset($data_num[1])) return $data;
$data_num = $data_num[1];
if (isset($this->config->data[$data_num]["db_name"])) {
return $this->config->data[$data_num]["db_name"];