summaryrefslogtreecommitdiffstats
path: root/codebase
diff options
context:
space:
mode:
authorStanislav-Wolski <stanislau.wolski@gmail.com>2012-05-07 19:32:41 +0300
committerStanislav-Wolski <stanislau.wolski@gmail.com>2012-05-07 19:32:41 +0300
commitcee7dfc2ccf94a1e69377d5f07b8e1473ad66b00 (patch)
treeadabac1e5514353878089a50d2585a1f50da6143 /codebase
parentc0e28d701243462cce6b1fa1a10d11097453a29a (diff)
downloadconnector-php-cee7dfc2ccf94a1e69377d5f07b8e1473ad66b00.zip
connector-php-cee7dfc2ccf94a1e69377d5f07b8e1473ad66b00.tar.gz
connector-php-cee7dfc2ccf94a1e69377d5f07b8e1473ad66b00.tar.bz2
[update] ability to include custom sections in the output
Diffstat (limited to 'codebase')
-rw-r--r--codebase/data_connector.php39
1 files changed, 31 insertions, 8 deletions
diff --git a/codebase/data_connector.php b/codebase/data_connector.php
index ef65069..d66e64b 100644
--- a/codebase/data_connector.php
+++ b/codebase/data_connector.php
@@ -90,9 +90,15 @@ class DataConnector extends Connector{
public function __construct($res,$type=false,$item_type=false,$data_type=false){
if (!$item_type) $item_type="CommonDataItem";
if (!$data_type) $data_type="CommonDataProcessor";
+ $section = array();
parent::__construct($res,$type,$item_type,$data_type);
}
+ protected $sections;
+ public function add_section($name, $string){
+ $this->sections[$name] = $string;
+ }
+
protected function parse_request_mode(){
//do nothing, at least for now
}
@@ -128,28 +134,45 @@ class DataConnector extends Connector{
/*! renders self as xml, starting part
*/
protected function xml_start(){
- return "<data>";
+ $start = "<data>";
+ foreach($this->sections as $k=>$v)
+ $start .= "<".$k.">".$v."</".$k.">\n";
+ return $start;
}
};
class JSONDataConnector extends DataConnector{
+
public function __construct($res,$type=false,$item_type=false,$data_type=false){
if (!$item_type) $item_type="JSONCommonDataItem";
if (!$data_type) $data_type="CommonDataProcessor";
$this->data_separator = ",\n";
parent::__construct($res,$type,$item_type,$data_type);
}
-
+
protected function output_as_xml($res){
$start = "[\n";
$end = substr($this->render_set($res),0,-2)."\n]";
-
- if ($this->dload){
+
+ $is_sections = sizeof($this->sections) && $this->is_first_call();
+ if ($this->dload || $is_sections){
$start = "{ \"data\":".$start.$end;
- if ($pos=$this->request->get_start())
- $end = ", \"pos\":".$pos." }";
- else
- $end = ", \"pos\":0, \"total_count\":".$this->sql->get_size($this->request)." }";
+ $end="";
+
+ if ($is_sections){
+ //extra sections
+ foreach($this->sections as $k=>$v)
+ $end.= ", ".$k.":".$v;
+ }
+
+ if ($this->dload){
+ //info for dyn. loadin
+ if ($pos=$this->request->get_start())
+ $end .= ", \"pos\":".$pos." }";
+ else
+ $end .= ", \"pos\":0, \"total_count\":".$this->sql->get_size($this->request)." }";
+ } else
+ $end .= " }";
}
$out = new OutputWriter($start, $end);
$out->set_type("json");