summaryrefslogtreecommitdiffstats
path: root/codebase/treegroup_connector.php
diff options
context:
space:
mode:
authorDmitry <dmitry@dhtmlx.com>2012-05-08 16:54:28 +0200
committerDmitry <dmitry@dhtmlx.com>2012-05-08 16:54:28 +0200
commitc5783990b8d84d764584dd8893397ddc181022ad (patch)
treeeb73a0748d3ba1439b7924abc0a62dd3d4f4ea6d /codebase/treegroup_connector.php
parentc0efba59747a13bd79af22b70d9c0d055118598c (diff)
downloadconnector-php-c5783990b8d84d764584dd8893397ddc181022ad.zip
connector-php-c5783990b8d84d764584dd8893397ddc181022ad.tar.gz
connector-php-c5783990b8d84d764584dd8893397ddc181022ad.tar.bz2
minimize code duplicating for GroupConnectors
Diffstat (limited to 'codebase/treegroup_connector.php')
-rw-r--r--codebase/treegroup_connector.php83
1 files changed, 18 insertions, 65 deletions
diff --git a/codebase/treegroup_connector.php b/codebase/treegroup_connector.php
index 80a15f1..09638fa 100644
--- a/codebase/treegroup_connector.php
+++ b/codebase/treegroup_connector.php
@@ -7,89 +7,42 @@ require_once("tree_connector.php");
class TreeGroupConnector extends TreeConnector{
- private $id_postfix = '__{group_param}';
-
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, 'check_id'));
+ $this->event->attach("beforeProcessing", Array($this->render, 'check_id'));
+ $this->event->attach("onInit", Array($this->render, 'replace_postfix'));
}
-
- public function get_id_postfix() {
- return $this->id_postfix;
+ /*! if not isset $_GET[id] then it's top level
+ */
+ protected function set_relation() {
+ if (!isset($_GET['id'])) $this->request->set_relation(false);
}
-
- public function render(){
- if (isset($_GET['id'])) {
- $_GET['id'] = str_replace($this->id_postfix, "", $_GET['id']);
- }
- $this->parse_request();
- if (!isset($_GET['id'])) {
- $this->request->set_relation(false);
- }
-
- if (isset($_GET["editing"]))
- $this->editing=true;
- else if (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();
-
- if (isset($_GET['id'])) {
- $this->output_as_xml( $this->sql->select($this->request) );
- } else {
- $relation_id = $this->config->relation_id['name'];
- $this->output_as_xml( $this->sql->get_variants($this->config->relation_id['name'], $this->request));
- }
- }
- $this->end_run();
+ /*! if it's first level then distinct level
+ * else select by parent
+ */
+ protected function get_resource() {
+ $resource = null;
+ if (isset($_GET['id']))
+ $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
+ /*! renders self as xml, starting part
*/
public function xml_start(){
if (isset($_GET['id'])) {
- return "<tree id='".$_GET['id'].$this->id_postfix."'>";
+ return "<tree id='".$_GET['id'].$this->render->get_postfix()."'>";
} else {
return "<tree id='0'>";
}
}
-
- public function check_id($action) {
- if (isset($_GET['editing'])) {
- $id = $action->get_id();
- $pid = $action->get_value($this->config->relation_id['name']);
- $pid = str_replace($this->id_postfix, "", $pid);
- $action->set_value($this->config->relation_id['name'], $pid);
- if (strpos($id, $this->id_postfix) == false) {
- return $action;
- } else {
- $action->error();
- $action->set_response_text("This record can't be updated!");
- return $action;
- }
- } else {
- return $action;
- }
- }
}
?> \ No newline at end of file