diff options
author | dmitry-radyno <dmitry.radyno@gmail.com> | 2013-09-24 11:49:47 +0300 |
---|---|---|
committer | dmitry-radyno <dmitry.radyno@gmail.com> | 2013-09-24 11:49:47 +0300 |
commit | e8adb5a9ce248e67c523fac807f9ee1bc33bcb7d (patch) | |
tree | 9daeac9008d7feaf017cc82cbfb4685f8a25cd32 /codebase/data_connector.php | |
parent | d15f7f2e3b673306b491c5d3d0ed78e73ac616b3 (diff) | |
parent | 351c266ee5165fd2588f96282dcff697c31d6e19 (diff) | |
download | connector-php-e8adb5a9ce248e67c523fac807f9ee1bc33bcb7d.zip connector-php-e8adb5a9ce248e67c523fac807f9ee1bc33bcb7d.tar.gz connector-php-e8adb5a9ce248e67c523fac807f9ee1bc33bcb7d.tar.bz2 |
Merge branch 'master' of 192.168.3.251:connector-php
Diffstat (limited to 'codebase/data_connector.php')
-rw-r--r-- | codebase/data_connector.php | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/codebase/data_connector.php b/codebase/data_connector.php index e4e5e08..e6786b9 100644 --- a/codebase/data_connector.php +++ b/codebase/data_connector.php @@ -145,14 +145,11 @@ class DataConnector extends Connector{ $this->request->set_limit($_GET["start"],$_GET["count"]); } - + /*! renders self as xml, starting part */ protected function xml_start(){ - $start = "<data"; - foreach($this->attributes as $k=>$v) - $start .= " ".$k."='".$v."'"; - $start.= ">"; + $start = parent::xml_start(); foreach($this->sections as $k=>$v) $start .= "<".$k.">".$v."</".$k.">\n"; @@ -418,6 +415,11 @@ class JSONTreeDataConnector extends TreeDataConnector{ $data = array(); $data["parent"] = $this->request->get_relation(); $data["data"] = $result; + + $this->fill_collections(); + if (!empty($this->options)) + $data["collections"] = $this->options; + $data = json_encode($data); // return as string @@ -430,6 +432,42 @@ class JSONTreeDataConnector extends TreeDataConnector{ $out->output("", true, $this->encoding); } + /*! assign options collection to the column + + @param name + name of the column + @param options + array or connector object + */ + public function set_options($name,$options){ + if (is_array($options)){ + $str=array(); + foreach($options as $k => $v) + $str[]=Array("id"=>$this->xmlentities($k), "value"=>$this->xmlentities($v));//'{"id":"'.$this->xmlentities($k).'", "value":"'.$this->xmlentities($v).'"}'; + $options=$str; + } + $this->options[$name]=$options; + } + + /*! generates xml description for options collections + + @param list + comma separated list of column names, for which options need to be generated + */ + protected function fill_collections($list=""){ + $options = array(); + foreach ($this->options as $k=>$v) { + $name = $k; + if (!is_array($this->options[$name])) + $option=$this->options[$name]->render(); + else + $option=$this->options[$name]; + $options[$name] = $option; + } + $this->options = $options; + $this->extra_output .= "'collections':".json_encode($options); + } + } |